TranslationQueryWalkerTest.php 22 KB

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