Changed quoting function for oracleDB.
[mediawiki.git] / tests / phpunit / includes / XmlSelectTest.php
blob08c031f8d786b5348d9e82586ab853254a399967
1 <?php
3 // TODO
4 class XmlSelectTest extends MediaWikiTestCase {
5 protected $select;
7 protected function setUp() {
8 parent::setUp();
9 $this->setMwGlobals( array(
10 'wgWellFormedXml' => true,
11 ) );
12 $this->select = new XmlSelect();
15 protected function tearDown() {
16 parent::tearDown();
17 $this->select = null;
20 ### START OF TESTS ###
22 public function testConstructWithoutParameters() {
23 $this->assertEquals( '<select></select>', $this->select->getHTML() );
26 /**
27 * Parameters are $name (false), $id (false), $default (false)
28 * @dataProvider provideConstructionParameters
30 public function testConstructParameters( $name, $id, $default, $expected ) {
31 $this->select = new XmlSelect( $name, $id, $default );
32 $this->assertEquals( $expected, $this->select->getHTML() );
35 /**
36 * Provide parameters for testConstructParameters() which use three
37 * parameters:
38 * - $name (default: false)
39 * - $id (default: false)
40 * - $default (default: false)
41 * Provides a fourth parameters representing the expected HTML output
44 public static function provideConstructionParameters() {
45 return array(
46 /**
47 * Values are set following a 3-bit Gray code where two successive
48 * values differ by only one value.
49 * See http://en.wikipedia.org/wiki/Gray_code
51 # $name $id $default
52 array( false, false, false, '<select></select>' ),
53 array( false, false, 'foo', '<select></select>' ),
54 array( false, 'id', 'foo', '<select id="id"></select>' ),
55 array( false, 'id', false, '<select id="id"></select>' ),
56 array( 'name', 'id', false, '<select name="name" id="id"></select>' ),
57 array( 'name', 'id', 'foo', '<select name="name" id="id"></select>' ),
58 array( 'name', false, 'foo', '<select name="name"></select>' ),
59 array( 'name', false, false, '<select name="name"></select>' ),
63 # Begin XmlSelect::addOption() similar to Xml::option
64 public function testAddOption() {
65 $this->select->addOption( 'foo' );
66 $this->assertEquals( '<select><option value="foo">foo</option></select>', $this->select->getHTML() );
69 public function testAddOptionWithDefault() {
70 $this->select->addOption( 'foo', true );
71 $this->assertEquals( '<select><option value="1">foo</option></select>', $this->select->getHTML() );
74 public function testAddOptionWithFalse() {
75 $this->select->addOption( 'foo', false );
76 $this->assertEquals( '<select><option value="foo">foo</option></select>', $this->select->getHTML() );
79 public function testAddOptionWithValueZero() {
80 $this->select->addOption( 'foo', 0 );
81 $this->assertEquals( '<select><option value="0">foo</option></select>', $this->select->getHTML() );
84 # End XmlSelect::addOption() similar to Xml::option
86 public function testSetDefault() {
87 $this->select->setDefault( 'bar1' );
88 $this->select->addOption( 'foo1' );
89 $this->select->addOption( 'bar1' );
90 $this->select->addOption( 'foo2' );
91 $this->assertEquals(
92 '<select><option value="foo1">foo1</option>' . "\n" .
93 '<option value="bar1" selected="">bar1</option>' . "\n" .
94 '<option value="foo2">foo2</option></select>', $this->select->getHTML() );
97 /**
98 * Adding default later on should set the correct selection or
99 * raise an exception.
100 * To handle this, we need to render the options in getHtml()
102 public function testSetDefaultAfterAddingOptions() {
103 $this->select->addOption( 'foo1' );
104 $this->select->addOption( 'bar1' );
105 $this->select->addOption( 'foo2' );
106 $this->select->setDefault( 'bar1' ); # setting default after adding options
107 $this->assertEquals(
108 '<select><option value="foo1">foo1</option>' . "\n" .
109 '<option value="bar1" selected="">bar1</option>' . "\n" .
110 '<option value="foo2">foo2</option></select>', $this->select->getHTML() );
113 public function testGetAttributes() {
114 # create some attributes
115 $this->select->setAttribute( 'dummy', 0x777 );
116 $this->select->setAttribute( 'string', 'euro €' );
117 $this->select->setAttribute( 1911, 'razor' );
119 # verify we can retrieve them
120 $this->assertEquals(
121 $this->select->getAttribute( 'dummy' ),
122 0x777
124 $this->assertEquals(
125 $this->select->getAttribute( 'string' ),
126 'euro €'
128 $this->assertEquals(
129 $this->select->getAttribute( 1911 ),
130 'razor'
133 # inexistant keys should give us 'null'
134 $this->assertEquals(
135 $this->select->getAttribute( 'I DO NOT EXIT' ),
136 null
139 # verify string / integer
140 $this->assertEquals(
141 $this->select->getAttribute( '1911' ),
142 'razor'
144 $this->assertEquals(
145 $this->select->getAttribute( 'dummy' ),
146 0x777