TranslationQueryWalkerTest.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558
  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. public function testSelectWithTranslationFallbackOnObjectHydration()
  139. {
  140. $this->em
  141. ->getConfiguration()
  142. ->expects($this->any())
  143. ->method('getCustomHydrationMode')
  144. ->with(TranslationWalker::HYDRATE_OBJECT_TRANSLATION)
  145. ->will($this->returnValue('Gedmo\\Translatable\\Hydrator\\ORM\\ObjectHydrator'));
  146. $dql = 'SELECT a FROM ' . self::ARTICLE . ' a';
  147. $q = $this->em->createQuery($dql);
  148. $q->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, self::TREE_WALKER_TRANSLATION);
  149. $this->translationListener->setTranslatableLocale('ru_ru');
  150. $this->translationListener->setTranslationFallback(false);
  151. // object hydration
  152. $this->startQueryLog();
  153. $result = $q->getResult();
  154. $this->assertEquals(1, $this->queryAnalyzer->getNumExecutedQueries());
  155. $this->assertEquals('', $result[0]->getTitle());
  156. $this->assertEquals('', $result[0]->getContent());
  157. $this->translationListener->setTranslationFallback(true);
  158. $this->queryAnalyzer->cleanUp();
  159. $result = $q->getResult();
  160. $this->assertEquals(1, $this->queryAnalyzer->getNumExecutedQueries());
  161. //Default translation is en_us, so we expect the results in that locale
  162. $this->assertEquals('Food', $result[0]->getTitle());
  163. $this->assertEquals('about food', $result[0]->getContent());
  164. }
  165. public function testSelectCountStatement()
  166. {
  167. $dql = 'SELECT COUNT(a) FROM ' . self::ARTICLE . ' a';
  168. $dql .= ' WHERE a.title LIKE :title';
  169. $q = $this->em->createQuery($dql);
  170. $q->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, self::TREE_WALKER_TRANSLATION);
  171. $this->translationListener->setTranslatableLocale('en_us');
  172. $q->setParameter('title', 'Foo%');
  173. $result = $q->getSingleScalarResult();
  174. $this->assertEquals(1, $result);
  175. $this->translationListener->setTranslatableLocale('lt_lt');
  176. $q->setParameter('title', 'Mai%');
  177. $result = $q->getSingleScalarResult();
  178. $this->assertEquals(1, $result);
  179. $this->translationListener->setTranslatableLocale('en_us');
  180. $q->setParameter('title', 'Mai%');
  181. $result = $q->getSingleScalarResult();
  182. $this->assertEquals(0, $result);
  183. }
  184. public function testSelectOrderedJoinedComponentTranslation()
  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. $this->populateMore();
  193. $dql = 'SELECT a, c FROM ' . self::ARTICLE . ' a';
  194. $dql .= ' LEFT JOIN a.comments c';
  195. $dql .= ' ORDER BY a.title';
  196. $q = $this->em->createQuery($dql);
  197. $q->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, self::TREE_WALKER_TRANSLATION);
  198. // array hydration
  199. $this->translationListener->setTranslatableLocale('en_us');
  200. $result = $q->getArrayResult();
  201. $this->assertEquals(4, count($result));
  202. $this->assertEquals('Alfabet', $result[0]['title']);
  203. $this->assertEquals('Cabbages', $result[1]['title']);
  204. $this->assertEquals('Food', $result[2]['title']);
  205. $this->assertEquals('Woman', $result[3]['title']);
  206. $this->translationListener->setTranslatableLocale('lt_lt');
  207. $result = $q->getArrayResult();
  208. $this->assertEquals(4, count($result));
  209. $this->assertEquals('Alfabetas', $result[0]['title']);
  210. $this->assertEquals('Kopustai', $result[1]['title']);
  211. $this->assertEquals('Maistas', $result[2]['title']);
  212. $this->assertEquals('Moteris', $result[3]['title']);
  213. // object hydration
  214. $this->translationListener->setTranslatableLocale('en_us');
  215. $result = $q->getResult();
  216. $this->assertEquals(4, count($result));
  217. $this->assertEquals('Alfabet', $result[0]->getTitle());
  218. $this->assertEquals('Cabbages', $result[1]->getTitle());
  219. $this->assertEquals('Food', $result[2]->getTitle());
  220. $this->assertEquals('Woman', $result[3]->getTitle());
  221. $this->translationListener->setTranslatableLocale('lt_lt');
  222. $result = $q->getResult();
  223. $this->assertEquals(4, count($result));
  224. $this->assertEquals('Alfabetas', $result[0]->getTitle());
  225. $this->assertEquals('Kopustai', $result[1]->getTitle());
  226. $this->assertEquals('Maistas', $result[2]->getTitle());
  227. $this->assertEquals('Moteris', $result[3]->getTitle());
  228. }
  229. public function testSelectSecondJoinedComponentTranslation()
  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. $dql = 'SELECT a, c FROM ' . self::ARTICLE . ' a';
  238. $dql .= ' LEFT JOIN a.comments c';
  239. $q = $this->em->createQuery($dql);
  240. $q->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, self::TREE_WALKER_TRANSLATION);
  241. // array hydration
  242. $this->translationListener->setTranslatableLocale('en_us');
  243. $result = $q->getArrayResult();
  244. $this->assertEquals(1, count($result));
  245. $food = $result[0];
  246. $this->assertEquals(4, count($food));
  247. $this->assertEquals('Food', $food['title']);
  248. $this->assertEquals('about food', $food['content']);
  249. $comments = $food['comments'];
  250. $this->assertEquals(2, count($comments));
  251. $good = $comments[0];
  252. $this->assertEquals(3, count($good));
  253. $this->assertEquals('good', $good['subject']);
  254. $this->assertEquals('food is good', $good['message']);
  255. $bad = $comments[1];
  256. $this->assertEquals(3, count($bad));
  257. $this->assertEquals('bad', $bad['subject']);
  258. $this->assertEquals('food is bad', $bad['message']);
  259. $this->translationListener->setTranslatableLocale('lt_lt');
  260. $result = $q->getArrayResult();
  261. $this->assertEquals(1, count($result));
  262. $food = $result[0];
  263. $this->assertEquals(4, count($food));
  264. $this->assertEquals('Maistas', $food['title']);
  265. $this->assertEquals('apie maista', $food['content']);
  266. $comments = $food['comments'];
  267. $this->assertEquals(2, count($comments));
  268. $good = $comments[0];
  269. $this->assertEquals(3, count($good));
  270. $this->assertEquals('geras', $good['subject']);
  271. $this->assertEquals('maistas yra geras', $good['message']);
  272. $bad = $comments[1];
  273. $this->assertEquals(3, count($bad));
  274. $this->assertEquals('blogas', $bad['subject']);
  275. $this->assertEquals('maistas yra blogas', $bad['message']);
  276. // object hydration
  277. $this->translationListener->setTranslatableLocale('en_us');
  278. $result = $q->getResult();
  279. $this->assertEquals(1, count($result));
  280. $food = $result[0];
  281. $this->assertEquals('Food', $food->getTitle());
  282. $this->assertEquals('about food', $food->getContent());
  283. $comments = $food->getComments();
  284. $this->assertEquals(2, count($comments));
  285. $good = $comments[0];
  286. $this->assertEquals('good', $good->getSubject());
  287. $this->assertEquals('food is good', $good->getMessage());
  288. $bad = $comments[1];
  289. $this->assertEquals('bad', $bad->getSubject());
  290. $this->assertEquals('food is bad', $bad->getMessage());
  291. $this->translationListener->setTranslatableLocale('lt_lt');
  292. $result = $q->getResult();
  293. $this->assertEquals(1, count($result));
  294. $food = $result[0];
  295. $this->assertEquals('Maistas', $food->getTitle());
  296. $this->assertEquals('apie maista', $food->getContent());
  297. $comments = $food->getComments();
  298. $this->assertEquals(2, count($comments));
  299. $good = $comments[0];
  300. $this->assertInstanceOf(self::COMMENT, $good);
  301. $this->assertEquals('geras', $good->getSubject());
  302. $this->assertEquals('maistas yra geras', $good->getMessage());
  303. $bad = $comments[1];
  304. $this->assertEquals('blogas', $bad->getSubject());
  305. $this->assertEquals('maistas yra blogas', $bad->getMessage());
  306. }
  307. public function testSelectSinglePartializedComponentTranslation()
  308. {
  309. $this->em
  310. ->getConfiguration()
  311. ->expects($this->any())
  312. ->method('getCustomHydrationMode')
  313. ->with(TranslationWalker::HYDRATE_OBJECT_TRANSLATION)
  314. ->will($this->returnValue('Gedmo\\Translatable\\Hydrator\\ORM\\ObjectHydrator'));
  315. $dql = 'SELECT a.title FROM ' . self::ARTICLE . ' a';
  316. $q = $this->em->createQuery($dql);
  317. $q->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, self::TREE_WALKER_TRANSLATION);
  318. // array hydration
  319. $this->translationListener->setTranslatableLocale('en_us');
  320. $result = $q->getArrayResult();
  321. $this->assertEquals(1, count($result));
  322. $food = $result[0];
  323. $this->assertEquals(1, count($food));
  324. $this->assertEquals('Food', $food['title']);
  325. $this->translationListener->setTranslatableLocale('lt_lt');
  326. $result = $q->getArrayResult();
  327. $this->assertEquals(1, count($result));
  328. $food = $result[0];
  329. $this->assertEquals(1, count($food));
  330. $this->assertEquals('Maistas', $food['title']);
  331. // object hydration
  332. $this->translationListener->setTranslatableLocale('en_us');
  333. $result = $q->getResult();
  334. $this->assertEquals(1, count($result));
  335. $food = $result[0];
  336. $this->assertEquals(1, count($food));
  337. $this->assertEquals('Food', $food['title']);
  338. $this->translationListener->setTranslatableLocale('lt_lt');
  339. $result = $q->getResult();
  340. $this->assertEquals(1, count($result));
  341. $food = $result[0];
  342. $this->assertEquals(1, count($food));
  343. $this->assertEquals('Maistas', $food['title']);
  344. }
  345. public function testSelectSingleComponentTranslation()
  346. {
  347. $this->em
  348. ->getConfiguration()
  349. ->expects($this->any())
  350. ->method('getCustomHydrationMode')
  351. ->with(TranslationWalker::HYDRATE_OBJECT_TRANSLATION)
  352. ->will($this->returnValue('Gedmo\\Translatable\\Hydrator\\ORM\\ObjectHydrator'));
  353. $dql = 'SELECT a FROM ' . self::ARTICLE . ' a';
  354. $q = $this->em->createQuery($dql);
  355. $q->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, self::TREE_WALKER_TRANSLATION);
  356. // array hydration
  357. $this->translationListener->setTranslatableLocale('en_us');
  358. $result = $q->getArrayResult();
  359. $this->assertEquals(1, count($result));
  360. $food = $result[0];
  361. $this->assertEquals(3, count($food));
  362. $this->assertEquals('Food', $food['title']);
  363. $this->assertEquals('about food', $food['content']);
  364. $this->translationListener->setTranslatableLocale('lt_lt');
  365. $result = $q->getArrayResult();
  366. $this->assertEquals(1, count($result));
  367. $food = $result[0];
  368. $this->assertEquals(3, count($food));
  369. $this->assertEquals('Maistas', $food['title']);
  370. $this->assertEquals('apie maista', $food['content']);
  371. // object hydration
  372. $this->translationListener->setTranslatableLocale('en_us');
  373. $result = $q->getResult();
  374. $this->assertEquals(1, count($result));
  375. $food = $result[0];
  376. $this->assertInstanceOf(self::ARTICLE, $food);
  377. $this->assertEquals('Food', $food->getTitle());
  378. $this->assertEquals('about food', $food->getContent());
  379. $this->translationListener->setTranslatableLocale('lt_lt');
  380. $result = $q->getResult();
  381. $this->assertEquals(1, count($result));
  382. $food = $result[0];
  383. $this->assertEquals('Maistas', $food->getTitle());
  384. $this->assertEquals('apie maista', $food->getContent());
  385. }
  386. /**
  387. * @group testSelectWithUnmappedField
  388. */
  389. public function testSelectWithUnmappedField()
  390. {
  391. $dql = 'SELECT a.title, count(a.id) AS num FROM ' . self::ARTICLE . ' a';
  392. $dql .= ' ORDER BY a.title';
  393. $q = $this->em->createQuery($dql);
  394. $q->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, self::TREE_WALKER_TRANSLATION);
  395. // array hydration
  396. $this->translationListener->setTranslatableLocale('en_us');
  397. $result = $q->getArrayResult();
  398. $this->assertEquals(1, count($result));
  399. $this->assertEquals('Food', $result[0]['title']);
  400. $this->assertEquals(1, $result[0]['num']);
  401. }
  402. protected function getUsedEntityFixtures()
  403. {
  404. return array(
  405. self::ARTICLE,
  406. self::TRANSLATION,
  407. self::COMMENT
  408. );
  409. }
  410. private function populateMore()
  411. {
  412. $repo = $this->em->getRepository(self::ARTICLE);
  413. $commentRepo = $this->em->getRepository(self::COMMENT);
  414. $this->translationListener->setTranslatableLocale('en_us');
  415. $alfabet = new Article;
  416. $alfabet->setTitle('Alfabet');
  417. $alfabet->setContent('hey wtf!');
  418. $woman = new Article;
  419. $woman->setTitle('Woman');
  420. $woman->setContent('i like them');
  421. $cabbages = new Article;
  422. $cabbages->setTitle('Cabbages');
  423. $cabbages->setContent('where went the woman?');
  424. $this->em->persist($alfabet);
  425. $this->em->persist($woman);
  426. $this->em->persist($cabbages);
  427. $this->em->flush();
  428. $this->em->clear();
  429. $this->translationListener->setTranslatableLocale('lt_lt');
  430. $alfabet = $repo->find(2);
  431. $alfabet->setTitle('Alfabetas');
  432. $alfabet->setContent('ei wtf!');
  433. $woman = $repo->find(3);
  434. $woman->setTitle('Moteris');
  435. $woman->setContent('as megstu jas');
  436. $cabbages = $repo->find(4);
  437. $cabbages->setTitle('Kopustai');
  438. $cabbages->setContent('kur dingo moteris?');
  439. $this->em->persist($alfabet);
  440. $this->em->persist($woman);
  441. $this->em->persist($cabbages);
  442. $this->em->flush();
  443. $this->em->clear();
  444. }
  445. private function populate()
  446. {
  447. $repo = $this->em->getRepository(self::ARTICLE);
  448. $commentRepo = $this->em->getRepository(self::COMMENT);
  449. $food = new Article;
  450. $food->setTitle('Food');
  451. $food->setContent('about food');
  452. $goodFood = new Comment;
  453. $goodFood->setArticle($food);
  454. $goodFood->setMessage('food is good');
  455. $goodFood->setSubject('good');
  456. $badFood = new Comment;
  457. $badFood->setArticle($food);
  458. $badFood->setMessage('food is bad');
  459. $badFood->setSubject('bad');
  460. $this->em->persist($food);
  461. $this->em->persist($goodFood);
  462. $this->em->persist($badFood);
  463. $this->em->flush();
  464. $this->em->clear();
  465. $this->translationListener->setTranslatableLocale('lt_lt');
  466. $food = $repo->find(1);
  467. $food->setTitle('Maistas');
  468. $food->setContent('apie maista');
  469. $goodFood = $commentRepo->find(1);
  470. $goodFood->setArticle($food);
  471. $goodFood->setMessage('maistas yra geras');
  472. $goodFood->setSubject('geras');
  473. $badFood = $commentRepo->find(2);
  474. $badFood->setArticle($food);
  475. $badFood->setMessage('maistas yra blogas');
  476. $badFood->setSubject('blogas');
  477. $this->em->persist($food);
  478. $this->em->persist($goodFood);
  479. $this->em->persist($badFood);
  480. $this->em->flush();
  481. $this->em->clear();
  482. }
  483. }