Browse Source

[tests] for issue75 all passes, reported as manytomany relation fail, references #75

gediminasm 14 years ago
parent
commit
a35c971b3d

+ 71 - 0
tests/Gedmo/Translatable/Fixture/Issue75/Article.php

@@ -0,0 +1,71 @@
+<?php
+
+namespace Translatable\Fixture\Issue75;
+
+/**
+ * @Entity
+ */
+class Article
+{
+    /**
+     * @Id
+     * @GeneratedValue
+     * @Column(type="integer")
+     */
+    private $id;
+
+    /**
+     * @gedmo:Translatable
+     * @Column(name="title", type="string", length=128)
+     */
+    private $title;
+
+    /**
+     * @ManyToMany(targetEntity="Image", inversedBy="articles")
+     * @JoinTable(name="article_images",
+     *      joinColumns={@JoinColumn(name="image_id", referencedColumnName="id")},
+     *      inverseJoinColumns={@JoinColumn(name="article_id", referencedColumnName="id")}
+     * )
+     */
+    private $images;
+
+    /**
+     * @ManyToMany(targetEntity="File")
+     */
+    private $files;
+
+    public function getId()
+    {
+        return $this->id;
+    }
+
+    public function addImage(Image $image)
+    {
+        $this->images[] = $image;
+    }
+
+    public function getImages()
+    {
+        return $this->images;
+    }
+
+    public function addFile(File $file)
+    {
+        $this->files[] = $file;
+    }
+
+    public function getFiles()
+    {
+        return $this->files;
+    }
+
+    public function setTitle($title)
+    {
+        $this->title = $title;
+    }
+
+    public function getTitle()
+    {
+        return $this->title;
+    }
+}

+ 37 - 0
tests/Gedmo/Translatable/Fixture/Issue75/File.php

@@ -0,0 +1,37 @@
+<?php
+
+namespace Translatable\Fixture\Issue75;
+
+/**
+ * @Entity
+ */
+class File
+{
+    /**
+     * @Id
+     * @GeneratedValue
+     * @Column(type="integer")
+     */
+    private $id;
+
+    /**
+     * @gedmo:Translatable
+     * @Column(name="title", type="string", length=128)
+     */
+    private $title;
+
+    public function getId()
+    {
+        return $this->id;
+    }
+
+    public function setTitle($title)
+    {
+        $this->title = $title;
+    }
+
+    public function getTitle()
+    {
+        return $this->title;
+    }
+}

+ 52 - 0
tests/Gedmo/Translatable/Fixture/Issue75/Image.php

@@ -0,0 +1,52 @@
+<?php
+
+namespace Translatable\Fixture\Issue75;
+
+/**
+ * @Entity
+ */
+class Image
+{
+    /**
+     * @Id
+     * @GeneratedValue
+     * @Column(type="integer")
+     */
+    private $id;
+
+    /**
+     * @gedmo:Translatable
+     * @Column(name="title", type="string", length=128)
+     */
+    private $title;
+
+    /**
+     * @ManyToMany(targetEntity="Article", mappedBy="images")
+     */
+    private $articles;
+
+    public function getId()
+    {
+        return $this->id;
+    }
+
+    public function addArticle(Article $article)
+    {
+        $this->articles[] = $article;
+    }
+
+    public function getArticles()
+    {
+        return $this->articles;
+    }
+
+    public function setTitle($title)
+    {
+        $this->title = $title;
+    }
+
+    public function getTitle()
+    {
+        return $this->title;
+    }
+}

+ 101 - 0
tests/Gedmo/Translatable/Issue75Test.php

@@ -0,0 +1,101 @@
+<?php
+
+namespace Gedmo\Translatable;
+
+use Doctrine\Common\EventManager;
+use Tool\BaseTestCaseORM;
+use Translatable\Fixture\Issue75\Article;
+use Translatable\Fixture\Issue75\Image;
+use Translatable\Fixture\Issue75\File;
+
+/**
+ * These are tests for translatable behavior
+ *
+ * @author Gediminas Morkevicius <gediminas.morkevicius@gmail.com>
+ * @package Gedmo.Translatable
+ * @link http://www.gediminasm.org
+ * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
+ */
+class Issue75Test extends BaseTestCaseORM
+{
+    const ARTICLE = 'Translatable\\Fixture\\Issue75\\Article';
+    const IMAGE = 'Translatable\\Fixture\\Issue75\\Image';
+    const FILE = 'Translatable\\Fixture\\Issue75\\File';
+    const TRANSLATION = 'Gedmo\\Translatable\\Entity\\Translation';
+
+    private $translatableListener;
+
+    protected function setUp()
+    {
+        parent::setUp();
+
+        $evm = new EventManager;
+        $this->translatableListener = new TranslationListener();
+        $this->translatableListener->setTranslatableLocale('en');
+        $this->translatableListener->setDefaultLocale('en');
+        $evm->addEventSubscriber($this->translatableListener);
+
+        $this->getMockSqliteEntityManager($evm);
+    }
+
+    public function testIssue75()
+    {
+        $repo = $this->em->getRepository(self::TRANSLATION);
+        $file1 = new File;
+        $file1->setTitle('en file1');
+        $this->em->persist($file1);
+
+        $file2 = new File;
+        $file2->setTitle('en file2');
+        $this->em->persist($file2);
+
+        $article = new Article;
+        $article->setTitle('en art');
+        $article->addFile($file1);
+        $article->addFile($file2);
+        $this->em->persist($article);
+
+        $image1 = new Image;
+        $image1->setTitle('en img1');
+        $this->em->persist($image1);
+
+        $image2 = new Image;
+        $image2->setTitle('en img2');
+        $this->em->persist($image2);
+
+        $article->addImage($image1);
+        $article->addImage($image2);
+
+        $this->em->flush();
+
+        $this->translatableListener->setTranslatableLocale('de');
+        $image1->setTitle('de img1');
+        $article->setTitle('de art');
+        $file2->setTitle('de file2');
+
+        $this->em->persist($article);
+        $this->em->persist($image1);
+        $this->em->persist($file2);
+
+        $this->em->flush();
+
+        $trans = $repo->findTranslations($article);
+        $this->assertEquals(2, count($trans));
+
+        $trans = $repo->findTranslations($file2);
+        $this->assertEquals(2, count($trans));
+
+        $trans = $repo->findTranslations($image2);
+        $this->assertEquals(1, count($trans));
+    }
+
+    protected function getUsedEntityFixtures()
+    {
+        return array(
+            self::ARTICLE,
+            self::TRANSLATION,
+            self::IMAGE,
+            self::FILE
+        );
+    }
+}