Fix doc error in new incr test
[lhc/web/wiklou.git] / tests / phpunit / includes / XmlTest.php
index b54731b..a0b33ee 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,11 +46,17 @@ class XmlTest extends MediaWikiTestCase {
                );
        }
 
+       /**
+        * @covers Xml::expandAttributes
+        */
        public function testExpandAttributesException() {
-               $this->setExpectedException('MWException');
-               Xml::expandAttributes('string');
+               $this->setExpectedException( 'MWException' );
+               Xml::expandAttributes( 'string' );
        }
 
+       /**
+        * @covers Xml::element
+        */
        function testElementOpen() {
                $this->assertEquals(
                        '<element>',
@@ -56,6 +65,9 @@ class XmlTest extends MediaWikiTestCase {
                );
        }
 
+       /**
+        * @covers Xml::element
+        */
        function testElementEmpty() {
                $this->assertEquals(
                        '<element />',
@@ -64,6 +76,9 @@ class XmlTest extends MediaWikiTestCase {
                );
        }
 
+       /**
+        * @covers Xml::input
+        */
        function testElementInputCanHaveAValueOfZero() {
                $this->assertEquals(
                        '<input name="name" value="0" />',
@@ -71,6 +86,10 @@ class XmlTest extends MediaWikiTestCase {
                        'Input with a value of 0 (bug 23797)'
                );
        }
+
+       /**
+        * @covers Xml::element
+        */
        function testElementEscaping() {
                $this->assertEquals(
                        '<element>hello &lt;there&gt; you &amp; you</element>',
@@ -79,12 +98,18 @@ class XmlTest extends MediaWikiTestCase {
                );
        }
 
+       /**
+        * @covers Xml::escapeTagsOnly
+        */
        public function testEscapeTagsOnly() {
                $this->assertEquals( '&quot;&gt;&lt;', Xml::escapeTagsOnly( '"><' ),
                        'replace " > and < with their HTML entitites'
                );
        }
 
+       /**
+        * @covers Xml::element
+        */
        function testElementAttributes() {
                $this->assertEquals(
                        '<element key="value" <>="&lt;&gt;">',
@@ -93,6 +118,9 @@ class XmlTest extends MediaWikiTestCase {
                );
        }
 
+       /**
+        * @covers Xml::openElement
+        */
        function testOpenElement() {
                $this->assertEquals(
                        '<element k="v">',
@@ -101,57 +129,67 @@ class XmlTest extends MediaWikiTestCase {
                );
        }
 
+       /**
+        * @covers Xml::closeElement
+        */
        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; }
+               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,26 +202,26 @@ 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
-       #
+       /**
+        * @covers Xml::textarea
+        */
        function testTextareaNoContent() {
                $this->assertEquals(
                        '<textarea name="name" id="name" cols="40" rows="5"></textarea>',
@@ -192,6 +230,9 @@ class XmlTest extends MediaWikiTestCase {
                );
        }
 
+       /**
+        * @covers Xml::textarea
+        */
        function testTextareaAttribs() {
                $this->assertEquals(
                        '<textarea name="name" id="name" cols="20" rows="10">&lt;txt&gt;</textarea>',
@@ -200,9 +241,9 @@ class XmlTest extends MediaWikiTestCase {
                );
        }
 
-       #
-       # input and label
-       #
+       /**
+        * @covers Xml::label
+        */
        function testLabelCreation() {
                $this->assertEquals(
                        '<label for="id">name</label>',
@@ -210,6 +251,10 @@ class XmlTest extends MediaWikiTestCase {
                        'label() with no attribs'
                );
        }
+
+       /**
+        * @covers Xml::label
+        */
        function testLabelAttributeCanOnlyBeClassOrTitle() {
                $this->assertEquals(
                        '<label for="id">name</label>',
@@ -229,16 +274,19 @@ 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"'
                );
        }
 
+       /**
+        * @covers Xml::languageSelector
+        */
        function testLanguageSelector() {
                $select = Xml::languageSelector( 'en', true, null,
                        array( 'id' => 'testlang' ), wfMessage( 'yourlanguage' ) );
@@ -248,9 +296,9 @@ class XmlTest extends MediaWikiTestCase {
                );
        }
 
-       #
-       # JS
-       #
+       /**
+        * @covers Xml::escapeJsString
+        */
        function testEscapeJsStringSpecialChars() {
                $this->assertEquals(
                        '\\\\\r\n',
@@ -259,6 +307,9 @@ class XmlTest extends MediaWikiTestCase {
                );
        }
 
+       /**
+        * @covers Xml::encodeJsVar
+        */
        function testEncodeJsVarBoolean() {
                $this->assertEquals(
                        'true',
@@ -267,6 +318,9 @@ class XmlTest extends MediaWikiTestCase {
                );
        }
 
+       /**
+        * @covers Xml::encodeJsVar
+        */
        function testEncodeJsVarNull() {
                $this->assertEquals(
                        'null',
@@ -275,6 +329,9 @@ class XmlTest extends MediaWikiTestCase {
                );
        }
 
+       /**
+        * @covers Xml::encodeJsVar
+        */
        function testEncodeJsVarArray() {
                $this->assertEquals(
                        '["a",1]',
@@ -288,6 +345,9 @@ class XmlTest extends MediaWikiTestCase {
                );
        }
 
+       /**
+        * @covers Xml::encodeJsVar
+        */
        function testEncodeJsVarObject() {
                $this->assertEquals(
                        '{"a":"a","b":1}',
@@ -296,6 +356,9 @@ class XmlTest extends MediaWikiTestCase {
                );
        }
 
+       /**
+        * @covers Xml::encodeJsVar
+        */
        function testEncodeJsVarInt() {
                $this->assertEquals(
                        '123456',
@@ -304,6 +367,9 @@ class XmlTest extends MediaWikiTestCase {
                );
        }
 
+       /**
+        * @covers Xml::encodeJsVar
+        */
        function testEncodeJsVarFloat() {
                $this->assertEquals(
                        '1.23456',
@@ -312,6 +378,9 @@ class XmlTest extends MediaWikiTestCase {
                );
        }
 
+       /**
+        * @covers Xml::encodeJsVar
+        */
        function testEncodeJsVarIntString() {
                $this->assertEquals(
                        '"123456"',
@@ -320,6 +389,9 @@ class XmlTest extends MediaWikiTestCase {
                );
        }
 
+       /**
+        * @covers Xml::encodeJsVar
+        */
        function testEncodeJsVarFloatString() {
                $this->assertEquals(
                        '"1.23456"',