Issue633Test.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <?php
  2. namespace Gedmo\Sluggable;
  3. use Doctrine\Common\EventManager;
  4. use Tool\BaseTestCaseORM;
  5. use Sluggable\Fixture\Issue633\Article;
  6. /**
  7. * These are tests for Sluggable behavior
  8. *
  9. * @author Derek Clapham <derek.clapham@gmail.com>
  10. * @link http://www.gediminasm.org
  11. * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
  12. */
  13. class Issue633Test extends BaseTestCaseORM
  14. {
  15. const TARGET = 'Sluggable\\Fixture\\Issue633\\Article';
  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 shouldHandleUniqueBasedSlug()
  27. {
  28. $test = new Article;
  29. $test->setTitle('Unique to code');
  30. $test->setCode('CODE001');
  31. $this->em->persist($test);
  32. $this->em->flush();
  33. $this->assertEquals('unique-to-code', $test->getSlug());
  34. $test2 = new Article;
  35. $test2->setTitle('Unique to code');
  36. $test2->setCode('CODE002');
  37. $this->em->persist($test2);
  38. $this->em->flush();
  39. $this->assertEquals('unique-to-code', $test2->getSlug());
  40. $test3 = new Article;
  41. $test3->setTitle('Unique to code');
  42. $test3->setCode('CODE001');
  43. $this->em->persist($test3);
  44. $this->em->flush();
  45. $this->assertEquals('unique-to-code-1', $test3->getSlug());
  46. }
  47. /**
  48. * @test
  49. */
  50. function handlePersistedSlugsForUniqueBased()
  51. {
  52. $test = new Article;
  53. $test->setTitle('Unique to code');
  54. $test->setCode('CODE001');
  55. $this->em->persist($test);
  56. $test2 = new Article;
  57. $test2->setTitle('Unique to code');
  58. $test2->setCode('CODE002');
  59. $this->em->persist($test2);
  60. $test3 = new Article;
  61. $test3->setTitle('Unique to code');
  62. $test3->setCode('CODE001');
  63. $this->em->persist($test3);
  64. $this->em->flush();
  65. $this->assertEquals('unique-to-code', $test->getSlug());
  66. $this->assertEquals('unique-to-code', $test2->getSlug());
  67. $this->assertEquals('unique-to-code-1', $test3->getSlug());
  68. }
  69. protected function getUsedEntityFixtures()
  70. {
  71. return array(
  72. self::TARGET
  73. );
  74. }
  75. }