Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Demonstrate expected behaviour for QueryBuilder::setLocale #607

Open
wants to merge 1 commit into
base: 2.x
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<?php

namespace Doctrine\Tests\ODM\PHPCR\Functional;

use Doctrine\ODM\PHPCR\DocumentRepository;
use Doctrine\ODM\PHPCR\Translation\LocaleChooser\LocaleChooser;
use Doctrine\Tests\Models\Translation\Article;
use Doctrine\Tests\ODM\PHPCR\PHPCRFunctionalTestCase;
use PHPCR\Util\PathHelper;
use PHPCR\Util\NodeHelper;

/**
* @group functional
*/
class QueryBuilderTranslationTest extends PHPCRFunctionalTestCase
{
/**
* @var \Doctrine\ODM\PHPCR\DocumentManager
*/
protected $dm;

/**
* @var \PHPCR\NodeInterface
*/
protected $node;

public function setUp()
{
$this->dm = $this->createDocumentManager();
$this->dm->setLocaleChooserStrategy(new LocaleChooser(array('en' => array('de'), 'de' => array('en')), 'en'));

$this->resetFunctionalNode($this->dm);


$article = new Article();
$article->id = '/functional/article';
$article->author = 'John Doe';
$article->topic = 'Some interesting subject';
$article->text = 'Lorem ipsum...';

$this->dm->persist($article);
$this->dm->bindTranslation($article, 'en');

$article->topic = 'Ein interessantes Thema';
$article->text = 'Lorem ipsum...';

$this->dm->bindTranslation($article, 'de');

$this->dm->flush();
}

protected function createQb()
{
$qb = $this->dm->createQueryBuilder();
return $qb;
}

public function testFindDe()
{
$de = $this->dm->findTranslation(null, '/functional/article', 'de');

$this->assertEquals('Ein interessantes Thema', $de->topic);
}

public function testFindEn()
{
$en = $this->dm->findTranslation(null, '/functional/article', 'en');

$this->assertEquals('Some interesting subject', $en->topic);
}

public function testDeQuery()
{
$qb = $this->createQb();
$qb->from()->document('Doctrine\Tests\Models\Translation\Article', 'a');
$qb->setLocale('de');
$res = $qb->getQuery()->execute();

$this->assertEquals('Ein interessantes Thema', $res->first()->topic);
}

public function testEnQuery()
{
$qb = $this->createQb();
$qb->from()->document('Doctrine\Tests\Models\Translation\Article', 'a');
$qb->setLocale('en');
$res = $qb->getQuery()->execute();

$this->assertEquals('Some interesting subject', $res->first()->topic);
}

}