partkeepr

fork of partkeepr
git clone https://git.e1e0.net/partkeepr.git
Log | Files | Refs | Submodules | README | LICENSE

commit 973bb1f9c6dca03c6e818f15790c4534946b0a03
parent 8b11ab87fa47431557b0e99953948112f436ce02
Author: Felicitus <felicitus@felicitus.org>
Date:   Sat, 12 Sep 2015 17:26:38 +0200

Added functional test for moving part categories

Diffstat:
Asrc/PartKeepr/PartBundle/DataFixtures/LoadCategoryData.php | 34++++++++++++++++++++++++++++++++++
Asrc/PartKeepr/PartBundle/Tests/MoveActionTest.php | 63+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 97 insertions(+), 0 deletions(-)

diff --git a/src/PartKeepr/PartBundle/DataFixtures/LoadCategoryData.php b/src/PartKeepr/PartBundle/DataFixtures/LoadCategoryData.php @@ -0,0 +1,33 @@ +<?php +namespace PartKeepr\PartBundle\DataFixtures; + +use Doctrine\Common\DataFixtures\AbstractFixture; +use Doctrine\Common\Persistence\ObjectManager; +use PartKeepr\PartBundle\Entity\PartCategory; + +class LoadCategoryData extends AbstractFixture +{ + public function load(ObjectManager $manager) + { + $rootNode = new PartCategory(); + $rootNode->setName("Root Node"); + + $firstCategory = new PartCategory(); + $firstCategory->setParent($rootNode); + $firstCategory->setName("First Category"); + + $secondCategory = new PartCategory(); + $secondCategory->setParent($firstCategory); + $secondCategory->setName("Second Category"); + + $manager->persist($rootNode); + $manager->persist($firstCategory); + $manager->persist($secondCategory); + $manager->flush(); + + $this->addReference("partcategory.root", $rootNode); + $this->addReference("partcategory.first", $firstCategory); + $this->addReference("partcategory.second", $secondCategory); + + } +}+ \ No newline at end of file diff --git a/src/PartKeepr/PartBundle/Tests/MoveActionTest.php b/src/PartKeepr/PartBundle/Tests/MoveActionTest.php @@ -0,0 +1,62 @@ +<?php +namespace PartKeepr\PartBundle\Tests; + +use Doctrine\Common\DataFixtures\ProxyReferenceRepository; +use Dunglas\ApiBundle\Api\IriConverter; +use Liip\FunctionalTestBundle\Test\WebTestCase; +use PartKeepr\PartBundle\Entity\PartCategory; + +class MoveActionTest extends WebTestCase +{ + /** + * @var ProxyReferenceRepository + */ + private $fixtures; + + public function setUp() + { + $this->fixtures = $this->loadFixtures( + array( + 'PartKeepr\PartBundle\DataFixtures\LoadCategoryData', + ) + )->getReferenceRepository(); + } + + public function testMoveCategory() + { + $client = static::createClient(); + + /** + * @var $secondCategory PartCategory + * @var $rootCategory PartCategory + */ + $secondCategory = $this->fixtures->getReference("partcategory.second"); + $rootCategory = $this->fixtures->getReference("partcategory.root"); + + /** + * @var $iriConverter IriConverter + */ + $iriConverter = $this->getContainer()->get("api.iri_converter"); + + $iri = $iriConverter->getIriFromItem($secondCategory); + $iri .= "/move"; + + $targetIri = $iriConverter->getIriFromItem($rootCategory); + + $request = array( + "parent" => $targetIri, + ); + + $client->request( + 'PUT', + $iri, + array(), + array(), + array('CONTENT_TYPE' => 'application/json'), + json_encode($request) + ); + + $this->assertEquals($rootCategory->getId(), $secondCategory->getParent()->getId()); + $this->assertEquals("Root Node / Second Category", $secondCategory->getCategoryPath()); + } +}+ \ No newline at end of file