TranslationQueryWalkerTest.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613
  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. $this->translationListener->setDefaultLocale('en_us');
  31. $evm->addEventSubscriber($this->translationListener);
  32. $this->getMockSqliteEntityManager($evm);
  33. $this->populate();
  34. }
  35. public function testSubselectByTranslatedField()
  36. {
  37. $this->populateMore();
  38. $dql = 'SELECT a FROM ' . self::ARTICLE . ' a';
  39. $subSelect = 'SELECT a2.title FROM ' . self::ARTICLE . ' a2';
  40. $subSelect .= " WHERE a2.title LIKE '%ab%'";
  41. $dql .= " WHERE a.title IN ({$subSelect})";
  42. $dql .= ' ORDER BY a.title';
  43. $q = $this->em->createQuery($dql);
  44. $q->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, self::TREE_WALKER_TRANSLATION);
  45. // array hydration
  46. $this->translationListener->setTranslatableLocale('en_us');
  47. $result = $q->getArrayResult();
  48. $this->assertEquals(2, count($result));
  49. $this->assertEquals('Alfabet', $result[0]['title']);
  50. $this->assertEquals('Cabbages', $result[1]['title']);
  51. }
  52. public function testSubselectStatements()
  53. {
  54. $this->populateMore();
  55. $dql = 'SELECT a FROM ' . self::ARTICLE . ' a';
  56. $subSelect = 'SELECT a2.id FROM ' . self::ARTICLE . ' a2';
  57. $subSelect .= " WHERE a2.title LIKE '%ab%'";
  58. $dql .= " WHERE a.id IN ({$subSelect})";
  59. $dql .= ' ORDER BY a.title';
  60. $q = $this->em->createQuery($dql);
  61. $q->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, self::TREE_WALKER_TRANSLATION);
  62. // array hydration
  63. $this->translationListener->setTranslatableLocale('en_us');
  64. $result = $q->getArrayResult();
  65. $this->assertEquals(2, count($result));
  66. $this->assertEquals('Alfabet', $result[0]['title']);
  67. $this->assertEquals('Cabbages', $result[1]['title']);
  68. }
  69. public function testJoinedWithStatements()
  70. {
  71. $this->populateMore();
  72. $dql = 'SELECT a, c FROM ' . self::ARTICLE . ' a';
  73. $dql .= ' LEFT JOIN a.comments c WITH c.subject LIKE :lookup';
  74. $dql .= ' WHERE a.title LIKE :filter';
  75. $dql .= ' ORDER BY a.title';
  76. $q = $this->em->createQuery($dql);
  77. $q->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, self::TREE_WALKER_TRANSLATION);
  78. // array hydration
  79. $this->translationListener->setTranslatableLocale('en_us');
  80. $q->setParameter('lookup', '%goo%');
  81. $q->setParameter('filter', 'Foo%');
  82. $result = $q->getArrayResult();
  83. $this->assertEquals(1, count($result));
  84. $this->assertEquals('Food', $result[0]['title']);
  85. $comments = $result[0]['comments'];
  86. $this->assertEquals(1, count($comments));
  87. $this->assertEquals('good', $comments[0]['subject']);
  88. }
  89. public function testSelectWithTranslationFallbackOnSimpleObjectHydration()
  90. {
  91. $this->em
  92. ->getConfiguration()
  93. ->expects($this->any())
  94. ->method('getCustomHydrationMode')
  95. ->with(TranslationWalker::HYDRATE_SIMPLE_OBJECT_TRANSLATION)
  96. ->will($this->returnValue('Gedmo\\Translatable\\Hydrator\\ORM\\SimpleObjectHydrator'));
  97. $dql = 'SELECT a FROM ' . self::ARTICLE . ' a';
  98. $q = $this->em->createQuery($dql);
  99. $q->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, self::TREE_WALKER_TRANSLATION);
  100. $this->translationListener->setTranslatableLocale('ru_ru');
  101. $this->translationListener->setTranslationFallback(false);
  102. // simple object hydration
  103. $this->startQueryLog();
  104. $result = $q->getResult(Query::HYDRATE_SIMPLEOBJECT);
  105. $this->assertEquals(1, $this->queryAnalyzer->getNumExecutedQueries());
  106. $this->assertEquals('', $result[0]->getTitle());
  107. $this->assertEquals('', $result[0]->getContent());
  108. $this->translationListener->setTranslationFallback(true);
  109. $this->queryAnalyzer->cleanUp();
  110. $result = $q->getResult(Query::HYDRATE_SIMPLEOBJECT);
  111. $this->assertEquals(1, $this->queryAnalyzer->getNumExecutedQueries());
  112. //Default translation is en_us, so we expect the results in that locale
  113. $this->assertEquals('Food', $result[0]->getTitle());
  114. $this->assertEquals('about food', $result[0]->getContent());
  115. }
  116. public function testSelectWithTranslationFallbackOnArrayHydration()
  117. {
  118. $dql = 'SELECT a, c FROM ' . self::ARTICLE . ' a';
  119. $dql .= ' LEFT JOIN a.comments c';
  120. $q = $this->em->createQuery($dql);
  121. $q->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, self::TREE_WALKER_TRANSLATION);
  122. $this->translationListener->setTranslatableLocale('ru_ru');
  123. $this->translationListener->setTranslationFallback(false);
  124. // array hydration
  125. $this->startQueryLog();
  126. $result = $q->getArrayResult();
  127. $this->assertEquals(1, $this->queryAnalyzer->getNumExecutedQueries());
  128. $this->assertEquals('', $result[0]['title']);
  129. $this->assertEquals('', $result[0]['content']);
  130. $this->translationListener->setTranslationFallback(true);
  131. $this->queryAnalyzer->cleanUp();
  132. $result = $q->getArrayResult();
  133. $this->assertEquals(1, $this->queryAnalyzer->getNumExecutedQueries());
  134. //Default translation is en_us, so we expect the results in that locale
  135. $this->assertEquals('Food', $result[0]['title']);
  136. $this->assertEquals('about food', $result[0]['content']);
  137. }
  138. /**
  139. * @test
  140. */
  141. public function shouldBeAbleToUseInnerJoinStrategyForTranslations()
  142. {
  143. $dql = 'SELECT a FROM ' . self::ARTICLE . ' a';
  144. $q = $this->em->createQuery($dql);
  145. $q->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, self::TREE_WALKER_TRANSLATION);
  146. $q->setHint(TranslationListener::HINT_INNER_JOIN, true);
  147. $this->translationListener->setTranslatableLocale('ru_ru');
  148. $this->translationListener->setTranslationFallback(false);
  149. // array hydration
  150. $result = $q->getArrayResult();
  151. $this->assertEquals(0, count($result));
  152. }
  153. /**
  154. * @test
  155. */
  156. public function shouldBeAbleToOverrideTranslatableLocale()
  157. {
  158. $dql = 'SELECT a FROM ' . self::ARTICLE . ' a';
  159. $q = $this->em->createQuery($dql);
  160. $q->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, self::TREE_WALKER_TRANSLATION);
  161. $q->setHint(TranslationListener::HINT_TRANSLATABLE_LOCALE, 'lt_lt');
  162. $this->translationListener->setTranslatableLocale('ru_ru');
  163. $this->translationListener->setTranslationFallback(false);
  164. // array hydration
  165. $result = $q->getArrayResult();
  166. $this->assertEquals(1, count($result));
  167. $this->assertEquals('Maistas', $result[0]['title']);
  168. }
  169. public function testSelectWithTranslationFallbackOnObjectHydration()
  170. {
  171. $this->em
  172. ->getConfiguration()
  173. ->expects($this->any())
  174. ->method('getCustomHydrationMode')
  175. ->with(TranslationWalker::HYDRATE_OBJECT_TRANSLATION)
  176. ->will($this->returnValue('Gedmo\\Translatable\\Hydrator\\ORM\\ObjectHydrator'));
  177. $dql = 'SELECT a FROM ' . self::ARTICLE . ' a';
  178. $q = $this->em->createQuery($dql);
  179. $q->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, self::TREE_WALKER_TRANSLATION);
  180. $this->translationListener->setTranslatableLocale('ru_ru');
  181. $this->translationListener->setTranslationFallback(false);
  182. // object hydration
  183. $this->startQueryLog();
  184. $result = $q->getResult();
  185. $this->assertEquals(1, $this->queryAnalyzer->getNumExecutedQueries());
  186. $this->assertEquals('', $result[0]->getTitle());
  187. $this->assertEquals('', $result[0]->getContent());
  188. $this->translationListener->setTranslationFallback(true);
  189. $this->queryAnalyzer->cleanUp();
  190. $result = $q->getResult();
  191. $this->assertEquals(1, $this->queryAnalyzer->getNumExecutedQueries());
  192. //Default translation is en_us, so we expect the results in that locale
  193. $this->assertEquals('Food', $result[0]->getTitle());
  194. $this->assertEquals('about food', $result[0]->getContent());
  195. // test fallback hint
  196. $this->translationListener->setTranslationFallback(false);
  197. $q->setHint(TranslationListener::HINT_FALLBACK, 1);
  198. $result = $q->getResult();
  199. //Default translation is en_us, so we expect the results in that locale
  200. $this->assertEquals('Food', $result[0]->getTitle());
  201. $this->assertEquals('about food', $result[0]->getContent());
  202. // test fallback hint
  203. $this->translationListener->setTranslationFallback(true);
  204. $q->setHint(TranslationListener::HINT_FALLBACK, 0);
  205. $result = $q->getResult();
  206. //Default translation is en_us, so we expect the results in that locale
  207. $this->assertEquals('', $result[0]->getTitle());
  208. $this->assertEquals('', $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. }