Issue135Test.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <?php
  2. namespace Gedmo\Translatable;
  3. use Doctrine\Common\EventManager;
  4. use Tool\BaseTestCaseORM;
  5. use Doctrine\ORM\Query;
  6. use Gedmo\Translatable\Query\TreeWalker\TranslationWalker;
  7. use Translatable\Fixture\Article;
  8. use Translatable\Fixture\Comment;
  9. /**
  10. * These are tests for translation query walker
  11. *
  12. * @author Gediminas Morkevicius <gediminas.morkevicius@gmail.com>
  13. * @link http://www.gediminasm.org
  14. * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
  15. */
  16. class Issue135Test extends BaseTestCaseORM
  17. {
  18. const ARTICLE = 'Translatable\\Fixture\\Article';
  19. const COMMENT = 'Translatable\\Fixture\\Comment';
  20. const TRANSLATION = 'Gedmo\\Translatable\\Entity\\Translation';
  21. const TREE_WALKER_TRANSLATION = 'Gedmo\\Translatable\\Query\\TreeWalker\\TranslationWalker';
  22. private $translatableListener;
  23. protected function setUp()
  24. {
  25. parent::setUp();
  26. $evm = new EventManager;
  27. $this->translatableListener = new TranslatableListener();
  28. $this->translatableListener->setTranslatableLocale('en_us');
  29. $this->translatableListener->setDefaultLocale('en_us');
  30. $evm->addEventSubscriber($this->translatableListener);
  31. $this->getMockSqliteEntityManager($evm);
  32. $this->populate();
  33. }
  34. public function testIssue135()
  35. {
  36. $query = $this->em->createQueryBuilder();
  37. $query->select('a')
  38. ->from(self::ARTICLE, 'a')
  39. ->add('where', $query->expr()->not($query->expr()->eq('a.title', ':title')))
  40. ->setParameter('title', 'NA')
  41. ;
  42. $this->translatableListener->setTranslatableLocale('en');
  43. $this->translatableListener->setTranslationFallback(true);
  44. $query = $query->getQuery();
  45. $query->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, self::TREE_WALKER_TRANSLATION);
  46. $count = 0;
  47. str_replace("locale = 'en'", '', $query->getSql(), $count);
  48. $this->assertEquals(0, $count);
  49. }
  50. protected function getUsedEntityFixtures()
  51. {
  52. return array(
  53. self::ARTICLE,
  54. self::TRANSLATION,
  55. self::COMMENT
  56. );
  57. }
  58. public function populate()
  59. {
  60. $this->translatableListener->setTranslatableLocale('en');
  61. $this->translatableListener->setDefaultLocale('en');
  62. $text0 = new Article;
  63. $text0->setTitle('text0');
  64. $this->em->persist($text0);
  65. $text1 = new Article;
  66. $text1->setTitle('text1');
  67. $this->em->persist($text1);
  68. $na = new Article;
  69. $na->setTitle('NA');
  70. $this->em->persist($na);
  71. $out = new Article;
  72. $out->setTitle('Out');
  73. $this->em->persist($out);
  74. $this->em->flush();
  75. $this->translatableListener->setTranslatableLocale('es');
  76. $text1->setTitle('texto1');
  77. $text0->setTitle('texto0');
  78. $this->em->persist($text1);
  79. $this->em->persist($text0);
  80. $this->em->flush();
  81. }
  82. }