Ver Fonte

[tests] tests for issue104, closes #104

gediminasm há 14 anos atrás
pai
commit
0ee342be30

+ 33 - 0
tests/Gedmo/Sluggable/Fixture/Issue104/Car.php

@@ -0,0 +1,33 @@
+<?php
+
+namespace Sluggable\Fixture\Issue104;
+
+use Doctrine\ORM\Mapping as ORM;
+use Gedmo\Mapping\Annotation as Gedmo;
+
+/**
+ * @ORM\Entity
+ */
+class Car extends Vehicle
+{
+    /**
+     * @Gedmo\Sluggable
+     * @ORM\Column(length=128)
+     */
+    protected $title;
+
+    /**
+     * @ORM\Column(length=128)
+     */
+    private $description;
+
+    public function setDescription($description)
+    {
+        $this->description = $description;
+    }
+
+    public function getDescription()
+    {
+        return $this->description;
+    }
+}

+ 50 - 0
tests/Gedmo/Sluggable/Fixture/Issue104/Vehicle.php

@@ -0,0 +1,50 @@
+<?php
+
+namespace Sluggable\Fixture\Issue104;
+
+use Doctrine\ORM\Mapping as ORM;
+use Gedmo\Mapping\Annotation as Gedmo;
+
+/**
+ * @ORM\MappedSuperclass
+ */
+class Vehicle
+{
+    /**
+     * @ORM\Id
+     * @ORM\GeneratedValue
+     * @ORM\Column(type="integer")
+     */
+    private $id;
+
+    /**
+     * @ORM\Column(length=128)
+     */
+    protected $title;
+
+    /**
+     * @Gedmo\Slug
+     * @ORM\Column(length=128, unique=true)
+     */
+    private $slug;
+
+    public function getId()
+    {
+        return $this->id;
+    }
+
+    public function setTitle($title)
+    {
+        $this->title = $title;
+    }
+
+    public function getTitle()
+    {
+        return $this->title;
+    }
+
+    public function getSlug()
+    {
+        return $this->slug;
+    }
+}

+ 53 - 0
tests/Gedmo/Sluggable/Issue104Test.php

@@ -0,0 +1,53 @@
+<?php
+
+namespace Gedmo\Sluggable;
+
+use Doctrine\Common\EventManager;
+use Tool\BaseTestCaseORM;
+use Sluggable\Fixture\Issue104\Car;
+
+/**
+ * These are tests for Sluggable behavior
+ *
+ * @author Gediminas Morkevicius <gediminas.morkevicius@gmail.com>
+ * @package Gedmo.Sluggable
+ * @link http://www.gediminasm.org
+ * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
+ */
+class Issue104Test extends BaseTestCaseORM
+{
+    const CAR = 'Sluggable\\Fixture\\Issue104\\Car';
+
+    protected function setUp()
+    {
+        parent::setUp();
+
+        $evm = new EventManager;
+        $evm->addEventSubscriber(new SluggableListener);
+
+        $this->getMockSqliteEntityManager($evm);
+    }
+
+    public function testSlugGeneration()
+    {
+        $audi = new Car;
+        $audi->setDescription('audi car');
+        $audi->setTitle('Audi');
+
+        $this->em->persist($audi);
+
+        $audi2 = new Car;
+        $audi2->setDescription('audi2 car');
+        $audi2->setTitle('Audi');
+
+        $this->em->persist($audi2);
+        $this->em->flush();
+    }
+
+    protected function getUsedEntityFixtures()
+    {
+        return array(
+            self::CAR
+        );
+    }
+}