10 $this->assertTrue(
true );
19 $this->assertTrue( $status->isGood() );
20 $this->assertTrue( $status->isOK() );
21 $this->assertEquals(
$value, $status->getValue() );
29 array(
new Exception() ),
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->assertEquals(
$ok, $status->isOK() );
67 $this->assertEquals(
$value, $status->getValue() );
74 array(
true,
'value' ),
75 array(
false,
'value' ),
86 $this->assertEquals(
$ok, $status->isOK() );
101 $status->value =
'foobar';
102 $this->assertEquals(
'foobar', $status->getValue() );
112 $status->errors = $errors;
113 $this->assertEquals( $expected, $status->isGood() );
136 $status->warning( $message );
138 $warnings = $status->getWarningsArray();
140 $this->assertEquals( count(
$messages ), count( $warnings ) );
142 $expectedArray = array_merge(
array( $message->getKey() ), $message->getParams() );
143 $this->assertEquals( $warnings[$key], $expectedArray );
158 $status->error( $message );
160 $errors = $status->getErrorsArray();
162 $this->assertEquals( count(
$messages ), count( $errors ) );
164 $expectedArray = array_merge(
array( $message->getKey() ), $message->getParams() );
165 $this->assertEquals( $errors[$key], $expectedArray );
180 $status->fatal( $message );
182 $errors = $status->getErrorsArray();
184 $this->assertEquals( count(
$messages ), count( $errors ) );
186 $expectedArray = array_merge(
array( $message->getKey() ), $message->getParams() );
187 $this->assertEquals( $errors[$key], $expectedArray );
189 $this->assertFalse( $status->isOK() );
193 $message = $this->getMockBuilder(
'Message' )
194 ->disableOriginalConstructor()
196 $message->expects( $this->atLeastOnce() )
198 ->will( $this->returnValue( $key ) );
199 $message->expects( $this->atLeastOnce() )
200 ->method(
'getParams' )
201 ->will( $this->returnValue(
$params ) );
211 foreach ( $messageDetails
as $key => $paramsArray ) {
232 $status1->warning( $message1 );
233 $status2->error( $message2 );
235 $status1->merge( $status2 );
236 $this->assertEquals( 2, count( $status1->getWarningsArray() ) + count( $status1->getErrorsArray() ) );
247 $status1->warning( $message1 );
248 $status2->error( $message2 );
249 $status2->value =
'FooValue';
251 $status1->merge( $status2,
true );
252 $this->assertEquals( 2, count( $status1->getWarningsArray() ) + count( $status1->getErrorsArray() ) );
253 $this->assertEquals(
'FooValue', $status1->getValue() );
261 $status->fatal(
'bad' );
262 $this->assertTrue( $status->hasMessage(
'bad' ) );
263 $this->assertFalse( $status->hasMessage(
'good' ) );
271 $method =
new ReflectionMethod(
'Status',
'cleanParams' );
272 $method->setAccessible(
true );
274 $status->cleanCallback = $cleanCallback;
276 $this->assertEquals( $expected, $method->invoke( $status,
$params ) );
280 $cleanCallback =
function(
$value ) {
281 return '-' .
$value .
'-';
286 array( $cleanCallback,
array(
'foo' =>
'bar' ),
array(
'foo' =>
'-bar-' ) ),
298 $this->assertEquals( $wikitext, $status->
getWikiText() );
318 $testCases =
array();
320 $testCases[
'GoodStatus' ] =
array(
322 "Internal error: Status::getWikiText called for a good result, this is incorrect\n",
323 "<p>Internal error: Status::getWikiText called for a good result, this is incorrect\n</p>",
328 $testCases[
'GoodButNoError' ] =
array(
330 "Internal error: Status::getWikiText: Invalid result object: no error text but not OK\n",
331 "<p>Internal error: Status::getWikiText: Invalid result object: no error text but not OK\n</p>",
335 $status->warning(
'fooBar!' );
336 $testCases[
'1StringWarning' ] =
array(
339 "<p><fooBar!>\n</p>",
343 $status->warning(
'fooBar!' );
344 $status->warning(
'fooBar2!' );
345 $testCases[
'2StringWarnings' ] =
array(
347 "* <fooBar!>\n* <fooBar2!>\n",
348 "<ul>\n<li> <fooBar!>\n</li>\n<li> <fooBar2!>\n</li>\n</ul>\n",
352 $status->warning(
new Message(
'fooBar!',
array(
'foo',
'bar' ) ) );
353 $testCases[
'1MessageWarning' ] =
array(
356 "<p><fooBar!>\n</p>",
360 $status->warning(
new Message(
'fooBar!',
array(
'foo',
'bar' ) ) );
361 $status->warning(
new Message(
'fooBar2!' ) );
362 $testCases[
'2MessageWarnings' ] =
array(
364 "* <fooBar!>\n* <fooBar2!>\n",
365 "<ul>\n<li> <fooBar!>\n</li>\n<li> <fooBar2!>\n</li>\n</ul>\n",
378 $this->assertInstanceOf(
'Message', $message );
379 $this->assertEquals( $expectedParams, $message->getParams(),
'Message::getParams' );
380 $this->assertEquals( $expectedKey, $message->getKey(),
'Message::getKey' );
390 $testCases =
array();
392 $testCases[
'GoodStatus' ] =
array(
394 array(
"Status::getMessage called for a good result, this is incorrect\n" ),
400 $testCases[
'GoodButNoError' ] =
array(
402 array(
"Status::getMessage: Invalid result object: no error text but not OK\n" ),
408 $testCases[
'1StringWarning' ] =
array(
429 $status->
warning(
new Message(
'fooBar!',
array(
'foo',
'bar' ) ) );
430 $testCases[
'1MessageWarning' ] =
array(
432 array(
'foo',
'bar' ),
437 $status->
warning(
new Message(
'fooBar!',
array(
'foo',
'bar' ) ) );
438 $status->
warning(
new Message(
'fooBar2!' ) );
439 $testCases[
'2MessageWarnings' ] =
array(
441 array(
new Message(
'fooBar!',
array(
'foo',
'bar' ) ),
new Message(
'fooBar2!' ) ),
453 $message =
new Message(
'key1',
array(
'foo1',
'bar1' ) );
454 $status->
error( $message );
455 $newMessage =
new Message(
'key2',
array(
'foo2',
'bar2' ) );
459 $this->assertEquals( $newMessage, $status->errors[0][
'message'] );
466 $method =
new ReflectionMethod(
'Status',
'getErrorMessage' );
467 $method->setAccessible(
true );
473 $message = $method->invoke( $status, array_merge(
array( $key ),
$params ) );
474 $this->assertInstanceOf(
'Message', $message );
475 $this->assertEquals( $key, $message->getKey() );
476 $this->assertEquals(
$params, $message->getParams() );
483 $method =
new ReflectionMethod(
'Status',
'getErrorMessageArray' );
484 $method->setAccessible(
true );
490 $messageArray = $method->invoke(
498 $this->assertInternalType(
'array', $messageArray );
499 $this->assertCount( 2, $messageArray );
500 foreach ( $messageArray
as $message ) {
501 $this->assertInstanceOf(
'Message', $message );
502 $this->assertEquals( $key, $message->getKey() );
503 $this->assertEquals(
$params, $message->getParams() );
512 $warning =
new Message(
'warning111' );
513 $error =
new Message(
'error111' );
520 $this->assertCount( 1, $warnings );
521 $this->assertCount( 1, $errors );
522 $this->assertEquals( $warning, $warnings[0][
'message'] );
523 $this->assertEquals(
$error, $errors[0][
'message'] );
531 $status->cleanCallback =
function(
$value ) {
532 return '-' .
$value .
'-';
535 $this->assertEquals(
false, $status->cleanCallback );
544 if ( !array_key_exists( 1, $nonObjMsg ) ) {
545 $status->
warning( $nonObjMsg[0] );
547 $status->
warning( $nonObjMsg[0], $nonObjMsg[1] );
552 $this->assertEquals( 1, count( $array ) );
553 $this->assertEquals( $nonObjMsg, $array[0] );