AbstractMoveCategoryTest.php (1827B)
1 <?php 2 3 namespace PartKeepr\CategoryBundle\Tests; 4 5 use Doctrine\Common\DataFixtures\ProxyReferenceRepository; 6 use Dunglas\ApiBundle\Api\IriConverter; 7 use PartKeepr\CategoryBundle\Entity\AbstractCategory; 8 use PartKeepr\CoreBundle\Tests\WebTestCase; 9 10 abstract class AbstractMoveCategoryTest extends WebTestCase 11 { 12 /** 13 * @var ProxyReferenceRepository 14 */ 15 protected $fixtures; 16 17 public function setUp() 18 { 19 $this->fixtures = $this->loadFixtures( 20 [ 21 $this->getFixtureLoaderClass(), 22 ] 23 )->getReferenceRepository(); 24 } 25 26 public function testMoveCategory() 27 { 28 $client = static::makeClient(true); 29 30 /** 31 * @var AbstractCategory 32 * @var $rootCategory AbstractCategory 33 */ 34 $secondCategory = $this->fixtures->getReference($this->getReferencePrefix().'.second'); 35 $rootCategory = $this->fixtures->getReference($this->getReferencePrefix().'.root'); 36 37 /** 38 * @var IriConverter 39 */ 40 $iriConverter = $this->getContainer()->get('api.iri_converter'); 41 42 $iri = $iriConverter->getIriFromItem($secondCategory); 43 $iri .= '/move'; 44 45 $targetIri = $iriConverter->getIriFromItem($rootCategory); 46 47 $request = [ 48 'parent' => $targetIri, 49 ]; 50 51 $client->request( 52 'PUT', 53 $iri, 54 [], 55 [], 56 ['CONTENT_TYPE' => 'application/json'], 57 json_encode($request) 58 ); 59 60 $this->assertEquals($rootCategory->getId(), $secondCategory->getParent()->getId()); 61 $this->assertEquals('Root Node ➤ Second Category', $secondCategory->getCategoryPath()); 62 } 63 64 abstract public function getFixtureLoaderClass(); 65 66 abstract public function getReferencePrefix(); 67 }