MediaWiki
REL1_24
|
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( 00076 '<select><option value="foo">foo</option></select>', 00077 $this->select->getHTML() 00078 ); 00079 } 00080 00084 public function testAddOptionWithDefault() { 00085 $this->select->addOption( 'foo', true ); 00086 $this->assertEquals( 00087 '<select><option value="1">foo</option></select>', 00088 $this->select->getHTML() 00089 ); 00090 } 00091 00095 public function testAddOptionWithFalse() { 00096 $this->select->addOption( 'foo', false ); 00097 $this->assertEquals( 00098 '<select><option value="foo">foo</option></select>', 00099 $this->select->getHTML() 00100 ); 00101 } 00102 00106 public function testAddOptionWithValueZero() { 00107 $this->select->addOption( 'foo', 0 ); 00108 $this->assertEquals( 00109 '<select><option value="0">foo</option></select>', 00110 $this->select->getHTML() 00111 ); 00112 } 00113 00117 public function testSetDefault() { 00118 $this->select->setDefault( 'bar1' ); 00119 $this->select->addOption( 'foo1' ); 00120 $this->select->addOption( 'bar1' ); 00121 $this->select->addOption( 'foo2' ); 00122 $this->assertEquals( 00123 '<select><option value="foo1">foo1</option>' . "\n" . 00124 '<option value="bar1" selected="">bar1</option>' . "\n" . 00125 '<option value="foo2">foo2</option></select>', $this->select->getHTML() ); 00126 } 00127 00134 public function testSetDefaultAfterAddingOptions() { 00135 $this->select->addOption( 'foo1' ); 00136 $this->select->addOption( 'bar1' ); 00137 $this->select->addOption( 'foo2' ); 00138 $this->select->setDefault( 'bar1' ); # setting default after adding options 00139 $this->assertEquals( 00140 '<select><option value="foo1">foo1</option>' . "\n" . 00141 '<option value="bar1" selected="">bar1</option>' . "\n" . 00142 '<option value="foo2">foo2</option></select>', $this->select->getHTML() ); 00143 } 00144 00149 public function testGetAttributes() { 00150 # create some attributes 00151 $this->select->setAttribute( 'dummy', 0x777 ); 00152 $this->select->setAttribute( 'string', 'euro €' ); 00153 $this->select->setAttribute( 1911, 'razor' ); 00154 00155 # verify we can retrieve them 00156 $this->assertEquals( 00157 $this->select->getAttribute( 'dummy' ), 00158 0x777 00159 ); 00160 $this->assertEquals( 00161 $this->select->getAttribute( 'string' ), 00162 'euro €' 00163 ); 00164 $this->assertEquals( 00165 $this->select->getAttribute( 1911 ), 00166 'razor' 00167 ); 00168 00169 # inexistant keys should give us 'null' 00170 $this->assertEquals( 00171 $this->select->getAttribute( 'I DO NOT EXIT' ), 00172 null 00173 ); 00174 00175 # verify string / integer 00176 $this->assertEquals( 00177 $this->select->getAttribute( '1911' ), 00178 'razor' 00179 ); 00180 $this->assertEquals( 00181 $this->select->getAttribute( 'dummy' ), 00182 0x777 00183 ); 00184 } 00185 }