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));
 }
 protected function createDummyData()
 {
     // 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 the terms
     $taxonomy->terms()->create(array('term' => 'lifestyle', 'slug' => 'lifestyle'));
 }
 protected function createDummyData()
 {
     $cType = ContentType::create(array('type' => 'Blog', 'enable_revisions' => true));
     $taxonomy = ContentTypeTaxonomy::create(array('taxonomy' => 'categories', 'description' => 'some description', 'content_type_id' => $cType->id));
     // create now terms
     ContentTypeTaxonomyTerm::create(array('term' => 'lifestyle', 'slug' => 'lifestyle', 'content_type_taxonomy_id' => $taxonomy->id));
     ContentTypeTaxonomyTerm::create(array('term' => 'sports', 'slug' => 'sports', 'content_type_taxonomy_id' => $taxonomy->id));
     ContentTypeTaxonomyTerm::create(array('term' => 'coding', 'slug' => 'coding', 'content_type_taxonomy_id' => $taxonomy->id));
     return $taxonomy;
 }
 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 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 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 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 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);
 }
 protected function createDummyData($user)
 {
     // create content type
     $ctype = ContentType::create(array('type' => 'Blog', 'enable_revisions' => true));
     // create content type taxonomy
     $taxonomy = $this->commandDispatcher->dispatchFromArray('Darryldecode\\Backend\\Components\\ContentBuilder\\Commands\\CreateContentTypeTaxonomyCommand', array('taxonomy' => 'category', 'description' => 'the blog post category', 'contentTypeId' => $ctype->id));
     $taxonomy = $taxonomy->getData()->toArray();
     // create taxonomy terms
     $technologyTerm = $this->commandDispatcher->dispatchFromArray('Darryldecode\\Backend\\Components\\ContentBuilder\\Commands\\CreateTypeTaxonomyTerm', array('term' => 'technology', 'slug' => 'technology', 'contentTypeTaxonomyId' => $taxonomy['id']));
     $technologyTerm = $technologyTerm->getData()->toArray();
     $healthTerm = $this->commandDispatcher->dispatchFromArray('Darryldecode\\Backend\\Components\\ContentBuilder\\Commands\\CreateTypeTaxonomyTerm', array('term' => 'health', 'slug' => 'health', 'contentTypeTaxonomyId' => $taxonomy['id']));
     $healthTerm = $healthTerm->getData()->toArray();
     $programmingTerm = $this->commandDispatcher->dispatchFromArray('Darryldecode\\Backend\\Components\\ContentBuilder\\Commands\\CreateTypeTaxonomyTerm', array('term' => 'programming', 'slug' => 'programming', 'contentTypeTaxonomyId' => $taxonomy['id']));
     $programmingTerm = $programmingTerm->getData()->toArray();
     // create blog post dummy contents
     // this will have ID of 1, we will use this on test query by ID
     $this->commandDispatcher->dispatchFromArray('Darryldecode\\Backend\\Components\\ContentBuilder\\Commands\\CreateContentCommand', array('title' => 'Some Title', 'body' => 'Some Body', 'slug' => 'some-title', 'status' => 'published', 'authorId' => $user->id, 'contentTypeId' => $ctype->id, 'taxonomies' => array($healthTerm['id'] => true), 'metaData' => array('form_1' => array('meta1' => 'meta value 1', 'meta2' => 'meta value 2')), 'miscData' => array()));
     $this->commandDispatcher->dispatchFromArray('Darryldecode\\Backend\\Components\\ContentBuilder\\Commands\\CreateContentCommand', array('title' => 'Some Entry 2', 'body' => 'Some entry entry', 'slug' => 'some-entry-2', 'status' => 'published', 'authorId' => $user->id, 'contentTypeId' => $ctype->id, 'taxonomies' => array($programmingTerm['id'] => true, $healthTerm['id'] => true), 'metaData' => array('form_1' => array('meta1' => 'meta value 1', 'meta2' => 'meta value 2')), 'miscData' => array()));
     $this->commandDispatcher->dispatchFromArray('Darryldecode\\Backend\\Components\\ContentBuilder\\Commands\\CreateContentCommand', array('title' => 'Some Entry 3', 'body' => 'Some entry entry 3', 'slug' => 'some-entry-3', 'status' => 'published', 'authorId' => $user->id, 'contentTypeId' => $ctype->id, 'taxonomies' => array(), 'metaData' => array('form_1' => array('meta1' => 'meta value 1', 'meta2' => 'meta value 2')), 'miscData' => array()));
 }
 /**
  * Execute the command.
  *
  * @param Factory $validator
  * @param ContentType $contentType
  * @param Dispatcher $dispatcher
  * @return CommandResult
  */
 public function handle(Factory $validator, ContentType $contentType, Dispatcher $dispatcher)
 {
     // validate authorization
     if (!$this->disablePermissionChecking) {
         if (!$this->user->hasAnyPermission(['contentBuilder.manage'])) {
             return new CommandResult(false, CommandResult::$responseForbiddenMessage, null, 403);
         }
     }
     // validate data
     $validationResult = $validator->make(array('type' => $this->type), ContentType::$rules);
     if ($validationResult->fails()) {
         return new CommandResult(false, $validationResult->getMessageBag()->first(), null, 400);
     }
     // prepare data to be created
     $contentTypeToBeCreated = array('type' => $this->type, 'enable_revisions' => $this->enableRevision == 'no' ? false : true);
     // fire content type creating event
     $dispatcher->fire('contentType.creating', array($contentTypeToBeCreated));
     // store
     $createdContentType = $contentType->create($contentTypeToBeCreated);
     // fire content type created event
     $dispatcher->fire('contentType.created', array($createdContentType));
     // return
     return new CommandResult(true, "Content type successfully created.", $createdContentType, 201);
 }
 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());
 }
 protected function seedSampleContentTypes()
 {
     ContentType::create(array('type' => 'blog', 'enable_revisions' => true));
 }
 protected function createDummyData($user, $enableRevisions = true)
 {
     $blogContentType = ContentType::create(array('type' => 'Blog', 'enable_revisions' => $enableRevisions));
     return Content::create(array('title' => 'Some Title', 'body' => 'Some Body', 'slug' => 'some-slug', 'status' => 'published', 'author_id' => $user->id, 'content_type_id' => $blogContentType->id, 'taxonomies' => array('luzon'), 'misc_data' => array()));
 }
 protected function createDummyContentTypes()
 {
     ContentType::create(array('type' => 'Blog', 'enable_revisions' => true));
     ContentType::create(array('type' => 'Events', 'enable_revisions' => true));
     ContentType::create(array('type' => 'News', 'enable_revisions' => true));
 }
 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 createContentType()
 {
     return ContentType::create(array('type' => 'blog', 'enable_revisions' => true));
 }
 protected function createDummyData($user)
 {
     $blogContentType = ContentType::create(array('type' => 'Blog', 'enable_revisions' => true));
     $result = $this->commandDispatcher->dispatchFromArray('Darryldecode\\Backend\\Components\\ContentBuilder\\Commands\\CreateContentCommand', array('title' => 'Some Title', 'body' => 'Some Body', 'slug' => 'some-slug', 'status' => 'published', 'authorId' => $user->id, 'contentTypeId' => $blogContentType->id, 'taxonomies' => array('luzon'), 'metaData' => array('form_1' => array('meta1' => 'meta value 1', 'meta2' => 'meta value 2')), 'miscData' => array()));
     return $result->getData();
 }