Ver Fonte

ZF-11620: FormRadio view helper ignores doctype when selecting default list separator

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@24865 44c647ce-9c0f-0410-b52a-842ac1e357ba
adamlundrigan há 13 anos atrás
pai
commit
795e8a57b6

+ 5 - 0
library/Zend/View/Helper/FormRadio.php

@@ -173,6 +173,11 @@ class Zend_View_Helper_FormRadio extends Zend_View_Helper_FormElement
             // add to the array of radio buttons
             $list[] = $radio;
         }
+        
+        // XHTML or HTML for standard list separator?
+        if (!$this->_isXhtml() && false !== strpos($listsep, '<br />')) {
+            $listsep = str_replace('<br />', '<br>', $listsep);
+        }
 
         // done!
         $xhtml .= implode($listsep, $list);

+ 46 - 1
tests/Zend/View/Helper/FormRadioTest.php

@@ -399,7 +399,7 @@ class Zend_View_Helper_FormRadioTest extends PHPUnit_Framework_TestCase
             )
         );
 
-        $expected = '<label><input type="radio" name="foo" id="foo-bar" value="bar">Bar</label><br />'
+        $expected = '<label><input type="radio" name="foo" id="foo-bar" value="bar">Bar</label><br>'
                   . "\n"
                   . '<label><input type="radio" name="foo" id="foo-baz" value="baz">Baz</label>';
 
@@ -469,6 +469,51 @@ class Zend_View_Helper_FormRadioTest extends PHPUnit_Framework_TestCase
         $this->assertContains('value="bar" />', $html);
         $this->assertContains('value="baz" />', $html);
     }
+
+     /**
+      * @group ZF-11620
+      */
+     public function testSeparatorCanRendersAsXhtmlByDefault()
+     {
+         $this->view->doctype('XHTML1_STRICT');
+         $options = array(
+             'foo' => 'Foo',
+             'bar' => 'Bar',
+             'baz' => 'Baz'
+         );
+         $html = $this->helper->formRadio(array(
+             'name'    => 'foo',
+             'value'   => 'bar',
+             'options' => $options,
+         ));
+ 
+         $this->assertContains('<br />', $html);
+         $count = substr_count($html, '<br />');
+         $this->assertEquals(2, $count);
+     }
+ 
+     /**
+      * @group ZF-11620
+      */
+     public function testeparatorCanRendersAsHtml()
+     {
+         $this->view->doctype('HTML4_STRICT');
+         $options = array(
+             'foo' => 'Foo',
+             'bar' => 'Bar',
+             'baz' => 'Baz'
+         );
+         $html = $this->helper->formRadio(array(
+             'name'    => 'foo',
+             'value'   => 'bar',
+             'options' => $options,
+         ));
+ 
+         $this->assertContains('<br>', $html);
+         $count = substr_count($html, '<br>');
+         $this->assertEquals(2, $count);
+     }
+
 }
 
 // Call Zend_View_Helper_FormRadioTest::main() if this source file is executed directly.