Issue449Test.php 2.1KB

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