SluggablePositionTest.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. namespace Gedmo\Sluggable;
  3. use Doctrine\Common\EventManager;
  4. use Tool\BaseTestCaseORM;
  5. use Sluggable\Fixture\Position;
  6. /**
  7. * These are tests for Sluggable behavior
  8. *
  9. * @author Gediminas Morkevicius <gediminas.morkevicius@gmail.com>
  10. * @link http://www.gediminasm.org
  11. * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
  12. */
  13. class SluggablePositionTest extends BaseTestCaseORM
  14. {
  15. const POSITION = 'Sluggable\\Fixture\\Position';
  16. protected function setUp()
  17. {
  18. parent::setUp();
  19. $evm = new EventManager;
  20. $evm->addEventSubscriber(new SluggableListener);
  21. $this->getMockSqliteEntityManager($evm);
  22. $this->populate();
  23. }
  24. public function testPositionedSlugOrder()
  25. {
  26. $meta = $this->em->getClassMetadata(self::POSITION);
  27. $repo = $this->em->getRepository(self::POSITION);
  28. $object = $repo->find(1);
  29. $slug = $meta->getReflectionProperty('slug')->getValue($object);
  30. $this->assertEquals('code-other-title-prop', $slug);
  31. }
  32. protected function getUsedEntityFixtures()
  33. {
  34. return array(
  35. self::POSITION,
  36. );
  37. }
  38. private function populate()
  39. {
  40. $meta = $this->em->getClassMetadata(self::POSITION);
  41. $object = new Position;
  42. $meta->getReflectionProperty('title')->setValue($object, 'title');
  43. $meta->getReflectionProperty('prop')->setValue($object, 'prop');
  44. $meta->getReflectionProperty('code')->setValue($object, 'code');
  45. $meta->getReflectionProperty('other')->setValue($object, 'other');
  46. $this->em->persist($object);
  47. $this->em->flush();
  48. }
  49. }