MediaWiki  master
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->select = new XmlSelect();
00010         }
00011         protected function tearDown() {
00012                 parent::tearDown();
00013                 $this->select = null;
00014         }
00015 
00016         ### START OF TESTS ###
00017 
00018         public function testConstructWithoutParameters() {
00019                 $this->assertEquals( '<select></select>', $this->select->getHTML() );
00020         }
00021 
00026         public function testConstructParameters( $name, $id, $default, $expected ) {
00027                 $this->select = new XmlSelect( $name, $id, $default );
00028                 $this->assertEquals( $expected, $this->select->getHTML() );
00029         }
00030 
00040         public static function provideConstructionParameters() {
00041                 return array(
00047                         #      $name   $id    $default
00048                         array( false , false, false,  '<select></select>' ),
00049                         array( false , false, 'foo',  '<select></select>' ),
00050                         array( false , 'id' , 'foo',  '<select id="id"></select>' ),
00051                         array( false , 'id' , false,  '<select id="id"></select>' ),
00052                         array( 'name', 'id' , false,  '<select name="name" id="id"></select>' ),
00053                         array( 'name', 'id' , 'foo',  '<select name="name" id="id"></select>' ),
00054                         array( 'name', false, 'foo',  '<select name="name"></select>' ),
00055                         array( 'name', false, false,  '<select name="name"></select>' ),
00056                 );
00057         }
00058 
00059         # Begin XmlSelect::addOption() similar to Xml::option
00060         public function testAddOption() {
00061                 $this->select->addOption( 'foo' );
00062                 $this->assertEquals( '<select><option value="foo">foo</option></select>', $this->select->getHTML() );
00063         }
00064         public function testAddOptionWithDefault() {
00065                 $this->select->addOption( 'foo', true );
00066                 $this->assertEquals( '<select><option value="1">foo</option></select>', $this->select->getHTML() );
00067         }
00068         public function testAddOptionWithFalse() {
00069                 $this->select->addOption( 'foo', false );
00070                 $this->assertEquals( '<select><option value="foo">foo</option></select>', $this->select->getHTML() );
00071         }
00072         public function testAddOptionWithValueZero() {
00073                 $this->select->addOption( 'foo', 0 );
00074                 $this->assertEquals( '<select><option value="0">foo</option></select>', $this->select->getHTML() );
00075         }
00076         # End XmlSelect::addOption() similar to Xml::option
00077 
00078         public function testSetDefault() {
00079                 $this->select->setDefault( 'bar1' );
00080                 $this->select->addOption( 'foo1' );
00081                 $this->select->addOption( 'bar1' );
00082                 $this->select->addOption( 'foo2' );
00083                 $this->assertEquals(
00084 '<select><option value="foo1">foo1</option>' . "\n" .
00085 '<option value="bar1" selected="">bar1</option>' . "\n" .
00086 '<option value="foo2">foo2</option></select>', $this->select->getHTML() );
00087         }
00088 
00094         public function testSetDefaultAfterAddingOptions() {
00095                 $this->select->addOption( 'foo1' );
00096                 $this->select->addOption( 'bar1' );
00097                 $this->select->addOption( 'foo2' );
00098                 $this->select->setDefault( 'bar1' ); # setting default after adding options
00099                 $this->assertEquals(
00100 '<select><option value="foo1">foo1</option>' . "\n" .
00101 '<option value="bar1" selected="">bar1</option>' . "\n" .
00102 '<option value="foo2">foo2</option></select>', $this->select->getHTML() );
00103         }
00104 
00105         public function testGetAttributes() {
00106                 # create some attributes
00107                 $this->select->setAttribute( 'dummy', 0x777 );
00108                 $this->select->setAttribute( 'string', 'euro €' );
00109                 $this->select->setAttribute( 1911, 'razor' );
00110 
00111                 # verify we can retrieve them
00112                 $this->assertEquals(
00113                         $this->select->getAttribute( 'dummy' ),
00114                         0x777
00115                 );
00116                 $this->assertEquals(
00117                         $this->select->getAttribute( 'string' ),
00118                         'euro €'
00119                 );
00120                 $this->assertEquals(
00121                         $this->select->getAttribute( 1911 ),
00122                         'razor'
00123                 );
00124 
00125                 # inexistant keys should give us 'null'
00126                 $this->assertEquals(
00127                         $this->select->getAttribute( 'I DO NOT EXIT' ),
00128                         null
00129                 );
00130 
00131                 # verify string / integer
00132                 $this->assertEquals(
00133                         $this->select->getAttribute( '1911' ),
00134                         'razor' 
00135                 );
00136                 $this->assertEquals(
00137                         $this->select->getAttribute( 'dummy' ),
00138                         0x777
00139                 );
00140         }
00141 }