Delay expansion of XmlSelect options until getting the HTML.
authorPlatonides <platonides@users.mediawiki.org>
Wed, 29 Jun 2011 14:15:47 +0000 (14:15 +0000)
committerPlatonides <platonides@users.mediawiki.org>
Wed, 29 Jun 2011 14:15:47 +0000 (14:15 +0000)
Setting the default after adding options now works.
Enabled testSetDefaultAfterAddingOptions().

includes/Xml.php
tests/phpunit/includes/XmlSelectTest.php

index a100a8b..ae7d2e4 100644 (file)
@@ -863,7 +863,7 @@ class XmlSelect {
        public function addOption( $name, $value = false ) {
                // Stab stab stab
                $value = ($value !== false) ? $value : $name;
-               $this->options[] = Xml::option( $name, $value, $value === $this->default );
+               $this->options[] = array( $name => $value ); //Xml::option( $name, $value, $value === $this->default );
        }
 
        /**
@@ -874,7 +874,7 @@ class XmlSelect {
         * @param  $options
         */
        public function addOptions( $options ) {
-               $this->options[] = trim( self::formatOptions( $options, $this->default ) );
+               $this->options[] = $options;
        }
 
        /**
@@ -904,7 +904,11 @@ class XmlSelect {
         * @return string
         */
        public function getHTML() {
-               return Xml::tags( 'select', $this->attributes, implode( "\n", $this->options ) );
+               $contents = '';
+               foreach ( $this->options as $options ) {
+                       $contents .= self::formatOptions( $options, $this->default );
+               }
+               return Xml::tags( 'select', $this->attributes, rtrim( $contents ) );
        }
 
 }
index 96a3b2a..e86b3bd 100644 (file)
@@ -90,8 +90,6 @@ class XmlSelectTest extends MediaWikiTestCase {
         * To handle this, we need to render the options in getHtml()
         */
        public function testSetDefaultAfterAddingOptions() {
-               $this->markTestSkipped( 'XmlSelect::setDefault() need to apply to previously added options');
-
                $this->select->addOption( 'foo1' );
                $this->select->addOption( 'bar1' );
                $this->select->addOption( 'foo2' );