Merge "Use parseAsBlock() instead of parse() to show the error message in OutputPage...
[lhc/web/wiklou.git] / tests / phpunit / includes / XmlTest.php
index 13f942c..3cc5422 100644 (file)
@@ -2,19 +2,34 @@
 
 class XmlTest extends MediaWikiTestCase {
        private static $oldLang;
+       private static $oldNamespaces;
 
-       public function setUp() {
-               global $wgLang, $wgLanguageCode;
+       protected function setUp() {
+               parent::setUp();
 
-               self::$oldLang = $wgLang;
-               $wgLanguageCode = 'en';
-               $wgLang = Language::factory( $wgLanguageCode );
-       }
+               $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',
+               ) );
 
-       public function tearDown() {
-               global $wgLang, $wgLanguageCode;
-               $wgLang = self::$oldLang;
-               $wgLanguageCode = $wgLang->getCode();
+               $this->setMwGlobals( array(
+                       'wgLang' => $langObj,
+               ) );
        }
 
        public function testExpandAttributes() {
@@ -99,7 +114,7 @@ class XmlTest extends MediaWikiTestCase {
                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" .
+                       '<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" .
@@ -116,7 +131,7 @@ class XmlTest extends MediaWikiTestCase {
                        "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" .
+                       '<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" .
@@ -138,18 +153,15 @@ class XmlTest extends MediaWikiTestCase {
                        "Date menu year is the current one when not specified"
                );
 
-               $this->markTestIncomplete( "Broken" );
-               // @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" .
+                       '<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" .
@@ -225,6 +237,15 @@ class XmlTest extends MediaWikiTestCase {
                );
        }
 
+       function testLanguageSelector() {
+               $select = Xml::languageSelector( 'en', true, null,
+                       array( 'id' => 'testlang' ), wfMessage( 'yourlanguage' ) );
+               $this->assertEquals(
+                       '<label for="testlang">Language:</label>',
+                       $select[0]
+               );
+       }
+
        #
        # JS
        #
@@ -254,12 +275,12 @@ class XmlTest extends MediaWikiTestCase {
 
        function testEncodeJsVarArray() {
                $this->assertEquals(
-                       '["a", 1]',
+                       '["a",1]',
                        Xml::encodeJsVar( array( 'a', 1 ) ),
                        'encodeJsVar() with array'
                );
                $this->assertEquals(
-                       '{"a": "a", "b": 1}',
+                       '{"a":"a","b":1}',
                        Xml::encodeJsVar( array( 'a' => 'a', 'b' => 1 ) ),
                        'encodeJsVar() with associative array'
                );
@@ -267,7 +288,7 @@ class XmlTest extends MediaWikiTestCase {
 
        function testEncodeJsVarObject() {
                $this->assertEquals(
-                       '{"a": "a", "b": 1}',
+                       '{"a":"a","b":1}',
                        Xml::encodeJsVar( (object)array( 'a' => 'a', 'b' => 1 ) ),
                        'encodeJsVar() with object'
                );