Merge "Check validity and availability of usernames during signup via AJAX"
[lhc/web/wiklou.git] / tests / phpunit / includes / XmlTest.php
index b54731b..86b4c35 100644 (file)
@@ -1,8 +1,9 @@
 <?php
 
+/**
+ * @group Xml
+ */
 class XmlTest extends MediaWikiTestCase {
-       private static $oldLang;
-       private static $oldNamespaces;
 
        protected function setUp() {
                parent::setUp();
@@ -11,31 +12,33 @@ class XmlTest extends MediaWikiTestCase {
                $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',
                ) );
 
                $this->setMwGlobals( array(
                        'wgLang' => $langObj,
-                       'wgHtml5' => true,
                        '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() ),
@@ -43,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 ),
@@ -56,7 +65,10 @@ class XmlTest extends MediaWikiTestCase {
                );
        }
 
-       function testElementEmpty() {
+       /**
+        * @covers Xml::element
+        */
+       public function testElementEmpty() {
                $this->assertEquals(
                        '<element />',
                        Xml::element( 'element', null, '' ),
@@ -64,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' ),
@@ -79,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 ),
@@ -93,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' ) ),
@@ -101,57 +129,64 @@ class XmlTest extends MediaWikiTestCase {
                );
        }
 
-       function testCloseElement() {
+       /**
+        * @covers Xml::closeElement
+        */
+       public function testCloseElement() {
                $this->assertEquals( '</element>', Xml::closeElement( 'element' ), 'closeElement() shortcut' );
        }
 
-       public function testDateMenu( ) {
-               $curYear   = intval(gmdate('Y'));
-               $prevYear  = $curYear - 1;
+       /**
+        * @covers Xml::dateMenu
+        */
+       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; }
                $nextMonth = $curMonth + 1;
-               if( $nextMonth == 13 ) { $nextMonth = 1; }
+               if ( $nextMonth == 13 ) {
+                       $nextMonth = 1;
+               }
 
                $this->assertEquals(
                        '<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>',
+                               '<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 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),
+                               '<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"
                );
 
@@ -164,27 +199,27 @@ class XmlTest extends MediaWikiTestCase {
 
                $this->assertEquals(
                        '<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>',
+                               '<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', '' ),
@@ -192,7 +227,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 ),
@@ -200,17 +238,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 ) ),
@@ -229,17 +271,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(
@@ -248,10 +293,10 @@ class XmlTest extends MediaWikiTestCase {
                );
        }
 
-       #
-       # JS
-       #
-       function testEscapeJsStringSpecialChars() {
+       /**
+        * @covers Xml::escapeJsString
+        */
+       public function testEscapeJsStringSpecialChars() {
                $this->assertEquals(
                        '\\\\\r\n',
                        Xml::escapeJsString( "\\\r\n" ),
@@ -259,7 +304,10 @@ class XmlTest extends MediaWikiTestCase {
                );
        }
 
-       function testEncodeJsVarBoolean() {
+       /**
+        * @covers Xml::encodeJsVar
+        */
+       public function testEncodeJsVarBoolean() {
                $this->assertEquals(
                        'true',
                        Xml::encodeJsVar( true ),
@@ -267,7 +315,10 @@ class XmlTest extends MediaWikiTestCase {
                );
        }
 
-       function testEncodeJsVarNull() {
+       /**
+        * @covers Xml::encodeJsVar
+        */
+       public function testEncodeJsVarNull() {
                $this->assertEquals(
                        'null',
                        Xml::encodeJsVar( null ),
@@ -275,7 +326,10 @@ class XmlTest extends MediaWikiTestCase {
                );
        }
 
-       function testEncodeJsVarArray() {
+       /**
+        * @covers Xml::encodeJsVar
+        */
+       public function testEncodeJsVarArray() {
                $this->assertEquals(
                        '["a",1]',
                        Xml::encodeJsVar( array( 'a', 1 ) ),
@@ -288,7 +342,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 ) ),
@@ -296,7 +353,10 @@ class XmlTest extends MediaWikiTestCase {
                );
        }
 
-       function testEncodeJsVarInt() {
+       /**
+        * @covers Xml::encodeJsVar
+        */
+       public function testEncodeJsVarInt() {
                $this->assertEquals(
                        '123456',
                        Xml::encodeJsVar( 123456 ),
@@ -304,7 +364,10 @@ class XmlTest extends MediaWikiTestCase {
                );
        }
 
-       function testEncodeJsVarFloat() {
+       /**
+        * @covers Xml::encodeJsVar
+        */
+       public function testEncodeJsVarFloat() {
                $this->assertEquals(
                        '1.23456',
                        Xml::encodeJsVar( 1.23456 ),
@@ -312,7 +375,10 @@ class XmlTest extends MediaWikiTestCase {
                );
        }
 
-       function testEncodeJsVarIntString() {
+       /**
+        * @covers Xml::encodeJsVar
+        */
+       public function testEncodeJsVarIntString() {
                $this->assertEquals(
                        '"123456"',
                        Xml::encodeJsVar( '123456' ),
@@ -320,7 +386,10 @@ class XmlTest extends MediaWikiTestCase {
                );
        }
 
-       function testEncodeJsVarFloatString() {
+       /**
+        * @covers Xml::encodeJsVar
+        */
+       public function testEncodeJsVarFloatString() {
                $this->assertEquals(
                        '"1.23456"',
                        Xml::encodeJsVar( '1.23456' ),