Przeglądaj źródła

Added 1 assertion in Translatable\Issue\Issue173Test. Added some fixtures in Translatable\Fixture\Issue173

Oscar Balladares 13 lat temu
rodzic
commit
8bd7af5f6e

+ 57 - 0
tests/Gedmo/Translatable/Fixture/Issue173/Article.php

@@ -0,0 +1,57 @@
+<?php
+
+namespace Translatable\Fixture\Issue173;
+
+use Gedmo\Mapping\Annotation as Gedmo;
+use Doctrine\ORM\Mapping as ORM;
+
+/**
+ * @ORM\Entity
+ */
+class Article
+{
+    /**
+     * @ORM\Id
+     * @ORM\GeneratedValue
+     * @ORM\Column(type="integer")
+     */
+    private $id;
+
+    /**
+     * @Gedmo\Translatable
+     * @ORM\Column(name="title", type="string", length=128)
+     */
+    private $title;
+    
+    /**
+     * @ORM\ManyToOne(targetEntity="Category", inversedBy="articles")
+     */
+    private $category;
+
+    
+    public function getId()
+    {
+        return $this->id;
+    }
+
+    public function setTitle($title)
+    {
+        $this->title = $title;
+    }
+
+    public function getTitle()
+    {
+        return $this->title;
+    }
+    
+    public function setCategory(Category $category)
+    {
+        $this->category = $category;
+    }
+    
+    public function getCategory()
+    {
+        return $this->category;
+    }
+}
+

+ 71 - 0
tests/Gedmo/Translatable/Fixture/Issue173/Category.php

@@ -0,0 +1,71 @@
+<?php
+
+namespace Translatable\Fixture\Issue173;
+
+use Gedmo\Mapping\Annotation as Gedmo;
+use Doctrine\ORM\Mapping as ORM;
+
+/**
+ * @ORM\Entity
+ */
+class Category
+{
+    /**
+     * @ORM\Id
+     * @ORM\GeneratedValue
+     * @ORM\Column(type="integer")
+     */
+    private $id;
+
+    /**
+     * @Gedmo\Translatable
+     * @ORM\Column(name="title", type="string", length=128)
+     */
+    private $title;
+    
+    /**
+     * @ORM\OneToMany(targetEntity="Article", mappedBy="category", cascade={"persist", "remove"})
+     */
+    private $articles;
+
+    /**
+     * @ORM\OneToMany(targetEntity="Product", mappedBy="category", cascade={"persist", "remove"})
+     */
+    private $products;
+    
+    public function getId()
+    {
+        return $this->id;
+    }
+    
+    public function setTitle($title)
+    {
+        $this->title = $title;
+    }
+    
+    public function getTitle()
+    {
+        return $this->title;
+    }
+    
+    public function addArticles(Article $article)
+    {
+        $this->articles[] = $article;
+    }
+    
+    public function getArticles()
+    {
+        return $this->articles;
+    }
+
+    public function addProducts(Product $product)
+    {
+        $this->products[] = $product;
+    }
+
+    public function getProducts()
+    {
+        return $this->products;
+    }
+}
+

+ 56 - 0
tests/Gedmo/Translatable/Fixture/Issue173/Product.php

@@ -0,0 +1,56 @@
+<?php
+
+namespace Translatable\Fixture\Issue173;
+
+use Gedmo\Mapping\Annotation as Gedmo;
+use Doctrine\ORM\Mapping as ORM; 
+
+/**
+ * @ORM\Entity
+ */
+class Product
+{
+    /**
+     * @ORM\Id
+     * @ORM\GeneratedValue
+     * @ORM\Column(type="integer")
+     */
+    private $id;
+
+    /**
+     * @Gedmo\Translatable
+     * @ORM\Column(name="title", type="string", length=128)
+     */
+    private $title;
+    
+    /**
+     * @ORM\ManyToOne(targetEntity="Category", inversedBy="products")
+     */
+    private $category;
+
+    
+    public function getId()
+    {
+        return $this->id;
+    }
+
+    public function setTitle($title)
+    {
+        $this->title = $title;
+    }
+
+    public function getTitle()
+    {
+        return $this->title;
+    }
+    
+    public function setCategory(Category $category)
+    {
+        $this->category = $category;
+    }
+    
+    public function getCategory()
+    {
+        return $this->category;
+    }
+}

+ 141 - 0
tests/Gedmo/Translatable/Issue/Issue173Test.php

@@ -0,0 +1,141 @@
+<?php
+
+namespace Gedmo\Translatable;
+
+use Doctrine\Common\EventManager;
+use Tool\BaseTestCaseORM;
+use Translatable\Fixture\Issue173\Article;
+use Translatable\Fixture\Issue173\Category;
+use Translatable\Fixture\Issue173\Product;
+
+/**
+ * These are tests for translatable behavior
+ *
+ * @author Gediminas Morkevicius <gediminas.morkevicius@gmail.com>
+ * @contributor Oscar Balladares liebegrube@gmail.com https://github.com/oscarballadares
+ * @package Gedmo.Translatable
+ * @link http://www.gediminasm.org
+ * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
+ */
+class Issue173Test extends BaseTestCaseORM
+{ 
+    const CATEGORY =   'Translatable\\Fixture\\Issue173\\Category';
+    const ARTICLE = 'Translatable\\Fixture\\Issue173\\Article';
+    const PRODUCT = 'Translatable\\Fixture\\Issue173\\Product';
+    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);
+
+        $this->populate();
+    }
+
+    public function testIssue173()
+    {
+        $categories = $this->getCategoriesThatHasNoAssociations();
+        $this->assertEquals(count($categories), 1, '$categoriy3 has no associations');
+           
+    }
+
+    public function getCategoriesThatHasNoAssociations()
+    {
+        $query = $this->em->createQueryBuilder();
+        $query2 = $this->em->createQueryBuilder();
+        $query3 = $this->em->createQueryBuilder();
+        $dql1 = $query2
+                    ->select('c1')
+                    ->from(self::CATEGORY, 'c1')
+                    ->join('c1.products', 'p')
+                    ->getDql()
+                ;
+        $dql2 = $query3
+                    ->select('c2')
+                    ->from(self::CATEGORY, 'c2')
+                    ->join('c2.articles', 'a')
+                    ->getDql()
+                ;   
+        $query
+            ->select('c')
+            ->from(self::CATEGORY, 'c')
+            ->where($query->expr()->notIn('c.id', $dql1))
+            ->andWhere($query->expr()->notIn('c.id', $dql2))
+            ; 
+    
+        return $query->getQuery()->setHint(
+                        \Doctrine\ORM\Query::HINT_CUSTOM_OUTPUT_WALKER,
+                        'Gedmo\\Translatable\\Query\\TreeWalker\\TranslationWalker'
+                )->getResult();
+    }
+
+    private function populate()
+    {
+        //Categories
+        $category1 = new Category;
+        $category1->setTitle('en category1');
+    
+        $category2 = new Category;
+        $category2->setTitle('en category2');
+        
+        $category3 = new Category;
+        $category3->setTitle('en category3');
+
+        $this->em->persist($category1);
+        $this->em->persist($category2);
+        $this->em->persist($category3);
+        $this->em->flush();
+
+        //Articles
+        $article1 = new Article;
+        $article1->setTitle('en article1');
+        $article1->setCategory($category1);
+
+        //Products
+        $product1 = new Product;
+        $product1->setTitle('en product1');
+        $product1->setCategory($category2);
+        
+        $this->em->persist($article1);
+        $this->em->persist($product1);
+        $this->em->flush();
+
+        $this->translatableListener->setTranslatableLocale('es');
+        
+        // Categories
+        $category1->setTitle('es title');
+        $category2->setTitle('es title');
+        $category3->setTitle('es title');
+
+        $article1->setTitle('es title');
+        $product1->setTitle('es name');
+
+        $this->em->persist($category1);
+        $this->em->persist($category2);
+        $this->em->persist($category3);
+        $this->em->persist($article1);
+        $this->em->persist($product1);
+       
+        $this->em->flush();
+    }
+
+    protected function getUsedEntityFixtures()
+    {
+        return array(
+            self::CATEGORY,
+            self::ARTICLE,
+            self::PRODUCT,
+            self::TRANSLATION,
+            
+        );
+    }
+}

+ 0 - 32
tests/phpunit.xml.dist

@@ -1,32 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<phpunit bootstrap="./bootstrap.php">
-    <testsuites>
-        <testsuite name="Translatable Extension">
-            <directory suffix=".php">./Gedmo/Translatable/</directory>
-        </testsuite>
-        <testsuite name="Sluggable Extension">
-            <directory suffix=".php">./Gedmo/Sluggable/</directory>
-        </testsuite>
-        <testsuite name="Sortable Extension">
-            <directory suffix=".php">./Gedmo/Sortable/</directory>
-        </testsuite>
-        <testsuite name="Tree Extension">
-            <directory suffix=".php">./Gedmo/Tree/</directory>
-        </testsuite>
-        <testsuite name="Timestampable Extension">
-            <directory suffix=".php">./Gedmo/Timestampable/</directory>
-        </testsuite>
-        <testsuite name="Mapping Extension">
-            <directory suffix=".php">./Gedmo/Mapping/</directory>
-        </testsuite>
-        <testsuite name="Loggable Extension">
-            <directory suffix=".php">./Gedmo/Loggable/</directory>
-        </testsuite>
-        <testsuite name="Sortable Extension">
-            <directory suffix=".php">./Gedmo/Sortable/</directory>
-        </testsuite>
-        <testsuite name="Object wrappers">
-            <directory suffix=".php">./Gedmo/Wrapper/</directory>
-        </testsuite>
-    </testsuites>
-</phpunit>