TranslationQueryWalkerTest.php 24 KB

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