public function testTranslatableWhereOnTranslatableCollectionWithArrayAndDifferentDefaultLocale() { $this->_translatableListener->setLocale($this->_languagePl); $this->_translatableListener->setDefaultLocale($this->_languageEn); $comment1 = new Comment(); $comment1->setId(1); $comment2 = new Comment(); $comment2->setId(2); $whereComments = array($comment1, $comment2); $qb = new QueryBuilder($this->_em); $qb->select('a'); $qb->from(self::ARTICLE, 'a'); $qb->addTranslatableWhere('a', 'comments', $whereComments); $this->assertEquals($this->normalizeDql(sprintf(' SELECT a FROM %s a LEFT JOIN a.translations atranslationspl WITH atranslationspl.locale = :atranslationsplloc LEFT JOIN a.translations atranslationsen WITH atranslationsen.locale = :atranslationsenloc LEFT JOIN atranslationspl.comments atranslationsplcommentsjoin LEFT JOIN atranslationsen.comments atranslationsencommentsjoin WHERE CASE WHEN atranslationspl.id IS NOT NULL AND atranslationsplcommentsjoin IN(:acommentsval) THEN TRUE WHEN atranslationsencommentsjoin IN(:acommentsval) THEN TRUE ELSE FALSE END = TRUE', self::ARTICLE)), $qb->getDQL()); $this->assertEquals($this->_languagePl, $qb->getParameter('atranslationsplloc')->getValue()); $this->assertEquals($this->_languageEn, $qb->getParameter('atranslationsenloc')->getValue()); $this->assertEquals($whereComments, $qb->getParameter('acommentsval')->getValue()); $qb->getQuery()->execute(); }
private function fillDataForFindTranslatable() { /** @var \FSi\DoctrineExtensions\Translatable\Entity\Repository\TranslatableRepository $repository */ $repository = $this->_em->getRepository(self::ARTICLE); $article1 = new Article(); $this->_em->persist($article1); $article1->setDate(new \DateTime('2014-01-01 00:00:00')); $translationEn = $repository->getTranslation($article1, $this->_languageEn); $translationEn->setTitle(self::ENGLISH_TITLE_1); $translationEn->setIntroduction(self::ENGLISH_TEASER); $translationEn->setContents(self::ENGLISH_CONTENTS_1); $this->_em->persist($translationEn); $article2 = new Article(); $this->_em->persist($article2); $article2->setDate(new \DateTime('2014-02-02 00:00:00')); $translationPl = $repository->getTranslation($article2, $this->_languagePl); $translationPl->setTitle(self::POLISH_TITLE_1); $translationPl->setIntroduction(self::POLISH_TEASER); $translationPl->setContents(self::POLISH_CONTENTS_1); $this->_em->persist($translationPl); $category1 = new Category(); $category1->setTitle(self::CATEGORY_1); $article1->addCategory($category1); $article2->addCategory($category1); $this->_em->persist($category1); $section = new Section(); $section->setTitle(self::SECTION_1); $article1->setSection($section); $article2->setSection($section); $this->_em->persist($section); $comment = new Comment(); $comment->setContent('Lorem'); $comment->setDate(new \DateTime()); $comment->setArticleTranslation($translationPl); $this->_em->persist($comment); $comment = new Comment(); $comment->setContent('Ipsum'); $comment->setDate(new \DateTime()); $comment->setArticleTranslation($translationPl); $this->_em->persist($comment); $this->_em->flush(); $this->_em->refresh($article1); $this->_em->refresh($article2); }