From cd9711ea350e9367829702eddc0adad8c9d88afb Mon Sep 17 00:00:00 2001 From: addshore Date: Sat, 22 Feb 2014 12:43:10 +0100 Subject: [PATCH] Add getMessage tests with Short and Long Contexts Change-Id: Ib5a1a225b7244490fe9d3a5631d3757614174453 --- tests/phpunit/includes/StatusTest.php | 59 +++++++++++++++++++++++++-- 1 file changed, 55 insertions(+), 4 deletions(-) diff --git a/tests/phpunit/includes/StatusTest.php b/tests/phpunit/includes/StatusTest.php index 209b54c3e6..438677068d 100644 --- a/tests/phpunit/includes/StatusTest.php +++ b/tests/phpunit/includes/StatusTest.php @@ -371,11 +371,20 @@ class StatusTest extends MediaWikiLangTestCase { /** * @dataProvider provideGetMessage * @covers Status::getMessage - * @todo test long and short context messages generated through this method + * @todo test with multiple messages at once */ - public function testGetMessage( Status $status, $expectedParams = array(), $expectedKey ) { - $message = $status->getMessage(); + public function testGetMessage( Status $status, $expectedParams = array(), $expectedKey, $shortContext = false, $longContext = false ) { + $message = $status->getMessage( $shortContext, $longContext ); $this->assertInstanceOf( 'Message', $message ); + + // Loop through until we get to the appropriate depth for the message + $loops = $shortContext ? 1 : ( $longContext ? 2 : 0 ); + for( $i = 1; $i <= $loops; $i++ ) { + $params = $message->getParams(); + $this->assertInstanceOf( 'Message', $params[0] ); + $message = $params[0]; + } + $this->assertEquals( $expectedParams, $message->getParams() ); $this->assertEquals( $expectedKey, $message->getKey() ); } @@ -383,7 +392,7 @@ class StatusTest extends MediaWikiLangTestCase { /** * @return array of arrays with values; * 0 => status object - * 1 => expected Message Params (with no context) + * 1 => expected Message Params */ public static function provideGetMessage() { $testCases = array(); @@ -402,6 +411,21 @@ class StatusTest extends MediaWikiLangTestCase { 'internalerror_info' ); + $testCases[ 'GoodButNoErrorShortContext' ] = array( + $status, + array( "Status::getMessage: Invalid result object: no error text but not OK\n" ), + 'internalerror_info', + true + ); + + $testCases[ 'GoodButNoErrorLongContext' ] = array( + $status, + array( "Status::getMessage: Invalid result object: no error text but not OK\n" ), + 'internalerror_info', + false, + true + ); + $status = new Status(); $status->warning( 'fooBar!' ); $testCases[ '1StringWarning' ] = array( @@ -438,6 +462,33 @@ class StatusTest extends MediaWikiLangTestCase { // "", // ); + $status = new Status(); + $status->error( new Message( 'fooBar!', array( 'foo', 'bar' ) ) ); + $testCases[ '1MessageError' ] = array( + $status, + array( 'foo', 'bar' ), + "fooBar!", + ); + + $status = new Status(); + $status->error( new Message( 'fooBar!', array( 'foo', 'bar' ) ) ); + $testCases[ '1MessageErrorShortContext' ] = array( + $status, + array( 'foo', 'bar' ), + "fooBar!", + true, + ); + + $status = new Status(); + $status->error( new Message( 'fooBar!', array( 'foo', 'bar' ) ) ); + $testCases[ '1MessageErrorLongContext' ] = array( + $status, + array( 'foo', 'bar' ), + "fooBar!", + false, + true, + ); + return $testCases; } -- 2.20.1