summaryrefslogtreecommitdiff
path: root/tests/phpunit/includes/XmlTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'tests/phpunit/includes/XmlTest.php')
-rw-r--r--tests/phpunit/includes/XmlTest.php302
1 files changed, 181 insertions, 121 deletions
diff --git a/tests/phpunit/includes/XmlTest.php b/tests/phpunit/includes/XmlTest.php
index 93ed3dc7..8205029f 100644
--- a/tests/phpunit/includes/XmlTest.php
+++ b/tests/phpunit/includes/XmlTest.php
@@ -1,48 +1,44 @@
<?php
+/**
+ * @group Xml
+ */
class XmlTest extends MediaWikiTestCase {
- private static $oldLang;
- private static $oldNamespaces;
- public function setUp() {
- global $wgLang, $wgContLang;
+ protected function setUp() {
+ parent::setUp();
- self::$oldLang = $wgLang;
- $wgLang = Language::factory( 'en' );
-
- // Hardcode namespaces during test runs,
- // so that html output based on existing namespaces
- // can be properly evaluated.
- self::$oldNamespaces = $wgContLang->getNamespaces();
- $wgContLang->setNamespaces( array(
+ $langObj = Language::factory( 'en' );
+ $langObj->setNamespaces( array(
-2 => 'Media',
-1 => 'Special',
- 0 => '',
- 1 => 'Talk',
- 2 => 'User',
- 3 => 'User_talk',
- 4 => 'MyWiki',
- 5 => 'MyWiki_Talk',
- 6 => 'File',
- 7 => 'File_talk',
- 8 => 'MediaWiki',
- 9 => 'MediaWiki_talk',
- 10 => 'Template',
- 11 => 'Template_talk',
- 100 => 'Custom',
- 101 => 'Custom_talk',
+ 0 => '',
+ 1 => 'Talk',
+ 2 => 'User',
+ 3 => 'User_talk',
+ 4 => 'MyWiki',
+ 5 => 'MyWiki_Talk',
+ 6 => 'File',
+ 7 => 'File_talk',
+ 8 => 'MediaWiki',
+ 9 => 'MediaWiki_talk',
+ 10 => 'Template',
+ 11 => 'Template_talk',
+ 100 => 'Custom',
+ 101 => 'Custom_talk',
) );
- }
- public function tearDown() {
- global $wgLang, $wgContLang;
- $wgLang = self::$oldLang;
-
- $wgContLang->setNamespaces( self::$oldNamespaces );
+ $this->setMwGlobals( array(
+ 'wgLang' => $langObj,
+ 'wgWellFormedXml' => true,
+ ) );
}
+ /**
+ * @covers Xml::expandAttributes
+ */
public function testExpandAttributes() {
- $this->assertNull( Xml::expandAttributes(null),
+ $this->assertNull( Xml::expandAttributes( null ),
'Converting a null list of attributes'
);
$this->assertEquals( '', Xml::expandAttributes( array() ),
@@ -50,12 +46,18 @@ class XmlTest extends MediaWikiTestCase {
);
}
+ /**
+ * @covers Xml::expandAttributes
+ */
public function testExpandAttributesException() {
- $this->setExpectedException('MWException');
- Xml::expandAttributes('string');
+ $this->setExpectedException( 'MWException' );
+ Xml::expandAttributes( 'string' );
}
- function testElementOpen() {
+ /**
+ * @covers Xml::element
+ */
+ public function testElementOpen() {
$this->assertEquals(
'<element>',
Xml::element( 'element', null, null ),
@@ -63,7 +65,10 @@ class XmlTest extends MediaWikiTestCase {
);
}
- function testElementEmpty() {
+ /**
+ * @covers Xml::element
+ */
+ public function testElementEmpty() {
$this->assertEquals(
'<element />',
Xml::element( 'element', null, '' ),
@@ -71,14 +76,21 @@ class XmlTest extends MediaWikiTestCase {
);
}
- function testElementInputCanHaveAValueOfZero() {
+ /**
+ * @covers Xml::input
+ */
+ public function testElementInputCanHaveAValueOfZero() {
$this->assertEquals(
'<input name="name" value="0" />',
Xml::input( 'name', false, 0 ),
'Input with a value of 0 (bug 23797)'
);
}
- function testElementEscaping() {
+
+ /**
+ * @covers Xml::element
+ */
+ public function testElementEscaping() {
$this->assertEquals(
'<element>hello &lt;there&gt; you &amp; you</element>',
Xml::element( 'element', null, 'hello <there> you & you' ),
@@ -86,13 +98,19 @@ class XmlTest extends MediaWikiTestCase {
);
}
+ /**
+ * @covers Xml::escapeTagsOnly
+ */
public function testEscapeTagsOnly() {
$this->assertEquals( '&quot;&gt;&lt;', Xml::escapeTagsOnly( '"><' ),
'replace " > and < with their HTML entitites'
);
}
- function testElementAttributes() {
+ /**
+ * @covers Xml::element
+ */
+ public function testElementAttributes() {
$this->assertEquals(
'<element key="value" <>="&lt;&gt;">',
Xml::element( 'element', array( 'key' => 'value', '<>' => '<>' ), null ),
@@ -100,7 +118,10 @@ class XmlTest extends MediaWikiTestCase {
);
}
- function testOpenElement() {
+ /**
+ * @covers Xml::openElement
+ */
+ public function testOpenElement() {
$this->assertEquals(
'<element k="v">',
Xml::openElement( 'element', array( 'k' => 'v' ) ),
@@ -108,95 +129,100 @@ class XmlTest extends MediaWikiTestCase {
);
}
- function testCloseElement() {
+ /**
+ * @covers Xml::closeElement
+ */
+ public function testCloseElement() {
$this->assertEquals( '</element>', Xml::closeElement( 'element' ), 'closeElement() shortcut' );
}
/**
- * @group Broken
+ * @covers Xml::dateMenu
*/
- public function testDateMenu( ) {
- $curYear = intval(gmdate('Y'));
- $prevYear = $curYear - 1;
+ public function testDateMenu() {
+ $curYear = intval( gmdate( 'Y' ) );
+ $prevYear = $curYear - 1;
- $curMonth = intval(gmdate('n'));
+ $curMonth = intval( gmdate( 'n' ) );
$prevMonth = $curMonth - 1;
- if( $prevMonth == 0 ) { $prevMonth = 12; }
+ if ( $prevMonth == 0 ) {
+ $prevMonth = 12;
+ }
$nextMonth = $curMonth + 1;
- if( $nextMonth == 13 ) { $nextMonth = 1; }
+ if ( $nextMonth == 13 ) {
+ $nextMonth = 1;
+ }
$this->assertEquals(
- '<label for="year">From year (and earlier):</label> <input name="year" size="4" value="2011" id="year" maxlength="4" /> <label for="month">From month (and earlier):</label> <select id="month" name="month" class="mw-month-selector"><option value="-1">all</option>' . "\n" .
-'<option value="1">January</option>' . "\n" .
-'<option value="2" selected="">February</option>' . "\n" .
-'<option value="3">March</option>' . "\n" .
-'<option value="4">April</option>' . "\n" .
-'<option value="5">May</option>' . "\n" .
-'<option value="6">June</option>' . "\n" .
-'<option value="7">July</option>' . "\n" .
-'<option value="8">August</option>' . "\n" .
-'<option value="9">September</option>' . "\n" .
-'<option value="10">October</option>' . "\n" .
-'<option value="11">November</option>' . "\n" .
-'<option value="12">December</option></select>',
+ '<label for="year">From year (and earlier):</label> <input id="year" maxlength="4" size="7" type="number" value="2011" name="year" /> <label for="month">From month (and earlier):</label> <select id="month" name="month" class="mw-month-selector"><option value="-1">all</option>' . "\n" .
+ '<option value="1">January</option>' . "\n" .
+ '<option value="2" selected="">February</option>' . "\n" .
+ '<option value="3">March</option>' . "\n" .
+ '<option value="4">April</option>' . "\n" .
+ '<option value="5">May</option>' . "\n" .
+ '<option value="6">June</option>' . "\n" .
+ '<option value="7">July</option>' . "\n" .
+ '<option value="8">August</option>' . "\n" .
+ '<option value="9">September</option>' . "\n" .
+ '<option value="10">October</option>' . "\n" .
+ '<option value="11">November</option>' . "\n" .
+ '<option value="12">December</option></select>',
Xml::dateMenu( 2011, 02 ),
"Date menu for february 2011"
);
$this->assertEquals(
- '<label for="year">From year (and earlier):</label> <input name="year" size="4" value="2011" id="year" maxlength="4" /> <label for="month">From month (and earlier):</label> <select id="month" name="month" class="mw-month-selector"><option value="-1">all</option>' . "\n" .
-'<option value="1">January</option>' . "\n" .
-'<option value="2">February</option>' . "\n" .
-'<option value="3">March</option>' . "\n" .
-'<option value="4">April</option>' . "\n" .
-'<option value="5">May</option>' . "\n" .
-'<option value="6">June</option>' . "\n" .
-'<option value="7">July</option>' . "\n" .
-'<option value="8">August</option>' . "\n" .
-'<option value="9">September</option>' . "\n" .
-'<option value="10">October</option>' . "\n" .
-'<option value="11">November</option>' . "\n" .
-'<option value="12">December</option></select>',
- Xml::dateMenu( 2011, -1),
+ '<label for="year">From year (and earlier):</label> <input id="year" maxlength="4" size="7" type="number" value="2011" name="year" /> <label for="month">From month (and earlier):</label> <select id="month" name="month" class="mw-month-selector"><option value="-1">all</option>' . "\n" .
+ '<option value="1">January</option>' . "\n" .
+ '<option value="2">February</option>' . "\n" .
+ '<option value="3">March</option>' . "\n" .
+ '<option value="4">April</option>' . "\n" .
+ '<option value="5">May</option>' . "\n" .
+ '<option value="6">June</option>' . "\n" .
+ '<option value="7">July</option>' . "\n" .
+ '<option value="8">August</option>' . "\n" .
+ '<option value="9">September</option>' . "\n" .
+ '<option value="10">October</option>' . "\n" .
+ '<option value="11">November</option>' . "\n" .
+ '<option value="12">December</option></select>',
+ Xml::dateMenu( 2011, -1 ),
"Date menu with negative month for 'All'"
);
$this->assertEquals(
Xml::dateMenu( $curYear, $curMonth ),
- Xml::dateMenu( '' , $curMonth ),
+ Xml::dateMenu( '', $curMonth ),
"Date menu year is the current one when not specified"
);
- // @todo FIXME: next month can be in the next year
- // test failing because it is now december
+ $wantedYear = $nextMonth == 1 ? $curYear : $prevYear;
$this->assertEquals(
- Xml::dateMenu( $prevYear, $nextMonth ),
+ Xml::dateMenu( $wantedYear, $nextMonth ),
Xml::dateMenu( '', $nextMonth ),
"Date menu next month is 11 months ago"
);
- # @todo FIXME: Please note there is no year there!
$this->assertEquals(
- '<label for="year">From year (and earlier):</label> <input name="year" size="4" value="" id="year" maxlength="4" /> <label for="month">From month (and earlier):</label> <select id="month" name="month" class="mw-month-selector"><option value="-1">all</option>' . "\n" .
-'<option value="1">January</option>' . "\n" .
-'<option value="2">February</option>' . "\n" .
-'<option value="3">March</option>' . "\n" .
-'<option value="4">April</option>' . "\n" .
-'<option value="5">May</option>' . "\n" .
-'<option value="6">June</option>' . "\n" .
-'<option value="7">July</option>' . "\n" .
-'<option value="8">August</option>' . "\n" .
-'<option value="9">September</option>' . "\n" .
-'<option value="10">October</option>' . "\n" .
-'<option value="11">November</option>' . "\n" .
-'<option value="12">December</option></select>',
+ '<label for="year">From year (and earlier):</label> <input id="year" maxlength="4" size="7" type="number" name="year" /> <label for="month">From month (and earlier):</label> <select id="month" name="month" class="mw-month-selector"><option value="-1">all</option>' . "\n" .
+ '<option value="1">January</option>' . "\n" .
+ '<option value="2">February</option>' . "\n" .
+ '<option value="3">March</option>' . "\n" .
+ '<option value="4">April</option>' . "\n" .
+ '<option value="5">May</option>' . "\n" .
+ '<option value="6">June</option>' . "\n" .
+ '<option value="7">July</option>' . "\n" .
+ '<option value="8">August</option>' . "\n" .
+ '<option value="9">September</option>' . "\n" .
+ '<option value="10">October</option>' . "\n" .
+ '<option value="11">November</option>' . "\n" .
+ '<option value="12">December</option></select>',
Xml::dateMenu( '', '' ),
"Date menu with neither year or month"
);
}
- #
- # textarea
- #
- function testTextareaNoContent() {
+ /**
+ * @covers Xml::textarea
+ */
+ public function testTextareaNoContent() {
$this->assertEquals(
'<textarea name="name" id="name" cols="40" rows="5"></textarea>',
Xml::textarea( 'name', '' ),
@@ -204,7 +230,10 @@ class XmlTest extends MediaWikiTestCase {
);
}
- function testTextareaAttribs() {
+ /**
+ * @covers Xml::textarea
+ */
+ public function testTextareaAttribs() {
$this->assertEquals(
'<textarea name="name" id="name" cols="20" rows="10">&lt;txt&gt;</textarea>',
Xml::textarea( 'name', '<txt>', 20, 10 ),
@@ -212,17 +241,21 @@ class XmlTest extends MediaWikiTestCase {
);
}
- #
- # input and label
- #
- function testLabelCreation() {
+ /**
+ * @covers Xml::label
+ */
+ public function testLabelCreation() {
$this->assertEquals(
'<label for="id">name</label>',
Xml::label( 'name', 'id' ),
'label() with no attribs'
);
}
- function testLabelAttributeCanOnlyBeClassOrTitle() {
+
+ /**
+ * @covers Xml::label
+ */
+ public function testLabelAttributeCanOnlyBeClassOrTitle() {
$this->assertEquals(
'<label for="id">name</label>',
Xml::label( 'name', 'id', array( 'generated' => true ) ),
@@ -241,17 +274,20 @@ class XmlTest extends MediaWikiTestCase {
$this->assertEquals(
'<label for="id" class="nice" title="nice tooltip">name</label>',
Xml::label( 'name', 'id', array(
- 'generated' => true,
- 'class' => 'nice',
- 'title' => 'nice tooltip',
- 'anotherattr' => 'value',
+ 'generated' => true,
+ 'class' => 'nice',
+ 'title' => 'nice tooltip',
+ 'anotherattr' => 'value',
)
),
'label() skip all attributes but "class" and "title"'
);
}
- function testLanguageSelector() {
+ /**
+ * @covers Xml::languageSelector
+ */
+ public function testLanguageSelector() {
$select = Xml::languageSelector( 'en', true, null,
array( 'id' => 'testlang' ), wfMessage( 'yourlanguage' ) );
$this->assertEquals(
@@ -260,10 +296,10 @@ class XmlTest extends MediaWikiTestCase {
);
}
- #
- # JS
- #
- function testEscapeJsStringSpecialChars() {
+ /**
+ * @covers Xml::escapeJsString
+ */
+ public function testEscapeJsStringSpecialChars() {
$this->assertEquals(
'\\\\\r\n',
Xml::escapeJsString( "\\\r\n" ),
@@ -271,7 +307,10 @@ class XmlTest extends MediaWikiTestCase {
);
}
- function testEncodeJsVarBoolean() {
+ /**
+ * @covers Xml::encodeJsVar
+ */
+ public function testEncodeJsVarBoolean() {
$this->assertEquals(
'true',
Xml::encodeJsVar( true ),
@@ -279,7 +318,10 @@ class XmlTest extends MediaWikiTestCase {
);
}
- function testEncodeJsVarNull() {
+ /**
+ * @covers Xml::encodeJsVar
+ */
+ public function testEncodeJsVarNull() {
$this->assertEquals(
'null',
Xml::encodeJsVar( null ),
@@ -287,7 +329,10 @@ class XmlTest extends MediaWikiTestCase {
);
}
- function testEncodeJsVarArray() {
+ /**
+ * @covers Xml::encodeJsVar
+ */
+ public function testEncodeJsVarArray() {
$this->assertEquals(
'["a",1]',
Xml::encodeJsVar( array( 'a', 1 ) ),
@@ -300,7 +345,10 @@ class XmlTest extends MediaWikiTestCase {
);
}
- function testEncodeJsVarObject() {
+ /**
+ * @covers Xml::encodeJsVar
+ */
+ public function testEncodeJsVarObject() {
$this->assertEquals(
'{"a":"a","b":1}',
Xml::encodeJsVar( (object)array( 'a' => 'a', 'b' => 1 ) ),
@@ -308,7 +356,10 @@ class XmlTest extends MediaWikiTestCase {
);
}
- function testEncodeJsVarInt() {
+ /**
+ * @covers Xml::encodeJsVar
+ */
+ public function testEncodeJsVarInt() {
$this->assertEquals(
'123456',
Xml::encodeJsVar( 123456 ),
@@ -316,7 +367,10 @@ class XmlTest extends MediaWikiTestCase {
);
}
- function testEncodeJsVarFloat() {
+ /**
+ * @covers Xml::encodeJsVar
+ */
+ public function testEncodeJsVarFloat() {
$this->assertEquals(
'1.23456',
Xml::encodeJsVar( 1.23456 ),
@@ -324,7 +378,10 @@ class XmlTest extends MediaWikiTestCase {
);
}
- function testEncodeJsVarIntString() {
+ /**
+ * @covers Xml::encodeJsVar
+ */
+ public function testEncodeJsVarIntString() {
$this->assertEquals(
'"123456"',
Xml::encodeJsVar( '123456' ),
@@ -332,7 +389,10 @@ class XmlTest extends MediaWikiTestCase {
);
}
- function testEncodeJsVarFloatString() {
+ /**
+ * @covers Xml::encodeJsVar
+ */
+ public function testEncodeJsVarFloatString() {
$this->assertEquals(
'"1.23456"',
Xml::encodeJsVar( '1.23456' ),