public function testQuery()
 {
     // 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('user.manage' => 1)));
     // logged in the user
     $this->application['auth']->loginUsingId($user->id);
     // create dummy groups to be evaluated with
     $this->createGroups();
     // -----------------
     // QUERY ALL
     // -----------------
     // dummy request, required first name
     $request = Request::create('', 'GET', array('name' => null, 'with' => array(), 'paginate' => false));
     $results = $this->commandDispatcher->dispatchFrom('Darryldecode\\Backend\\Components\\User\\Commands\\QueryGroupsCommand', $request);
     $this->assertTrue($results->isSuccessful(), 'Transaction should be good');
     $this->assertEquals(200, $results->getStatusCode(), 'Status code should be 200');
     $this->assertEquals('Query groups command successful.', $results->getMessage());
     $this->assertCount(3, $results->getData()->toArray(), 'There should be 3 groups');
     // -----------------
     // QUERY BY NAME
     // -----------------
     // dummy request, required first name
     $request = Request::create('', 'GET', array('name' => 'blogger', 'with' => array(), 'paginate' => false));
     $results = $this->commandDispatcher->dispatchFrom('Darryldecode\\Backend\\Components\\User\\Commands\\QueryGroupsCommand', $request);
     $this->assertTrue($results->isSuccessful(), 'Transaction should be good');
     $this->assertEquals(200, $results->getStatusCode(), 'Status code should be 200');
     $this->assertEquals('Query groups command successful.', $results->getMessage());
     $this->assertCount(1, $results->getData()->toArray(), 'There should be 1 group');
 }
 public function testContentTypeNotValid()
 {
     // 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);
     // required contentTypeId field numeric
     $request = Request::create('', 'GET', array('taxonomy' => 'categories', 'description' => '', 'contentTypeId' => 3));
     $result = $this->commandDispatcher->dispatchFrom('Darryldecode\\Backend\\Components\\ContentBuilder\\Commands\\CreateContentTypeTaxonomyCommand', $request);
     $this->assertFalse($result->isSuccessful());
     $this->assertEquals(400, $result->getStatusCode());
     $this->assertEquals('Invalid Content Type.', $result->getMessage());
 }
 public function testCreatingAndCreatedEvents()
 {
     // 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 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('group.creating'), $this->isType('array')), array($this->equalTo('group.created'), $this->isType('array')));
     // inject to laravel "events" IoC alias
     $this->application['events'] = $eventDispatcherMock;
     // dummy request
     $request = Request::create('', 'POST', array('name' => 'moderator', 'permissions' => array('forum.create' => 1, 'forum.delete' => -1)));
     // begin
     $this->commandDispatcher->dispatchFrom('Darryldecode\\Backend\\Components\\User\\Commands\\CreateGroupCommand', $request);
 }
 public function testBeforeAndAfterQueryEvents()
 {
     // create user and logged in
     $user = User::create(array('first_name' => 'darryl', 'email' => '*****@*****.**', 'password' => 'pass$darryl', 'permissions' => array('user.manage' => 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('groups.beforeQuery'), $this->isType('array')), array($this->equalTo('groups.afterQuery'), $this->isType('array')));
     // inject to laravel "events" IoC alias
     $this->application['events'] = $eventDispatcherMock;
     // dummy request, required first name
     $request = Request::create('', 'GET', array('name' => null, 'with' => array()));
     // begin
     $this->commandDispatcher->dispatchFrom('Darryldecode\\Backend\\Components\\User\\Commands\\QueryGroupsCommand', $request);
 }
 public function testCreatingAndCreatedEvent()
 {
     // 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);
     // 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.creating'), $this->isType('array')), array($this->equalTo('contentType.created'), $this->isType('array')));
     // inject to laravel "events" IoC alias
     $this->application['events'] = $eventDispatcherMock;
     // dummy request
     $request = Request::create('', 'GET', array('type' => 'blog', 'enableRevision' => true));
     // begin creation
     $this->commandDispatcher->dispatchFrom('Darryldecode\\Backend\\Components\\ContentBuilder\\Commands\\CreateContentTypeCommand', $request);
 }
 public function testCreatingAndCreatedEvent()
 {
     // 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 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('contentTypeTaxonomy.creating'), $this->isType('array')), array($this->equalTo('contentTypeTaxonomy.created'), $this->isType('array')));
     // inject to laravel "events" IoC alias
     $this->application['events'] = $eventDispatcherMock;
     $contentType = $this->createContentType();
     // required taxonomy field
     $request = Request::create('', 'GET', array('taxonomy' => 'categories', 'description' => '', 'parent' => '', 'contentTypeId' => $contentType->id));
     $this->commandDispatcher->dispatchFrom('Darryldecode\\Backend\\Components\\ContentBuilder\\Commands\\CreateContentTypeTaxonomyCommand', $request);
 }
 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();
     // se expectations
     $eventDispatcherMock->expects($this->exactly(2))->method('fire')->withConsecutive(array($this->equalTo('taxonomyTerm.deleting'), $this->isType('array')), array($this->equalTo('taxonomyTerm.deleted'), $this->isType('array')));
     // inject to laravel "events" IoC alias
     $this->application['events'] = $eventDispatcherMock;
     // lets generate dummy data so we have something to work on
     $this->createDummyData();
     // let's prove first we now have a term
     $this->assertNotEmpty(ContentTypeTaxonomyTerm::all()->toArray());
     $this->assertEquals('lifestyle', ContentTypeTaxonomyTerm::all()->first()->term);
     // now let's delete the term
     $request = Request::create('', 'GET', array('taxonomyId' => 1, 'termId' => 1));
     $result = $this->commandDispatcher->dispatchFrom('Darryldecode\\Backend\\Components\\ContentBuilder\\Commands\\DeleteTaxonomyTermCommand', $request);
 }
 public function testShouldNowCreateWhenAllCheckPointsPassed()
 {
     // 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);
     // required type field
     $request = Request::create('', 'GET', array('type' => '', 'enableRevision' => ''));
     $result = $this->commandDispatcher->dispatchFrom('Darryldecode\\Backend\\Components\\ContentBuilder\\Commands\\CreateContentTypeCommand', $request);
     $this->assertFalse($result->isSuccessful());
     $this->assertEquals(400, $result->getStatusCode());
     $this->assertEquals('The type field is required.', $result->getMessage());
     // required type field
     $request = Request::create('', 'GET', array('type' => 'blog', 'enableRevision' => true));
     $result = $this->commandDispatcher->dispatchFrom('Darryldecode\\Backend\\Components\\ContentBuilder\\Commands\\CreateContentTypeCommand', $request);
     $this->assertTrue($result->isSuccessful());
     $this->assertEquals(201, $result->getStatusCode());
     $this->assertEquals('Content type successfully created.', $result->getMessage());
 }
 public function testCreatingAndCreatedEvent()
 {
     // 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();
     // se expectations
     $eventDispatcherMock->expects($this->exactly(2))->method('fire')->withConsecutive(array($this->equalTo('contentTypeTaxonomyTerm.creating'), $this->isType('array')), array($this->equalTo('contentTypeTaxonomyTerm.created'), $this->isType('array')));
     // inject to laravel "events" IoC alias
     $this->application['events'] = $eventDispatcherMock;
     // 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' => '', 'parent' => null));
     // term field required
     $request = Request::create('', 'GET', array('term' => 'lifestyle', 'slug' => 'lifestyle', 'parent' => '', 'contentTypeTaxonomyId' => $taxonomy->id));
     $this->commandDispatcher->dispatchFrom('Darryldecode\\Backend\\Components\\ContentBuilder\\Commands\\CreateTypeTaxonomyTerm', $request);
 }
 public function testShouldCreateGroupEvenWithoutPermissionsYet()
 {
     // 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);
     $request = Request::create('', 'POST', array('name' => 'moderator', 'permissions' => array()));
     // begin
     $result = $this->commandDispatcher->dispatchFrom('Darryldecode\\Backend\\Components\\User\\Commands\\CreateGroupCommand', $request);
     $this->assertTrue($result->isSuccessful(), 'Transaction should be successful.');
     $this->assertEquals(201, $result->getStatusCode(), 'Status code should be 400.');
     $this->assertEquals('Group successfully created.', $result->getMessage());
 }
 public function testCreateContentShouldBePersistedWhenAllValidationPassed()
 {
     $loggedInUser = $this->createUserAndLoggedIn();
     $contentType = $this->createContentType();
     // dummy request
     $request = Request::create('', 'GET', 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()));
     // begin
     $result = $this->commandDispatcher->dispatchFrom(Darryldecode\Backend\Components\ContentBuilder\Commands\CreateContentCommand::class, $request);
     $this->assertTrue($result->isSuccessful());
     $this->assertEquals(201, $result->getStatusCode());
     $this->assertEquals('Content successfully created.', $result->getMessage());
     // prove it exist
     $content = Content::with('metaData')->find($result->getData()->id);
     $this->assertEquals('Some Title', $content->title);
     $this->assertEquals('Some Body', $content->body);
     $this->assertEquals('some-slug', $content->slug);
     //$this->assertEquals('published', $content->status); this passed but annoying for IDE mapper giving error
     $this->assertEquals($loggedInUser->id, $content->author_id);
     $this->assertEquals($contentType->id, $content->content_type_id);
     $contentMeta = Content::parseMetaData($content->metaData->toArray());
     $this->assertCount(2, $contentMeta['form_1']);
     $this->assertArrayHasKey('meta1', $contentMeta['form_1']);
     $this->assertArrayHasKey('meta2', $contentMeta['form_1']);
 }
 public function testShouldAssociateTheUserToTheGroupIfThereIsAnyProvided()
 {
     // 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 dummy groups
     $blogger = Group::create(array('name' => 'blogger', 'permissions' => array('blog.list' => 1, 'blog.create' => 1, 'blog.edit' => 1, 'blog.delete' => -1)));
     $artist = Group::create(array('name' => 'artist', 'permissions' => array('blog.list' => -1, 'art.create' => 1, 'art.edit' => 1, 'art.delete' => -1)));
     $moderator = Group::create(array('name' => 'moderator', 'permissions' => array('blog.list' => -1, 'art.create' => 1, 'art.edit' => 1, 'art.delete' => -1)));
     // dummy request, required first name
     $request = Request::create('', 'GET', array('firstName' => 'Darryl', 'lastName' => 'Fernandez', 'email' => '*****@*****.**', 'password' => 'password', 'permissions' => array(), 'groups' => array($blogger->id, $artist->id)));
     // begin
     $result = $this->commandDispatcher->dispatchFrom('Darryldecode\\Backend\\Components\\User\\Commands\\CreateUserCommand', $request);
     $createdUser = User::find($result->getData()->id);
     $this->assertTrue($createdUser->inGroup($blogger), 'User should be in blogger group');
     $this->assertTrue($createdUser->inGroup($artist), 'User should be in artist group');
     $this->assertFalse($createdUser->inGroup($moderator), 'User should not be in moderator group');
 }
 public function testTaxonomyShouldBeCreatedWhenAllCheckPointsPassed()
 {
     // 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' => ''));
     // term field required
     $request = Request::create('', 'GET', array('term' => 'lifestyle', 'slug' => 'lifestyle', 'contentTypeTaxonomyId' => $taxonomy->id));
     $result = $this->commandDispatcher->dispatchFrom('Darryldecode\\Backend\\Components\\ContentBuilder\\Commands\\CreateTypeTaxonomyTerm', $request);
     $this->assertTrue($result->isSuccessful());
     $this->assertEquals(201, $result->getStatusCode());
     $this->assertEquals('Taxonomy term successfully created.', $result->getMessage());
     // verify that term now exist on DB
     $term = ContentTypeTaxonomyTerm::find($result->getData()->id);
     $this->assertEquals($result->getData()->id, $term->id);
     $this->assertEquals('lifestyle', $term->term);
     $this->assertEquals($taxonomy->id, $term->content_type_taxonomy_id);
 }
 public function testShouldFailWithLoginThrottlingAndShouldBeBannedAfter5Attempts()
 {
     // create user and logged in (the user who will perform the action)
     User::create(array('first_name' => 'darryl', 'email' => '*****@*****.**', 'password' => 'admin', 'permissions' => array()));
     // dummy request with none existing credentials
     $request = Request::create('', 'POST', array('email' => '*****@*****.**', 'password' => 'somewrongpassword'));
     // begin first attempt
     $result = $this->commandDispatcher->dispatchFrom('Darryldecode\\Backend\\Components\\Auth\\Commands\\AuthenticateCommand', $request);
     $this->assertFalse($result->isSuccessful(), 'Transaction should not be successful.');
     $this->assertEquals(401, $result->getStatusCode(), 'Status code should be unauthorized.');
     $this->assertEquals('These credentials do not match our records. Login attempt remaining: 4', $result->getMessage());
     // begin second attempt
     $result = $this->commandDispatcher->dispatchFrom('Darryldecode\\Backend\\Components\\Auth\\Commands\\AuthenticateCommand', $request);
     $this->assertFalse($result->isSuccessful(), 'Transaction should not be successful.');
     $this->assertEquals(401, $result->getStatusCode(), 'Status code should be unauthorized.');
     $this->assertEquals('These credentials do not match our records. Login attempt remaining: 3', $result->getMessage());
     // begin third attempt
     $result = $this->commandDispatcher->dispatchFrom('Darryldecode\\Backend\\Components\\Auth\\Commands\\AuthenticateCommand', $request);
     $this->assertFalse($result->isSuccessful(), 'Transaction should not be successful.');
     $this->assertEquals(401, $result->getStatusCode(), 'Status code should be unauthorized.');
     $this->assertEquals('These credentials do not match our records. Login attempt remaining: 2', $result->getMessage());
     // begin fourth attempt
     $result = $this->commandDispatcher->dispatchFrom('Darryldecode\\Backend\\Components\\Auth\\Commands\\AuthenticateCommand', $request);
     $this->assertFalse($result->isSuccessful(), 'Transaction should not be successful.');
     $this->assertEquals(401, $result->getStatusCode(), 'Status code should be unauthorized.');
     $this->assertEquals('These credentials do not match our records. Login attempt remaining: 1', $result->getMessage());
     // begin fifth attempt
     $result = $this->commandDispatcher->dispatchFrom('Darryldecode\\Backend\\Components\\Auth\\Commands\\AuthenticateCommand', $request);
     $this->assertFalse($result->isSuccessful(), 'Transaction should not be successful.');
     $this->assertEquals(401, $result->getStatusCode(), 'Status code should be unauthorized.');
     $this->assertEquals('These credentials do not match our records. Login attempt remaining: 0', $result->getMessage());
     // user now be on suspended state
     $result = $this->commandDispatcher->dispatchFrom('Darryldecode\\Backend\\Components\\Auth\\Commands\\AuthenticateCommand', $request);
     $this->assertFalse($result->isSuccessful(), 'Transaction should not be successful.');
     $this->assertEquals(401, $result->getStatusCode(), 'Status code should be unauthorized.');
     $this->assertEquals('This account is currently suspended. You can login after 15 minutes.', $result->getMessage());
 }
 public function testShouldDeleteTerm()
 {
     // create user and logged in
     $user = User::create(array('first_name' => 'darryl', 'email' => '*****@*****.**', 'password' => 'pass$darryl', 'permissions' => array('blog.manage' => 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' => ''));
     // add term to the taxonomy
     $taxonomy->terms()->create(array('term' => 'coding', 'slug' => 'coding'));
     // let's prove first we have now 1 taxonomy term for categories which is coding
     $this->assertCount(1, ContentTypeTaxonomyTerm::all()->toArray());
     $this->assertEquals('coding', ContentTypeTaxonomyTerm::all()->first()->term);
     // now let's delete the term
     $request = Request::create('', 'GET', array('taxonomyId' => $blogContentType->id, 'termId' => $taxonomy->id));
     $result = $this->commandDispatcher->dispatchFrom('Darryldecode\\Backend\\Components\\ContentBuilder\\Commands\\DeleteTaxonomyTermCommand', $request);
     // we should not be able to delete it because we don't have a permission for a blog to manage
     $this->assertTrue($result->isSuccessful());
     $this->assertEquals('Taxonomy Term successfully deleted.', $result->getMessage());
     $this->assertEquals(200, $result->getStatusCode());
     // let's prove that there is no term now on our records
     $this->assertEmpty(ContentTypeTaxonomyTerm::all()->toArray());
 }