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 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 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'); }
protected function createDummyUserAndGroup() { $blogger = Group::create(array('name' => 'blogger', 'permissions' => array('blog.list' => -1, 'art.create' => 1, 'art.edit' => 1, 'art.delete' => -1))); $user = User::create(array('first_name' => 'jane', 'last_name' => 'stark', 'email' => '*****@*****.**', 'password' => 'pass$jane', 'permissions' => array('blog.create' => 0, 'forum.create' => 0))); $user->groups()->attach($blogger); return array('blogger' => $blogger, 'user' => $user); }
protected function createUserAndLoggedIn() { // 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); return $user; }
protected function createUserAndLoggedIn() { $group = Group::create(array('name' => 'blogger', 'permissions' => array('superuser' => 1))); $user = User::create(array('first_name' => 'darryl', 'email' => '*****@*****.**', 'password' => 'pass$darryl', 'permissions' => array('blog.create' => 0, 'forum.create' => 0))); $user->groups()->attach($group); $this->application['auth']->loginUsingId($user->id); return $user; }
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 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 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 testQueryWithTerms() { // 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 $this->createDummyData($user); // begin $result = $this->commandDispatcher->dispatchFromArray('Darryldecode\\Backend\\Components\\ContentBuilder\\Commands\\QueryContentsCommand', array('type' => 'Blog', 'terms' => array('category' => 'health'))); // prove successful $this->assertTrue($result->isSuccessful()); $this->assertEquals('Query contents successful.', $result->getMessage()); $this->assertEquals(200, $result->getStatusCode(), 'Status code should be ok'); $this->assertCount(2, $result->getData()->toArray()['data']); }
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 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 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 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 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 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()); }
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 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 testBeforeAndAfterQuery() { // 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.beforeQuery'), $this->isType('array')), array($this->equalTo('contentType.afterQuery'), $this->isType('array'))); // inject to laravel "events" IoC alias $this->application['events'] = $eventDispatcherMock; // 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 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()); }
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()); }
protected function createUserAndLoggedIn() { $user = User::create(array('first_name' => 'darryl', 'email' => '*****@*****.**', 'password' => 'pass$darryl', 'permissions' => array('superuser' => 1))); $this->application['auth']->loginUsingId($user->id); return $user; }
public function testUserInGroup() { $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))); $user = User::create(array('first_name' => 'darryl', 'last_name' => 'Fernandez', 'email' => '*****@*****.**', 'password' => 'pass$darryl', 'permissions' => array('blog.create' => 0, 'forum.create' => 0))); $user->groups()->attach($blogger); $user->groups()->attach($artist); // by using the group object $this->assertTrue($user->inGroup($blogger)); // by using the group name $this->assertTrue($user->inGroup($blogger->name)); }
/** * */ public function testContentTypeShouldBeCreatedWhenAllCheckPointsPassed() { // 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); $contentType = $this->createContentType(); // required taxonomy field $request = Request::create('', 'GET', array('taxonomy' => 'categories', 'description' => 'some description', 'contentTypeId' => $contentType->id)); $result = $this->commandDispatcher->dispatchFromArray('Darryldecode\\Backend\\Components\\ContentBuilder\\Commands\\CreateContentTypeTaxonomyCommand', array('taxonomy' => $request->get('taxonomy', null), 'description' => $request->get('description', null), 'contentTypeId' => $request->get('contentTypeId', null))); $this->assertTrue($result->isSuccessful()); $this->assertEquals(201, $result->getStatusCode()); $this->assertEquals('Content type taxonomy successfully created.', $result->getMessage()); // verify content type taxonomy $cTypeTaxonomy = ContentTypeTaxonomy::find($result->getData()->id); $this->assertEquals($result->getData()->id, $cTypeTaxonomy->id); $this->assertEquals('categories', $cTypeTaxonomy->taxonomy); }
protected function seedUser() { $group = \Darryldecode\Backend\Components\User\Models\Group::create(array('name' => 'Super User', 'permissions' => array('superuser' => 1))); $user = \Darryldecode\Backend\Components\User\Models\User::create(array('first_name' => 'John', 'last_name' => 'Doe', 'email' => '*****@*****.**', 'password' => 'admin', 'permissions' => array('superuser' => 1))); $user->groups()->attach($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); }
protected function createUsers() { User::create(array('first_name' => 'darryl', 'email' => '*****@*****.**', 'password' => 'pass$darryl', 'permissions' => array('superuser' => 1))); User::create(array('first_name' => 'noemi', 'email' => '*****@*****.**', 'password' => 'pass$darryl', 'permissions' => array('blogger' => 1))); User::create(array('first_name' => 'jane', 'email' => '*****@*****.**', 'password' => 'pass$darryl', 'permissions' => array('moderator' => 1))); User::create(array('first_name' => 'janelyn', 'email' => '*****@*****.**', 'password' => 'pass$darryl', 'permissions' => array('moderator' => 1))); }
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); }
/** * check if email is provided * * @param User $user * @param string $email * @return bool */ protected function isEmailAlreadyInUsed(User $user, $email) { $found = $user->with(array())->where('email', $email)->first(); return $found ? true : false; }