コード例 #1
0
 public function testSetPrefixAndGetPropertyName()
 {
     $dm = $this->getMockBuilder('Doctrine\\ODM\\PHPCR\\DocumentManager')->disableOriginalConstructor()->getMock();
     $s = new AttributeTranslationStrategy($dm);
     $s->setPrefix('test');
     $class = new \ReflectionClass('Doctrine\\ODM\\PHPCR\\Translation\\TranslationStrategy\\AttributeTranslationStrategy');
     $method = $class->getMethod('getTranslatedPropertyName');
     $method->setAccessible(true);
     $name = $method->invokeArgs($s, array('fr', 'field'));
     $this->assertEquals('test:fr-field', $name);
 }
コード例 #2
0
 /**
  * {@inheritdoc}
  */
 public function loadTranslation($document, NodeInterface $node, ClassMetadata $metadata, $locale)
 {
     $translationNode = $this->getTranslationNode($node, $locale, false);
     if (!$translationNode) {
         return false;
     }
     return parent::loadTranslation($document, $translationNode, $metadata, $locale);
 }
コード例 #3
0
 public function testGetLocaleFor()
 {
     $node = $this->getTestNode();
     $node->setProperty(self::propertyNameForLocale('en', 'topic'), 'English topic');
     $node->setProperty(self::propertyNameForLocale('en', 'text'), 'English text');
     $node->setProperty(self::propertyNameForLocale('fr', 'topic'), 'Sujet français');
     $node->setProperty(self::propertyNameForLocale('fr', 'text'), 'Texte français');
     $node->setProperty(self::propertyNameForLocale('de', 'topic'), 'Deutche Betreff');
     $node->setProperty(self::propertyNameForLocale('de', 'text'), 'Deutche Texte');
     $this->session->save();
     $doc = new Article();
     $strategy = new AttributeTranslationStrategy();
     $locales = $strategy->getLocalesFor($doc, $node, $this->metadata);
     $this->assertTrue(is_array($locales));
     $this->assertEquals(3, count($locales));
     $this->assertContains('fr', $locales);
     $this->assertContains('en', $locales);
     $this->assertContains('de', $locales);
 }
コード例 #4
0
 /**
  * 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['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');
     $strategy = new AttributeTranslationStrategy($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 = 'John Doe';
     $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());
 }