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();
180 $expectedArray = array_merge( [ $message->getKey() ], $message->getParams() );
181 $this->assertEquals( $warnings[$key], $expectedArray );
199 $errors =
$status->getErrorsArray();
203 $expectedArray = array_merge( [ $message->getKey() ], $message->getParams() );
204 $this->assertEquals( $errors[$key], $expectedArray );
221 $errors =
$status->getErrorsArray();
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>",
414 $status->warning(
new Message(
'fooBar!', [
'foo',
'bar' ] ) );
415 $testCases[
'1MessageWarning'] = [
418 "(wrap-short: (fooBar!: foo, bar))",
419 "<p>⧼fooBar!⧽\n</p>",
420 "<p>(wrap-short: (fooBar!: foo, bar))\n</p>",
424 $status->warning(
new Message(
'fooBar!', [
'foo',
'bar' ] ) );
425 $status->warning(
new Message(
'fooBar2!' ) );
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 ) {
439 return $p instanceof Message
441 'key' => $p->getKey(),
443 'lang' => $p->getLanguage()->getCode(),
446 }, $message->getParams() );
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' );
467 $message =
$status->getMessage(
'wrapper' );
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' ]
526 $status->warning(
new Message(
'fooBar!', [
'foo',
'bar' ] ) );
527 $testCases[
'1MessageWarning'] = [
535 $status->warning(
new Message(
'fooBar!', [
'foo',
'bar' ] ) );
536 $status->warning(
new Message(
'fooBar2!' ) );
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',