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