10 $this->assertTrue(
true );
19 $this->assertTrue(
$status->isGood() );
20 $this->assertTrue(
$status->isOK() );
28 [ [
'foo' =>
'bar' ] ],
38 $message = $this->getMockBuilder(
'Message' )
39 ->disableOriginalConstructor()
43 $this->assertFalse(
$status->isGood() );
44 $this->assertFalse(
$status->isOK() );
45 $this->assertEquals( $message,
$status->getMessage() );
54 $this->assertFalse(
$status->isGood() );
55 $this->assertFalse(
$status->isOK() );
56 $this->assertEquals( $message,
$status->getMessage()->getKey() );
64 $this->assertTrue(
$status->ok );
66 $this->assertFalse(
$status->ok );
86 $this->assertEquals( $ok,
$status->isOK() );
106 $this->assertEquals( $ok,
$status->isOK() );
122 $this->assertEquals(
'foobar',
$status->getValue() );
132 foreach ( $errors
as $error ) {
135 $this->assertEquals( $expected,
$status->isGood() );
141 [
true, [
'foo' ],
false ],
142 [
false, [],
false ],
143 [
false, [
'foo' ],
false ],
160 $warnings =
$status->getWarningsArray();
162 $this->assertEquals( count(
$messages ), count( $warnings ) );
164 $expectedArray = array_merge( [ $message->getKey() ], $message->getParams() );
165 $this->assertEquals( $warnings[
$key], $expectedArray );
182 $errors =
$status->getErrorsArray();
184 $this->assertEquals( count(
$messages ), count( $errors ) );
186 $expectedArray = array_merge( [ $message->getKey() ], $message->getParams() );
187 $this->assertEquals( $errors[
$key], $expectedArray );
204 $errors =
$status->getErrorsArray();
206 $this->assertEquals( count(
$messages ), count( $errors ) );
208 $expectedArray = array_merge( [ $message->getKey() ], $message->getParams() );
209 $this->assertEquals( $errors[
$key], $expectedArray );
211 $this->assertFalse(
$status->isOK() );
215 $message = $this->getMockBuilder(
'Message' )
216 ->disableOriginalConstructor()
218 $message->expects( $this->atLeastOnce() )
220 ->will( $this->returnValue(
$key ) );
221 $message->expects( $this->atLeastOnce() )
222 ->method(
'getParams' )
223 ->will( $this->returnValue(
$params ) );
233 foreach ( $messageDetails
as $key => $paramsArray ) {
241 [ [
'key1' => [
'foo' =>
'bar' ] ] ],
242 [ [
'key1' => [
'foo' =>
'bar' ],
'key2' => [
'foo2' =>
'bar2' ] ] ],
254 $status1->warning( $message1 );
255 $status2->error( $message2 );
257 $status1->merge( $status2 );
260 count( $status1->getWarningsArray() ) + count( $status1->getErrorsArray() )
272 $status1->warning( $message1 );
273 $status2->error( $message2 );
274 $status2->value =
'FooValue';
276 $status1->merge( $status2,
true );
279 count( $status1->getWarningsArray() ) + count( $status1->getErrorsArray() )
281 $this->assertEquals(
'FooValue', $status1->getValue() );
291 $this->assertTrue(
$status->hasMessage(
'bad' ) );
292 $this->assertTrue(
$status->hasMessage(
'bad-msg' ) );
294 $this->assertFalse(
$status->hasMessage(
'good' ) );
302 $method =
new ReflectionMethod(
'Status',
'cleanParams' );
303 $method->setAccessible(
true );
305 $status->cleanCallback = $cleanCallback;
307 $this->assertEquals( $expected, $method->invoke(
$status,
$params ) );
311 $cleanCallback =
function (
$value ) {
312 return '-' .
$value .
'-';
316 [
false, [
'foo' =>
'bar' ], [
'foo' =>
'bar' ] ],
317 [ $cleanCallback, [
'foo' =>
'bar' ], [
'foo' =>
'-bar-' ] ],
328 $this->assertEquals( $wikitext, $status->
getWikiText() );
330 $this->assertEquals( $wrappedWikitext, $status->
getWikiText(
'wrap-short',
'wrap-long',
'qqx' ) );
342 $this->assertEquals( $wrappedHtml, $status->
getHTML(
'wrap-short',
'wrap-long',
'qqx' ) );
353 $testCases[
'GoodStatus'] = [
355 "Internal error: Status::getWikiText called for a good result, this is incorrect\n",
356 "(wrap-short: (internalerror_info: Status::getWikiText called for a good result, " .
357 "this is incorrect\n))",
358 "<p>Internal error: Status::getWikiText called for a good result, this is incorrect\n</p>",
359 "<p>(wrap-short: (internalerror_info: Status::getWikiText called for a good result, " .
360 "this is incorrect\n))\n</p>",
365 $testCases[
'GoodButNoError'] = [
367 "Internal error: Status::getWikiText: Invalid result object: no error text but not OK\n",
368 "(wrap-short: (internalerror_info: Status::getWikiText: Invalid result object: " .
369 "no error text but not OK\n))",
370 "<p>Internal error: Status::getWikiText: Invalid result object: no error text but not OK\n</p>",
371 "<p>(wrap-short: (internalerror_info: Status::getWikiText: Invalid result object: " .
372 "no error text but not OK\n))\n</p>",
377 $testCases[
'1StringWarning'] = [
380 "(wrap-short: (fooBar!))",
381 "<p><fooBar!>\n</p>",
382 "<p>(wrap-short: (fooBar!))\n</p>",
387 $status->warning(
'fooBar2!' );
388 $testCases[
'2StringWarnings'] = [
390 "* <fooBar!>\n* <fooBar2!>\n",
391 "(wrap-long: * (fooBar!)\n* (fooBar2!)\n)",
392 "<ul><li> <fooBar!></li>\n<li> <fooBar2!></li></ul>\n",
393 "<p>(wrap-long: * (fooBar!)\n</p>\n<ul><li> (fooBar2!)</li></ul>\n<p>)\n</p>",
398 $testCases[
'1MessageWarning'] = [
401 "(wrap-short: (fooBar!: foo, bar))",
402 "<p><fooBar!>\n</p>",
403 "<p>(wrap-short: (fooBar!: foo, bar))\n</p>",
409 $testCases[
'2MessageWarnings'] = [
411 "* <fooBar!>\n* <fooBar2!>\n",
412 "(wrap-long: * (fooBar!: foo, bar)\n* (fooBar2!)\n)",
413 "<ul><li> <fooBar!></li>\n<li> <fooBar2!></li></ul>\n",
414 "<p>(wrap-long: * (fooBar!: foo, bar)\n</p>\n<ul><li> (fooBar2!)</li></ul>\n<p>)\n</p>",
421 return array_map(
function ( $p ) {
424 'key' => $p->getKey(),
425 'params' => self::sanitizedMessageParams( $p ),
426 'lang' => $p->getLanguage()->getCode(),
437 Status $status, $expectedParams = [], $expectedKey, $expectedWrapper
439 $message = $status->
getMessage( null, null,
'qqx' );
440 $this->assertInstanceOf(
'Message', $message );
441 $this->assertEquals( $expectedParams, self::sanitizedMessageParams( $message ),
442 'Message::getParams' );
443 $this->assertEquals( $expectedKey, $message->getKey(),
'Message::getKey' );
445 $message = $status->
getMessage(
'wrapper-short',
'wrapper-long' );
446 $this->assertInstanceOf(
'Message', $message );
447 $this->assertEquals( $expectedWrapper, $message->getKey(),
'Message::getKey with wrappers' );
448 $this->assertCount( 1, $message->getParams(),
'Message::getParams with wrappers' );
451 $this->assertInstanceOf(
'Message', $message );
452 $this->assertEquals(
'wrapper', $message->getKey(),
'Message::getKey with wrappers' );
453 $this->assertCount( 1, $message->getParams(),
'Message::getParams with wrappers' );
455 $message = $status->
getMessage(
false,
'wrapper' );
456 $this->assertInstanceOf(
'Message', $message );
457 $this->assertEquals(
'wrapper', $message->getKey(),
'Message::getKey with wrappers' );
458 $this->assertCount( 1, $message->getParams(),
'Message::getParams with wrappers' );
470 $testCases[
'GoodStatus'] = [
472 [
"Status::getMessage called for a good result, this is incorrect\n" ],
473 'internalerror_info',
479 $testCases[
'GoodButNoError'] = [
481 [
"Status::getMessage: Invalid result object: no error text but not OK\n" ],
482 'internalerror_info',
488 $testCases[
'1StringWarning'] = [
497 $status->warning(
'fooBar2!' );
498 $testCases[
'2StringWarnings' ] = [
501 [
'key' =>
'fooBar!',
'params' => [],
'lang' =>
'qqx' ],
502 [
'key' =>
'fooBar2!',
'params' => [],
'lang' =>
'qqx' ]
510 $testCases[
'1MessageWarning'] = [
520 $testCases[
'2MessageWarnings'] = [
523 [
'key' =>
'fooBar!',
'params' => [
'foo',
'bar' ],
'lang' =>
'qqx' ],
524 [
'key' =>
'fooBar2!',
'params' => [],
'lang' =>
'qqx' ]
538 $message =
new Message(
'key1', [
'foo1',
'bar1' ] );
540 $newMessage =
new Message(
'key2', [
'foo2',
'bar2' ] );
542 $status->replaceMessage( $message, $newMessage );
544 $this->assertEquals( $newMessage,
$status->errors[0][
'message'] );
551 $method =
new ReflectionMethod(
'Status',
'getErrorMessage' );
552 $method->setAccessible(
true );
559 $this->assertInstanceOf(
'Message', $message );
560 $this->assertEquals(
$key, $message->getKey() );
561 $this->assertEquals(
$params, $message->getParams() );
568 $method =
new ReflectionMethod(
'Status',
'getErrorMessageArray' );
569 $method->setAccessible(
true );
575 $messageArray = $method->invoke(
583 $this->assertInternalType(
'array', $messageArray );
584 $this->assertCount( 2, $messageArray );
585 foreach ( $messageArray
as $message ) {
586 $this->assertInstanceOf(
'Message', $message );
587 $this->assertEquals(
$key, $message->getKey() );
588 $this->assertEquals(
$params, $message->getParams() );
597 $warning =
new Message(
'warning111' );
598 $error =
new Message(
'error111' );
602 $warnings =
$status->getErrorsByType(
'warning' );
603 $errors =
$status->getErrorsByType(
'error' );
605 $this->assertCount( 1, $warnings );
606 $this->assertCount( 1, $errors );
607 $this->assertEquals( $warning, $warnings[0][
'message'] );
608 $this->assertEquals( $error, $errors[0][
'message'] );
617 return '-' .
$value .
'-';
620 $this->assertEquals(
false,
$status->cleanCallback );
629 if ( !array_key_exists( 1, $nonObjMsg ) ) {
630 $status->warning( $nonObjMsg[0] );
632 $status->warning( $nonObjMsg[0], $nonObjMsg[1] );
635 $array =
$status->getWarningsArray();
637 $this->assertEquals( 1, count( $array ) );
638 $this->assertEquals( $nonObjMsg, $array[0] );
643 [ [
'ImaString', [
'param1' =>
'value1' ] ] ],
testGetErrorMessage()
Status::getErrorMessage.
testMergeWithOverwriteValue()
Status::merge.
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return an< a > element with HTML attributes $attribs and contents $html will be returned If you return $ret will be returned and may include noclasses & $html
testFatalWithMessage($mockDetails)
provideMockMessageDetails Status::fatal Status::getErrorsArray Status::getStatusArray ...
magic word the default is to use $key to get the and $key value or $key value text $key value html to format the value $key
testGetErrorMessageArray()
Status::getErrorMessageArray.
testReplaceMessage()
Status::replaceMessage.
getWikiText($shortContext=false, $longContext=false, $lang=null)
Get the error list as a wikitext formatted list.
processing should stop and the error should be shown to the user * false
testNewFatalWithMessage()
Status::newFatal.
testMerge()
Status::merge.
testWarningWithMessage($mockDetails)
provideMockMessageDetails Status::warning Status::getWarningsArray Status::getStatusArray ...
testNewFatalWithString()
Status::newFatal.
testIsOk($ok)
provideIsOk Status::isOk
testGetValue()
Status::getValue.
static sanitizedMessageParams(Message $message)
static newFatal($message)
Factory function for fatal errors.
static provideNonObjectMessages()
getHTML($shortContext=false, $longContext=false, $lang=null)
Get the error message as HTML.
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return true
getParams()
Returns the message parameters.
testHasMessage()
Status::hasMessage.
testGetStatusArrayWithNonObjectMessages($nonObjMsg)
provideNonObjectMessages Status::getStatusArray
testWakeUpSanitizesCallback()
Status::__wakeup.
static provideSetResult()
static provideGetMessage()
static provideCleanParams()
testGetErrorsByType()
Status::getErrorsByType.
testGetHtml(Status $status, $wikitext, $wrappedWikitext, $html, $wrappedHtml)
provideGetWikiTextAndHtml Status::getHtml
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return an< a > element with HTML attributes $attribs and contents $html will be returned If you return $ret will be returned and may include noclasses after processing 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"<
testGetMessage(Status $status, $expectedParams=[], $expectedKey, $expectedWrapper)
provideGetMessage Status::getMessage
testNewGood($value=null)
provideValues Status::newGood
static provideGetWikiTextAndHtml()
testErrorWithMessage($mockDetails)
provideMockMessageDetails Status::error Status::getErrorsArray Status::getStatusArray ...
getMockMessage($key= 'key', $params=[])
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
getMessage($shortContext=false, $longContext=false, $lang=null)
Get a bullet list of the errors as a Message object.
testGetWikiText(Status $status, $wikitext, $wrappedWikitext, $html, $wrappedHtml)
provideGetWikiTextAndHtml Status::getWikiText
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
static provideMockMessageDetails()
testIsGood($ok, $errors, $expected)
provideIsGood Status::isGood
testCleanParams($cleanCallback, $params, $expected)
provideCleanParams Status::cleanParams
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist e g Watchlist removed from all revisions and log entries to which it was applied This gives extensions a chance to take it off their books as the deletion has already been partly carried out by this point or something similar the user will be unable to create the tag set $status
testSetResult($ok, $value=null)
provideSetResult Status::setResult
getMockMessages($messageDetails)
static newGood($value=null)
Factory function for good results.