Sfoglia il codice sorgente

[translator] fix typo in the test fixtures, and add test for proxies

gedi 13 anni fa
parent
commit
0f03dcb5e2

+ 15 - 0
tests/Gedmo/Translator/Fixture/Person.php

@@ -68,6 +68,21 @@ class Person
      */
     private $translations;
 
+    /**
+     * @ORM\ManyToOne(targetEntity="Person")
+     */
+    private $parent;
+
+    public function setParent(Person $parent)
+    {
+        $this->parent = $parent;
+    }
+
+    public function getParent()
+    {
+        return $this->parent;
+    }
+
     public function __construct()
     {
         $this->translations = new ArrayCollection();

+ 1 - 1
tests/Gedmo/Translator/Fixture/PersonCustomTranslation.php

@@ -19,7 +19,7 @@ use Gedmo\Translator\Entity\Translation;
 class PersonCustomTranslation extends Translation
 {
     /**
-     * @ORM\ManyToOne(targetEntity="Person", inversedBy="translations")
+     * @ORM\ManyToOne(targetEntity="PersonCustom", inversedBy="translations")
      */
     protected $translatable;
 }

+ 54 - 3
tests/Gedmo/Translator/TranslatableTest.php

@@ -6,6 +6,7 @@ use Doctrine\Common\EventManager;
 use Tool\BaseTestCaseORM;
 use Translator\Fixture\Person;
 use Translator\Fixture\PersonCustom;
+use Doctrine\ORM\Proxy\Proxy;
 
 /**
  * These are tests for translatable behavior
@@ -86,6 +87,59 @@ class TranslatableTest extends BaseTestCaseORM
         $this->assertSame('multilingual description', $person->translate('ru_RU')->getDescription());
     }
 
+    /**
+     * @test
+     */
+    function shouldTranslateRelation()
+    {
+        $person = new Person();
+        $person->setName('Jen');
+        $person->translate('ru')->setName('Женя');
+        $person->setDescription('description');
+        $person->translate('ru')->setDescription('multilingual description');
+
+        $parent = new Person();
+        $parent->setName('Jen');
+        $parent->translate('ru')->setName('Женя starshai');
+        $parent->translate('fr')->setName('zenia');
+        $parent->setDescription('description');
+        $parent->translate('ru')->setDescription('multilingual description');
+
+        $person->setParent($parent);
+        $this->em->persist($person);
+        $this->em->persist($parent);
+        $this->em->flush();
+        $this->em->clear();
+
+        $person = $this->em->getRepository(self::PERSON)->findOneByName('Jen');
+        $this->assertSame('Женя', $person->translate('ru')->getName());
+        $parent = $person->getParent();
+        $this->assertTrue($parent instanceof Proxy);
+        $this->assertSame('Женя starshai', $parent->translate('ru')->getName());
+        $this->assertSame('zenia', $parent->translate('fr')->getName());
+    }
+
+    /**
+     * @test
+     */
+    function shouldHandleDomainObjectProxy()
+    {
+        $person = new Person();
+        $person->setName('Jen');
+        $person->translate('ru_RU')->setName('Женя');
+        $person->setDescription('description');
+        $person->translate('ru_RU')->setDescription('multilingual description');
+
+        $this->em->persist($person);
+        $this->em->flush();
+        $this->em->clear();
+
+        $personProxy = $this->em->getReference(self::PERSON, array('id' => 1));
+        $this->assertTrue($personProxy instanceof Proxy);
+        $name = $personProxy->translate('ru_RU')->getName();
+        $this->assertSame('Женя', $name);
+    }
+
     public function testTranslatableWithMagicProperties()
     {
         $person = new Person();
@@ -102,9 +156,6 @@ class TranslatableTest extends BaseTestCaseORM
 
     public function testTranslatableWithCustomProxy()
     {
-        if (\Doctrine\ORM\Version::compare('2.3.0-dev') <= 0) {
-            $this->markTestSkipped('Seems that orm strictly checks the class name in higher version');
-        }
         $person = new PersonCustom();
         $person->setName('Jen');
         $person->translate('ru_RU')->setName('Женя');