14 $this->assertTrue(
$status->isGood() );
15 $this->assertTrue(
$status->isOK() );
23 [ [
'foo' =>
'bar' ] ],
34 ->disableOriginalConstructor()
38 $this->assertFalse(
$status->isGood() );
39 $this->assertFalse(
$status->isOK() );
40 $this->assertEquals( $message,
$status->getMessage() );
49 $this->assertFalse(
$status->isGood() );
50 $this->assertFalse(
$status->isOK() );
51 $this->assertEquals( $message,
$status->getMessage()->getKey() );
61 $this->assertTrue(
$status->ok );
63 $this->assertFalse(
$status->ok );
84 $this->assertFalse(
$status->isOK() );
86 $this->assertTrue(
$status->isOK() );
96 $this->assertEquals( $ok,
$status->isOK() );
117 $this->assertEquals( $ok,
$status->isOK() );
133 $this->assertEquals(
'foobar',
$status->getValue() );
143 foreach ( $errors
as $error ) {
146 $this->assertEquals( $expected,
$status->isGood() );
152 [
true, [
'foo' ],
false ],
153 [
false, [],
false ],
154 [
false, [
'foo' ],
false ],
171 $warnings =
$status->getWarningsArray();
175 $expectedArray = array_merge( [ $message->getKey() ], $message->getParams() );
176 $this->assertEquals( $warnings[$key], $expectedArray );
194 $errors =
$status->getErrorsArray();
198 $expectedArray = array_merge( [ $message->getKey() ], $message->getParams() );
199 $this->assertEquals( $errors[$key], $expectedArray );
216 $errors =
$status->getErrorsArray();
220 $expectedArray = array_merge( [ $message->getKey() ], $message->getParams() );
221 $this->assertEquals( $errors[$key], $expectedArray );
223 $this->assertFalse(
$status->isOK() );
228 ->disableOriginalConstructor()
230 $message->expects( $this->atLeastOnce() )
232 ->will( $this->returnValue( $key ) );
233 $message->expects( $this->atLeastOnce() )
234 ->method(
'getParams' )
235 ->will( $this->returnValue(
$params ) );
245 foreach ( $messageDetails
as $key => $paramsArray ) {
253 [ [
'key1' => [
'foo' =>
'bar' ] ] ],
254 [ [
'key1' => [
'foo' =>
'bar' ],
'key2' => [
'foo2' =>
'bar2' ] ] ],
266 $status1->warning( $message1 );
267 $status2->error( $message2 );
269 $status1->merge( $status2 );
272 count( $status1->getWarningsArray() ) +
count( $status1->getErrorsArray() )
284 $status1->warning( $message1 );
285 $status2->error( $message2 );
286 $status2->value =
'FooValue';
288 $status1->merge( $status2,
true );
291 count( $status1->getWarningsArray() ) +
count( $status1->getErrorsArray() )
293 $this->assertEquals(
'FooValue', $status1->getValue() );
303 $this->assertTrue(
$status->hasMessage(
'bad' ) );
304 $this->assertTrue(
$status->hasMessage(
'bad-msg' ) );
306 $this->assertFalse(
$status->hasMessage(
'good' ) );
314 $method =
new ReflectionMethod(
Status::class,
'cleanParams' );
315 $method->setAccessible(
true );
317 $status->cleanCallback = $cleanCallback;
319 $this->assertEquals( $expected, $method->invoke(
$status,
$params ) );
323 $cleanCallback =
function (
$value ) {
324 return '-' .
$value .
'-';
328 [
false, [
'foo' =>
'bar' ], [
'foo' =>
'bar' ] ],
329 [ $cleanCallback, [
'foo' =>
'bar' ], [
'foo' =>
'-bar-' ] ],
340 $this->assertEquals( $wikitext,
$status->getWikiText() );
342 $this->assertEquals( $wrappedWikitext,
$status->getWikiText(
'wrap-short',
'wrap-long',
'qqx' ) );
354 $this->assertEquals( $wrappedHtml,
$status->getHTML(
'wrap-short',
'wrap-long',
'qqx' ) );
365 $testCases[
'GoodStatus'] = [
367 "Internal error: Status::getWikiText called for a good result, this is incorrect\n",
368 "(wrap-short: (internalerror_info: Status::getWikiText called for a good result, " .
369 "this is incorrect\n))",
370 "<p>Internal error: Status::getWikiText called for a good result, this is incorrect\n</p>",
371 "<p>(wrap-short: (internalerror_info: Status::getWikiText called for a good result, " .
372 "this is incorrect\n))\n</p>",
377 $testCases[
'GoodButNoError'] = [
379 "Internal error: Status::getWikiText: Invalid result object: no error text but not OK\n",
380 "(wrap-short: (internalerror_info: Status::getWikiText: Invalid result object: " .
381 "no error text but not OK\n))",
382 "<p>Internal error: Status::getWikiText: Invalid result object: no error text but not OK\n</p>",
383 "<p>(wrap-short: (internalerror_info: Status::getWikiText: Invalid result object: " .
384 "no error text but not OK\n))\n</p>",
389 $testCases[
'1StringWarning'] = [
392 "(wrap-short: (fooBar!))",
393 "<p>⧼fooBar!⧽\n</p>",
394 "<p>(wrap-short: (fooBar!))\n</p>",
399 $status->warning(
'fooBar2!' );
400 $testCases[
'2StringWarnings'] = [
402 "* ⧼fooBar!⧽\n* ⧼fooBar2!⧽\n",
403 "(wrap-long: * (fooBar!)\n* (fooBar2!)\n)",
404 "<ul><li>⧼fooBar!⧽</li>\n<li>⧼fooBar2!⧽</li></ul>\n",
405 "<p>(wrap-long: * (fooBar!)\n</p>\n<ul><li>(fooBar2!)</li></ul>\n<p>)\n</p>",
409 $status->warning(
new Message(
'fooBar!', [
'foo',
'bar' ] ) );
410 $testCases[
'1MessageWarning'] = [
413 "(wrap-short: (fooBar!: foo, bar))",
414 "<p>⧼fooBar!⧽\n</p>",
415 "<p>(wrap-short: (fooBar!: foo, bar))\n</p>",
419 $status->warning(
new Message(
'fooBar!', [
'foo',
'bar' ] ) );
420 $status->warning(
new Message(
'fooBar2!' ) );
421 $testCases[
'2MessageWarnings'] = [
423 "* ⧼fooBar!⧽\n* ⧼fooBar2!⧽\n",
424 "(wrap-long: * (fooBar!: foo, bar)\n* (fooBar2!)\n)",
425 "<ul><li>⧼fooBar!⧽</li>\n<li>⧼fooBar2!⧽</li></ul>\n",
426 "<p>(wrap-long: * (fooBar!: foo, bar)\n</p>\n<ul><li>(fooBar2!)</li></ul>\n<p>)\n</p>",
433 return array_map(
function ( $p ) {
434 return $p instanceof Message
436 'key' => $p->getKey(),
438 'lang' => $p->getLanguage()->getCode(),
441 }, $message->getParams() );
449 Status $status, $expectedParams = [], $expectedKey, $expectedWrapper
451 $message =
$status->getMessage(
null,
null,
'qqx' );
453 $this->assertEquals( $expectedParams, self::sanitizedMessageParams( $message ),
454 'Message::getParams' );
455 $this->assertEquals( $expectedKey, $message->getKey(),
'Message::getKey' );
457 $message =
$status->getMessage(
'wrapper-short',
'wrapper-long' );
459 $this->assertEquals( $expectedWrapper, $message->getKey(),
'Message::getKey with wrappers' );
460 $this->assertCount( 1, $message->getParams(),
'Message::getParams with wrappers' );
462 $message =
$status->getMessage(
'wrapper' );
464 $this->assertEquals(
'wrapper', $message->getKey(),
'Message::getKey with wrappers' );
465 $this->assertCount( 1, $message->getParams(),
'Message::getParams with wrappers' );
467 $message =
$status->getMessage(
false,
'wrapper' );
469 $this->assertEquals(
'wrapper', $message->getKey(),
'Message::getKey with wrappers' );
470 $this->assertCount( 1, $message->getParams(),
'Message::getParams with wrappers' );
482 $testCases[
'GoodStatus'] = [
484 [
"Status::getMessage called for a good result, this is incorrect\n" ],
485 'internalerror_info',
491 $testCases[
'GoodButNoError'] = [
493 [
"Status::getMessage: Invalid result object: no error text but not OK\n" ],
494 'internalerror_info',
500 $testCases[
'1StringWarning'] = [
509 $status->warning(
'fooBar2!' );
510 $testCases[
'2StringWarnings' ] = [
513 [
'key' =>
'fooBar!',
'params' => [],
'lang' =>
'qqx' ],
514 [
'key' =>
'fooBar2!',
'params' => [],
'lang' =>
'qqx' ]
521 $status->warning(
new Message(
'fooBar!', [
'foo',
'bar' ] ) );
522 $testCases[
'1MessageWarning'] = [
530 $status->warning(
new Message(
'fooBar!', [
'foo',
'bar' ] ) );
531 $status->warning(
new Message(
'fooBar2!' ) );
532 $testCases[
'2MessageWarnings'] = [
535 [
'key' =>
'fooBar!',
'params' => [
'foo',
'bar' ],
'lang' =>
'qqx' ],
536 [
'key' =>
'fooBar2!',
'params' => [],
'lang' =>
'qqx' ]
550 $message =
new Message(
'key1', [
'foo1',
'bar1' ] );
552 $newMessage =
new Message(
'key2', [
'foo2',
'bar2' ] );
554 $status->replaceMessage( $message, $newMessage );
556 $this->assertEquals( $newMessage,
$status->errors[0][
'message'] );
563 $method =
new ReflectionMethod(
Status::class,
'getErrorMessage' );
564 $method->setAccessible(
true );
570 $message = $method->invoke(
$status, array_merge( [ $key ],
$params ) );
572 $this->assertEquals( $key, $message->getKey() );
573 $this->assertEquals(
$params, $message->getParams() );
580 $method =
new ReflectionMethod(
Status::class,
'getErrorMessageArray' );
581 $method->setAccessible(
true );
587 $messageArray = $method->invoke(
590 array_merge( [ $key ],
$params ),
591 array_merge( [ $key ],
$params )
595 $this->assertInternalType(
'array', $messageArray );
596 $this->assertCount( 2, $messageArray );
597 foreach ( $messageArray
as $message ) {
599 $this->assertEquals( $key, $message->getKey() );
600 $this->assertEquals(
$params, $message->getParams() );
609 $warning =
new Message(
'warning111' );
610 $error =
new Message(
'error111' );
614 $warnings =
$status->getErrorsByType(
'warning' );
615 $errors =
$status->getErrorsByType(
'error' );
617 $this->assertCount( 1, $warnings );
618 $this->assertCount( 1, $errors );
619 $this->assertEquals( $warning, $warnings[0][
'message'] );
620 $this->assertEquals( $error, $errors[0][
'message'] );
629 return '-' .
$value .
'-';
632 $this->assertEquals(
false,
$status->cleanCallback );
641 if ( !array_key_exists( 1, $nonObjMsg ) ) {
642 $status->warning( $nonObjMsg[0] );
644 $status->warning( $nonObjMsg[0], $nonObjMsg[1] );
647 $array =
$status->getWarningsArray();
649 $this->assertEquals( 1,
count( $array ) );
650 $this->assertEquals( $nonObjMsg, $array[0] );
655 [ [
'ImaString', [
'param1' =>
'value1' ] ] ],
672 if ( $warningText ) {
673 $status->warning( $warningText );
676 $this->assertEquals( $errorResult, $testStatus->getErrorsByType(
'error' ) );
677 $this->assertEquals( $warningResult, $testStatus->getErrorsByType(
'warning' ) );
689 'message' =>
'Just an error',
702 'message' =>
'Just a warning',