Browse Source

ZF-8252

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@24157 44c647ce-9c0f-0410-b52a-842ac1e357ba
ezimuel 14 years ago
parent
commit
646840e7cb
2 changed files with 22 additions and 0 deletions
  1. 3 0
      library/Zend/View/Helper/FormSelect.php
  2. 19 0
      tests/Zend/View/Helper/FormSelectTest.php

+ 3 - 0
library/Zend/View/Helper/FormSelect.php

@@ -123,8 +123,11 @@ class Zend_View_Helper_FormSelect extends Zend_View_Helper_FormElement
                 if (null !== $translator) {
                     $opt_value = $translator->translate($opt_value);
                 }
+                $opt_id = ' id="' . $this->view->escape($id) . '-optgroup-'
+                        . $this->view->escape($opt_value) . '"';
                 $list[] = '<optgroup'
                         . $opt_disable
+                        . $opt_id
                         . ' label="' . $this->view->escape($opt_value) .'">';
                 foreach ($opt_label as $val => $lab) {
                     $list[] = $this->_build($val, $lab, $value, $disable);

+ 19 - 0
tests/Zend/View/Helper/FormSelectTest.php

@@ -311,6 +311,25 @@ class Zend_View_Helper_FormSelectTest extends PHPUnit_Framework_TestCase
         $this->assertRegexp('/<select[^>]*?(name="baz\[\]")/', $html, $html);
         $this->assertNotRegexp('/<select[^>]*?(multiple="multiple")/', $html, $html);
     }
+    /** 
+     * @group ZF-8252
+     */
+    public function testOptGroupHasAnId()
+    {
+        $html = $this->helper->formSelect(array(
+            'name'    => 'baz',
+            'options' => array(
+                'foo' => 'Foo',
+                'bar' => array(
+                    '1' => 'one',
+                    '2' => 'two'
+                ),
+                'baz' => 'Baz,'
+            )
+        ));
+        $this->assertRegexp('/<optgroup[^>]*?id="baz-optgroup-bar"[^>]*?"bar"[^>]*?/', $html, $html);
+    }
+ 
 }
 
 // Call Zend_View_Helper_FormSelectTest::main() if this source file is executed directly.