MediaWiki  REL1_22
XmlSelectTest.php
Go to the documentation of this file.
00001 <?php
00002 
00006 class XmlSelectTest extends MediaWikiTestCase {
00007 
00011     protected $select;
00012 
00013     protected function setUp() {
00014         parent::setUp();
00015         $this->setMwGlobals( array(
00016             'wgWellFormedXml' => true,
00017         ) );
00018         $this->select = new XmlSelect();
00019     }
00020 
00021     protected function tearDown() {
00022         parent::tearDown();
00023         $this->select = null;
00024     }
00025 
00029     public function testConstructWithoutParameters() {
00030         $this->assertEquals( '<select></select>', $this->select->getHTML() );
00031     }
00032 
00038     public function testConstructParameters( $name, $id, $default, $expected ) {
00039         $this->select = new XmlSelect( $name, $id, $default );
00040         $this->assertEquals( $expected, $this->select->getHTML() );
00041     }
00042 
00051     public static function provideConstructionParameters() {
00052         return array(
00058             #      $name   $id    $default
00059             array( false, false, false, '<select></select>' ),
00060             array( false, false, 'foo', '<select></select>' ),
00061             array( false, 'id', 'foo', '<select id="id"></select>' ),
00062             array( false, 'id', false, '<select id="id"></select>' ),
00063             array( 'name', 'id', false, '<select name="name" id="id"></select>' ),
00064             array( 'name', 'id', 'foo', '<select name="name" id="id"></select>' ),
00065             array( 'name', false, 'foo', '<select name="name"></select>' ),
00066             array( 'name', false, false, '<select name="name"></select>' ),
00067         );
00068     }
00069 
00073     public function testAddOption() {
00074         $this->select->addOption( 'foo' );
00075         $this->assertEquals( '<select><option value="foo">foo</option></select>', $this->select->getHTML() );
00076     }
00077 
00081     public function testAddOptionWithDefault() {
00082         $this->select->addOption( 'foo', true );
00083         $this->assertEquals( '<select><option value="1">foo</option></select>', $this->select->getHTML() );
00084     }
00085 
00089     public function testAddOptionWithFalse() {
00090         $this->select->addOption( 'foo', false );
00091         $this->assertEquals( '<select><option value="foo">foo</option></select>', $this->select->getHTML() );
00092     }
00093 
00097     public function testAddOptionWithValueZero() {
00098         $this->select->addOption( 'foo', 0 );
00099         $this->assertEquals( '<select><option value="0">foo</option></select>', $this->select->getHTML() );
00100     }
00101 
00105     public function testSetDefault() {
00106         $this->select->setDefault( 'bar1' );
00107         $this->select->addOption( 'foo1' );
00108         $this->select->addOption( 'bar1' );
00109         $this->select->addOption( 'foo2' );
00110         $this->assertEquals(
00111             '<select><option value="foo1">foo1</option>' . "\n" .
00112                 '<option value="bar1" selected="">bar1</option>' . "\n" .
00113                 '<option value="foo2">foo2</option></select>', $this->select->getHTML() );
00114     }
00115 
00122     public function testSetDefaultAfterAddingOptions() {
00123         $this->select->addOption( 'foo1' );
00124         $this->select->addOption( 'bar1' );
00125         $this->select->addOption( 'foo2' );
00126         $this->select->setDefault( 'bar1' ); # setting default after adding options
00127         $this->assertEquals(
00128             '<select><option value="foo1">foo1</option>' . "\n" .
00129                 '<option value="bar1" selected="">bar1</option>' . "\n" .
00130                 '<option value="foo2">foo2</option></select>', $this->select->getHTML() );
00131     }
00132 
00137     public function testGetAttributes() {
00138         # create some attributes
00139         $this->select->setAttribute( 'dummy', 0x777 );
00140         $this->select->setAttribute( 'string', 'euro €' );
00141         $this->select->setAttribute( 1911, 'razor' );
00142 
00143         # verify we can retrieve them
00144         $this->assertEquals(
00145             $this->select->getAttribute( 'dummy' ),
00146             0x777
00147         );
00148         $this->assertEquals(
00149             $this->select->getAttribute( 'string' ),
00150             'euro €'
00151         );
00152         $this->assertEquals(
00153             $this->select->getAttribute( 1911 ),
00154             'razor'
00155         );
00156 
00157         # inexistant keys should give us 'null'
00158         $this->assertEquals(
00159             $this->select->getAttribute( 'I DO NOT EXIT' ),
00160             null
00161         );
00162 
00163         # verify string / integer
00164         $this->assertEquals(
00165             $this->select->getAttribute( '1911' ),
00166             'razor'
00167         );
00168         $this->assertEquals(
00169             $this->select->getAttribute( 'dummy' ),
00170             0x777
00171         );
00172     }
00173 }