commit 95438d5ee21e5c3a7be4f4512e175cddf79728fa
parent 973bb1f9c6dca03c6e818f15790c4534946b0a03
Author: Felicitus <felicitus@felicitus.org>
Date: Sat, 12 Sep 2015 18:40:53 +0200
Added functional tests for the category move actions
Diffstat:
9 files changed, 196 insertions(+), 87 deletions(-)
diff --git a/src/PartKeepr/CategoryBundle/DataFixtures/AbstractCategoryDataLoader.php b/src/PartKeepr/CategoryBundle/DataFixtures/AbstractCategoryDataLoader.php
@@ -0,0 +1,43 @@
+<?php
+namespace PartKeepr\CategoryBundle\DataFixtures;
+
+use Doctrine\Common\DataFixtures\AbstractFixture;
+use Doctrine\Common\Persistence\ObjectManager;
+
+abstract class AbstractCategoryDataLoader extends AbstractFixture
+{
+ public function load(ObjectManager $manager)
+ {
+ $entityClass = $this->getEntityClass();
+ $rootNode = new $entityClass();
+ $rootNode->setName("Root Node");
+
+ $firstCategory = new $entityClass();
+ $firstCategory->setParent($rootNode);
+ $firstCategory->setName("First Category");
+
+ $secondCategory = new $entityClass();
+ $secondCategory->setParent($firstCategory);
+ $secondCategory->setName("Second Category");
+
+ $manager->persist($rootNode);
+ $manager->persist($firstCategory);
+ $manager->persist($secondCategory);
+ $manager->flush();
+
+ $this->addReference($this->getReferencePrefix() . ".root", $rootNode);
+ $this->addReference($this->getReferencePrefix() . ".first", $firstCategory);
+ $this->addReference($this->getReferencePrefix() . ".second", $secondCategory);
+ }
+
+ /**
+ * @return string The name of the target entity class
+ */
+ abstract protected function getEntityClass();
+
+ /**
+ * @return string Returns the prefix for the reference
+ */
+ abstract protected function getReferencePrefix();
+
+}
diff --git a/src/PartKeepr/CategoryBundle/Tests/AbstractMoveCategoryTest.php b/src/PartKeepr/CategoryBundle/Tests/AbstractMoveCategoryTest.php
@@ -0,0 +1,67 @@
+<?php
+namespace PartKeepr\CategoryBundle\Tests;
+
+
+use Doctrine\Common\DataFixtures\ProxyReferenceRepository;
+use Dunglas\ApiBundle\Api\IriConverter;
+use Liip\FunctionalTestBundle\Test\WebTestCase;
+use PartKeepr\CategoryBundle\Entity\AbstractCategory;
+
+abstract class AbstractMoveCategoryTest extends WebTestCase
+{
+ /**
+ * @var ProxyReferenceRepository
+ */
+ protected $fixtures;
+
+ public function setUp()
+ {
+ $this->fixtures = $this->loadFixtures(
+ array(
+ $this->getFixtureLoaderClass(),
+ )
+ )->getReferenceRepository();
+ }
+
+ public function testMoveCategory()
+ {
+ $client = static::createClient();
+
+ /**
+ * @var $secondCategory AbstractCategory
+ * @var $rootCategory AbstractCategory
+ */
+ $secondCategory = $this->fixtures->getReference($this->getReferencePrefix().".second");
+ $rootCategory = $this->fixtures->getReference($this->getReferencePrefix().".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());
+ }
+
+ abstract public function getFixtureLoaderClass();
+
+ abstract public function getReferencePrefix();
+}
diff --git a/src/PartKeepr/FootprintBundle/DataFixtures/CategoryDataLoader.php b/src/PartKeepr/FootprintBundle/DataFixtures/CategoryDataLoader.php
@@ -0,0 +1,15 @@
+<?php
+namespace PartKeepr\FootprintBundle\DataFixtures;
+
+use PartKeepr\CategoryBundle\DataFixtures\AbstractCategoryDataLoader;
+
+class CategoryDataLoader extends AbstractCategoryDataLoader
+{
+ protected function getEntityClass () {
+ return 'PartKeepr\FootprintBundle\Entity\FootprintCategory';
+ }
+
+ protected function getReferencePrefix () {
+ return "footprintcategory";
+ }
+}
diff --git a/src/PartKeepr/FootprintBundle/Tests/MoveActionTest.php b/src/PartKeepr/FootprintBundle/Tests/MoveActionTest.php
@@ -0,0 +1,17 @@
+<?php
+namespace PartKeepr\FootprintBundle\Tests;
+
+use PartKeepr\CategoryBundle\Tests\AbstractMoveCategoryTest;
+
+class MoveActionTest extends AbstractMoveCategoryTest
+{
+ public function getFixtureLoaderClass()
+ {
+ return 'PartKeepr\FootprintBundle\DataFixtures\CategoryDataLoader';
+ }
+
+ public function getReferencePrefix()
+ {
+ return "footprintcategory";
+ }
+}
diff --git a/src/PartKeepr/PartBundle/DataFixtures/CategoryDataLoader.php b/src/PartKeepr/PartBundle/DataFixtures/CategoryDataLoader.php
@@ -0,0 +1,15 @@
+<?php
+namespace PartKeepr\PartBundle\DataFixtures;
+
+use PartKeepr\CategoryBundle\DataFixtures\AbstractCategoryDataLoader;
+
+class CategoryDataLoader extends AbstractCategoryDataLoader
+{
+ protected function getEntityClass () {
+ return 'PartKeepr\PartBundle\Entity\PartCategory';
+ }
+
+ protected function getReferencePrefix () {
+ return "partcategory";
+ }
+}
diff --git a/src/PartKeepr/PartBundle/DataFixtures/LoadCategoryData.php b/src/PartKeepr/PartBundle/DataFixtures/LoadCategoryData.php
@@ -1,33 +0,0 @@
-<?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
@@ -1,62 +1,17 @@
<?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;
+use PartKeepr\CategoryBundle\Tests\AbstractMoveCategoryTest;
-class MoveActionTest extends WebTestCase
+class MoveActionTest extends AbstractMoveCategoryTest
{
- /**
- * @var ProxyReferenceRepository
- */
- private $fixtures;
-
- public function setUp()
+ public function getFixtureLoaderClass()
{
- $this->fixtures = $this->loadFixtures(
- array(
- 'PartKeepr\PartBundle\DataFixtures\LoadCategoryData',
- )
- )->getReferenceRepository();
+ return 'PartKeepr\PartBundle\DataFixtures\CategoryDataLoader';
}
- public function testMoveCategory()
+ public function getReferencePrefix()
{
- $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());
+ return "partcategory";
}
-}-
\ No newline at end of file
+}
diff --git a/src/PartKeepr/StorageLocationBundle/DataFixtures/CategoryDataLoader.php b/src/PartKeepr/StorageLocationBundle/DataFixtures/CategoryDataLoader.php
@@ -0,0 +1,15 @@
+<?php
+namespace PartKeepr\StorageLocationBundle\DataFixtures;
+
+use PartKeepr\CategoryBundle\DataFixtures\AbstractCategoryDataLoader;
+
+class CategoryDataLoader extends AbstractCategoryDataLoader
+{
+ protected function getEntityClass () {
+ return 'PartKeepr\StorageLocationBundle\Entity\StorageLocationCategory';
+ }
+
+ protected function getReferencePrefix () {
+ return "storagelocationcategory";
+ }
+}
diff --git a/src/PartKeepr/StorageLocationBundle/Tests/MoveActionTest.php b/src/PartKeepr/StorageLocationBundle/Tests/MoveActionTest.php
@@ -0,0 +1,17 @@
+<?php
+namespace PartKeepr\StorageLocationBundle\Tests;
+
+use PartKeepr\CategoryBundle\Tests\AbstractMoveCategoryTest;
+
+class MoveActionTest extends AbstractMoveCategoryTest
+{
+ public function getFixtureLoaderClass()
+ {
+ return 'PartKeepr\StorageLocationBundle\DataFixtures\CategoryDataLoader';
+ }
+
+ public function getReferencePrefix()
+ {
+ return "storagelocationcategory";
+ }
+}