Issue449Test.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. namespace Gedmo\Sluggable;
  3. use Doctrine\Common\EventManager;
  4. use Tool\BaseTestCaseORM;
  5. use Gedmo\SoftDeleteable\SoftDeleteableListener;
  6. use Sluggable\Fixture\Issue449\Article;
  7. /**
  8. * These are tests for Sluggable behavior
  9. *
  10. * @author Craig Marvelley <craig.marvelley@gmail.com>
  11. * @link http://marvelley.com
  12. * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
  13. */
  14. class Issue449Test extends BaseTestCaseORM
  15. {
  16. const TARGET = 'Sluggable\\Fixture\\Issue449\\Article';
  17. const SOFT_DELETEABLE_FILTER_NAME = 'soft-deleteable';
  18. private $softDeleteableListener;
  19. protected function setUp()
  20. {
  21. parent::setUp();
  22. $evm = new EventManager;
  23. $sluggableListener = new SluggableListener;
  24. $sluggableListener->addManagedFilter(self::SOFT_DELETEABLE_FILTER_NAME, true);
  25. $evm->addEventSubscriber($sluggableListener);
  26. $this->softDeleteableListener = new SoftDeleteableListener();
  27. $evm->addEventSubscriber($this->softDeleteableListener);
  28. $config = $this->getMockAnnotatedConfig();
  29. $config->addFilter(self::SOFT_DELETEABLE_FILTER_NAME, 'Gedmo\SoftDeleteable\Filter\SoftDeleteableFilter');
  30. $this->em = $this->getMockSqliteEntityManager($evm, $config);
  31. $this->em->getFilters()->enable(self::SOFT_DELETEABLE_FILTER_NAME);
  32. }
  33. protected function getUsedEntityFixtures()
  34. {
  35. return array(
  36. self::TARGET
  37. );
  38. }
  39. /**
  40. * @test
  41. */
  42. public function shouldBuildUniqueSlugAfterSoftDeleteFilterIsDisabled()
  43. {
  44. $article = new Article();
  45. $article->setTitle('the soft title');
  46. $article->setCode('my soft code');
  47. $this->em->persist($article);
  48. $this->em->flush();
  49. $slug = $article->getSlug();
  50. $this->em->remove($article);
  51. $this->em->flush();
  52. $article = new Article();
  53. $article->setTitle('the soft title');
  54. $article->setCode('my soft code');
  55. $this->em->persist($article);
  56. $this->em->flush();
  57. $this->em->clear();
  58. $this->assertNotEquals($slug, $article->getSlug());
  59. }
  60. }