public function testLoadTranslation()
 {
     // First save some translations
     $data = array();
     $data['author'] = 'John Doe';
     $data['topic'] = 'English topic';
     $data['text'] = 'English text';
     $node = $this->getTestNode();
     $strategy = new ChildTranslationStrategy();
     $strategy->saveTranslation($data, $node, $this->metadata, 'en');
     // Save translation in another language
     $data['topic'] = 'Sujet français';
     $data['text'] = null;
     $strategy->saveTranslation($data, $node, $this->metadata, 'fr');
     $this->dm->flush();
     $doc = new Article();
     $doc->author = $data['author'];
     $doc->topic = $data['topic'];
     $doc->setText($data['text']);
     $strategy->loadTranslation($doc, $node, $this->metadata, 'en');
     // And check the translatable properties have the correct value
     $this->assertEquals('English topic', $doc->topic);
     $this->assertEquals('English text', $doc->getText());
     // Load another language and test the document has been updated
     $strategy->loadTranslation($doc, $node, $this->metadata, 'fr');
     $this->assertEquals('Sujet français', $doc->topic);
     $this->assertNull($doc->getText());
 }
Пример #2
0
 public function testRemove()
 {
     $this->dm->persist($this->doc);
     $this->dm->bindTranslation($this->doc, 'en');
     $this->dm->bindTranslation($this->doc, 'fr');
     $this->dm->flush();
     $this->dm->remove($this->doc);
     $this->dm->flush();
     $this->dm->clear();
     $this->doc = $this->dm->find($this->class, '/functional/' . $this->testNodeName);
     $this->assertNull($this->doc, 'Document must be null after deletion');
     $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->dm->persist($this->doc);
     $this->dm->bindTranslation($this->doc, 'en');
     $this->dm->flush();
     $locales = $this->dm->getLocalesFor($this->doc);
     $this->assertEquals(array('en'), $locales, 'Removing a document must remove all translations');
 }
 /**
  * Caution : Jackalope\Property guess the property type on the first element
  * So if it's an boolean, all your array will be set to true
  * The Array has to be an array of string
  */
 public function testTranslationArrayProperties()
 {
     // First save some translations
     $data = array();
     $data['author'] = 'John Doe';
     $data['topic'] = 'Some interesting subject';
     $data['text'] = 'Lorem ipsum...';
     $data['settings'] = array('is-active' => 'true', 'url' => 'great-article-in-english.html');
     $node = $this->getTestNode();
     $strategy = new ChildTranslationStrategy($this->dm);
     $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();
     $doc = new Article();
     $doc->author = $data['author'];
     $doc->topic = $data['topic'];
     $doc->setText($data['text']);
     $strategy->loadTranslation($doc, $node, $this->metadata, 'en');
     $this->assertEquals(array('is-active', 'url'), array_keys($doc->getSettings()));
     $this->assertEquals(array('is-active' => 'true', 'url' => 'great-article-in-english.html'), $doc->getSettings());
     $strategy->loadTranslation($doc, $node, $this->metadata, 'fr');
     $this->assertEquals(array('is-active', 'url'), array_keys($doc->getSettings()));
     $this->assertEquals(array('is-active' => 'true', 'url' => 'super-article-en-francais.html'), $doc->getSettings());
 }
 public function testRemoveTranslation()
 {
     // First save some translations
     $data = array();
     $data['author'] = 'John Doe';
     $data['topic'] = 'Some interesting subject';
     $data['text'] = 'Lorem ipsum...';
     $node = $this->getTestNode();
     $strategy = new AttributeTranslationStrategy();
     $strategy->saveTranslation($data, $node, $this->metadata, 'en');
     $doc['topic'] = 'sujet interessant';
     $strategy->saveTranslation($data, $node, $this->metadata, 'fr');
     $this->assertTrue($node->hasProperty(self::propertyNameForLocale('en', 'topic')));
     $this->assertTrue($node->hasProperty(self::propertyNameForLocale('en', 'text')));
     // Then remove the french translation
     $doc = new Article();
     $doc->author = $data['author'];
     $doc->topic = $data['topic'];
     $doc->setText($data['text']);
     $strategy->removeTranslation($doc, $node, $this->metadata, 'fr');
     $this->assertFalse($node->hasProperty(self::propertyNameForLocale('fr', 'topic')));
     $this->assertFalse($node->hasProperty(self::propertyNameForLocale('fr', 'text')));
     $this->assertTrue($node->hasProperty(self::propertyNameForLocale('en', 'topic')));
     $this->assertTrue($node->hasProperty(self::propertyNameForLocale('en', 'text')));
 }
 /**
  * Just make one field of a document untranslated again
  */
 public function testPartialUntranslateAttribute()
 {
     $article = new Article();
     $article->id = '/functional/convert';
     $article->topic = 'Some interesting subject';
     $article->setText('Lorem ipsum...');
     $this->dm->persist($article);
     $this->dm->flush();
     $this->dm->clear();
     $class = 'Doctrine\\Tests\\Models\\Translation\\Article';
     $field = 'author';
     $comment = $this->node->getNode('convert');
     $comment->setProperty(AttributeTranslationStrategyTest::propertyNameForLocale('en', $field), 'Move to untranslated');
     $this->session->save();
     $this->assertFalse($this->converter->convert($class, array('en'), array($field)));
     $this->session->save();
     $this->dm->clear();
     $this->dm = $this->createDocumentManager();
     $this->dm->setLocaleChooserStrategy(new LocaleChooser($this->localePrefs, 'en'));
     $this->assertTrue($comment->hasProperty($field), 'new property was not created');
     $this->assertFalse($comment->hasProperty(AttributeTranslationStrategyTest::propertyNameForLocale('en', $field)), 'old property was not removed');
     $article = $this->dm->find(null, '/functional/convert');
     $this->assertInstanceof($class, $article);
     $this->assertEquals('Move to untranslated', $article->author);
     $this->assertEquals('Lorem ipsum...', $article->getText());
     $this->dm->clear();
     $article = $this->dm->find(null, '/functional/convert');
     $this->assertInstanceof($class, $article);
     $this->assertEquals('Move to untranslated', $article->author);
     $this->assertEquals('Lorem ipsum...', $article->getText());
 }