SluggableIdentifierTest.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. namespace Gedmo\Sluggable;
  3. use Doctrine\Common\EventManager;
  4. use Tool\BaseTestCaseORM;
  5. use Sluggable\Fixture\Identifier;
  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 SluggableIdentifierTest extends BaseTestCaseORM
  14. {
  15. const TARGET = 'Sluggable\\Fixture\\Identifier';
  16. protected function setUp()
  17. {
  18. parent::setUp();
  19. $evm = new EventManager;
  20. $evm->addEventSubscriber(new SluggableListener);
  21. $this->getMockSqliteEntityManager($evm);
  22. }
  23. /**
  24. * @test
  25. */
  26. function shouldBePossibleToSlugIdentifiers()
  27. {
  28. $sport = new Identifier;
  29. $sport->setTitle('Sport');
  30. $this->em->persist($sport);
  31. $this->em->flush();
  32. $this->assertEquals('sport', $sport->getId());
  33. }
  34. /**
  35. * @test
  36. */
  37. function shouldPersistMultipleNonConflictingIdentifierSlugs()
  38. {
  39. $sport = new Identifier;
  40. $sport->setTitle('Sport');
  41. $this->em->persist($sport);
  42. $sport2 = new Identifier;
  43. $sport2->setTitle('Sport');
  44. $this->em->persist($sport2);
  45. $this->em->flush();
  46. $this->assertEquals('sport', $sport->getId());
  47. $this->assertEquals('sport_1', $sport2->getId());
  48. }
  49. protected function getUsedEntityFixtures()
  50. {
  51. return array(
  52. self::TARGET,
  53. );
  54. }
  55. }