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() );
66 $this->assertTrue(
$status->ok );
68 $this->assertFalse(
$status->ok );
89 $this->assertFalse(
$status->isOK() );
91 $this->assertTrue(
$status->isOK() );
101 $this->assertEquals( $ok,
$status->isOK() );
122 $this->assertEquals( $ok,
$status->isOK() );
138 $this->assertEquals(
'foobar',
$status->getValue() );
148 foreach ( $errors
as $error ) {
151 $this->assertEquals( $expected,
$status->isGood() );
157 [
true, [
'foo' ],
false ],
158 [
false, [],
false ],
159 [
false, [
'foo' ],
false ],
176 $warnings =
$status->getWarningsArray();
178 $this->assertEquals( count(
$messages ), count( $warnings ) );
180 $expectedArray = array_merge( [ $message->getKey() ], $message->getParams() );
181 $this->assertEquals( $warnings[$key], $expectedArray );
199 $errors =
$status->getErrorsArray();
201 $this->assertEquals( count(
$messages ), count( $errors ) );
203 $expectedArray = array_merge( [ $message->getKey() ], $message->getParams() );
204 $this->assertEquals( $errors[$key], $expectedArray );
221 $errors =
$status->getErrorsArray();
223 $this->assertEquals( count(
$messages ), count( $errors ) );
225 $expectedArray = array_merge( [ $message->getKey() ], $message->getParams() );
226 $this->assertEquals( $errors[$key], $expectedArray );
228 $this->assertFalse(
$status->isOK() );
232 $message = $this->getMockBuilder(
'Message' )
233 ->disableOriginalConstructor()
235 $message->expects( $this->atLeastOnce() )
237 ->will( $this->returnValue( $key ) );
238 $message->expects( $this->atLeastOnce() )
239 ->method(
'getParams' )
240 ->will( $this->returnValue(
$params ) );
250 foreach ( $messageDetails
as $key => $paramsArray ) {
258 [ [
'key1' => [
'foo' =>
'bar' ] ] ],
259 [ [
'key1' => [
'foo' =>
'bar' ],
'key2' => [
'foo2' =>
'bar2' ] ] ],
271 $status1->warning( $message1 );
272 $status2->error( $message2 );
274 $status1->merge( $status2 );
277 count( $status1->getWarningsArray() ) + count( $status1->getErrorsArray() )
289 $status1->warning( $message1 );
290 $status2->error( $message2 );
291 $status2->value =
'FooValue';
293 $status1->merge( $status2,
true );
296 count( $status1->getWarningsArray() ) + count( $status1->getErrorsArray() )
298 $this->assertEquals(
'FooValue', $status1->getValue() );
308 $this->assertTrue(
$status->hasMessage(
'bad' ) );
309 $this->assertTrue(
$status->hasMessage(
'bad-msg' ) );
311 $this->assertFalse(
$status->hasMessage(
'good' ) );
319 $method =
new ReflectionMethod(
'Status',
'cleanParams' );
320 $method->setAccessible(
true );
322 $status->cleanCallback = $cleanCallback;
324 $this->assertEquals( $expected, $method->invoke(
$status,
$params ) );
328 $cleanCallback =
function (
$value ) {
329 return '-' .
$value .
'-';
333 [
false, [
'foo' =>
'bar' ], [
'foo' =>
'bar' ] ],
334 [ $cleanCallback, [
'foo' =>
'bar' ], [
'foo' =>
'-bar-' ] ],
345 $this->assertEquals( $wikitext, $status->
getWikiText() );
347 $this->assertEquals( $wrappedWikitext, $status->
getWikiText(
'wrap-short',
'wrap-long',
'qqx' ) );
359 $this->assertEquals( $wrappedHtml, $status->
getHTML(
'wrap-short',
'wrap-long',
'qqx' ) );
370 $testCases[
'GoodStatus'] = [
372 "Internal error: Status::getWikiText called for a good result, this is incorrect\n",
373 "(wrap-short: (internalerror_info: Status::getWikiText called for a good result, " .
374 "this is incorrect\n))",
375 "<p>Internal error: Status::getWikiText called for a good result, this is incorrect\n</p>",
376 "<p>(wrap-short: (internalerror_info: Status::getWikiText called for a good result, " .
377 "this is incorrect\n))\n</p>",
382 $testCases[
'GoodButNoError'] = [
384 "Internal error: Status::getWikiText: Invalid result object: no error text but not OK\n",
385 "(wrap-short: (internalerror_info: Status::getWikiText: Invalid result object: " .
386 "no error text but not OK\n))",
387 "<p>Internal error: Status::getWikiText: Invalid result object: no error text but not OK\n</p>",
388 "<p>(wrap-short: (internalerror_info: Status::getWikiText: Invalid result object: " .
389 "no error text but not OK\n))\n</p>",
394 $testCases[
'1StringWarning'] = [
397 "(wrap-short: (fooBar!))",
398 "<p>⧼fooBar!⧽\n</p>",
399 "<p>(wrap-short: (fooBar!))\n</p>",
404 $status->warning(
'fooBar2!' );
405 $testCases[
'2StringWarnings'] = [
407 "* ⧼fooBar!⧽\n* ⧼fooBar2!⧽\n",
408 "(wrap-long: * (fooBar!)\n* (fooBar2!)\n)",
409 "<ul><li> ⧼fooBar!⧽</li>\n<li> ⧼fooBar2!⧽</li></ul>\n",
410 "<p>(wrap-long: * (fooBar!)\n</p>\n<ul><li> (fooBar2!)</li></ul>\n<p>)\n</p>",
415 $testCases[
'1MessageWarning'] = [
418 "(wrap-short: (fooBar!: foo, bar))",
419 "<p>⧼fooBar!⧽\n</p>",
420 "<p>(wrap-short: (fooBar!: foo, bar))\n</p>",
426 $testCases[
'2MessageWarnings'] = [
428 "* ⧼fooBar!⧽\n* ⧼fooBar2!⧽\n",
429 "(wrap-long: * (fooBar!: foo, bar)\n* (fooBar2!)\n)",
430 "<ul><li> ⧼fooBar!⧽</li>\n<li> ⧼fooBar2!⧽</li></ul>\n",
431 "<p>(wrap-long: * (fooBar!: foo, bar)\n</p>\n<ul><li> (fooBar2!)</li></ul>\n<p>)\n</p>",
438 return array_map(
function ( $p ) {
441 'key' => $p->getKey(),
442 'params' => self::sanitizedMessageParams( $p ),
443 'lang' => $p->getLanguage()->getCode(),
454 Status $status, $expectedParams = [], $expectedKey, $expectedWrapper
456 $message = $status->
getMessage( null, null,
'qqx' );
457 $this->assertInstanceOf(
'Message', $message );
458 $this->assertEquals( $expectedParams, self::sanitizedMessageParams( $message ),
459 'Message::getParams' );
460 $this->assertEquals( $expectedKey, $message->getKey(),
'Message::getKey' );
462 $message = $status->
getMessage(
'wrapper-short',
'wrapper-long' );
463 $this->assertInstanceOf(
'Message', $message );
464 $this->assertEquals( $expectedWrapper, $message->getKey(),
'Message::getKey with wrappers' );
465 $this->assertCount( 1, $message->getParams(),
'Message::getParams with wrappers' );
468 $this->assertInstanceOf(
'Message', $message );
469 $this->assertEquals(
'wrapper', $message->getKey(),
'Message::getKey with wrappers' );
470 $this->assertCount( 1, $message->getParams(),
'Message::getParams with wrappers' );
472 $message = $status->
getMessage(
false,
'wrapper' );
473 $this->assertInstanceOf(
'Message', $message );
474 $this->assertEquals(
'wrapper', $message->getKey(),
'Message::getKey with wrappers' );
475 $this->assertCount( 1, $message->getParams(),
'Message::getParams with wrappers' );
487 $testCases[
'GoodStatus'] = [
489 [
"Status::getMessage called for a good result, this is incorrect\n" ],
490 'internalerror_info',
496 $testCases[
'GoodButNoError'] = [
498 [
"Status::getMessage: Invalid result object: no error text but not OK\n" ],
499 'internalerror_info',
505 $testCases[
'1StringWarning'] = [
514 $status->warning(
'fooBar2!' );
515 $testCases[
'2StringWarnings' ] = [
518 [
'key' =>
'fooBar!',
'params' => [],
'lang' =>
'qqx' ],
519 [
'key' =>
'fooBar2!',
'params' => [],
'lang' =>
'qqx' ]
527 $testCases[
'1MessageWarning'] = [
537 $testCases[
'2MessageWarnings'] = [
540 [
'key' =>
'fooBar!',
'params' => [
'foo',
'bar' ],
'lang' =>
'qqx' ],
541 [
'key' =>
'fooBar2!',
'params' => [],
'lang' =>
'qqx' ]
555 $message =
new Message(
'key1', [
'foo1',
'bar1' ] );
557 $newMessage =
new Message(
'key2', [
'foo2',
'bar2' ] );
559 $status->replaceMessage( $message, $newMessage );
561 $this->assertEquals( $newMessage,
$status->errors[0][
'message'] );
568 $method =
new ReflectionMethod(
'Status',
'getErrorMessage' );
569 $method->setAccessible(
true );
575 $message = $method->invoke(
$status, array_merge( [ $key ],
$params ) );
576 $this->assertInstanceOf(
'Message', $message );
577 $this->assertEquals( $key, $message->getKey() );
578 $this->assertEquals(
$params, $message->getParams() );
585 $method =
new ReflectionMethod(
'Status',
'getErrorMessageArray' );
586 $method->setAccessible(
true );
592 $messageArray = $method->invoke(
595 array_merge( [ $key ],
$params ),
596 array_merge( [ $key ],
$params )
600 $this->assertInternalType(
'array', $messageArray );
601 $this->assertCount( 2, $messageArray );
602 foreach ( $messageArray
as $message ) {
603 $this->assertInstanceOf(
'Message', $message );
604 $this->assertEquals( $key, $message->getKey() );
605 $this->assertEquals(
$params, $message->getParams() );
614 $warning =
new Message(
'warning111' );
615 $error =
new Message(
'error111' );
619 $warnings =
$status->getErrorsByType(
'warning' );
620 $errors =
$status->getErrorsByType(
'error' );
622 $this->assertCount( 1, $warnings );
623 $this->assertCount( 1, $errors );
624 $this->assertEquals( $warning, $warnings[0][
'message'] );
625 $this->assertEquals( $error, $errors[0][
'message'] );
634 return '-' .
$value .
'-';
637 $this->assertEquals(
false,
$status->cleanCallback );
646 if ( !array_key_exists( 1, $nonObjMsg ) ) {
647 $status->warning( $nonObjMsg[0] );
649 $status->warning( $nonObjMsg[0], $nonObjMsg[1] );
652 $array =
$status->getWarningsArray();
654 $this->assertEquals( 1, count( $array ) );
655 $this->assertEquals( $nonObjMsg, $array[0] );
660 [ [
'ImaString', [
'param1' =>
'value1' ] ] ],
677 if ( $warningText ) {
678 $status->warning( $warningText );
681 $this->assertEquals( $errorResult, $testStatus->getErrorsByType(
'error' ) );
682 $this->assertEquals( $warningResult, $testStatus->getErrorsByType(
'warning' ) );
694 'message' =>
'Just an error',
707 'message' =>
'Just a warning',
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 ...
testGetErrorMessageArray()
Status::getErrorMessageArray.
processing should stop and the error should be shown to the user * false
testReplaceMessage()
Status::replaceMessage.
static newFatal($message)
Factory function for fatal errors.
getWikiText($shortContext=false, $longContext=false, $lang=null)
Get the error list as a wikitext formatted list.
testNewFatalWithMessage()
Status::newFatal.
testMerge()
Status::merge.
testOkSetter()
Test 'ok' setter.
testWarningWithMessage($mockDetails)
provideMockMessageDetails Status::warning Status::getWarningsArray Status::getStatusArray ...
testNewFatalWithString()
Status::newFatal.
testIsOk($ok)
provideIsOk Status::setOK Status::isOK
testGetValue()
Status::getValue.
static sanitizedMessageParams(Message $message)
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.
testGetErrorsWarningsOnlyStatus($errorText, $warningText, $type, $errorResult, $warningResult)
provideErrorsWarningsOnly Status::splitByErrorType StatusValue::splitByErrorType
testHasMessage()
Status::hasMessage.
testGetStatusArrayWithNonObjectMessages($nonObjMsg)
provideNonObjectMessages Status::getStatusArray
static provideErrorsWarningsOnly()
testWakeUpSanitizesCallback()
Status::__wakeup.
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"<
static provideSetResult()
static provideGetMessage()
static provideCleanParams()
testGetErrorsByType()
Status::getErrorsByType.
testGetHtml(Status $status, $wikitext, $wrappedWikitext, $html, $wrappedHtml)
provideGetWikiTextAndHtml Status::getHtml
testGetMessage(Status $status, $expectedParams=[], $expectedKey, $expectedWrapper)
provideGetMessage Status::getMessage
testNewGood($value=null)
provideValues Status::newGood
static provideGetWikiTextAndHtml()
static newGood($value=null)
Factory function for good results.
testErrorWithMessage($mockDetails)
provideMockMessageDetails Status::error Status::getErrorsArray Status::getStatusArray Status::getErro...
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
testOkAndErrorsGetters()
Test 'ok' and 'errors' getters.
testSetResult($ok, $value=null)
provideSetResult Status::setResult
do that in ParserLimitReportFormat instead use this to modify the parameters of the image and a DIV can begin in one section and end in another Make sure your code can handle that case gracefully See the EditSectionClearerLink extension for an example zero but section is usually empty its values are the globals values before the output is cached one of or reset my talk my contributions etc etc otherwise the built in rate limiting checks are if enabled allows for interception of redirect as a string mapping parameter names to values & $type
getMockMessages($messageDetails)