public function testShouldUpdate()
 {
     // create user and logged in (the user who will perform the action)
     $user = User::create(array('first_name' => 'darryl', 'email' => '*****@*****.**', 'password' => 'pass$darryl', 'permissions' => array('superuser' => 1)));
     $this->application['auth']->loginUsingId($user->id);
     // create the group that we will be updating
     $blogger = Group::create(array('name' => 'blogger', 'permissions' => array('blog.list' => 1, 'blog.create' => 1, 'blog.edit' => 1, 'blog.delete' => -1)));
     // dummy request
     // we will update the blogger group that it will not be able to create a blog now
     $request = Request::create('', 'POST', array('id' => $blogger->id, 'name' => 'blogger-renamed', 'permissions' => array('blog.list' => 1, 'blog.create' => -1, 'blog.edit' => 1, 'blog.delete' => -1)));
     // begin
     $result = $this->commandDispatcher->dispatchFromArray('Darryldecode\\Backend\\Components\\User\\Commands\\UpdateGroupCommand', array('id' => $request->get('id', null), 'name' => $request->get('name', null), 'permissions' => $request->get('permissions', array())));
     $this->assertTrue($result->isSuccessful(), 'Transaction should be successful.');
     $this->assertEquals(200, $result->getStatusCode(), 'Status code should be 200.');
     $this->assertEquals('Group successfully updated.', $result->getMessage());
     // now prove it has been updated
     $updatedGroup = Group::find($result->getData()->id);
     //$this->assertEquals('blogger-renamed', $updatedGroup->name);
     $this->assertArrayHasKey('blog.list', $updatedGroup->getPermissionsAttribute(), 'Group permissions should have key blog.list');
     $this->assertArrayHasKey('blog.create', $updatedGroup->getPermissionsAttribute(), 'Group permissions should have key blog.create');
     $this->assertArrayHasKey('blog.edit', $updatedGroup->getPermissionsAttribute(), 'Group permissions should have key blog.edit');
     $this->assertArrayHasKey('blog.delete', $updatedGroup->getPermissionsAttribute(), 'Group permissions should have key blog.delete');
     $this->assertEquals(1, $updatedGroup->getPermissionsAttribute()['blog.list'], 'Permission blog.list should be allow');
     $this->assertEquals(-1, $updatedGroup->getPermissionsAttribute()['blog.create'], 'Permission blog.create should be deny');
     $this->assertEquals(1, $updatedGroup->getPermissionsAttribute()['blog.edit'], 'Permission blog.edit should be allow');
     $this->assertEquals(-1, $updatedGroup->getPermissionsAttribute()['blog.delete'], 'Permission blog.delete should be deny');
 }
 public function testShouldDeleteTaxonomy()
 {
     // this is not a super user
     $user = User::create(array('first_name' => 'darryl', 'email' => '*****@*****.**', 'password' => 'pass$darryl', 'permissions' => array('superuser' => 1)));
     $this->application['auth']->loginUsingId($user->id);
     // create dummy content type
     $cType = ContentType::create(array('type' => 'Blog', 'enable_revisions' => true));
     // create taxonomy and give it also a child
     $taxonomy = ContentTypeTaxonomy::create(array('taxonomy' => 'categories', 'description' => 'some description', 'content_type_id' => $cType->id));
     $childTaxonomy = ContentTypeTaxonomy::create(array('taxonomy' => 'categories-child', 'description' => 'some description', 'content_type_id' => $cType->id));
     // create now terms
     $lifestyleTerm = ContentTypeTaxonomyTerm::create(array('term' => 'lifestyle', 'slug' => 'lifestyle', 'content_type_taxonomy_id' => $taxonomy->id));
     $sportsTerm = ContentTypeTaxonomyTerm::create(array('term' => 'sports', 'slug' => 'sports', 'content_type_taxonomy_id' => $taxonomy->id));
     $codingTerm = ContentTypeTaxonomyTerm::create(array('term' => 'coding', 'slug' => 'coding', 'content_type_taxonomy_id' => $taxonomy->id));
     // create a Blog post
     $content = Content::create(array('title' => 'Blog Post Title', 'body' => 'Some blog body', 'slug' => 'blog-post-title', 'status' => Content::CONTENT_PUBLISHED, 'author_id' => $user->id, 'content_type_id' => $cType->id));
     $content->terms()->attach($lifestyleTerm);
     $content->terms()->attach($sportsTerm);
     $content->terms()->attach($codingTerm);
     // lets verify first that the post was indeed to have those 3 terms
     $c = Content::with('terms')->find($content->id);
     $this->assertCount(3, $c->terms->toArray(), "The Blog post should have 3 terms");
     $this->assertCount(3, ContentTypeTaxonomyTerm::all()->toArray(), "Ther should be 3 terms");
     // now lets start to delete the taxonomy
     // it should also delete the terms and the BLog post should no longer have those terms
     $result = $this->commandDispatcher->dispatchFromArray('Darryldecode\\Backend\\Components\\ContentBuilder\\Commands\\DeleteTaxonomyCommand', array('taxonomyId' => $taxonomy->id));
     $this->assertTrue($result->isSuccessful());
     $this->assertEquals(200, $result->getStatusCode());
     $this->assertEquals('Taxonomy successfully deleted.', $result->getMessage());
     // the blog post should not contain any terms anymore
     $c = Content::with('terms')->find($content->id);
     $this->assertCount(0, $c->terms->toArray(), "The Blog Post should not have any terms anymore");
     // taxonomy should be delete
     $this->assertInternalType('null', ContentTypeTaxonomy::find($taxonomy->id));
 }
 public function testDeletingAndDeletedEvent()
 {
     $loggedInUser = $this->createUserAndLoggedIn();
     // create event dispatcher mock and inject it to laravel application
     $eventDispatcherMock = $this->getMockBuilder('Illuminate\\Events\\Dispatcher')->setMethods(array('fire'))->getMock();
     // set expectations
     $eventDispatcherMock->expects($this->exactly(2))->method('fire')->withConsecutive(array($this->equalTo('taxonomy.deleting'), $this->isType('array')), array($this->equalTo('taxonomy.deleted'), $this->isType('array')));
     // inject to laravel "events" IoC alias
     $this->application['events'] = $eventDispatcherMock;
     // create dummy content type
     $cType = ContentType::create(array('type' => 'Blog', 'enable_revisions' => true));
     // create taxonomy
     $taxonomy = ContentTypeTaxonomy::create(array('taxonomy' => 'categories', 'description' => 'some description', 'parent' => null, 'content_type_id' => $cType->id));
     // create now terms
     $lifestyleTerm = ContentTypeTaxonomyTerm::create(array('term' => 'lifestyle', 'slug' => 'lifestyle', 'content_type_taxonomy_id' => $taxonomy->id));
     $sportsTerm = ContentTypeTaxonomyTerm::create(array('term' => 'sports', 'slug' => 'sports', 'content_type_taxonomy_id' => $taxonomy->id));
     $codingTerm = ContentTypeTaxonomyTerm::create(array('term' => 'coding', 'slug' => 'coding', 'content_type_taxonomy_id' => $taxonomy->id));
     // create a Blog post
     $content = Content::create(array('title' => 'Blog Post Title', 'body' => 'Some blog body', 'slug' => 'blog-post-title', 'status' => Content::CONTENT_PUBLISHED, 'author_id' => $loggedInUser->id, 'content_type_id' => $cType->id));
     $content->terms()->attach($lifestyleTerm);
     $content->terms()->attach($sportsTerm);
     $content->terms()->attach($codingTerm);
     // begin
     $this->commandDispatcher->dispatchFromArray('Darryldecode\\Backend\\Components\\ContentBuilder\\Commands\\DeleteTaxonomyCommand', array('taxonomyId' => $taxonomy->id));
 }
 public function testShouldDeleteUser()
 {
     // create user and logged in (the user who will perform the action)
     $user = User::create(array('first_name' => 'darryl', 'email' => '*****@*****.**', 'password' => 'pass$darryl', 'permissions' => array('superuser' => 1)));
     $this->application['auth']->loginUsingId($user->id);
     $res = $this->createDummyUserAndGroup();
     // before deleting the user and detaching to any group
     // lets just prove that the the group the user is being associated with
     // contains 1 user
     $artistGroup = Group::with('users')->find($res['artist']->id);
     $this->assertCount(1, $artistGroup->users->toArray());
     $this->assertEquals('jane', $artistGroup->users->first()->first_name);
     $blogger = Group::with('users')->find($res['blogger']->id);
     $this->assertCount(1, $blogger->users->toArray());
     $this->assertEquals('jane', $blogger->users->first()->first_name);
     // create dummy
     $u = $res['user'];
     // begin deletion
     $result = $this->commandDispatcher->dispatchFromArray('Darryldecode\\Backend\\Components\\User\\Commands\\DeleteUserCommand', array('id' => $u->id));
     // prove deletion response should be successful
     $this->assertTrue($result->isSuccessful(), 'Transaction should be successful.');
     $this->assertEquals(200, $result->getStatusCode(), 'Status code should be forbidden.');
     $this->assertEquals('User successfully deleted.', $result->getMessage());
     // now this groups should have no user in it now
     $blogger = Group::with('users')->find($res['blogger']->id);
     $artistGroup = Group::with('users')->find($res['artist']->id);
     $this->assertCount(0, $artistGroup->users->toArray());
     $this->assertCount(0, $blogger->users->toArray());
     // user deleted should not exist
     $this->assertInternalType('null', User::find($u->id));
 }
 public function testShouldDeleteNavigation()
 {
     $user = $this->createUserAndLoggedIn(array('navigationBuilder.delete' => 1));
     $nav = $this->createDummyNavigation();
     $result = $this->commandDispatcher->dispatchFromArray('Darryldecode\\Backend\\Components\\Navigation\\Commands\\DeleteCustomNavigationCommand', array('id' => $nav->id));
     $this->assertTrue($result->isSuccessful());
     $this->assertEquals('Navigation successfully deleted.', $result->getMessage());
     $this->assertEquals(200, $result->getStatusCode());
 }
 public function testShouldFireCreatingAndCreatedEvents()
 {
     $user = $this->createUserAndLoggedIn(array('navigationBuilder.manage' => 1));
     // 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('navigationBuilder.creating'), $this->isType('array')), array($this->equalTo('navigationBuilder.created'), $this->isType('array')));
     // inject to laravel "events" IoC alias
     $this->application['events'] = $eventDispatcherMock;
     $result = $this->commandDispatcher->dispatchFromArray('Darryldecode\\Backend\\Components\\Navigation\\Commands\\CreateNavigationCommand', array('name' => 'SomeNavigationName', 'data' => array('title' => 'home', 'class' => 'some-class', 'url' => 'www.url.com', 'items' => [])));
 }
 public function testShouldFireBeforeQueryAndAfterQueryEvents()
 {
     $this->createUserAndLoggedIn(array('navigationBuilder.manage' => 1));
     // 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('navigationBuilder.beforeQuery'), $this->isType('array')), array($this->equalTo('navigationBuilder.afterQuery'), $this->isType('array')));
     // inject to laravel "events" IoC alias
     $this->application['events'] = $eventDispatcherMock;
     $this->commandDispatcher->dispatchFromArray('Darryldecode\\Backend\\Components\\Navigation\\Commands\\ListCustomNavigationCommand', array());
 }
 public function testShouldQueryTermsOfTheGivenTaxonomy()
 {
     $taxonomy = $this->createDummyData();
     // begin
     $result = $this->commandDispatcher->dispatchFromArray('Darryldecode\\Backend\\Components\\ContentBuilder\\Commands\\QueryTermsByTaxonomyCommand', array('taxonomyId' => $taxonomy->id));
     // prove successful
     $this->assertTrue($result->isSuccessful());
     $this->assertEquals('Query terms by taxonomy command successful.', $result->getMessage());
     $this->assertEquals(200, $result->getStatusCode(), 'Status code should be ok');
     // prove contents
     $this->assertCount(3, $result->getData()->toArray(), "Should have 3 terms");
 }
 public function testShouldNowCreateIfAllCheckPointPassed()
 {
     $user = $this->createUserAndLoggedIn(array('navigationBuilder.manage' => 1));
     $result = $this->commandDispatcher->dispatchFromArray('Darryldecode\\Backend\\Components\\Navigation\\Commands\\CreateNavigationCommand', array('name' => 'SomeNavigationName', 'data' => array('title' => 'home', 'class' => 'some-class', 'url' => 'www.url.com', 'items' => [])));
     $this->assertTrue($result->isSuccessful(), "Command should be a success.");
     $this->assertEquals(201, $result->getStatusCode(), "Status code should be created.");
     $this->assertEquals('Navigation successfully created.', $result->getMessage());
     // prove that nav exist
     $this->assertCount(1, Navigation::all()->toArray());
     $this->assertEquals('SomeNavigationName', Navigation::all()->first()->name);
     $this->assertInternalType('array', Navigation::all()->first()->data);
 }
 public function testShouldUpdateNavigation()
 {
     $this->createUserAndLoggedIn(array('navigationBuilder.manage' => 1));
     $nav = $this->createDummyNavigation();
     $result = $this->commandDispatcher->dispatchFromArray('Darryldecode\\Backend\\Components\\Navigation\\Commands\\UpdateNavigationCommand', array('id' => $nav->id, 'name' => 'main navigation updated', 'data' => array(array('title' => 'home', 'attr' => array('class' => 'some-class', 'id' => 'some-id'), 'url' => 'http://www.url.com', 'items' => []), array('title' => 'about', 'attr' => array('class' => 'some-class', 'id' => 'some-id'), 'url' => 'http://www.url.com/about', 'items' => []))));
     $this->assertTrue($result->isSuccessful());
     $this->assertEquals('Navigation successfully updated.', $result->getMessage());
     // prove the data has been changed/updated
     $updatedNav = Navigation::all()->first();
     $this->assertEquals('main navigation updated', $updatedNav->name);
     $this->assertCount(2, $updatedNav->data);
 }
 public function testShouldReturnPaginationAwareInstanceIFQueryParamIsPaginated()
 {
     $this->createUserAndLoggedIn(array('navigationBuilder.manage' => 1));
     $this->createDummyData();
     $result = $this->commandDispatcher->dispatchFromArray('Darryldecode\\Backend\\Components\\Navigation\\Commands\\ListCustomNavigationCommand', array());
     $this->assertTrue($result->isSuccessful(), "Command should fail a success.");
     $this->assertEquals(200, $result->getStatusCode(), "Command should be ok.");
     $this->assertEquals('List custom navigation command successful.', $result->getMessage());
     // prove result is a collection
     $this->assertInstanceOf('Illuminate\\Pagination\\LengthAwarePaginator', $result->getData());
     // should have 3 items
     $this->assertCount(3, $result->getData()->toArray()['data']);
 }
 public function testUpdatingAndUpdatedEvents()
 {
     $loggedInUser = $this->createUserAndLoggedIn();
     $content = $this->createDummyData($loggedInUser);
     // 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('blog.updating'), $this->isType('array')), array($this->equalTo('blog.updated'), $this->isType('array')));
     // inject to laravel "events" IoC alias
     $this->application['events'] = $eventDispatcherMock;
     // begin
     $result = $this->commandDispatcher->dispatchFromArray('Darryldecode\\Backend\\Components\\ContentBuilder\\Commands\\UpdateContentCommand', array('id' => $content->id, 'title' => 'Some Title 2', 'body' => 'Some Body', 'slug' => 'some-slug', 'status' => 'published', 'contentTypeId' => $content->type->id));
 }
 public function testCreatingAndCreatedEvent()
 {
     $loggedInUser = $this->createUserAndLoggedIn();
     $contentType = $this->createContentType();
     // 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('blog.creating'), $this->isType('array')), array($this->equalTo('blog.created'), $this->isType('array')));
     // inject to laravel "events" IoC alias
     $this->application['events'] = $eventDispatcherMock;
     // begin
     $this->commandDispatcher->dispatchFromArray('Darryldecode\\Backend\\Components\\ContentBuilder\\Commands\\CreateContentCommand', array('title' => 'Some Title', 'body' => 'Some Body', 'slug' => 'some-slug', 'status' => 'published', 'authorId' => $loggedInUser->id, 'contentTypeId' => $contentType->id, 'taxonomies' => array(), 'metaData' => array('form_1' => array('meta1' => 'meta value 1', 'meta2' => 'meta value 2')), 'miscData' => array()));
 }
 public function testShouldNotCreateRevisionIfContentBodyDidNotChanged()
 {
     $user = $this->createUserAndLoggedIn(array('superuser' => 1));
     $content = $this->createDummyData($user);
     $result = $this->commandDispatcher->dispatchFromArray('Darryldecode\\Backend\\Components\\ContentBuilder\\Commands\\UpdateContentCommand', array('id' => $content->id, 'title' => 'Some Title 2', 'body' => 'Some Body', 'slug' => 'some-slug', 'status' => 'published', 'contentTypeId' => $content->type->id));
     $this->assertTrue($result->isSuccessful());
     $this->assertEquals(200, $result->getStatusCode());
     $this->assertEquals('Content successfully updated.', $result->getMessage());
     // prove content title was changed
     $this->assertEquals('Some Title 2', $result->getData()->title);
     // there should be no revisions because content body is the same
     $revision = ContentRevisions::all();
     $this->assertCount(0, $revision->toArray());
 }
 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 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 testUpdateGroup()
 {
     $this->createAndLoginUser(array('superuser' => 1));
     $user = $this->createDummyUserAndGroup();
     // begin
     $result = $this->commandDispatcher->dispatchFromArray('Darryldecode\\Backend\\Components\\User\\Commands\\UpdateUserCommand', array('id' => $user->id, 'firstName' => null, 'lastName' => null, 'email' => null, 'password' => null, 'permissions' => null, 'groups' => array()));
     $updatedUser = $result->getData();
     $this->assertTrue($result->isSuccessful(), 'Transaction should be successful.');
     $this->assertEquals(200, $result->getStatusCode(), 'Status code should be 200.');
     $this->assertEquals('User successfully updated.', $result->getMessage());
     // prove first name was updated
     $this->assertEquals('jane', $updatedUser->first_name);
     // should not be changed
     $this->assertEquals('stark', $updatedUser->last_name);
     // should not be changed
     $this->assertEquals('*****@*****.**', $updatedUser->email);
     // should be changed
     // should be still in group
     $this->assertFalse($updatedUser->inGroup('artist'), "Should still be removed in group artist");
     // should have no following permissions now
     $this->assertFalse($updatedUser->hasPermission('art.create'));
     $this->assertFalse($updatedUser->hasPermission('art.edit'));
     // should not have permissions
     $this->assertFalse($updatedUser->hasPermission('blog.create'));
     $this->assertFalse($updatedUser->hasPermission('blog.list'));
     $this->assertFalse($updatedUser->hasPermission('art.delete'));
     $this->assertFalse($updatedUser->hasPermission('forum.create'));
     // pass should be the same
     $this->assertTrue($this->application['hash']->check('pass$jane', $updatedUser->password), "password should be changed");
 }
 public function testShouldDeleteContentType()
 {
     // 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 dummy content type
     $blog = ContentType::create(array('type' => 'Blog', 'enable_revisions' => true));
     // begin
     $result = $this->commandDispatcher->dispatchFromArray('Darryldecode\\Backend\\Components\\ContentBuilder\\Commands\\DeleteContentTypeCommand', array('contentTypeId' => $blog->id));
     $this->assertTrue($result->isSuccessful());
     $this->assertEquals('Content type successfully deleted.', $result->getMessage());
     $this->assertEquals(200, $result->getStatusCode(), 'Status code should be ok');
     // prove content type has been deleted
     $this->assertInternalType('null', ContentType::find($blog->id));
 }
 public function testDeletingAndDeletedEvents()
 {
     // setup needed data
     $user = $this->createUserAndLoggedIn(array('navigationBuilder.delete' => 1));
     $nav = $this->createDummyNavigation();
     // 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('navigationBuilder.deleting'), $this->isType('array')), array($this->equalTo('navigationBuilder.deleted'), $this->isType('array')));
     // inject to laravel "events" IoC alias
     $this->application['events'] = $eventDispatcherMock;
     $result = $this->commandDispatcher->dispatchFromArray('Darryldecode\\Backend\\Components\\Navigation\\Commands\\DeleteCustomNavigationCommand', array('id' => $nav->id));
     $this->assertTrue($result->isSuccessful());
     $this->assertEquals('Navigation successfully deleted.', $result->getMessage());
     $this->assertEquals(200, $result->getStatusCode());
 }
 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 testShouldPreventDuplicateSlugs()
 {
     // create user and logged in
     $user = User::create(array('first_name' => 'darryl', 'email' => '*****@*****.**', 'password' => 'pass$darryl', 'permissions' => array('superuser' => 1)));
     $this->application['auth']->loginUsingId($user->id);
     // create content type
     $blogContentType = ContentType::create(array('type' => 'blog', 'enable_revisions' => true));
     // create taxonomy for blog content type
     $taxonomy = $blogContentType->taxonomies()->create(array('taxonomy' => 'categories', 'description' => ''));
     // create first the 1st term
     $this->commandDispatcher->dispatchFromArray('Darryldecode\\Backend\\Components\\ContentBuilder\\Commands\\CreateTypeTaxonomyTerm', array('term' => 'lifestyle', 'slug' => 'lifestyle', 'contentTypeTaxonomyId' => $taxonomy->id));
     // create second the 2nd term that would cause duplication
     $result = $this->commandDispatcher->dispatchFromArray('Darryldecode\\Backend\\Components\\ContentBuilder\\Commands\\CreateTypeTaxonomyTerm', array('term' => 'lifestyle', 'slug' => 'lifestyle', 'contentTypeTaxonomyId' => $taxonomy->id));
     $this->assertFalse($result->isSuccessful());
     $this->assertEquals(400, $result->getStatusCode());
     $this->assertEquals('The slug has already been taken.', $result->getMessage());
 }
 public function testDeletingAndDeletedEventShouldBeFiredWhenContentTypeIsSuccessfullyDeleted()
 {
     // 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('contentType.deleting'), $this->isType('array')), array($this->equalTo('contentType.deleted'), $this->isType('array')));
     // inject to laravel "events" IoC alias
     $this->application['events'] = $eventDispatcherMock;
     // create dummy content type
     $blog = ContentType::create(array('type' => 'Blog', 'enable_revisions' => true));
     // begin
     $this->commandDispatcher->dispatchFromArray('Darryldecode\\Backend\\Components\\ContentBuilder\\Commands\\DeleteContentTypeCommand', array('contentTypeId' => $blog->id));
 }
 public function testCreatingAndCreatedEvent()
 {
     $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.creating'), $this->isType('array')), array($this->equalTo('formGroup.created'), $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));
     // should require name field
     $result = $this->commandDispatcher->dispatchFromArray('Darryldecode\\Backend\\Components\\ContentBuilder\\Commands\\CreateFormGroupCommand', array('name' => 'Event Organizer', 'formName' => 'event_organizer', 'conditions' => array(), 'fields' => array('some_field' => 'some'), 'contentTypeId' => $contentType->id));
     $this->assertTrue($result->isSuccessful(), "transaction should be successful.");
     $this->assertEquals(201, $result->getStatusCode(), "status code should be 201");
     $this->assertEquals('Form group successfully created.', $result->getMessage());
 }
 public function testShouldFireDeletingAndDeletedEvents()
 {
     // create user and logged in
     $user = User::create(array('first_name' => 'darryl', 'email' => '*****@*****.**', 'password' => 'pass$darryl', 'permissions' => array('superuser' => 1)));
     $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();
     // set expectations
     $eventDispatcherMock->expects($this->exactly(2))->method('fire')->withConsecutive(array($this->equalTo('user.deleting'), $this->isType('array')), array($this->equalTo('user.deleted'), $this->isType('array')));
     // inject to laravel "events" IoC alias
     $this->application['events'] = $eventDispatcherMock;
     // create dummy
     $res = $this->createDummyUserAndGroup();
     $u = $res['user'];
     // begin deletion
     $result = $this->commandDispatcher->dispatchFromArray('Darryldecode\\Backend\\Components\\User\\Commands\\DeleteUserCommand', array('id' => $u->id));
 }
 public function testQueryWithNameParameterShouldReturnResults()
 {
     // 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 dummies
     $this->createDummyContentTypes();
     // begin
     $result = $this->commandDispatcher->dispatchFromArray('Darryldecode\\Backend\\Components\\ContentBuilder\\Commands\\QueryContentTypeCommand', array('type' => 'blog'));
     // prove successful
     $this->assertTrue($result->isSuccessful());
     $this->assertEquals('Query content types successful.', $result->getMessage());
     $this->assertEquals(200, $result->getStatusCode(), 'Status code should be ok');
     // prove contents
     $this->assertCount(1, $result->getData()->toArray(), "Should have 3 content types");
     $this->assertEquals('Blog', $result->getData()->first()->type);
 }
 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 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 testShouldCreateFormGroupIfAllCheckPointPassed()
 {
     $user = User::create(array('first_name' => 'darryl', 'email' => '*****@*****.**', 'password' => 'pass$darryl', 'permissions' => array('superuser' => 1)));
     $this->application['auth']->loginUsingId($user->id);
     // create a dummy content type
     $contentType = ContentType::create(array('type' => 'Event', 'enable_revisions' => true));
     // should require name field
     $result = $this->commandDispatcher->dispatchFromArray('Darryldecode\\Backend\\Components\\ContentBuilder\\Commands\\CreateFormGroupCommand', array('name' => 'Event Organizer', 'formName' => 'event_organizer', 'conditions' => array(), 'fields' => array('some_field' => 'some'), 'contentTypeId' => $contentType->id));
     $this->assertTrue($result->isSuccessful(), "transaction should be successful.");
     $this->assertEquals(201, $result->getStatusCode(), "status code should be 201");
     $this->assertEquals('Form group successfully created.', $result->getMessage());
 }
 public function testCreateContentTypeWithDisabledRevisions()
 {
     // this is a super user
     $user = User::create(array('first_name' => 'darryl', 'email' => '*****@*****.**', 'password' => 'pass$darryl', 'permissions' => array('superuser' => 1)));
     $this->application['auth']->loginUsingId($user->id);
     $result = $this->commandDispatcher->dispatchFromArray('Darryldecode\\Backend\\Components\\ContentBuilder\\Commands\\CreateContentTypeCommand', array('type' => 'Products', 'enableRevision' => 'no'));
     $this->assertTrue($result->isSuccessful());
     $this->assertEquals(201, $result->getStatusCode());
     $this->assertEquals('Content type successfully created.', $result->getMessage());
     // prove
     $cType = ContentType::find($result->getData()->id);
     $this->assertFalse((bool) $cType->enable_revisions);
 }
 public function testShouldDeleteGroup()
 {
     // create user and logged in (the user who will perform the action)
     $user = User::create(array('first_name' => 'darryl', 'email' => '*****@*****.**', 'password' => 'pass$darryl', 'permissions' => array('superuser' => 1)));
     $this->application['auth']->loginUsingId($user->id);
     $res = $this->createDummyUserAndGroup();
     // prove first that the blog group exist
     // and that user "jane" is in blog group
     $blog = $res['blogger'];
     $jane = $res['user'];
     $this->assertEquals('blogger', Group::find($blog->id)->name);
     $this->assertTrue($jane->inGroup($blog), "Jane should be in blogger group");
     // now lets delete the blogger group
     $result = $this->commandDispatcher->dispatchFromArray('Darryldecode\\Backend\\Components\\User\\Commands\\DeleteGroupCommand', array('id' => $blog->id));
     // prove deletion response should be successful
     $this->assertTrue($result->isSuccessful(), 'Transaction should be successful.');
     $this->assertEquals(200, $result->getStatusCode(), 'Status code should be forbidden.');
     $this->assertEquals('Group successfully deleted.', $result->getMessage());
     // blog should not exist now
     $this->assertInternalType('null', Group::find($blog->id));
     // user "jane" should not be in group "blogger" now
     $j = User::find($jane->id);
     $this->assertFalse($j->inGroup($blog), "Jane should not be in blogger group anymore");
 }