Explorar o código

[sluggable] do not allow protected properties mapped in mappedsuperclass

gediminasm %!s(int64=13) %!d(string=hai) anos
pai
achega
5d919962cc

+ 1 - 1
lib/Gedmo/Sluggable/Mapping/Driver/Annotation.php

@@ -126,7 +126,7 @@ class Annotation implements AnnotationDriverInterface
                     throw new InvalidMappingException("Slug must contain at least one field for slug generation in class - {$meta->name}");
                 }
                 foreach ($slug->fields as $slugField) {
-                    if (!$meta->hasField($slugField) || $meta->isInheritedField($slugField)) {
+                    if (!$meta->hasField($slugField)) {
                         throw new InvalidMappingException("Unable to find slug [{$slugField}] as mapped property in entity - {$meta->name}");
                     }
                     if (!$this->isValidField($meta, $slugField)) {

+ 34 - 0
tests/Gedmo/Sluggable/Fixture/Issue104/Bus.php

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

+ 38 - 0
tests/Gedmo/Sluggable/Fixture/Issue104/Icarus.php

@@ -0,0 +1,38 @@
+<?php
+
+namespace Sluggable\Fixture\Issue104;
+
+use Doctrine\ORM\Mapping as ORM;
+use Gedmo\Mapping\Annotation as Gedmo;
+
+/**
+ * @ORM\Entity
+ */
+class Icarus extends Bus
+{
+    /**
+     * @ORM\Column(length=128)
+     */
+    private $description;
+
+    /**
+     * @Gedmo\Slug(fields={"title"})
+     * @ORM\Column(length=128, unique=true)
+     */
+    private $slug;
+
+    public function setDescription($description)
+    {
+        $this->description = $description;
+    }
+
+    public function getDescription()
+    {
+        return $this->description;
+    }
+
+    public function getSlug()
+    {
+        return $this->slug;
+    }
+}

+ 51 - 0
tests/Gedmo/Sluggable/Issue/Issue104Right.php

@@ -0,0 +1,51 @@
+<?php
+
+namespace Gedmo\Sluggable;
+
+use Doctrine\Common\EventManager;
+use Tool\BaseTestCaseORM;
+use Sluggable\Fixture\Issue104\Icarus;
+
+/**
+ * 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 Issue104RightTest extends BaseTestCaseORM
+{
+    const ICARUS = 'Sluggable\\Fixture\\Issue104\\Icarus';
+
+    protected function setUp()
+    {
+        parent::setUp();
+    }
+
+    /**
+     * @test
+     */
+    public function shouldMapMappedSuperclassPrivateInheritedProperty()
+    {
+        $evm = new EventManager;
+        $evm->addEventSubscriber(new SluggableListener);
+        $this->getMockSqliteEntityManager($evm);
+
+        $audi = new Icarus;
+        $audi->setDescription('audi car');
+        $audi->setTitle('Audi');
+
+        $this->em->persist($audi);
+        $this->em->flush();
+
+        $this->assertEquals('audi', $audi->getSlug());
+    }
+
+    protected function getUsedEntityFixtures()
+    {
+        return array(
+            self::ICARUS
+        );
+    }
+}

+ 7 - 10
tests/Gedmo/Sluggable/Issue/Issue104Test.php

@@ -21,26 +21,23 @@ class Issue104Test extends BaseTestCaseORM
     protected function setUp()
     {
         parent::setUp();
+    }
 
+    /**
+     * @test
+     * @expectedException Gedmo\Exception\InvalidMappingException
+     */
+    public function shouldThrowAnExceptionWhenMappedSuperclassProtectedProperty()
+    {
         $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();
     }