TransliterationTest.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. namespace Gedmo\Sluggable;
  3. use Doctrine\Common\EventManager;
  4. use Tool\BaseTestCaseORM;
  5. use Doctrine\Common\Util\Debug,
  6. Sluggable\Fixture\Article;
  7. /**
  8. * These are tests for sluggable behavior
  9. *
  10. * @author Gediminas Morkevicius <gediminas.morkevicius@gmail.com>
  11. * @link http://www.gediminasm.org
  12. * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
  13. */
  14. class TransliterationTest extends BaseTestCaseORM
  15. {
  16. const ARTICLE = 'Sluggable\\Fixture\\Article';
  17. protected function setUp()
  18. {
  19. parent::setUp();
  20. $evm = new EventManager;
  21. $evm->addEventSubscriber(new SluggableListener);
  22. $this->getMockSqliteEntityManager($evm);
  23. $this->populate();
  24. }
  25. public function testInsertedNewSlug()
  26. {
  27. $repo = $this->em->getRepository(self::ARTICLE);
  28. $lithuanian = $repo->findOneByCode('lt');
  29. $this->assertEquals('transliteration-test-usage-uz-lt', $lithuanian->getSlug());
  30. $bulgarian = $repo->findOneByCode('bg');
  31. $this->assertEquals('tova-ie-tiestovo-zaghlaviie-bg', $bulgarian->getSlug());
  32. $russian = $repo->findOneByCode('ru');
  33. $this->assertEquals('eto-tiestovyi-zagholovok-ru', $russian->getSlug());
  34. $german = $repo->findOneByCode('de');
  35. $this->assertEquals('fuhren-aktivitaten-haglofs-de', $german->getSlug());
  36. }
  37. private function populate()
  38. {
  39. $lithuanian = new Article;
  40. $lithuanian->setTitle('trąnslįteration tėst ųsąge ūž');
  41. $lithuanian->setCode('lt');
  42. $bulgarian = new Article;
  43. $bulgarian->setTitle('това е тестово заглавие');
  44. $bulgarian->setCode('bg');
  45. $russian = new Article;
  46. $russian->setTitle('это тестовый заголовок');
  47. $russian->setCode('ru');
  48. $german = new Article;
  49. $german->setTitle('führen Aktivitäten Haglöfs');
  50. $german->setCode('de');
  51. $this->em->persist($lithuanian);
  52. $this->em->persist($bulgarian);
  53. $this->em->persist($russian);
  54. $this->em->persist($german);
  55. $this->em->flush();
  56. $this->em->clear();
  57. }
  58. protected function getUsedEntityFixtures()
  59. {
  60. return array(
  61. self::ARTICLE
  62. );
  63. }
  64. }