6 protected function setUp() {
10 'wgForceUIMsgAsContentMsg' => [],
22 $this->assertEquals( $key, $message->getKey() );
23 $this->assertEquals(
$params, $message->getParams() );
24 $this->assertEquals( $expectedLang, $message->getLanguage() );
26 $messageSpecifier = $this->getMockForAbstractClass(
'MessageSpecifier' );
27 $messageSpecifier->expects( $this->any() )
28 ->method(
'getKey' )->will( $this->returnValue( $key ) );
29 $messageSpecifier->expects( $this->any() )
30 ->method(
'getParams' )->will( $this->returnValue(
$params ) );
31 $message =
new Message( $messageSpecifier, [], $language );
33 $this->assertEquals( $key, $message->getKey() );
34 $this->assertEquals(
$params, $message->getParams() );
35 $this->assertEquals( $expectedLang, $message->getLanguage() );
43 [ $langDe,
'foo', [], $langDe ],
44 [ $langDe,
'foo', [
'bar' ], $langDe ],
45 [ $langEn,
'foo', [
'bar' ], null ]
73 [ [
'baz',
'foo' ],
'hhh' ],
77 [ [
'baz',
'foo' ],
'hhh', [
'ahahahahha' ] ],
81 [ [
'baz',
'foo' ], [
'ahahahahha' ] ],
85 [ [
'baz' ], [
'ahahahahha' ] ],
96 $msg =
new Message(
'imasomething' );
98 $returned = call_user_func_array( [ $msg,
'params' ],
$args );
100 $this->assertSame( $msg, $returned );
101 $this->assertEquals( $expected, $msg->getParams() );
106 [
'foo', [
'bar' ],
'en' ],
107 [
'foo', [
'bar' ],
'de' ]
120 $this->assertEquals( $language, $message->getLanguage() );
127 'expected' => [
'mainpage' ],
130 'key' => [
'mainpage' ],
131 'expected' => [
'mainpage' ],
134 'key' => [
'mainpage-foo',
'mainpage-bar',
'mainpage' ],
135 'expected' => [
'mainpage-foo',
'mainpage-bar',
'mainpage' ],
140 'exception' =>
'InvalidArgumentException',
145 'exception' =>
'InvalidArgumentException',
150 'exception' =>
'InvalidArgumentException',
162 public function testKeys( $key, $expected, $exception = null ) {
164 $this->setExpectedException( $exception );
168 $this->assertContains( $msg->getKey(), $expected );
169 $this->assertEquals( $expected, $msg->getKeysToTry() );
170 $this->assertEquals( count( $expected ) > 1, $msg->isMultiKey() );
177 $this->assertInstanceOf(
'Message',
wfMessage(
'mainpage' ) );
178 $this->assertInstanceOf(
'Message',
wfMessage(
'i-dont-exist-evar' ) );
194 $this->assertEquals(
'Return to $1.',
wfMessage(
'returnto' )->
text() );
195 $this->assertEquals(
'Return to $1.',
wfMessage(
'returnto', [] )->
text() );
197 'You have foo (bar).',
201 'You have foo (bar).',
210 $this->assertTrue(
wfMessage(
'mainpage' )->exists() );
211 $this->assertTrue(
wfMessage(
'mainpage' )->params( [] )->exists() );
212 $this->assertTrue(
wfMessage(
'mainpage' )->rawParams(
'foo', 123 )->exists() );
213 $this->assertFalse(
wfMessage(
'i-dont-exist-evar' )->exists() );
214 $this->assertFalse(
wfMessage(
'i-dont-exist-evar' )->params( [] )->exists() );
215 $this->assertFalse(
wfMessage(
'i-dont-exist-evar' )->rawParams(
'foo', 123 )->exists() );
226 $this->assertEquals(
'Main Page',
wfMessage(
'mainpage' )->
text() );
227 $this->assertEquals(
'⧼i-dont-exist-evar⧽',
wfMessage(
'i-dont-exist-evar' )->
text() );
228 $this->assertEquals(
'⧼i<dont>exist-evar⧽',
wfMessage(
'i<dont>exist-evar' )->
text() );
229 $this->assertEquals(
'⧼i-dont-exist-evar⧽',
wfMessage(
'i-dont-exist-evar' )->
plain() );
230 $this->assertEquals(
'⧼i<dont>exist-evar⧽',
wfMessage(
'i<dont>exist-evar' )->
plain() );
231 $this->assertEquals(
'⧼i-dont-exist-evar⧽',
wfMessage(
'i-dont-exist-evar' )->escaped() );
233 '⧼i<dont>exist-evar⧽',
234 wfMessage(
'i<dont>exist-evar' )->escaped()
240 [
'mainpage',
'Main Page' ],
241 [
'i-dont-exist-evar',
'⧼i-dont-exist-evar⧽' ],
242 [
'i-dont-exist-evar',
'⧼i-dont-exist-evar⧽',
'escaped' ],
243 [
'script>alert(1)</script',
'⧼script>alert(1)</script⧽',
'escaped' ],
244 [
'script>alert(1)</script',
'⧼script>alert(1)</script⧽' ],
256 $this->assertEquals( $expect, $msg->toString() );
257 $this->assertEquals( $expect, $msg->__toString() );
264 $this->assertEquals(
'Main Page',
wfMessage(
'mainpage' )->inLanguage(
'en' )->
text() );
265 $this->assertEquals(
'Заглавная страница',
270 $this->assertEquals(
'Main Page', $msg->inLanguage(
Language::factory(
'en' ) )->text() );
272 'Заглавная страница',
283 '(Заглавная страница)',
287 '(Заглавная страница $1)',
291 '(Заглавная страница)',
292 wfMessage(
'parentheses' )->rawParams(
'Заглавная страница' )->
plain()
295 '(Заглавная страница $1)',
296 wfMessage(
'parentheses' )->rawParams(
'Заглавная страница $1' )->
plain()
306 $this->assertEquals(
'example &', $msg->plain() );
307 $this->assertEquals(
'example &', $msg->escaped() );
320 $msg =
new RawMessage(
'<html><script>alert("xss")</script></html>' );
321 $txt =
'<span class="error"><html> tags cannot be' .
322 ' used outside of normal pages.</span>';
323 $this->assertSame( $txt, $msg->parse() );
332 $msg =
new RawMessage(
'$1$2$3$4$5$6$7$8$9$10$11$12' );
334 $params = [
'a',
'b',
'c',
'd',
'e',
'f',
'g',
'h',
'i',
'j',
'k' ];
337 $msg->params(
$params )->plain(),
338 'Params > 9 are replaced correctly'
342 $params = [
'ab',
'bc',
'cd' ];
344 'Params: ab, bc, cd',
345 $msg->params(
$params )->text()
358 $lang->formatNum( 123456.789 ),
359 $msg->inLanguage(
$lang )->numParams( 123456.789 )->plain(),
360 'numParams is handled correctly'
373 $lang->formatDuration( 1234 ),
374 $msg->inLanguage(
$lang )->durationParams( 1234 )->plain(),
375 'durationParams is handled correctly'
392 'expiryParams is handled correctly'
405 $lang->formatTimePeriod( 1234 ),
406 $msg->inLanguage(
$lang )->timeperiodParams( 1234 )->plain(),
407 'timeperiodParams is handled correctly'
420 $lang->formatSize( 123456 ),
421 $msg->inLanguage(
$lang )->sizeParams( 123456 )->plain(),
422 'sizeParams is handled correctly'
435 $lang->formatBitrate( 123456 ),
436 $msg->inLanguage(
$lang )->bitrateParams( 123456 )->plain(),
437 'bitrateParams is handled correctly'
444 'one $2 <div>foo</div> [[Bar]] {{Baz}} <',
450 'one $2 <div>foo</div> [[Bar]] {{Baz}} <',
455 'one $2 <div>foo</div> [[Bar]] {{Baz}} &lt;',
460 'one $2 <div>foo</div> [[Bar]] {{Baz}} &lt;',
465 "<p>one $2 <div>foo</div> [[Bar]] {{Baz}} &lt;\n</p>",
486 '<div>foo</div> [[Bar]] {{Baz}} <',
490 $msg->inLanguage(
$lang )->plaintextParams(
$params )->$format(),
491 "Fail formatting for $format"
498 "''&'' <x><!-- x -->",
503 "''&'' <x><!-- x -->",
507 '<i>&</i> <x>',
512 "<p><i>&</i> <x>\n</p>",
528 $msg =
new RawMessage(
"''&'' <x><!-- x -->" );
531 $msg->inLanguage(
'en' )->$format()
543 $this->assertEquals(
'Hauptseite', $msg->inLanguage(
'de' )->plain(),
"inLanguage( 'de' )" );
544 $this->assertEquals(
'Main Page', $msg->inContentLanguage()->plain(),
"inContentLanguage()" );
545 $this->assertEquals(
'Accueil', $msg->inLanguage(
'fr' )->plain(),
"inLanguage( 'fr' )" );
553 'wgForceUIMsgAsContentMsg' => [
'mainpage' ],
562 $msg->inContentLanguage()->plain(),
563 'inContentLanguage() with ForceUIMsg override enabled'
565 $this->assertEquals(
'Main Page', $msg->inLanguage(
'en' )->plain(),
"inLanguage( 'en' )" );
568 $msg->inContentLanguage()->plain(),
569 'inContentLanguage() with ForceUIMsg override enabled'
571 $this->assertEquals(
'Hauptseite', $msg->inLanguage(
'de' )->plain(),
"inLanguage( 'de' )" );
587 $msg =
new Message(
'parentheses' );
588 $msg->rawParams(
'<a>foo</a>' );
590 $this->assertEquals(
'(<a>foo</a>)', $msg->parse(),
'Sanity check' );
592 $this->assertEquals(
'(<a>foo</a>)', $msg->parse() );
594 $this->assertInstanceOf(
'Title', $title );
595 $this->assertEquals(
'Testing', $title->getFullText() );
597 $msg =
new Message(
'mainpage' );
598 $msg->inLanguage(
'de' );
599 $this->assertEquals(
'Hauptseite', $msg->plain(),
'Sanity check' );
601 $this->assertEquals(
'Hauptseite', $msg->plain() );
612 $this->assertInstanceOf( get_class(
$value ), $message );
613 $this->assertEquals(
$value, $message );
615 $this->assertSame( $expectedText, $message->text() );
620 $messageSpecifier->expects( $this->any() )->method(
'getKey' )->willReturn(
'mainpage' );
621 $messageSpecifier->expects( $this->any() )->method(
'getParams' )->willReturn( [] );
624 'string' => [
'mainpage',
'Main Page' ],
625 'array' => [ [
'youhavenewmessages',
'foo',
'bar' ],
'You have foo (bar).' ],
626 'Message' => [
new Message(
'youhavenewmessages', [
'foo',
'bar' ] ),
'You have foo (bar).' ],
627 'RawMessage' => [
new RawMessage(
'foo ($1)', [
'bar' ] ),
'foo (bar)' ],
628 'ApiMessage' => [
new ApiMessage( [
'mainpage' ],
'code', [
'data' ] ),
'Main Page' ],
629 'MessageSpecifier' => [ $messageSpecifier,
'Main Page' ],
630 'nested RawMessage' => [ [
new RawMessage(
'foo ($1)', [
'bar' ] ) ],
'foo (bar)' ],
testSerialization()
Message::serialize Message::unserialize.
testExists()
Message::exists.
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
testDurationParams()
Message::durationParam Message::durationParams.
if(!isset($args[0])) $lang
static destroyInstance()
Destroy the singleton instance.
testNewFromKey()
Message::newFromKey.
testToStringKey()
Message::__construct Message::text Message::plain Message::escaped Message::toString.
testConstructorParams($expected, $args)
Message::__construct Message::getParams provideConstructorParams.
testInContentLanguage()
Message::inContentLanguage.
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency MediaWikiServices
static constructClassInstance($clazz, $args)
Construct an instance of the given class using the given arguments.
static newFromText($text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
when a variable name is used in a it is silently declared as a new local masking the global
testInLanguage()
Message::inLanguage.
testInLanguageThrows()
MWException Message::inLanguage.
testNewFromSpecifier($value, $expectedText)
Message::newFromSpecifier provideNewFromSpecifier.
testSizeParams()
Message::sizeParam Message::sizeParams.
testRawMessage()
RawMessage::__construct RawMessage::fetchMessage.
static provideConstructorLanguage()
testPlaintextParams($expect, $format)
Message::plaintextParam Message::plaintextParams Message::formatPlaintext Message::toString Message::...
either a unescaped string or a HtmlArmor object after in associative array form externallinks including delete and has completed for all link tables whether this was an auto creation default is conds Array Extra conditions for the No matching items in log is displayed if loglist is empty msgKey Array If you want a nice box with a set this to the key of the message First element is the message additional optional elements are parameters for the key that are processed with wfMessage() -> params() ->parseAsBlock()-offset Set to overwrite offset parameter in $wgRequest set to ''to unsetoffset-wrap String Wrap the message in html(usually something like"<
testToString($key, $expect, $format= 'plain')
Message::toString Message::__toString provideToString.
wfTimestampNow()
Convenience function; returns MediaWiki timestamp for the present time.
static provideConstructor()
Extension of Message implementing IApiMessage.
provideNewFromSpecifier()
namespace and then decline to actually register it file or subcat img or subcat $title
testParser($expect, $format)
Message::text Message::parse Message::parseAsBlock Message::toString Message::transformText Message::...
design txt This is a brief overview of the new design More thorough and up to date information is available on the documentation wiki at etc Handles the details of getting and saving to the user table of the and dealing with sessions and cookies OutputPage Encapsulates the entire HTML page that will be sent in response to any server request It is used by calling its functions to add text
testNumParams()
Message::numParam Message::numParams.
static newFromKey($key)
Factory function that is just wrapper for the real constructor.
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
testTimeperiodParams()
Message::timeperiodParam Message::timeperiodParams.
testReplaceManyParams()
Message::params Message::toString Message::replaceParameters.
testConstructor($expectedLang, $key, $params, $language)
Message::__construct provideConstructor.
you have access to all of the normal MediaWiki so you can get a DB use the etc For full docs on the Maintenance class
testRawParams()
Message::rawParam Message::rawParams.
Variant of the Message class.
testBitrateParams()
Message::bitrateParam Message::bitrateParams.
testKeys($key, $expected, $exception=null)
Message::__construct Message::getKey Message::isMultiKey Message::getKeysToTry provideKeys.
static providePlaintextParams()
static provideConstructorParams()
testExpiryParams()
FIXME: This should not need database, but Language::formatExpiry does (bug 55912) Database Message::e...
static newFromObject($object)
Return the same object, without access restrictions.
static factory($code)
Get a cached or new language object for a given language code.
testInContentLanguageOverride()
Message::inContentLanguage.
testConstructorLanguage($key, $params, $languageCode)
Message::__construct Message::getLanguage provideConstructorLanguage.
testWfMessageParams()
wfMessage Message::__construct
static newFromSpecifier($value)
Transform a MessageSpecifier or a primitive value used interchangeably with specifiers (a message key...