From: Platonides Date: Wed, 29 Jun 2011 14:15:47 +0000 (+0000) Subject: Delay expansion of XmlSelect options until getting the HTML. X-Git-Tag: 1.31.0-rc.0~29197 X-Git-Url: http://git.cyclocoop.org/%22.%28%24lien.?a=commitdiff_plain;h=eadb8a3e732a7ee602628609ba0b53aea03b1abf;p=lhc%2Fweb%2Fwiklou.git Delay expansion of XmlSelect options until getting the HTML. Setting the default after adding options now works. Enabled testSetDefaultAfterAddingOptions(). --- diff --git a/includes/Xml.php b/includes/Xml.php index a100a8bf28..ae7d2e4de6 100644 --- a/includes/Xml.php +++ b/includes/Xml.php @@ -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 ) ); } } diff --git a/tests/phpunit/includes/XmlSelectTest.php b/tests/phpunit/includes/XmlSelectTest.php index 96a3b2a0bb..e86b3bdbb3 100644 --- a/tests/phpunit/includes/XmlSelectTest.php +++ b/tests/phpunit/includes/XmlSelectTest.php @@ -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' );