public function testDeletingAndDeletedEvent()
 {
     $user = $this->createUserAndLoggedIn();
     // create event dispatcher mock and inject it to laravel application
     $eventDispatcherMock = $this->getMockBuilder('Illuminate\\Events\\Dispatcher')->setMethods(array('fire'))->getMock();
     // se expectations
     $eventDispatcherMock->expects($this->exactly(2))->method('fire')->withConsecutive(array($this->equalTo('formGroup.deleting'), $this->isType('array')), array($this->equalTo('formGroup.deleted'), $this->isType('array')));
     // inject to laravel "events" IoC alias
     $this->application['events'] = $eventDispatcherMock;
     // create dummy form group
     $fGroup = ContentTypeFormGroup::create(array('name' => 'Event Organizer Details', 'form_name' => 'event_organizer_details', 'conditions' => array(), 'fields' => array(), 'content_type_id' => 1));
     // begin
     $this->commandDispatcher->dispatchFromArray('Darryldecode\\Backend\\Components\\ContentBuilder\\Commands\\DeleteFormGroupCommand', array('id' => $fGroup->id));
 }
 public function testShouldDeleteFormGroup()
 {
     $user = User::create(array('first_name' => 'darryl', 'email' => '*****@*****.**', 'password' => 'pass$darryl', 'permissions' => array('superuser' => 1)));
     $this->application['auth']->loginUsingId($user->id);
     // create dummy form group
     $fGroup = ContentTypeFormGroup::create(array('name' => 'Event Organizer Details', 'form_name' => 'event_organizer_details', 'conditions' => array(), 'fields' => array(), 'content_type_id' => 1));
     // begin
     $result = $this->commandDispatcher->dispatchFromArray('Darryldecode\\Backend\\Components\\ContentBuilder\\Commands\\DeleteFormGroupCommand', array('id' => $fGroup->id));
     $this->assertTrue($result->isSuccessful(), "transaction should success.");
     $this->assertEquals(200, $result->getStatusCode(), "status code should be ok");
     $this->assertEquals('Form group successfully deleted.', $result->getMessage());
     // prove the form group do not exist
     $this->assertInternalType('null', ContentTypeFormGroup::find($fGroup->id));
 }
 public function testUpdatingAndUpdatedEvent()
 {
     $user = $this->createUserAndLoggedIn();
     // create event dispatcher mock and inject it to laravel application
     $eventDispatcherMock = $this->getMockBuilder('Illuminate\\Events\\Dispatcher')->setMethods(array('fire'))->getMock();
     // se expectations
     $eventDispatcherMock->expects($this->exactly(2))->method('fire')->withConsecutive(array($this->equalTo('formGroup.updating'), $this->isType('array')), array($this->equalTo('formGroup.updated'), $this->isType('array')));
     // inject to laravel "events" IoC alias
     $this->application['events'] = $eventDispatcherMock;
     // create a dummy Form group
     $formGroup = ContentTypeFormGroup::create(array('name' => 'Event Location', 'form_name' => 'event_location', 'conditions' => array(), 'fields' => array(), 'content_type_id' => 2));
     // begin
     $result = $this->commandDispatcher->dispatchFromArray('Darryldecode\\Backend\\Components\\ContentBuilder\\Commands\\UpdateFormGroupCommand', array('id' => $formGroup->id));
     $this->assertTrue($result->isSuccessful(), "transaction should be successful.");
     $this->assertEquals(200, $result->getStatusCode(), "status code should be 201");
     $this->assertEquals('Form group successfully updated.', $result->getMessage());
 }
 public function testBeforeAndAfterQueryEvents()
 {
     // create user and logged in (the user who will perform the action)
     $user = User::create(array('first_name' => 'dianne', 'email' => '*****@*****.**', 'password' => 'pass$dianne', 'permissions' => array('superuser' => 1)));
     // logged in the user
     $this->application['auth']->loginUsingId($user->id);
     // create event dispatcher mock and inject it to laravel application
     $eventDispatcherMock = $this->getMockBuilder('Illuminate\\Events\\Dispatcher')->setMethods(array('fire'))->getMock();
     // se expectations
     $eventDispatcherMock->expects($this->exactly(2))->method('fire')->withConsecutive(array($this->equalTo('formGroup.beforeQuery'), $this->isType('array')), array($this->equalTo('formGroup.afterQuery'), $this->isType('array')));
     // inject to laravel "events" IoC alias
     $this->application['events'] = $eventDispatcherMock;
     // create a dummy content type
     $contentType = ContentType::create(array('type' => 'Event', 'enable_revisions' => true));
     // create dummy Form Groups
     ContentTypeFormGroup::create(array('name' => 'Event Organizer', 'form_name' => 'event_organizer', 'conditions' => array(), 'fields' => array(), 'content_type_id' => $contentType->id));
     // begin
     $result = $this->commandDispatcher->dispatchFromArray('Darryldecode\\Backend\\Components\\ContentBuilder\\Commands\\QueryFormGroupCommand', array('paginated' => true, 'perPage' => 6, 'contentTypeId' => $contentType->id));
 }
 public function testShouldUpdateWithoutFillingAllFields()
 {
     $user = User::create(array('first_name' => 'darryl', 'email' => '*****@*****.**', 'password' => 'pass$darryl', 'permissions' => array('superuser' => 1)));
     $this->application['auth']->loginUsingId($user->id);
     // create a dummy Form group
     $formGroup = ContentTypeFormGroup::create(array('name' => 'Event Location', 'form_name' => 'event_location', 'conditions' => array(), 'fields' => array(), 'content_type_id' => 2));
     // begin
     $result = $this->commandDispatcher->dispatchFromArray('Darryldecode\\Backend\\Components\\ContentBuilder\\Commands\\UpdateFormGroupCommand', array('id' => $formGroup->id));
     $this->assertTrue($result->isSuccessful(), "transaction should be successful.");
     $this->assertEquals(200, $result->getStatusCode(), "status code should be ok");
     $this->assertEquals('Form group successfully updated.', $result->getMessage());
     // fields should have the same value as there is no provided values
     $fGroup = ContentTypeFormGroup::find($formGroup->id);
     //$this->assertEquals('Event Location', $fGroup->name);
     $this->assertEquals('event_location', $fGroup->form_name);
     $this->assertCount(0, $fGroup->conditions);
     $this->assertCount(0, $fGroup->fields);
     $this->assertEquals(2, $fGroup->content_type_id);
 }
 public function testQueryShouldReturnCollectionObjectIfQuestedWithNotPaginated()
 {
     $user = User::create(array('first_name' => 'darryl', 'email' => '*****@*****.**', 'password' => 'pass$darryl', 'permissions' => array('Event.manage' => 1)));
     $this->application['auth']->loginUsingId($user->id);
     // create a dummy content type
     $contentType = ContentType::create(array('type' => 'Event', 'enable_revisions' => true));
     // create dummy Form Groups
     ContentTypeFormGroup::create(array('name' => 'Event Organizer', 'form_name' => 'event_organizer', 'conditions' => array(), 'fields' => array(), 'content_type_id' => $contentType->id));
     ContentTypeFormGroup::create(array('name' => 'Event Location', 'form_name' => 'event_location', 'conditions' => array(), 'fields' => array(), 'content_type_id' => $contentType->id));
     // begin
     $result = $this->commandDispatcher->dispatchFromArray('Darryldecode\\Backend\\Components\\ContentBuilder\\Commands\\QueryFormGroupCommand', array('paginated' => false, 'perPage' => 6, 'contentTypeId' => $contentType->id));
     $this->assertTrue($result->isSuccessful(), "transaction should be successful.");
     $this->assertEquals(200, $result->getStatusCode(), "status code should be ok");
     $this->assertEquals('Query form groups command successful.', $result->getMessage());
     // prove paginated instance
     $this->assertInstanceOf('Illuminate\\Database\\Eloquent\\Collection', $result->getData());
     // prove has two items
     $this->assertCount(2, $result->getData()->toArray());
 }