MediaWiki  1.23.1
XmlSelectTest.php
Go to the documentation of this file.
1 <?php
2 
7 
11  protected $select;
12 
13  protected function setUp() {
14  parent::setUp();
15  $this->setMwGlobals( array(
16  'wgWellFormedXml' => true,
17  ) );
18  $this->select = new XmlSelect();
19  }
20 
21  protected function tearDown() {
22  parent::tearDown();
23  $this->select = null;
24  }
25 
29  public function testConstructWithoutParameters() {
30  $this->assertEquals( '<select></select>', $this->select->getHTML() );
31  }
32 
38  public function testConstructParameters( $name, $id, $default, $expected ) {
39  $this->select = new XmlSelect( $name, $id, $default );
40  $this->assertEquals( $expected, $this->select->getHTML() );
41  }
42 
51  public static function provideConstructionParameters() {
52  return array(
58  # $name $id $default
59  array( false, false, false, '<select></select>' ),
60  array( false, false, 'foo', '<select></select>' ),
61  array( false, 'id', 'foo', '<select id="id"></select>' ),
62  array( false, 'id', false, '<select id="id"></select>' ),
63  array( 'name', 'id', false, '<select name="name" id="id"></select>' ),
64  array( 'name', 'id', 'foo', '<select name="name" id="id"></select>' ),
65  array( 'name', false, 'foo', '<select name="name"></select>' ),
66  array( 'name', false, false, '<select name="name"></select>' ),
67  );
68  }
69 
73  public function testAddOption() {
74  $this->select->addOption( 'foo' );
75  $this->assertEquals( '<select><option value="foo">foo</option></select>', $this->select->getHTML() );
76  }
77 
81  public function testAddOptionWithDefault() {
82  $this->select->addOption( 'foo', true );
83  $this->assertEquals( '<select><option value="1">foo</option></select>', $this->select->getHTML() );
84  }
85 
89  public function testAddOptionWithFalse() {
90  $this->select->addOption( 'foo', false );
91  $this->assertEquals( '<select><option value="foo">foo</option></select>', $this->select->getHTML() );
92  }
93 
97  public function testAddOptionWithValueZero() {
98  $this->select->addOption( 'foo', 0 );
99  $this->assertEquals( '<select><option value="0">foo</option></select>', $this->select->getHTML() );
100  }
101 
105  public function testSetDefault() {
106  $this->select->setDefault( 'bar1' );
107  $this->select->addOption( 'foo1' );
108  $this->select->addOption( 'bar1' );
109  $this->select->addOption( 'foo2' );
110  $this->assertEquals(
111  '<select><option value="foo1">foo1</option>' . "\n" .
112  '<option value="bar1" selected="">bar1</option>' . "\n" .
113  '<option value="foo2">foo2</option></select>', $this->select->getHTML() );
114  }
115 
122  public function testSetDefaultAfterAddingOptions() {
123  $this->select->addOption( 'foo1' );
124  $this->select->addOption( 'bar1' );
125  $this->select->addOption( 'foo2' );
126  $this->select->setDefault( 'bar1' ); # setting default after adding options
127  $this->assertEquals(
128  '<select><option value="foo1">foo1</option>' . "\n" .
129  '<option value="bar1" selected="">bar1</option>' . "\n" .
130  '<option value="foo2">foo2</option></select>', $this->select->getHTML() );
131  }
132 
137  public function testGetAttributes() {
138  # create some attributes
139  $this->select->setAttribute( 'dummy', 0x777 );
140  $this->select->setAttribute( 'string', 'euro €' );
141  $this->select->setAttribute( 1911, 'razor' );
142 
143  # verify we can retrieve them
144  $this->assertEquals(
145  $this->select->getAttribute( 'dummy' ),
146  0x777
147  );
148  $this->assertEquals(
149  $this->select->getAttribute( 'string' ),
150  'euro €'
151  );
152  $this->assertEquals(
153  $this->select->getAttribute( 1911 ),
154  'razor'
155  );
156 
157  # inexistant keys should give us 'null'
158  $this->assertEquals(
159  $this->select->getAttribute( 'I DO NOT EXIT' ),
160  null
161  );
162 
163  # verify string / integer
164  $this->assertEquals(
165  $this->select->getAttribute( '1911' ),
166  'razor'
167  );
168  $this->assertEquals(
169  $this->select->getAttribute( 'dummy' ),
170  0x777
171  );
172  }
173 }
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
XmlSelectTest\testConstructParameters
testConstructParameters( $name, $id, $default, $expected)
Parameters are $name (false), $id (false), $default (false) @dataProvider provideConstructionParamete...
Definition: XmlSelectTest.php:37
XmlSelectTest\testGetAttributes
testGetAttributes()
@covers XmlSelect::setAttribute @covers XmlSelect::getAttribute
Definition: XmlSelectTest.php:136
XmlSelectTest\testSetDefault
testSetDefault()
@covers XmlSelect::setDefault
Definition: XmlSelectTest.php:104
XmlSelectTest
@group Xml
Definition: XmlSelectTest.php:6
XmlSelect
Definition: Xml.php:842
XmlSelectTest\provideConstructionParameters
static provideConstructionParameters()
Provide parameters for testConstructParameters() which use three parameters:
Definition: XmlSelectTest.php:50
MediaWikiTestCase\setMwGlobals
setMwGlobals( $pairs, $value=null)
Definition: MediaWikiTestCase.php:302
MediaWikiTestCase
Definition: MediaWikiTestCase.php:6
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
XmlSelectTest\testAddOptionWithValueZero
testAddOptionWithValueZero()
@covers XmlSelect::addOption
Definition: XmlSelectTest.php:96
$name
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:336
options
We ve cleaned up the code here by removing clumps of infrequently used code and moving them off somewhere else It s much easier for someone working with this code to see what s _really_ going and make changes or fix bugs In we can take all the code that deals with the little used title reversing options(say) and put it in one place. Instead of having little title-reversing if-blocks spread all over the codebase in showAnArticle
XmlSelectTest\setUp
setUp()
Definition: XmlSelectTest.php:12
XmlSelectTest\testSetDefaultAfterAddingOptions
testSetDefaultAfterAddingOptions()
Adding default later on should set the correct selection or raise an exception.
Definition: XmlSelectTest.php:121
XmlSelectTest\$select
XmlSelect $select
Definition: XmlSelectTest.php:10
XmlSelectTest\testAddOptionWithFalse
testAddOptionWithFalse()
@covers XmlSelect::addOption
Definition: XmlSelectTest.php:88
XmlSelectTest\testAddOptionWithDefault
testAddOptionWithDefault()
@covers XmlSelect::addOption
Definition: XmlSelectTest.php:80
XmlSelectTest\testConstructWithoutParameters
testConstructWithoutParameters()
@covers XmlSelect::__construct
Definition: XmlSelectTest.php:28
select
We use the convention $dbr for read and $dbw for write to help you keep track of whether the database object is a the world will explode Or to be a subsequent write query which succeeded on the master may fail when replicated to the slave due to a unique key collision Replication on the slave will stop and it may take hours to repair the database and get it back online Setting read_only in my cnf on the slave will avoid this but given the dire we prefer to have as many checks as possible We provide a but the wrapper functions like select() and insert() are usually more convenient. They take care of things like table prefixes and escaping for you. If you really need to make your own SQL
XmlSelectTest\testAddOption
testAddOption()
@covers XmlSelect::addOption
Definition: XmlSelectTest.php:72
XmlSelectTest\tearDown
tearDown()
Definition: XmlSelectTest.php:20