SluggableIdentifierTest.php 1.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. * @package Gedmo.Sluggable
  11. * @link http://www.gediminasm.org
  12. * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
  13. */
  14. class SluggableIdentifierTest extends BaseTestCaseORM
  15. {
  16. const TARGET = 'Sluggable\\Fixture\\Identifier';
  17. protected function setUp()
  18. {
  19. parent::setUp();
  20. $evm = new EventManager;
  21. $evm->addEventSubscriber(new SluggableListener);
  22. $this->getMockSqliteEntityManager($evm);
  23. }
  24. /**
  25. * @test
  26. */
  27. function shouldBePossibleToSlugIdentifiers()
  28. {
  29. $sport = new Identifier;
  30. $sport->setTitle('Sport');
  31. $this->em->persist($sport);
  32. $this->em->flush();
  33. $this->assertEquals('sport', $sport->getId());
  34. }
  35. /**
  36. * @test
  37. */
  38. function shouldPersistMultipleNonConflictingIdentifierSlugs()
  39. {
  40. $sport = new Identifier;
  41. $sport->setTitle('Sport');
  42. $this->em->persist($sport);
  43. $sport2 = new Identifier;
  44. $sport2->setTitle('Sport');
  45. $this->em->persist($sport2);
  46. $this->em->flush();
  47. $this->assertEquals('sport', $sport->getId());
  48. $this->assertEquals('sport_1', $sport2->getId());
  49. }
  50. protected function getUsedEntityFixtures()
  51. {
  52. return array(
  53. self::TARGET,
  54. );
  55. }
  56. }