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(); // 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 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()); }