Преглед изворни кода

Merge r25242 to 1.12 release branch

git-svn-id: http://framework.zend.com/svn/framework/standard/branches/release-1.12@25243 44c647ce-9c0f-0410-b52a-842ac1e357ba
frosch пре 13 година
родитељ
комит
fdef766954

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

@@ -308,10 +308,6 @@ class Zend_Form_Decorator_Label extends Zend_Form_Decorator_Abstract
             return '';
         }
 
-        if (null !== ($translator = $element->getTranslator())) {
-            $label = $translator->translate($label);
-        }
-
         $optPrefix = $this->getOptPrefix();
         $optSuffix = $this->getOptSuffix();
         $reqPrefix = $this->getReqPrefix();

+ 33 - 0
tests/Zend/Form/Decorator/DescriptionTest.php

@@ -181,6 +181,39 @@ class Zend_Form_Decorator_DescriptionTest extends PHPUnit_Framework_TestCase
         $html = $this->decorator->render('');
         $this->assertContains($translations['description'], $html);
     }
+
+    /**
+     * @group ZF-8694
+     */
+    public function testDescriptionIsNotTranslatedTwice()
+    {
+        // Init translator
+        require_once 'Zend/Translate.php';
+        $translate = new Zend_Translate(
+            array(
+                 'adapter' => 'array',
+                 'content' => array(
+                     'firstDescription'  => 'secondDescription',
+                     'secondDescription' => 'thirdDescription',
+                 ),
+                 'locale'  => 'en'
+            )
+        );
+
+        // Create element
+        $element = new Zend_Form_Element('foo');
+        $element->setView($this->getView())
+                ->setDescription('firstDescription')
+                ->setTranslator($translate);
+
+        $this->decorator->setElement($element);
+
+        // Test
+        $this->assertEquals(
+            '<p class="hint">secondDescription</p>',
+            trim($this->decorator->render(''))
+        );
+    }
 }
 
 // Call Zend_Form_Decorator_DescriptionTest::main() if this source file is executed directly.

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

@@ -398,6 +398,36 @@ class Zend_Form_Decorator_LabelTest extends PHPUnit_Framework_TestCase
 
         $this->assertEquals($expected, $actual);
     }
+
+    /**
+     * @group ZF-8694
+     */
+    public function testLabelIsNotTranslatedTwice()
+    {
+        // Init translator
+        require_once 'Zend/Translate.php';
+        $translate = new Zend_Translate(
+            array(
+                 'adapter' => 'array',
+                 'content' => array(
+                     'firstLabel'  => 'secondLabel',
+                     'secondLabel' => 'thirdLabel',
+                 ),
+                 'locale'  => 'en'
+            )
+        );
+
+        // Create element
+        $element = new Zend_Form_Element('foo');
+        $element->setView($this->getView())
+                ->setLabel('firstLabel')
+                ->setTranslator($translate);
+
+        $this->decorator->setElement($element);
+
+        // Test
+        $this->assertEquals('secondLabel', $this->decorator->getLabel());
+    }
 }
 
 // Call Zend_Form_Decorator_LabelTest::main() if this source file is executed directly.