TranslationQueryWalkerTest.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641
  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. * @package Gedmo.Translatable
  14. * @link http://www.gediminasm.org
  15. * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
  16. */
  17. class TranslationQueryWalkerTest extends BaseTestCaseORM
  18. {
  19. const ARTICLE = 'Translatable\\Fixture\\Article';
  20. const COMMENT = 'Translatable\\Fixture\\Comment';
  21. const TRANSLATION = 'Gedmo\\Translatable\\Entity\\Translation';
  22. const TREE_WALKER_TRANSLATION = 'Gedmo\\Translatable\\Query\\TreeWalker\\TranslationWalker';
  23. private $translationListener;
  24. protected function setUp()
  25. {
  26. parent::setUp();
  27. $evm = new EventManager;
  28. $this->translationListener = new TranslationListener();
  29. $this->translationListener->setTranslatableLocale('en_us');
  30. $evm->addEventSubscriber($this->translationListener);
  31. $this->getMockSqliteEntityManager($evm);
  32. $this->populate();
  33. }
  34. public function testIssue135()
  35. {
  36. $this->populateIssue109();
  37. $query = $this->em->createQueryBuilder();
  38. $query->select('a')
  39. ->from(self::ARTICLE, 'a')
  40. ->add('where', $query->expr()->not($query->expr()->eq('a.title', ':title')))
  41. ->setParameter('title', 'NA')
  42. ;
  43. $this->translationListener->setTranslatableLocale('en');
  44. $this->translationListener->setDefaultLocale('en');
  45. $this->translationListener->setTranslationFallback(true);
  46. $query = $query->getQuery();
  47. $query->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, self::TREE_WALKER_TRANSLATION);
  48. $count = 0;
  49. str_replace("locale = 'en'", '', $query->getSql(), $count);
  50. $this->assertEquals(2, $count);
  51. }
  52. public function testIssue109()
  53. {
  54. $this->populateIssue109();
  55. $this->em
  56. ->getConfiguration()
  57. ->expects($this->any())
  58. ->method('getCustomHydrationMode')
  59. ->with(TranslationWalker::HYDRATE_OBJECT_TRANSLATION)
  60. ->will($this->returnValue('Gedmo\\Translatable\\Hydrator\\ORM\\ObjectHydrator'))
  61. ;
  62. $query = $this->em->createQueryBuilder();
  63. $query->select('a')
  64. ->from(self::ARTICLE, 'a')
  65. ->add('where', $query->expr()->not($query->expr()->eq('a.title', ':title')))
  66. ->setParameter('title', 'NA')
  67. ;
  68. $this->translationListener->setTranslatableLocale('es');
  69. $this->translationListener->setDefaultLocale('en');
  70. $this->translationListener->setTranslationFallback(true);
  71. $query = $query->getQuery();
  72. $query->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, self::TREE_WALKER_TRANSLATION);
  73. $result = $query->getResult();
  74. $this->assertEquals(3, count($result));
  75. }
  76. public function testSubselectByTranslatedField()
  77. {
  78. $this->populateMore();
  79. $dql = 'SELECT a FROM ' . self::ARTICLE . ' a';
  80. $subSelect = 'SELECT a2.title FROM ' . self::ARTICLE . ' a2';
  81. $subSelect .= " WHERE a2.title LIKE '%ab%'";
  82. $dql .= " WHERE a.title IN ({$subSelect})";
  83. $dql .= ' ORDER BY a.title';
  84. $q = $this->em->createQuery($dql);
  85. $q->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, self::TREE_WALKER_TRANSLATION);
  86. // array hydration
  87. $this->translationListener->setTranslatableLocale('en_us');
  88. $result = $q->getArrayResult();
  89. $this->assertEquals(2, count($result));
  90. $this->assertEquals('Alfabet', $result[0]['title']);
  91. $this->assertEquals('Cabbages', $result[1]['title']);
  92. }
  93. public function testSubselectStatements()
  94. {
  95. $this->populateMore();
  96. $dql = 'SELECT a FROM ' . self::ARTICLE . ' a';
  97. $subSelect = 'SELECT a2.id FROM ' . self::ARTICLE . ' a2';
  98. $subSelect .= " WHERE a2.title LIKE '%ab%'";
  99. $dql .= " WHERE a.id IN ({$subSelect})";
  100. $dql .= ' ORDER BY a.title';
  101. $q = $this->em->createQuery($dql);
  102. $q->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, self::TREE_WALKER_TRANSLATION);
  103. // array hydration
  104. $this->translationListener->setTranslatableLocale('en_us');
  105. $result = $q->getArrayResult();
  106. $this->assertEquals(2, count($result));
  107. $this->assertEquals('Alfabet', $result[0]['title']);
  108. $this->assertEquals('Cabbages', $result[1]['title']);
  109. }
  110. public function testJoinedWithStatements()
  111. {
  112. $this->populateMore();
  113. $dql = 'SELECT a, c FROM ' . self::ARTICLE . ' a';
  114. //@todo: its impossible to support translated values in WITH statement
  115. $dql .= ' LEFT JOIN a.comments c WITH c.subject LIKE :lookup';
  116. $dql .= ' WHERE a.title LIKE :filter';
  117. $dql .= ' ORDER BY a.title';
  118. $q = $this->em->createQuery($dql);
  119. $q->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, self::TREE_WALKER_TRANSLATION);
  120. // array hydration
  121. $this->translationListener->setTranslatableLocale('en_us');
  122. $q->setParameter('lookup', '%ger%');
  123. $q->setParameter('filter', 'Foo%');
  124. $result = $q->getArrayResult();
  125. $this->assertEquals(1, count($result));
  126. $this->assertEquals('Food', $result[0]['title']);
  127. $comments = $result[0]['comments'];
  128. $this->assertEquals(1, count($comments));
  129. $this->assertEquals('good', $comments[0]['subject']);
  130. }
  131. public function testSelectWithTranslationFallbackOnSimpleObjectHydration()
  132. {
  133. $this->em
  134. ->getConfiguration()
  135. ->expects($this->any())
  136. ->method('getCustomHydrationMode')
  137. ->with(TranslationWalker::HYDRATE_SIMPLE_OBJECT_TRANSLATION)
  138. ->will($this->returnValue('Gedmo\\Translatable\\Hydrator\\ORM\\SimpleObjectHydrator'));
  139. $dql = 'SELECT a FROM ' . self::ARTICLE . ' a';
  140. $q = $this->em->createQuery($dql);
  141. $q->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, self::TREE_WALKER_TRANSLATION);
  142. $this->translationListener->setTranslatableLocale('ru_ru');
  143. $this->translationListener->setTranslationFallback(false);
  144. // simple object hydration
  145. $this->startQueryLog();
  146. $result = $q->getResult(Query::HYDRATE_SIMPLEOBJECT);
  147. $this->assertEquals(1, $this->queryAnalyzer->getNumExecutedQueries());
  148. $this->assertEquals('', $result[0]->getTitle());
  149. $this->assertEquals('', $result[0]->getContent());
  150. $this->translationListener->setTranslationFallback(true);
  151. $this->queryAnalyzer->cleanUp();
  152. $result = $q->getResult(Query::HYDRATE_SIMPLEOBJECT);
  153. $this->assertEquals(1, $this->queryAnalyzer->getNumExecutedQueries());
  154. $this->assertEquals('Maistas', $result[0]->getTitle());
  155. $this->assertEquals('apie maista', $result[0]->getContent());
  156. }
  157. public function testSelectWithTranslationFallbackOnArrayHydration()
  158. {
  159. $this->em
  160. ->getConfiguration()
  161. ->expects($this->any())
  162. ->method('getCustomHydrationMode')
  163. ->with(TranslationWalker::HYDRATE_ARRAY_TRANSLATION)
  164. ->will($this->returnValue('Gedmo\\Translatable\\Hydrator\\ORM\\ArrayHydrator'));
  165. $dql = 'SELECT a, c FROM ' . self::ARTICLE . ' a';
  166. $dql .= ' LEFT JOIN a.comments c';
  167. $q = $this->em->createQuery($dql);
  168. $q->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, self::TREE_WALKER_TRANSLATION);
  169. $this->translationListener->setTranslatableLocale('ru_ru');
  170. $this->translationListener->setTranslationFallback(false);
  171. // array hydration
  172. $this->startQueryLog();
  173. $result = $q->getArrayResult();
  174. $this->assertEquals(1, $this->queryAnalyzer->getNumExecutedQueries());
  175. $this->assertEquals('', $result[0]['title']);
  176. $this->assertEquals('', $result[0]['content']);
  177. $this->translationListener->setTranslationFallback(true);
  178. $this->queryAnalyzer->cleanUp();
  179. $result = $q->getArrayResult();
  180. $this->assertEquals(1, $this->queryAnalyzer->getNumExecutedQueries());
  181. $this->assertEquals('Maistas', $result[0]['title']);
  182. $this->assertEquals('apie maista', $result[0]['content']);
  183. }
  184. public function testSelectWithTranslationFallbackOnObjectHydration()
  185. {
  186. $this->em
  187. ->getConfiguration()
  188. ->expects($this->any())
  189. ->method('getCustomHydrationMode')
  190. ->with(TranslationWalker::HYDRATE_OBJECT_TRANSLATION)
  191. ->will($this->returnValue('Gedmo\\Translatable\\Hydrator\\ORM\\ObjectHydrator'));
  192. $dql = 'SELECT a FROM ' . self::ARTICLE . ' a';
  193. $q = $this->em->createQuery($dql);
  194. $q->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, self::TREE_WALKER_TRANSLATION);
  195. $this->translationListener->setTranslatableLocale('ru_ru');
  196. $this->translationListener->setTranslationFallback(false);
  197. // object hydration
  198. $this->startQueryLog();
  199. $result = $q->getResult();
  200. $this->assertEquals(1, $this->queryAnalyzer->getNumExecutedQueries());
  201. $this->assertEquals('', $result[0]->getTitle());
  202. $this->assertEquals('', $result[0]->getContent());
  203. $this->translationListener->setTranslationFallback(true);
  204. $this->queryAnalyzer->cleanUp();
  205. $result = $q->getResult();
  206. $this->assertEquals(1, $this->queryAnalyzer->getNumExecutedQueries());
  207. $this->assertEquals('Maistas', $result[0]->getTitle());
  208. $this->assertEquals('apie maista', $result[0]->getContent());
  209. }
  210. public function testSelectCountStatement()
  211. {
  212. $dql = 'SELECT COUNT(a) FROM ' . self::ARTICLE . ' a';
  213. $dql .= ' WHERE a.title LIKE :title';
  214. $q = $this->em->createQuery($dql);
  215. $q->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, self::TREE_WALKER_TRANSLATION);
  216. $this->translationListener->setTranslatableLocale('en_us');
  217. $q->setParameter('title', 'Foo%');
  218. $result = $q->getSingleScalarResult();
  219. $this->assertEquals(1, $result);
  220. $this->translationListener->setTranslatableLocale('lt_lt');
  221. $q->setParameter('title', 'Mai%');
  222. $result = $q->getSingleScalarResult();
  223. $this->assertEquals(1, $result);
  224. $this->translationListener->setTranslatableLocale('en_us');
  225. $q->setParameter('title', 'Mai%');
  226. $result = $q->getSingleScalarResult();
  227. $this->assertEquals(0, $result);
  228. }
  229. public function testSelectOrderedJoinedComponentTranslation()
  230. {
  231. $this->em
  232. ->getConfiguration()
  233. ->expects($this->any())
  234. ->method('getCustomHydrationMode')
  235. ->with(TranslationWalker::HYDRATE_OBJECT_TRANSLATION)
  236. ->will($this->returnValue('Gedmo\\Translatable\\Hydrator\\ORM\\ObjectHydrator'));
  237. $this->populateMore();
  238. $dql = 'SELECT a, c FROM ' . self::ARTICLE . ' a';
  239. $dql .= ' LEFT JOIN a.comments c';
  240. $dql .= ' ORDER BY a.title';
  241. $q = $this->em->createQuery($dql);
  242. $q->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, self::TREE_WALKER_TRANSLATION);
  243. // array hydration
  244. $this->translationListener->setTranslatableLocale('en_us');
  245. $result = $q->getArrayResult();
  246. $this->assertEquals(4, count($result));
  247. $this->assertEquals('Alfabet', $result[0]['title']);
  248. $this->assertEquals('Cabbages', $result[1]['title']);
  249. $this->assertEquals('Food', $result[2]['title']);
  250. $this->assertEquals('Woman', $result[3]['title']);
  251. $this->translationListener->setTranslatableLocale('lt_lt');
  252. $result = $q->getArrayResult();
  253. $this->assertEquals(4, count($result));
  254. $this->assertEquals('Alfabetas', $result[0]['title']);
  255. $this->assertEquals('Kopustai', $result[1]['title']);
  256. $this->assertEquals('Maistas', $result[2]['title']);
  257. $this->assertEquals('Moteris', $result[3]['title']);
  258. // object hydration
  259. $this->translationListener->setTranslatableLocale('en_us');
  260. $result = $q->getResult();
  261. $this->assertEquals(4, count($result));
  262. $this->assertEquals('Alfabet', $result[0]->getTitle());
  263. $this->assertEquals('Cabbages', $result[1]->getTitle());
  264. $this->assertEquals('Food', $result[2]->getTitle());
  265. $this->assertEquals('Woman', $result[3]->getTitle());
  266. $this->translationListener->setTranslatableLocale('lt_lt');
  267. $result = $q->getResult();
  268. $this->assertEquals(4, count($result));
  269. $this->assertEquals('Alfabetas', $result[0]->getTitle());
  270. $this->assertEquals('Kopustai', $result[1]->getTitle());
  271. $this->assertEquals('Maistas', $result[2]->getTitle());
  272. $this->assertEquals('Moteris', $result[3]->getTitle());
  273. }
  274. public function testSelectSecondJoinedComponentTranslation()
  275. {
  276. $this->em
  277. ->getConfiguration()
  278. ->expects($this->any())
  279. ->method('getCustomHydrationMode')
  280. ->with(TranslationWalker::HYDRATE_OBJECT_TRANSLATION)
  281. ->will($this->returnValue('Gedmo\\Translatable\\Hydrator\\ORM\\ObjectHydrator'));
  282. $dql = 'SELECT a, c FROM ' . self::ARTICLE . ' a';
  283. $dql .= ' LEFT JOIN a.comments c';
  284. $q = $this->em->createQuery($dql);
  285. $q->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, self::TREE_WALKER_TRANSLATION);
  286. // array hydration
  287. $this->translationListener->setTranslatableLocale('en_us');
  288. $result = $q->getArrayResult();
  289. $this->assertEquals(1, count($result));
  290. $food = $result[0];
  291. $this->assertEquals(4, count($food));
  292. $this->assertEquals('Food', $food['title']);
  293. $this->assertEquals('about food', $food['content']);
  294. $comments = $food['comments'];
  295. $this->assertEquals(2, count($comments));
  296. $good = $comments[0];
  297. $this->assertEquals(3, count($good));
  298. $this->assertEquals('good', $good['subject']);
  299. $this->assertEquals('food is good', $good['message']);
  300. $bad = $comments[1];
  301. $this->assertEquals(3, count($bad));
  302. $this->assertEquals('bad', $bad['subject']);
  303. $this->assertEquals('food is bad', $bad['message']);
  304. $this->translationListener->setTranslatableLocale('lt_lt');
  305. $result = $q->getArrayResult();
  306. $this->assertEquals(1, count($result));
  307. $food = $result[0];
  308. $this->assertEquals(4, count($food));
  309. $this->assertEquals('Maistas', $food['title']);
  310. $this->assertEquals('apie maista', $food['content']);
  311. $comments = $food['comments'];
  312. $this->assertEquals(2, count($comments));
  313. $good = $comments[0];
  314. $this->assertEquals(3, count($good));
  315. $this->assertEquals('geras', $good['subject']);
  316. $this->assertEquals('maistas yra geras', $good['message']);
  317. $bad = $comments[1];
  318. $this->assertEquals(3, count($bad));
  319. $this->assertEquals('blogas', $bad['subject']);
  320. $this->assertEquals('maistas yra blogas', $bad['message']);
  321. // object hydration
  322. $this->translationListener->setTranslatableLocale('en_us');
  323. $result = $q->getResult();
  324. $this->assertEquals(1, count($result));
  325. $food = $result[0];
  326. $this->assertEquals('Food', $food->getTitle());
  327. $this->assertEquals('about food', $food->getContent());
  328. $comments = $food->getComments();
  329. $this->assertEquals(2, count($comments));
  330. $good = $comments[0];
  331. $this->assertEquals('good', $good->getSubject());
  332. $this->assertEquals('food is good', $good->getMessage());
  333. $bad = $comments[1];
  334. $this->assertEquals('bad', $bad->getSubject());
  335. $this->assertEquals('food is bad', $bad->getMessage());
  336. $this->translationListener->setTranslatableLocale('lt_lt');
  337. $result = $q->getResult();
  338. $this->assertEquals(1, count($result));
  339. $food = $result[0];
  340. $this->assertEquals('Maistas', $food->getTitle());
  341. $this->assertEquals('apie maista', $food->getContent());
  342. $comments = $food->getComments();
  343. $this->assertEquals(2, count($comments));
  344. $good = $comments[0];
  345. $this->assertInstanceOf(self::COMMENT, $good);
  346. $this->assertEquals('geras', $good->getSubject());
  347. $this->assertEquals('maistas yra geras', $good->getMessage());
  348. $bad = $comments[1];
  349. $this->assertEquals('blogas', $bad->getSubject());
  350. $this->assertEquals('maistas yra blogas', $bad->getMessage());
  351. }
  352. public function testSelectSinglePartializedComponentTranslation()
  353. {
  354. $this->em
  355. ->getConfiguration()
  356. ->expects($this->any())
  357. ->method('getCustomHydrationMode')
  358. ->with(TranslationWalker::HYDRATE_OBJECT_TRANSLATION)
  359. ->will($this->returnValue('Gedmo\\Translatable\\Hydrator\\ORM\\ObjectHydrator'));
  360. $dql = 'SELECT a.title FROM ' . self::ARTICLE . ' a';
  361. $q = $this->em->createQuery($dql);
  362. $q->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, self::TREE_WALKER_TRANSLATION);
  363. // array hydration
  364. $this->translationListener->setTranslatableLocale('en_us');
  365. $result = $q->getArrayResult();
  366. $this->assertEquals(1, count($result));
  367. $food = $result[0];
  368. $this->assertEquals(1, count($food));
  369. $this->assertEquals('Food', $food['title']);
  370. $this->translationListener->setTranslatableLocale('lt_lt');
  371. $result = $q->getArrayResult();
  372. $this->assertEquals(1, count($result));
  373. $food = $result[0];
  374. $this->assertEquals(1, count($food));
  375. $this->assertEquals('Maistas', $food['title']);
  376. // object hydration
  377. $this->translationListener->setTranslatableLocale('en_us');
  378. $result = $q->getResult();
  379. $this->assertEquals(1, count($result));
  380. $food = $result[0];
  381. $this->assertEquals(1, count($food));
  382. $this->assertEquals('Food', $food['title']);
  383. $this->translationListener->setTranslatableLocale('lt_lt');
  384. $result = $q->getResult();
  385. $this->assertEquals(1, count($result));
  386. $food = $result[0];
  387. $this->assertEquals(1, count($food));
  388. $this->assertEquals('Maistas', $food['title']);
  389. }
  390. public function testSelectSingleComponentTranslation()
  391. {
  392. $this->em
  393. ->getConfiguration()
  394. ->expects($this->any())
  395. ->method('getCustomHydrationMode')
  396. ->with(TranslationWalker::HYDRATE_OBJECT_TRANSLATION)
  397. ->will($this->returnValue('Gedmo\\Translatable\\Hydrator\\ORM\\ObjectHydrator'));
  398. $dql = 'SELECT a FROM ' . self::ARTICLE . ' a';
  399. $q = $this->em->createQuery($dql);
  400. $q->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, self::TREE_WALKER_TRANSLATION);
  401. // array hydration
  402. $this->translationListener->setTranslatableLocale('en_us');
  403. $result = $q->getArrayResult();
  404. $this->assertEquals(1, count($result));
  405. $food = $result[0];
  406. $this->assertEquals(3, count($food));
  407. $this->assertEquals('Food', $food['title']);
  408. $this->assertEquals('about food', $food['content']);
  409. $this->translationListener->setTranslatableLocale('lt_lt');
  410. $result = $q->getArrayResult();
  411. $this->assertEquals(1, count($result));
  412. $food = $result[0];
  413. $this->assertEquals(3, count($food));
  414. $this->assertEquals('Maistas', $food['title']);
  415. $this->assertEquals('apie maista', $food['content']);
  416. // object hydration
  417. $this->translationListener->setTranslatableLocale('en_us');
  418. $result = $q->getResult();
  419. $this->assertEquals(1, count($result));
  420. $food = $result[0];
  421. $this->assertInstanceOf(self::ARTICLE, $food);
  422. $this->assertEquals('Food', $food->getTitle());
  423. $this->assertEquals('about food', $food->getContent());
  424. $this->translationListener->setTranslatableLocale('lt_lt');
  425. $result = $q->getResult();
  426. $this->assertEquals(1, count($result));
  427. $food = $result[0];
  428. $this->assertEquals('Maistas', $food->getTitle());
  429. $this->assertEquals('apie maista', $food->getContent());
  430. }
  431. /**
  432. * @group testSelectWithUnmappedField
  433. */
  434. public function testSelectWithUnmappedField()
  435. {
  436. $dql = 'SELECT a.title, count(a.id) AS num FROM ' . self::ARTICLE . ' a';
  437. $dql .= ' ORDER BY a.title';
  438. $q = $this->em->createQuery($dql);
  439. $q->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, self::TREE_WALKER_TRANSLATION);
  440. // array hydration
  441. $this->translationListener->setTranslatableLocale('en_us');
  442. $result = $q->getArrayResult();
  443. $this->assertEquals(1, count($result));
  444. $this->assertEquals('Food', $result[0]['title']);
  445. $this->assertEquals(1, $result[0]['num']);
  446. }
  447. protected function getUsedEntityFixtures()
  448. {
  449. return array(
  450. self::ARTICLE,
  451. self::TRANSLATION,
  452. self::COMMENT
  453. );
  454. }
  455. private function populateMore()
  456. {
  457. $repo = $this->em->getRepository(self::ARTICLE);
  458. $commentRepo = $this->em->getRepository(self::COMMENT);
  459. $this->translationListener->setTranslatableLocale('en_us');
  460. $alfabet = new Article;
  461. $alfabet->setTitle('Alfabet');
  462. $alfabet->setContent('hey wtf!');
  463. $woman = new Article;
  464. $woman->setTitle('Woman');
  465. $woman->setContent('i like them');
  466. $cabbages = new Article;
  467. $cabbages->setTitle('Cabbages');
  468. $cabbages->setContent('where went the woman?');
  469. $this->em->persist($alfabet);
  470. $this->em->persist($woman);
  471. $this->em->persist($cabbages);
  472. $this->em->flush();
  473. $this->em->clear();
  474. $this->translationListener->setTranslatableLocale('lt_lt');
  475. $alfabet = $repo->find(2);
  476. $alfabet->setTitle('Alfabetas');
  477. $alfabet->setContent('ei wtf!');
  478. $woman = $repo->find(3);
  479. $woman->setTitle('Moteris');
  480. $woman->setContent('as megstu jas');
  481. $cabbages = $repo->find(4);
  482. $cabbages->setTitle('Kopustai');
  483. $cabbages->setContent('kur dingo moteris?');
  484. $this->em->persist($alfabet);
  485. $this->em->persist($woman);
  486. $this->em->persist($cabbages);
  487. $this->em->flush();
  488. $this->em->clear();
  489. }
  490. private function populate()
  491. {
  492. $repo = $this->em->getRepository(self::ARTICLE);
  493. $commentRepo = $this->em->getRepository(self::COMMENT);
  494. $food = new Article;
  495. $food->setTitle('Food');
  496. $food->setContent('about food');
  497. $goodFood = new Comment;
  498. $goodFood->setArticle($food);
  499. $goodFood->setMessage('food is good');
  500. $goodFood->setSubject('good');
  501. $badFood = new Comment;
  502. $badFood->setArticle($food);
  503. $badFood->setMessage('food is bad');
  504. $badFood->setSubject('bad');
  505. $this->em->persist($food);
  506. $this->em->persist($goodFood);
  507. $this->em->persist($badFood);
  508. $this->em->flush();
  509. $this->em->clear();
  510. $this->translationListener->setTranslatableLocale('lt_lt');
  511. $food = $repo->find(1);
  512. $food->setTitle('Maistas');
  513. $food->setContent('apie maista');
  514. $goodFood = $commentRepo->find(1);
  515. $goodFood->setArticle($food);
  516. $goodFood->setMessage('maistas yra geras');
  517. $goodFood->setSubject('geras');
  518. $badFood = $commentRepo->find(2);
  519. $badFood->setArticle($food);
  520. $badFood->setMessage('maistas yra blogas');
  521. $badFood->setSubject('blogas');
  522. $this->em->persist($food);
  523. $this->em->persist($goodFood);
  524. $this->em->persist($badFood);
  525. $this->em->flush();
  526. $this->em->clear();
  527. }
  528. public function populateIssue109()
  529. {
  530. $this->translationListener->setTranslatableLocale('en');
  531. $text0 = new Article;
  532. $text0->setTitle('text0');
  533. $this->em->persist($text0);
  534. $text1 = new Article;
  535. $text1->setTitle('text1');
  536. $this->em->persist($text1);
  537. $na = new Article;
  538. $na->setTitle('NA');
  539. $this->em->persist($na);
  540. $out = new Article;
  541. $out->setTitle('Out');
  542. $this->em->persist($out);
  543. $this->em->flush();
  544. $this->translationListener->setTranslatableLocale('es');
  545. $text1->setTitle('texto1');
  546. $text0->setTitle('texto0');
  547. $this->em->persist($text1);
  548. $this->em->persist($text0);
  549. $this->em->flush();
  550. }
  551. }