瀏覽代碼

ZF-4841: passing empty tag to Label decorator should remove tag [patch courtesy Steve Hollis]

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@19049 44c647ce-9c0f-0410-b52a-842ac1e357ba
matthew 16 年之前
父節點
當前提交
36d200108f
共有 2 個文件被更改,包括 16 次插入0 次删除
  1. 3 0
      library/Zend/Form/Decorator/Label.php
  2. 13 0
      tests/Zend/Form/Decorator/LabelTest.php

+ 3 - 0
library/Zend/Form/Decorator/Label.php

@@ -103,6 +103,9 @@ class Zend_Form_Decorator_Label extends Zend_Form_Decorator_Abstract
         } else {
             $this->_tag = (string) $tag;
         }
+
+        $this->removeOption('tag');
+
         return $this;
     }
 

+ 13 - 0
tests/Zend/Form/Decorator/LabelTest.php

@@ -298,6 +298,19 @@ class Zend_Form_Decorator_LabelTest extends PHPUnit_Framework_TestCase
         $content = $this->decorator->render('');
         $this->assertTrue(empty($content), $content);
     }
+
+    /**
+     * @group ZF-4841
+     */
+    public function testSettingTagToEmptyValueShouldSetTagToNull()
+    {
+        $element = new Zend_Form_Element_Text('foo', array('label' => 'Foo'));
+        $this->decorator->setElement($element)
+                        ->setOptions(array('tag' => 'dt'));
+        $this->decorator->setTag('');
+        $tag = $this->decorator->getTag();
+        $this->assertTrue( NULL === $tag, $tag );
+    }
 }
 
 // Call Zend_Form_Decorator_LabelTest::main() if this source file is executed directly.