public function setUp()
 {
     $this->listener = new ChangesetListener();
     $this->dm = $this->createDocumentManager();
     $this->dm->setLocaleChooserStrategy(new LocaleChooser(array('en' => array('fr'), 'fr' => array('en')), 'en'));
     $this->node = $this->resetFunctionalNode($this->dm);
 }
Ejemplo n.º 2
0
 public function testComputingBetweenEventsWithTranslation()
 {
     $this->dm->getEventManager()->addEventListener(array(Event::preCreateTranslation, Event::postLoadTranslation, Event::preRemoveTranslation, Event::postRemoveTranslation), $this->listener);
     $this->dm->setLocaleChooserStrategy(new LocaleChooser($this->localePrefs, 'en'));
     // Create initial user
     $user = new \Doctrine\Tests\Models\CMS\CmsUserTranslatable();
     $user->name = 'mdekrijger';
     $user->username = '******';
     $user->status = 'active';
     $this->dm->persist($user);
     $this->dm->flush();
     $this->dm->clear();
     $user = $this->dm->findTranslation('Doctrine\\Tests\\Models\\CMS\\CmsUserTranslatable', $user->id, 'en');
     // username should be changed after loading the translation
     $this->assertEquals('loadTranslation', $user->username);
     // name had been changed pre binding translation
     $this->assertEquals('preCreateTranslation', $user->name);
     $this->dm->name = 'neuer Name';
     $this->dm->bindTranslation($user, 'de');
     $this->dm->flush();
     $this->dm->clear();
     $user = $this->dm->findTranslation('Doctrine\\Tests\\Models\\CMS\\CmsUserTranslatable', $user->id, 'en');
     $this->dm->removeTranslation($user, 'en');
     $this->assertEquals('preRemoveTranslation', $user->name);
     $this->dm->flush();
     $this->dm->clear();
     $this->assertEquals('postRemoveTranslation', $user->username);
 }
Ejemplo n.º 3
0
 public function setUp()
 {
     $this->dm = $this->createDocumentManager();
     $this->dm->setLocaleChooserStrategy(new LocaleChooser($this->localePrefs, 'en'));
     $this->node = $this->resetFunctionalNode($this->dm);
     $this->dm->clear();
     $this->session = $this->dm->getPhpcrSession();
     $this->metadata = $this->dm->getClassMetadata($this->class);
     $this->doc = new Article();
     $this->doc->id = '/functional/' . $this->testNodeName;
     $this->doc->author = 'John Doe';
     $this->doc->topic = 'Some interesting subject';
     $this->doc->setText('Lorem ipsum...');
     $this->doc->setSettings(array());
     $this->doc->assoc = array('key' => 'value');
 }
 public function setUp()
 {
     $this->type = 'Doctrine\\Tests\\Models\\Translation\\Article';
     $this->dm = $this->createDocumentManager();
     $this->dm->setLocaleChooserStrategy(new LocaleChooser(array('en' => array('fr'), 'fr' => array('en')), 'en'));
     $this->node = $this->resetFunctionalNode($this->dm);
     $user = $this->node->addNode('thename');
     $user->setProperty('phpcr:class', $this->type, \PHPCR\PropertyType::STRING);
     $user->setProperty('phpcr_locale:fr-topic', 'french', \PHPCR\PropertyType::STRING);
     $user->setProperty('phpcr_locale:fr-text', 'french text', \PHPCR\PropertyType::STRING);
     $user->setProperty('phpcr_locale:frnullfields', array('nullable'), \PHPCR\PropertyType::STRING);
     $user->setProperty('phpcr_locale:en-topic', 'english', \PHPCR\PropertyType::STRING);
     $user->setProperty('phpcr_locale:en-text', 'english text', \PHPCR\PropertyType::STRING);
     $user->setProperty('phpcr_locale:ennullfields', array('nullable'), \PHPCR\PropertyType::STRING);
     $this->dm->getPhpcrSession()->save();
 }
Ejemplo n.º 5
0
 public function testTriggerTranslationEvents()
 {
     $this->dm->getEventManager()->addEventListener(array(Event::preCreateTranslation, Event::postLoadTranslation, Event::preRemoveTranslation, Event::postRemoveTranslation), $this->listener);
     $this->dm->setLocaleChooserStrategy(new LocaleChooser($this->localePrefs, 'en'));
     $page = new CmsPageTranslatable();
     $page->title = "my-page";
     $page->content = "long story";
     $this->dm->persist($page);
     $this->assertFalse($this->listener->preCreateTranslation);
     $this->assertFalse($this->listener->postLoadTranslation);
     $this->assertFalse($this->listener->postRemoveTranslation);
     $this->assertFalse($this->listener->postRemoveTranslation);
     $this->dm->bindTranslation($page, 'en');
     $this->assertTrue($this->listener->preCreateTranslation);
     $this->assertFalse($this->listener->postLoadTranslation);
     $this->assertFalse($this->listener->postRemoveTranslation);
     $this->dm->flush();
     $this->dm->clear();
     $page = $this->dm->findTranslation('Doctrine\\Tests\\Models\\CMS\\CmsPageTranslatable', $page->id, 'en');
     $this->assertTrue($this->listener->postLoadTranslation);
     $page->title = 'neuer Titel';
     $this->dm->bindTranslation($page, 'de');
     $this->dm->flush();
     $this->dm->removeTranslation($page, 'en');
     $this->assertFalse($this->listener->postRemoveTranslation);
     $this->assertTrue($this->listener->preRemoveTranslation);
     $this->dm->flush();
     $this->assertTrue($this->listener->postRemoveTranslation);
 }
 public function testSecondLevelOverwrite()
 {
     $localePrefs = array('en' => array('en', 'de'), 'de' => array('de', 'en'));
     $this->dm->setLocaleChooserStrategy(new LocaleChooser($localePrefs, 'en'));
     $secondTrans = new SecondLevelWithDuplicateOverwrite();
     $secondTrans->id = '/functional/secondTrans';
     $secondTrans->text = 'deutsch';
     $this->dm->persist($secondTrans);
     $this->dm->bindTranslation($secondTrans, 'de');
     $secondTrans->text = 'english';
     $this->dm->bindTranslation($secondTrans, 'en');
     $this->dm->flush();
     $tmpDocDe = $this->dm->findTranslation(null, '/functional/secondTrans', 'de');
     $this->assertEquals($tmpDocDe->text, 'deutsch');
     $tmpDocEn = $this->dm->findTranslation(null, '/functional/secondTrans', 'en');
     $this->assertEquals($tmpDocEn->text, 'english');
 }
 public function testQueryBuilder()
 {
     $strategy = new ChildTranslationStrategy($this->dm);
     $this->dm->setTranslationStrategy('children', $strategy);
     $this->dm->setLocaleChooserStrategy(new LocaleChooser(array('en' => array('fr'), 'fr' => array('en')), 'en'));
     // First save some translations
     $data = array();
     $data['topic'] = 'Some interesting subject';
     $data['text'] = 'Lorem ipsum...';
     $data['settings'] = array('is-active' => 'true', 'url' => 'great-article-in-english.html');
     $node = $this->getTestNode();
     $node->setProperty('author', 'John Doe');
     $node->setProperty('phpcr:class', 'Doctrine\\Tests\\Models\\Translation\\ChildTranslationArticle');
     $strategy->saveTranslation($data, $node, $this->metadata, 'en');
     // Save translation in another language
     $data['topic'] = 'Un sujet intéressant';
     $data['settings'] = array('is-active' => 'true', 'url' => 'super-article-en-francais.html');
     $strategy->saveTranslation($data, $node, $this->metadata, 'fr');
     $this->dm->flush();
     $qb = $this->dm->createQueryBuilder();
     $qb->from()->document('Doctrine\\Tests\\Models\\Translation\\ChildTranslationArticle', 'a');
     $qb->where()->eq()->field('a.topic')->literal('Not Exist')->end();
     $res = $qb->getQuery()->execute();
     $this->assertCount(0, $res);
     $qb = $this->dm->createQueryBuilder();
     $qb->from()->document('Doctrine\\Tests\\Models\\Translation\\ChildTranslationArticle', 'a');
     $qb->where()->eq()->field('a.topic')->literal('Un sujet intéressant')->end();
     $res = $qb->getQuery()->execute();
     $this->assertCount(0, $res);
     $qb = $this->dm->createQueryBuilder();
     $qb->setLocale(false);
     $qb->from()->document('Doctrine\\Tests\\Models\\Translation\\ChildTranslationArticle', 'a');
     $qb->where()->eq()->field('a.topic')->literal('Un sujet intéressant')->end();
     $res = $qb->getQuery()->execute();
     $this->assertCount(0, $res);
     $qb = $this->dm->createQueryBuilder();
     $qb->from()->document('Doctrine\\Tests\\Models\\Translation\\ChildTranslationArticle', 'a');
     $qb->where()->eq()->field('a.topic')->literal('Some interesting subject')->end();
     $res = $qb->getQuery()->execute();
     $this->assertCount(1, $res);
     $qb = $this->dm->createQueryBuilder();
     $qb->setLocale('fr');
     $qb->from()->document('Doctrine\\Tests\\Models\\Translation\\ChildTranslationArticle', 'a');
     $qb->where()->eq()->field('a.topic')->literal('Un sujet intéressant')->end();
     $res = $qb->getQuery()->execute();
     $this->assertCount(1, $res);
 }
Ejemplo n.º 8
0
 /**
  * There was a bug that documents translated fields where overwritten when they are re-created
  *
  * depends testCreate
  */
 public function testMultilangReferrers()
 {
     $this->dm->setLocaleChooserStrategy(new \Doctrine\ODM\PHPCR\Translation\LocaleChooser\LocaleChooser($this->localePrefs, 'en'));
     $this->dm->setTranslationStrategy('attribute', new \Doctrine\ODM\PHPCR\Translation\TranslationStrategy\AttributeTranslationStrategy($this->dm));
     $referrerTestObj = new ReferrerTestObjMultilang();
     $referrerRefTestObj = new ReferrerRefTestObj();
     $referrerTestObj->id = "/functional/referrerTestObj";
     $referrerTestObj->name = "referrer";
     $referrerRefTestObj->id = "/functional/referrerRefTestObj";
     $referrerTestObj->reference = $referrerRefTestObj;
     $this->dm->persist($referrerTestObj);
     $this->dm->flush();
     $this->dm->clear();
     $referrer = $this->dm->find(null, '/functional/referrerTestObj');
     $referenced = $this->dm->find(null, "/functional/referrerRefTestObj");
     $referrer->name = 'changed';
     $this->assertEquals('changed', $referrer->name);
     $this->assertCount(1, $referenced->referrers);
     $this->assertSame($referrer, $referenced->referrers->first());
     $this->assertEquals('changed', $referrer->name);
 }