SluggableFltersTest.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. namespace Gedmo\Sluggable;
  3. use Doctrine\Common\EventManager;
  4. use Tool\BaseTestCaseORM;
  5. use Sluggable\Fixture\Article;
  6. /**
  7. * These are tests for Sluggable behavior
  8. *
  9. * @author Florian Vilpoix <florianv@gmail.com>
  10. * @link http://www.gediminasm.org
  11. * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
  12. */
  13. class SluggableFltersTest extends BaseTestCaseORM
  14. {
  15. const TARGET = 'Sluggable\\Fixture\\Article';
  16. const SOFT_DELETEABLE_FILTER_NAME = 'soft-deleteable';
  17. const FAKE_FILTER_NAME = 'fake-filter';
  18. protected function setUp()
  19. {
  20. parent::setUp();
  21. $evm = new EventManager;
  22. $sluggableListener = new SluggableListener;
  23. $sluggableListener->addManagedFilter(self::SOFT_DELETEABLE_FILTER_NAME, true);
  24. $sluggableListener->addManagedFilter(self::FAKE_FILTER_NAME, true);
  25. $evm->addEventSubscriber($sluggableListener);
  26. $config = $this->getMockAnnotatedConfig();
  27. $config->addFilter(self::SOFT_DELETEABLE_FILTER_NAME, 'Gedmo\SoftDeleteable\Filter\SoftDeleteableFilter');
  28. $config->addFilter(self::FAKE_FILTER_NAME, 'Sluggable\Fixture\Doctrine\FakeFilter');
  29. $this->em = $this->getMockSqliteEntityManager($evm, $config);
  30. $this->em->getFilters()->enable(self::SOFT_DELETEABLE_FILTER_NAME);
  31. $this->em->getFilters()->enable(self::FAKE_FILTER_NAME);
  32. }
  33. protected function getUsedEntityFixtures()
  34. {
  35. return array(
  36. self::TARGET
  37. );
  38. }
  39. /**
  40. * @test
  41. */
  42. function shouldSuccessWhenManagedFilterHasAlreadyBeenDisabled()
  43. {
  44. // disable one managed doctrine filter
  45. $this->em->getFilters()->disable(self::FAKE_FILTER_NAME);
  46. $slug = new Article;
  47. $slug->setCode('My code');
  48. $slug->setTitle('My title');
  49. $this->em->persist($slug);
  50. $this->em->flush();
  51. $this->assertEquals('my-title-my-code', $slug->getSlug());
  52. }
  53. }