r91072 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r91071‎ | r91072 | r91073 >
Date:14:15, 29 June 2011
Author:platonides
Status:ok (Comments)
Tags:
Comment:
Delay expansion of XmlSelect options until getting the HTML.
Setting the default after adding options now works.
Enabled testSetDefaultAfterAddingOptions().
Modified paths:
  • /trunk/phase3/includes/Xml.php (modified) (history)
  • /trunk/phase3/tests/phpunit/includes/XmlSelectTest.php (modified) (history)

Diff [purge]

Index: trunk/phase3/tests/phpunit/includes/XmlSelectTest.php
@@ -90,8 +90,6 @@
9191 * To handle this, we need to render the options in getHtml()
9292 */
9393 public function testSetDefaultAfterAddingOptions() {
94 - $this->markTestSkipped( 'XmlSelect::setDefault() need to apply to previously added options');
95 -
9694 $this->select->addOption( 'foo1' );
9795 $this->select->addOption( 'bar1' );
9896 $this->select->addOption( 'foo2' );
Index: trunk/phase3/includes/Xml.php
@@ -863,7 +863,7 @@
864864 public function addOption( $name, $value = false ) {
865865 // Stab stab stab
866866 $value = ($value !== false) ? $value : $name;
867 - $this->options[] = Xml::option( $name, $value, $value === $this->default );
 867+ $this->options[] = array( $name => $value ); //Xml::option( $name, $value, $value === $this->default );
868868 }
869869
870870 /**
@@ -874,7 +874,7 @@
875875 * @param $options
876876 */
877877 public function addOptions( $options ) {
878 - $this->options[] = trim( self::formatOptions( $options, $this->default ) );
 878+ $this->options[] = $options;
879879 }
880880
881881 /**
@@ -904,7 +904,11 @@
905905 * @return string
906906 */
907907 public function getHTML() {
908 - return Xml::tags( 'select', $this->attributes, implode( "\n", $this->options ) );
 908+ $contents = '';
 909+ foreach ( $this->options as $options ) {
 910+ $contents .= self::formatOptions( $options, $this->default );
 911+ }
 912+ return Xml::tags( 'select', $this->attributes, rtrim( $contents ) );
909913 }
910914
911915 }

Follow-up revisions

RevisionCommit summaryAuthorDate
r91131Follow up r91072. This is indeed not needed.platonides22:37, 29 June 2011

Comments

#Comment by Nikerabbit (talk | contribs)   15:24, 29 June 2011

Yay. I think you can remove that commented out code.

Status & tagging log