Merge "Simplify profiler output class selection"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Thu, 2 Apr 2015 18:22:44 +0000 (18:22 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Thu, 2 Apr 2015 18:22:44 +0000 (18:22 +0000)
26 files changed:
includes/CategoryViewer.php
includes/Message.php
includes/parser/CoreParserFunctions.php
includes/parser/DateFormatter.php
includes/parser/Parser.php
includes/parser/ParserOptions.php
includes/parser/ParserOutput.php
languages/i18n/en.json
languages/i18n/qqq.json
languages/messages/MessagesArc.php
languages/messages/MessagesAz.php
languages/messages/MessagesAzb.php
languages/messages/MessagesCkb.php
languages/messages/MessagesDv.php
languages/messages/MessagesFa.php
languages/messages/MessagesHe.php
languages/messages/MessagesKhw.php
languages/messages/MessagesKk_arab.php
languages/messages/MessagesKs_arab.php
languages/messages/MessagesMzn.php
languages/messages/MessagesNds.php
languages/messages/MessagesUr.php
tests/phpunit/MediaWikiTestCase.php
tests/phpunit/includes/MessageTest.php
tests/phpunit/includes/UserTest.php
tests/phpunit/includes/api/ApiMainTest.php

index 48436c5..66079c0 100644 (file)
@@ -603,7 +603,7 @@ class CategoryViewer extends ContextSource {
         * @return string HTML
         */
        private function pagingLinks( $first, $last, $type = '' ) {
-               $prevLink = $this->msg( 'prevn' )->numParams( $this->limit )->escaped();
+               $prevLink = $this->msg( 'prev-page' )->text();
 
                if ( $first != '' ) {
                        $prevQuery = $this->query;
@@ -617,7 +617,7 @@ class CategoryViewer extends ContextSource {
                        );
                }
 
-               $nextLink = $this->msg( 'nextn' )->numParams( $this->limit )->escaped();
+               $nextLink = $this->msg( 'next-page' )->text();
 
                if ( $last != '' ) {
                        $lastQuery = $this->query;
index 49437f4..134af0e 100644 (file)
@@ -249,7 +249,7 @@ class Message implements MessageSpecifier {
                $this->key = reset( $this->keysToTry );
 
                $this->parameters = array_values( $params );
-               $this->language = $language ? $language : $wgLang;
+               $this->language = $language ?: $wgLang;
        }
 
        /**
index 2b495b1..830a68f 100644 (file)
@@ -893,9 +893,17 @@ class CoreParserFunctions {
                }
        }
 
-       // Usage {{filepath|300}}, {{filepath|nowiki}}, {{filepath|nowiki|300}}
-       // or {{filepath|300|nowiki}} or {{filepath|300px}}, {{filepath|200x300px}},
-       // {{filepath|nowiki|200x300px}}, {{filepath|200x300px|nowiki}}.
+       /**
+        * Usage {{filepath|300}}, {{filepath|nowiki}}, {{filepath|nowiki|300}}
+        * or {{filepath|300|nowiki}} or {{filepath|300px}}, {{filepath|200x300px}},
+        * {{filepath|nowiki|200x300px}}, {{filepath|200x300px|nowiki}}.
+        *
+        * @param Parser $parser
+        * @param string $name
+        * @param string $argA
+        * @param string $argB
+        * @return array|string
+        */
        public static function filepath( $parser, $name = '', $argA = '', $argB = '' ) {
                $file = wfFindFile( $name );
 
@@ -934,7 +942,7 @@ class CoreParserFunctions {
         * Parser function to extension tag adaptor
         * @param Parser $parser
         * @param PPFrame $frame
-        * @param array $args
+        * @param PPNode[] $args
         * @return string
         */
        public static function tagObj( $parser, $frame, $args ) {
index 3db8d1e..ef295ab 100644 (file)
@@ -33,7 +33,7 @@ class DateFormatter {
        public $regexes, $pDays, $pMonths, $pYears;
        public $rules, $xMonths, $preferences;
 
-       protected $lang;
+       protected $lang, $mLinked;
 
        const ALL = -1;
        const NONE = 0;
index 40b0a4f..7c221d8 100644 (file)
@@ -147,7 +147,11 @@ class Parser {
         */
        public $mSubstWords;
        # Initialised in constructor
-       public $mConf, $mPreprocessor, $mExtLinkBracketedRegex, $mUrlProtocols;
+       public $mConf, $mExtLinkBracketedRegex, $mUrlProtocols;
+
+       # Initialized in getPreprocessor()
+       /** @var Preprocessor */
+       public $mPreprocessor;
 
        # Cleared with clearState():
        /**
@@ -393,7 +397,6 @@ class Parser {
                 */
 
                global $wgShowHostnames;
-               $fname = __METHOD__ . '-' . wfGetCaller();
 
                if ( $clearState ) {
                        $magicScopeVariable = $this->lock();
@@ -1199,7 +1202,7 @@ class Parser {
         *
         * @param string $text
         * @param bool $isMain
-        * @param bool $frame
+        * @param PPFrame|bool $frame
         *
         * @return string
         */
@@ -5427,7 +5430,7 @@ class Parser {
        }
 
        /**
-        * @param string $handler
+        * @param MediaHandler $handler
         * @return array
         */
        public function getImageParams( $handler ) {
index 9e06ee2..5fa52ff 100644 (file)
@@ -669,6 +669,7 @@ class ParserOptions {
         *
         * This ignores report limit settings that only affect HTML comments
         *
+        * @param ParserOptions $other
         * @return bool
         * @since 1.25
         */
index bae3eaa..65b527c 100644 (file)
@@ -57,6 +57,7 @@ class ParserOutput extends CacheTime {
        private $mLimitReportData = array(); # Parser limit report data
        private $mParseStartTime = array(); # Timestamps for getTimeSinceStart()
        private $mPreventClickjacking = false; # Whether to emit X-Frame-Options: DENY
+       private $mFlags = array();        # Generic flags
 
        const EDITSECTION_REGEX =
                '#<(?:mw:)?editsection page="(.*?)" section="(.*?)"(?:/>|>(.*?)(</(?:mw:)?editsection>))#';
index fb7056c..16a1e6a 100644 (file)
        "notextmatches": "No page text matches",
        "prevn": "previous {{PLURAL:$1|$1}}",
        "nextn": "next {{PLURAL:$1|$1}}",
+       "prev-page": "previous page",
+       "next-page": "next page",
        "prevn-title": "Previous $1 {{PLURAL:$1|result|results}}",
        "nextn-title": "Next $1 {{PLURAL:$1|result|results}}",
        "shown-title": "Show $1 {{PLURAL:$1|result|results}} per page",
index b7c31fc..4cfc3e8 100644 (file)
        "notextmatches": "Error message when there are no results",
        "prevn": "This is part of the navigation message on the top and bottom of Special pages (lists of things in alphabetical order, i.e. the '[[Special:Categories]]' page), where it is used as the first argument of {{msg-mw|Viewprevnext}}.\nIt is also used by Category pages (which do ''not'' use {{msg-mw|Viewprevnext}}).\n{{PLURAL:$1|$1}} is the number of items shown per page. It is not used when {{PLURAL:$1|$1}} is zero; not sure what happens when {{PLURAL:$1|$1}} is one.\n[[Special:WhatLinksHere|Whatlinkshere]] pages use {{msg-mw|Whatlinkshere-prev}} instead (still as an argument to {{msg-mw|Viewprevnext}}).\n\n{{Identical|Previous}}",
        "nextn": "This is part of the navigation message on the top and bottom of Special pages (lists of things in alphabetical order, i.e. the '[[Special:Categories]]' page), where it is used as the second argument of {{msg-mw|Viewprevnext}}.\n\nIt is also used by Category pages (which do ''not'' use {{msg-mw|Viewprevnext}}).\n\nParameters:\n* $1 - the number of items shown per page. It is not used when $1 is zero; not sure what happens when $1 is one.\n[[Special:WhatLinksHere|Whatlinkshere]] pages use {{msg-mw|Whatlinkshere-next}} instead (still as an argument to {{msg-mw|Viewprevnext}}).\n\n{{Identical|Next}}",
+       "prev-page": "This is part of the navigation message on the top and bottom of Category pages which links to the previous page",
+       "next-page": "This is part of the navigation message on the top and bottom of Category pages which links to the next page",
        "prevn-title": "Parameters:\n* $1 - number of search results\nSee also:\n* {{msg-mw|Viewprevnext}}",
        "nextn-title": "Parameters:\n* $1 - number of search results\nSee also:\n* {{msg-mw|Viewprevnext}}",
        "shown-title": "Parameters:\n* $1 - number of search results",
index 2247b36..f88650b 100644 (file)
@@ -13,7 +13,6 @@ $rtl = true;
 $namespaceNames = array(
        NS_MEDIA            => 'ܡܝܕܝܐ',
        NS_SPECIAL          => 'ܕܝܠܢܝܐ',
-       NS_MAIN             => '',
        NS_TALK             => 'ܡܡܠܠܐ',
        NS_USER             => 'ܡܦܠܚܢܐ',
        NS_USER_TALK        => 'ܡܡܠܠܐ_ܕܡܦܠܚܢܐ',
index b218e3c..23da7a3 100644 (file)
@@ -10,7 +10,6 @@
 
 $namespaceNames = array(
        NS_SPECIAL          => 'Xüsusi',
-       NS_MAIN             => '',
        NS_TALK             => 'Müzakirə',
        NS_USER             => 'İstifadəçi',
        NS_USER_TALK        => 'İstifadəçi_müzakirəsi',
index 63c88a8..74d3bb9 100644 (file)
@@ -14,7 +14,6 @@ $rtl = true;
 $namespaceNames = array(
        NS_MEDIA            => 'مئدیا',
        NS_SPECIAL          => 'اؤزل',
-       NS_MAIN             => '',
        NS_TALK             => 'دانیشیق',
        NS_USER             => 'ایستیفاده‌چی',
        NS_USER_TALK        => 'ایستیفاده‌چی_دانیشیغی',
index 393c6e5..027161f 100644 (file)
@@ -14,7 +14,6 @@ $fallback8bitEncoding = 'windows-1256';
 $namespaceNames = array(
        NS_MEDIA            => 'میدیا',
        NS_SPECIAL          => 'تایبەت',
-       NS_MAIN             => '',
        NS_TALK             => 'وتووێژ',
        NS_USER             => 'بەکارھێنەر',
        NS_USER_TALK        => 'لێدوانی_بەکارھێنەر',
index 1f49212..72d645e 100644 (file)
@@ -13,7 +13,6 @@ $rtl = true;
 $namespaceNames = array(
        NS_MEDIA            => 'މީޑިއާ',
        NS_SPECIAL          => 'ޚާއްސަ',
-       NS_MAIN             => '',
        NS_TALK             => 'ޚިޔާލު',
        NS_USER             => 'މެމްބަރު',
        NS_USER_TALK        => 'މެމްބަރުގެ_ވާހަކަ',
index 6c03f1d..4d964fb 100644 (file)
@@ -14,7 +14,6 @@ $fallback8bitEncoding = 'windows-1256';
 $namespaceNames = array(
        NS_MEDIA            => 'مدیا',
        NS_SPECIAL          => 'ویژه',
-       NS_MAIN             => '',
        NS_TALK             => 'بحث',
        NS_USER             => 'کاربر',
        NS_USER_TALK        => 'بحث_کاربر',
index 1f578a3..3d7fc43 100644 (file)
@@ -16,7 +16,6 @@ $fallback8bitEncoding = 'windows-1255';
 $namespaceNames = array(
        NS_MEDIA            => 'מדיה',
        NS_SPECIAL          => 'מיוחד',
-       NS_MAIN             => '',
        NS_TALK             => 'שיחה',
        NS_USER             => 'משתמש',
        NS_USER_TALK        => 'שיחת_משתמש',
index 4cd2495..bcc8328 100644 (file)
@@ -12,7 +12,6 @@ $fallback = 'ur';
 $rtl = true;
 
 $namespaceNames = array(
-       NS_MAIN             => '',
        NS_MEDIA            => 'میڈیا',
        NS_SPECIAL          => 'خاص',
        NS_TALK             => 'مشقولگی',
index a33efef..8749ccb 100644 (file)
@@ -50,7 +50,6 @@ $fallback8bitEncoding = 'windows-1256';
 $namespaceNames = array(
        NS_MEDIA            => 'تاسپا',
        NS_SPECIAL          => 'ارنايى',
-       NS_MAIN             => '',
        NS_TALK             => 'تالقىلاۋ',
        NS_USER             => 'قاتىسۋشى',
        NS_USER_TALK        => 'قاتىسۋشى_تالقىلاۋى',
index 89f877f..cdea1f4 100644 (file)
@@ -16,7 +16,6 @@ $rtl = true;
 $namespaceNames = array(
        NS_MEDIA            => 'میڈیا',
        NS_SPECIAL          => 'خاص',
-       NS_MAIN             => '',
        NS_TALK             => 'بَحَژ',
        NS_USER             => 'رُکُن',
        NS_USER_TALK        => 'رُکُن_بَحَژ',
index 16ecac2..6203b24 100644 (file)
@@ -26,7 +26,6 @@ $rtl = true;
 $namespaceNames = array(
        NS_MEDIA            => 'مدیا',
        NS_SPECIAL          => 'شا',
-       NS_MAIN             => '',
        NS_TALK             => 'گپ',
        NS_USER             => 'کارور',
        NS_USER_TALK        => 'کارور_گپ',
index e66cb02..f87d770 100644 (file)
@@ -96,7 +96,6 @@ $bookstoreList = array(
 $namespaceNames = array(
        NS_MEDIA          => 'Media',
        NS_SPECIAL        => 'Spezial',
-       NS_MAIN           => '',
        NS_TALK           => 'Diskuschoon',
        NS_USER           => 'Bruker',
        NS_USER_TALK      => 'Bruker_Diskuschoon',
index 1394c16..81a6d2f 100644 (file)
@@ -31,7 +31,6 @@ $rtl = true;
 $namespaceNames = array(
        NS_MEDIA            => 'وسیط',
        NS_SPECIAL          => 'خاص',
-       NS_MAIN             => '',
        NS_TALK             => 'تبادلۂ_خیال',
        NS_USER             => 'صارف',
        NS_USER_TALK        => 'تبادلۂ_خیال_صارف',
index 0253284..72cac05 100644 (file)
@@ -104,7 +104,6 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase {
                ObjectCache::$instances[CACHE_DB] = new HashBagOStuff;
 
                $needsResetDB = false;
-               $logName = get_class( $this ) . '::' . $this->getName( false );
 
                if ( $this->needsDB() ) {
                        // set up a DB connection for this test to use
@@ -632,7 +631,7 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase {
         * @param string $msg
         */
        private function assertEmpty2( $value, $msg ) {
-               return $this->assertTrue( $value == '', $msg );
+               $this->assertTrue( $value == '', $msg );
        }
 
        private static function unprefixTable( $tableName ) {
@@ -648,7 +647,7 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase {
        /**
         * @since 1.18
         *
-        * @param DataBaseBase $db
+        * @param DatabaseBase $db
         *
         * @return array
         */
index 4c5424c..99ec2e4 100644 (file)
@@ -16,22 +16,11 @@ class MessageTest extends MediaWikiLangTestCase {
         * @dataProvider provideConstructor
         */
        public function testConstructor( $expectedLang, $key, $params, $language ) {
-               $reflection = new ReflectionClass( 'Message' );
-
-               $keyProperty = $reflection->getProperty( 'key' );
-               $keyProperty->setAccessible( true );
-
-               $paramsProperty = $reflection->getProperty( 'parameters' );
-               $paramsProperty->setAccessible( true );
-
-               $langProperty = $reflection->getProperty( 'language' );
-               $langProperty->setAccessible( true );
-
                $message = new Message( $key, $params, $language );
 
-               $this->assertEquals( $key, $keyProperty->getValue( $message ) );
-               $this->assertEquals( $params, $paramsProperty->getValue( $message ) );
-               $this->assertEquals( $expectedLang, $langProperty->getValue( $message ) );
+               $this->assertEquals( $key, $message->getKey() );
+               $this->assertEquals( $params, $message->getParams() );
+               $this->assertEquals( $expectedLang, $message->getLanguage() );
        }
 
        public static function provideConstructor() {
@@ -45,21 +34,62 @@ class MessageTest extends MediaWikiLangTestCase {
                );
        }
 
-       public static function provideTestParams() {
+       public static function provideConstructorParams() {
                return array(
-                       array( array() ),
-                       array( array( 'foo' ), 'foo' ),
-                       array( array( 'foo', 'bar' ), 'foo', 'bar' ),
-                       array( array( 'baz' ), array( 'baz' ) ),
-                       array( array( 'baz', 'foo' ), array( 'baz', 'foo' ) ),
-                       array( array( 'baz', 'foo' ), array( 'baz', 'foo' ), 'hhh' ),
-                       array( array( 'baz', 'foo' ), array( 'baz', 'foo' ), 'hhh', array( 'ahahahahha' ) ),
-                       array( array( 'baz', 'foo' ), array( 'baz', 'foo' ), array( 'ahahahahha' ) ),
-                       array( array( 'baz' ), array( 'baz' ), array( 'ahahahahha' ) ),
+                       array(
+                               array(),
+                               array(),
+                       ),
+                       array(
+                               array( 'foo' ),
+                               array( 'foo' ),
+                       ),
+                       array(
+                               array( 'foo', 'bar' ),
+                               array( 'foo', 'bar' ),
+                       ),
+                       array(
+                               array( 'baz' ),
+                               array( array( 'baz' ) ),
+                       ),
+                       array(
+                               array( 'baz', 'foo' ),
+                               array( array( 'baz', 'foo' ) ),
+                       ),
+                       array(
+                               array( 'baz', 'foo' ),
+                               array( array( 'baz', 'foo' ), 'hhh' ),
+                       ),
+                       array(
+                               array( 'baz', 'foo' ),
+                               array( array( 'baz', 'foo' ), 'hhh', array( 'ahahahahha' ) ),
+                       ),
+                       array(
+                               array( 'baz', 'foo' ),
+                               array( array( 'baz', 'foo' ), array( 'ahahahahha' ) ),
+                       ),
+                       array(
+                               array( 'baz' ),
+                               array( array( 'baz' ), array( 'ahahahahha' ) ),
+                       ),
                );
        }
 
-       public function getLanguageProvider() {
+       /**
+        * @covers Message::__construct
+        * @covers Message::getParams
+        * @dataProvider provideConstructorParams
+        */
+       public function testConstructorParams( $expected, $args ) {
+               $msg = new Message( 'imasomething' );
+
+               $returned = call_user_func_array( array( $msg, 'params' ), $args );
+
+               $this->assertSame( $msg, $returned );
+               $this->assertEquals( $expected, $msg->getParams() );
+       }
+
+       public static function provideConstructorLanguage() {
                return array(
                        array( 'foo', array( 'bar' ), 'en' ),
                        array( 'foo', array( 'bar' ), 'de' )
@@ -67,27 +97,98 @@ class MessageTest extends MediaWikiLangTestCase {
        }
 
        /**
+        * @covers Message::__construct
         * @covers Message::getLanguage
-        * @dataProvider getLanguageProvider
+        * @dataProvider provideConstructorLanguage
         */
-       public function testGetLanguageCode( $key, $params, $languageCode ) {
+       public function testConstructorLanguage( $key, $params, $languageCode ) {
                $language = Language::factory( $languageCode );
                $message = new Message( $key, $params, $language );
 
                $this->assertEquals( $language, $message->getLanguage() );
        }
 
+       public static function provideKeys() {
+               return array(
+                       'string' => array(
+                               'key' => 'mainpage',
+                               'expected' => array( 'mainpage' ),
+                       ),
+                       'single' => array(
+                               'key' => array( 'mainpage' ),
+                               'expected' => array( 'mainpage' ),
+                       ),
+                       'multi' => array(
+                               'key' => array( 'mainpage-foo', 'mainpage-bar', 'mainpage' ),
+                               'expected' => array( 'mainpage-foo', 'mainpage-bar', 'mainpage' ),
+                       ),
+                       'empty' => array(
+                               'key' => array(),
+                               'expected' => null,
+                               'exception' => 'InvalidArgumentException',
+                       ),
+                       'null' => array(
+                               'key' => null,
+                               'expected' => null,
+                               'exception' => 'InvalidArgumentException',
+                       ),
+                       'bad type' => array(
+                               'key' => 123,
+                               'expected' => null,
+                               'exception' => 'InvalidArgumentException',
+                       ),
+               );
+       }
+
        /**
-        * @covers Message::params
-        * @dataProvider provideTestParams
+        * @covers Message::__construct
+        * @covers Message::getKey
+        * @covers Message::isMultiKey
+        * @covers Message::getKeysToTry
+        * @dataProvider provideKeys
         */
-       public function testParams( $expected ) {
-               $msg = new Message( 'imasomething' );
+       public function testKeys( $key, $expected, $exception = null ) {
+               if ( $exception ) {
+                       $this->setExpectedException( $exception );
+               }
 
-               $returned = call_user_func_array( array( $msg, 'params' ), array_slice( func_get_args(), 1 ) );
+               $msg = new Message( $key );
+               $this->assertContains( $msg->getKey(), $expected );
+               $this->assertEquals( $expected, $msg->getKeysToTry() );
+               $this->assertEquals( count( $expected ) > 1, $msg->isMultiKey() );
+       }
 
-               $this->assertSame( $msg, $returned );
-               $this->assertEquals( $expected, $msg->getParams() );
+       /**
+        * @covers ::wfMessage
+        */
+       public function testWfMessage() {
+               $this->assertInstanceOf( 'Message', wfMessage( 'mainpage' ) );
+               $this->assertInstanceOf( 'Message', wfMessage( 'i-dont-exist-evar' ) );
+       }
+
+       /**
+        * @covers Message::newFromKey
+        */
+       public function testNewFromKey() {
+               $this->assertInstanceOf( 'Message', Message::newFromKey( 'mainpage' ) );
+               $this->assertInstanceOf( 'Message', Message::newFromKey( 'i-dont-exist-evar' ) );
+       }
+
+       /**
+        * @covers ::wfMessage
+        * @covers Message::__construct
+        */
+       public function testWfMessageParams() {
+               $this->assertEquals( 'Return to $1.', wfMessage( 'returnto' )->text() );
+               $this->assertEquals( 'Return to $1.', wfMessage( 'returnto', array() )->text() );
+               $this->assertEquals(
+                       'You have foo (bar).',
+                       wfMessage( 'youhavenewmessages', 'foo', 'bar' )->text()
+               );
+               $this->assertEquals(
+                       'You have foo (bar).',
+                       wfMessage( 'youhavenewmessages', array( 'foo', 'bar' ) )->text()
+               );
        }
 
        /**
@@ -104,10 +205,12 @@ class MessageTest extends MediaWikiLangTestCase {
 
        /**
         * @covers Message::__construct
+        * @covers Message::text
+        * @covers Message::plain
+        * @covers Message::escaped
+        * @covers Message::toString
         */
-       public function testKey() {
-               $this->assertInstanceOf( 'Message', wfMessage( 'mainpage' ) );
-               $this->assertInstanceOf( 'Message', wfMessage( 'i-dont-exist-evar' ) );
+       public function testToStringKey() {
                $this->assertEquals( 'Main Page', wfMessage( 'mainpage' )->text() );
                $this->assertEquals( '<i-dont-exist-evar>', wfMessage( 'i-dont-exist-evar' )->text() );
                $this->assertEquals( '<i<dont>exist-evar>', wfMessage( 'i<dont>exist-evar' )->text() );
@@ -120,6 +223,26 @@ class MessageTest extends MediaWikiLangTestCase {
                );
        }
 
+       public static function provideToString() {
+               return array(
+                       array( 'mainpage', 'Main Page' ),
+                       array( 'i-dont-exist-evar', '<i-dont-exist-evar>' ),
+                       array( 'i-dont-exist-evar', '&lt;i-dont-exist-evar&gt;', 'escaped' ),
+               );
+       }
+
+       /**
+        * @covers Message::toString
+        * @covers Message::__toString
+        * @dataProvider provideToString
+        */
+       public function testToString( $key, $expect, $format = 'plain' ) {
+               $msg = new Message( $key );
+               $msg->$format();
+               $this->assertEquals( $expect, $msg->toString() );
+               $this->assertEquals( $expect, $msg->__toString() );
+       }
+
        /**
         * @covers Message::inLanguage
         */
@@ -138,26 +261,10 @@ class MessageTest extends MediaWikiLangTestCase {
        }
 
        /**
-        * @covers Message::__construct
-        */
-       public function testMessageParams() {
-               $this->assertEquals( 'Return to $1.', wfMessage( 'returnto' )->text() );
-               $this->assertEquals( 'Return to $1.', wfMessage( 'returnto', array() )->text() );
-               $this->assertEquals(
-                       'You have foo (bar).',
-                       wfMessage( 'youhavenewmessages', 'foo', 'bar' )->text()
-               );
-               $this->assertEquals(
-                       'You have foo (bar).',
-                       wfMessage( 'youhavenewmessages', array( 'foo', 'bar' ) )->text()
-               );
-       }
-
-       /**
-        * @covers Message::__construct
+        * @covers Message::rawParam
         * @covers Message::rawParams
         */
-       public function testMessageParamSubstitution() {
+       public function testRawParams() {
                $this->assertEquals(
                        '(Заглавная страница)',
                        wfMessage( 'parentheses', 'Заглавная страница' )->plain()
@@ -177,10 +284,21 @@ class MessageTest extends MediaWikiLangTestCase {
        }
 
        /**
-        * @covers Message::__construct
+        * @covers RawMessage::__construct
+        * @covers RawMessage::fetchMessage
+        */
+       public function testRawMessage() {
+               $msg = new RawMessage( 'example &' );
+               $this->assertEquals( 'example &', $msg->plain() );
+               $this->assertEquals( 'example &amp;', $msg->escaped() );
+       }
+
+       /**
         * @covers Message::params
+        * @covers Message::toString
+        * @covers Message::replaceParameters
         */
-       public function testDeliciouslyManyParams() {
+       public function testReplaceManyParams() {
                $msg = new RawMessage( '$1$2$3$4$5$6$7$8$9$10$11$12' );
                // One less than above has placeholders
                $params = array( 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k' );
@@ -189,12 +307,20 @@ class MessageTest extends MediaWikiLangTestCase {
                        $msg->params( $params )->plain(),
                        'Params > 9 are replaced correctly'
                );
+
+               $msg = new RawMessage( 'Params$*' );
+               $params = array( 'ab', 'bc', 'cd' );
+               $this->assertEquals(
+                       'Params: ab, bc, cd',
+                       $msg->params( $params )->text()
+               );
        }
 
        /**
+        * @covers Message::numParam
         * @covers Message::numParams
         */
-       public function testMessageNumParams() {
+       public function testNumParams() {
                $lang = Language::factory( 'en' );
                $msg = new RawMessage( '$1' );
 
@@ -206,9 +332,10 @@ class MessageTest extends MediaWikiLangTestCase {
        }
 
        /**
+        * @covers Message::durationParam
         * @covers Message::durationParams
         */
-       public function testMessageDurationParams() {
+       public function testDurationParams() {
                $lang = Language::factory( 'en' );
                $msg = new RawMessage( '$1' );
 
@@ -222,9 +349,10 @@ class MessageTest extends MediaWikiLangTestCase {
        /**
         * FIXME: This should not need database, but Language#formatExpiry does (bug 55912)
         * @group Database
+        * @covers Message::expiryParam
         * @covers Message::expiryParams
         */
-       public function testMessageExpiryParams() {
+       public function testExpiryParams() {
                $lang = Language::factory( 'en' );
                $msg = new RawMessage( '$1' );
 
@@ -236,9 +364,10 @@ class MessageTest extends MediaWikiLangTestCase {
        }
 
        /**
+        * @covers Message::timeperiodParam
         * @covers Message::timeperiodParams
         */
-       public function testMessageTimeperiodParams() {
+       public function testTimeperiodParams() {
                $lang = Language::factory( 'en' );
                $msg = new RawMessage( '$1' );
 
@@ -250,9 +379,10 @@ class MessageTest extends MediaWikiLangTestCase {
        }
 
        /**
+        * @covers Message::sizeParam
         * @covers Message::sizeParams
         */
-       public function testMessageSizeParams() {
+       public function testSizeParams() {
                $lang = Language::factory( 'en' );
                $msg = new RawMessage( '$1' );
 
@@ -264,9 +394,10 @@ class MessageTest extends MediaWikiLangTestCase {
        }
 
        /**
+        * @covers Message::bitrateParam
         * @covers Message::bitrateParams
         */
-       public function testMessageBitrateParams() {
+       public function testBitrateParams() {
                $lang = Language::factory( 'en' );
                $msg = new RawMessage( '$1' );
 
@@ -277,7 +408,7 @@ class MessageTest extends MediaWikiLangTestCase {
                );
        }
 
-       public function messagePlaintextParamsProvider() {
+       public static function providePlaintextParams() {
                return array(
                        array(
                                'one $2 <div>foo</div> [[Bar]] {{Baz}} &lt;',
@@ -308,10 +439,15 @@ class MessageTest extends MediaWikiLangTestCase {
        }
 
        /**
-        * @dataProvider messagePlaintextParamsProvider
+        * @covers Message::plaintextParam
         * @covers Message::plaintextParams
+        * @covers Message::formatPlaintext
+        * @covers Message::toString
+        * @covers Message::parse
+        * @covers Message::parseAsBlock
+        * @dataProvider providePlaintextParams
         */
-       public function testMessagePlaintextParams( $expect, $format ) {
+       public function testPlaintextParams( $expect, $format ) {
                $lang = Language::factory( 'en' );
 
                $msg = new RawMessage( '$1 $2' );
@@ -326,6 +462,46 @@ class MessageTest extends MediaWikiLangTestCase {
                );
        }
 
+       public static function provideParser() {
+               return array(
+                       array(
+                               "''&'' <x><!-- x -->",
+                               'plain',
+                       ),
+
+                       array(
+                               "''&'' <x><!-- x -->",
+                               'text',
+                       ),
+                       array(
+                               '<i>&amp;</i> &lt;x&gt;',
+                               'parse',
+                       ),
+
+                       array(
+                               "<p><i>&amp;</i> &lt;x&gt;\n</p>",
+                               'parseAsBlock',
+                       ),
+               );
+       }
+
+       /**
+        * @covers Message::text
+        * @covers Message::parse
+        * @covers Message::parseAsBlock
+        * @covers Message::toString
+        * @covers Message::transformText
+        * @covers Message::parseText
+        * @dataProvider provideParser
+        */
+       public function testParser( $expect, $format ) {
+               $msg = new RawMessage( "''&'' <x><!-- x -->" );
+               $this->assertEquals(
+                       $expect,
+                       $msg->inLanguage( 'en' )->$format()
+               );
+       }
+
        /**
         * @covers Message::inContentLanguage
         */
@@ -372,52 +548,4 @@ class MessageTest extends MediaWikiLangTestCase {
        public function testInLanguageThrows() {
                wfMessage( 'foo' )->inLanguage( 123 );
        }
-
-       public function keyProvider() {
-               return array(
-                       'string' => array(
-                               'key' => 'mainpage',
-                               'expected' => array( 'mainpage' ),
-                       ),
-                       'single' => array(
-                               'key' => array( 'mainpage' ),
-                               'expected' => array( 'mainpage' ),
-                       ),
-                       'multi' => array(
-                               'key' => array( 'mainpage-foo', 'mainpage-bar', 'mainpage' ),
-                               'expected' => array( 'mainpage-foo', 'mainpage-bar', 'mainpage' ),
-                       ),
-                       'empty' => array(
-                               'key' => array(),
-                               'expected' => null,
-                               'exception' => 'InvalidArgumentException',
-                       ),
-                       'null' => array(
-                               'key' => null,
-                               'expected' => null,
-                               'exception' => 'InvalidArgumentException',
-                       ),
-                       'bad type' => array(
-                               'key' => 17,
-                               'expected' => null,
-                               'exception' => 'InvalidArgumentException',
-                       ),
-               );
-       }
-
-       /**
-        * @dataProvider keyProvider()
-        *
-        * @covers Message::getKey
-        */
-       public function testGetKey( $key, $expected, $exception = null ) {
-               if ( $exception ) {
-                       $this->setExpectedException( $exception );
-               }
-
-               $msg = new Message( $key );
-               $this->assertEquals( $expected, $msg->getKeysToTry() );
-               $this->assertEquals( count( $expected ) > 1, $msg->isMultiKey() );
-               $this->assertContains( $msg->getKey(), $expected );
-       }
 }
index 73e5051..b74a7ea 100644 (file)
@@ -397,4 +397,32 @@ class UserTest extends MediaWikiTestCase {
                $sixth = User::newFromName( 'EqualUnitTestUser' );
                $this->assertTrue( $fifth->equals( $sixth ) );
        }
+
+       /**
+        * @covers User::getId
+        */
+       public function testGetId() {
+               $user = User::newFromName( 'UTSysop' );
+               $this->assertTrue( $user->getId() > 0 );
+
+       }
+
+       /**
+        * @covers User::isLoggedIn
+        * @covers User::isAnon
+        */
+       public function testLoggedIn() {
+               $user = User::newFromName( 'UTSysop' );
+               $this->assertTrue( $user->isLoggedIn() );
+               $this->assertFalse( $user->isAnon() );
+
+               // Non-existent users are perceived as anonymous
+               $user = User::newFromName( 'UTNonexistent' );
+               $this->assertFalse( $user->isLoggedIn() );
+               $this->assertTrue( $user->isAnon() );
+
+               $user = new User;
+               $this->assertFalse( $user->isLoggedIn() );
+               $this->assertTrue( $user->isAnon() );
+       }
 }
index e91edcb..7a03f7d 100644 (file)
@@ -2,7 +2,6 @@
 
 /**
  * @group API
- * @group Database
  * @group medium
  *
  * @covers ApiMain
@@ -23,20 +22,12 @@ class ApiMainTest extends ApiTestCase {
        }
 
        public static function provideAssert() {
-               $anon = new User();
-               $bot = new User();
-               $bot->setName( 'Bot' );
-               $bot->addToDatabase();
-               $bot->addGroup( 'bot' );
-               $user = new User();
-               $user->setName( 'User' );
-               $user->addToDatabase();
                return array(
-                       array( $anon, 'user', 'assertuserfailed' ),
-                       array( $user, 'user', false ),
-                       array( $user, 'bot', 'assertbotfailed' ),
-                       array( $bot, 'user', false ),
-                       array( $bot, 'bot', false ),
+                       array( false, array(), 'user', 'assertuserfailed' ),
+                       array( true, array(), 'user', false ),
+                       array( true, array(), 'bot', 'assertbotfailed' ),
+                       array( true, array( 'bot' ), 'user', false ),
+                       array( true, array( 'bot' ), 'bot', false ),
                );
        }
 
@@ -45,11 +36,17 @@ class ApiMainTest extends ApiTestCase {
         *
         * @covers ApiMain::checkAsserts
         * @dataProvider provideAssert
-        * @param User $user
+        * @param bool $registered
+        * @param array $rights
         * @param string $assert
         * @param string|bool $error False if no error expected
         */
-       public function testAssert( $user, $assert, $error ) {
+       public function testAssert( $registered, $rights, $assert, $error ) {
+               $user = new User();
+               if ( $registered ) {
+                       $user->setId( 1 );
+               }
+               $user->mRights = $rights;
                try {
                        $this->doApiRequest( array(
                                'action' => 'query',