MediaWiki  REL1_21
XmlSelectTest.php
Go to the documentation of this file.
00001 <?php
00002 
00003 // TODO
00004 class XmlSelectTest extends MediaWikiTestCase {
00005         protected $select;
00006 
00007         protected function setUp() {
00008                 parent::setUp();
00009                 $this->setMwGlobals( array(
00010                         'wgHtml5' => true,
00011                         'wgWellFormedXml' => true,
00012                 ) );
00013                 $this->select = new XmlSelect();
00014         }
00015 
00016         protected function tearDown() {
00017                 parent::tearDown();
00018                 $this->select = null;
00019         }
00020 
00021         ### START OF TESTS ###
00022 
00023         public function testConstructWithoutParameters() {
00024                 $this->assertEquals( '<select></select>', $this->select->getHTML() );
00025         }
00026 
00031         public function testConstructParameters( $name, $id, $default, $expected ) {
00032                 $this->select = new XmlSelect( $name, $id, $default );
00033                 $this->assertEquals( $expected, $this->select->getHTML() );
00034         }
00035 
00045         public static function provideConstructionParameters() {
00046                 return array(
00052                         #      $name   $id    $default
00053                         array( false, false, false, '<select></select>' ),
00054                         array( false, false, 'foo', '<select></select>' ),
00055                         array( false, 'id', 'foo', '<select id="id"></select>' ),
00056                         array( false, 'id', false, '<select id="id"></select>' ),
00057                         array( 'name', 'id', false, '<select name="name" id="id"></select>' ),
00058                         array( 'name', 'id', 'foo', '<select name="name" id="id"></select>' ),
00059                         array( 'name', false, 'foo', '<select name="name"></select>' ),
00060                         array( 'name', false, false, '<select name="name"></select>' ),
00061                 );
00062         }
00063 
00064         # Begin XmlSelect::addOption() similar to Xml::option
00065         public function testAddOption() {
00066                 $this->select->addOption( 'foo' );
00067                 $this->assertEquals( '<select><option value="foo">foo</option></select>', $this->select->getHTML() );
00068         }
00069 
00070         public function testAddOptionWithDefault() {
00071                 $this->select->addOption( 'foo', true );
00072                 $this->assertEquals( '<select><option value="1">foo</option></select>', $this->select->getHTML() );
00073         }
00074 
00075         public function testAddOptionWithFalse() {
00076                 $this->select->addOption( 'foo', false );
00077                 $this->assertEquals( '<select><option value="foo">foo</option></select>', $this->select->getHTML() );
00078         }
00079 
00080         public function testAddOptionWithValueZero() {
00081                 $this->select->addOption( 'foo', 0 );
00082                 $this->assertEquals( '<select><option value="0">foo</option></select>', $this->select->getHTML() );
00083         }
00084 
00085         # End XmlSelect::addOption() similar to Xml::option
00086 
00087         public function testSetDefault() {
00088                 $this->select->setDefault( 'bar1' );
00089                 $this->select->addOption( 'foo1' );
00090                 $this->select->addOption( 'bar1' );
00091                 $this->select->addOption( 'foo2' );
00092                 $this->assertEquals(
00093                         '<select><option value="foo1">foo1</option>' . "\n" .
00094                                 '<option value="bar1" selected="">bar1</option>' . "\n" .
00095                                 '<option value="foo2">foo2</option></select>', $this->select->getHTML() );
00096         }
00097 
00103         public function testSetDefaultAfterAddingOptions() {
00104                 $this->select->addOption( 'foo1' );
00105                 $this->select->addOption( 'bar1' );
00106                 $this->select->addOption( 'foo2' );
00107                 $this->select->setDefault( 'bar1' ); # setting default after adding options
00108                 $this->assertEquals(
00109                         '<select><option value="foo1">foo1</option>' . "\n" .
00110                                 '<option value="bar1" selected="">bar1</option>' . "\n" .
00111                                 '<option value="foo2">foo2</option></select>', $this->select->getHTML() );
00112         }
00113 
00114         public function testGetAttributes() {
00115                 # create some attributes
00116                 $this->select->setAttribute( 'dummy', 0x777 );
00117                 $this->select->setAttribute( 'string', 'euro €' );
00118                 $this->select->setAttribute( 1911, 'razor' );
00119 
00120                 # verify we can retrieve them
00121                 $this->assertEquals(
00122                         $this->select->getAttribute( 'dummy' ),
00123                         0x777
00124                 );
00125                 $this->assertEquals(
00126                         $this->select->getAttribute( 'string' ),
00127                         'euro €'
00128                 );
00129                 $this->assertEquals(
00130                         $this->select->getAttribute( 1911 ),
00131                         'razor'
00132                 );
00133 
00134                 # inexistant keys should give us 'null'
00135                 $this->assertEquals(
00136                         $this->select->getAttribute( 'I DO NOT EXIT' ),
00137                         null
00138                 );
00139 
00140                 # verify string / integer
00141                 $this->assertEquals(
00142                         $this->select->getAttribute( '1911' ),
00143                         'razor'
00144                 );
00145                 $this->assertEquals(
00146                         $this->select->getAttribute( 'dummy' ),
00147                         0x777
00148                 );
00149         }
00150 }