From: addshore Date: Fri, 15 Nov 2013 22:42:59 +0000 (+0100) Subject: Further expand Status unit tests X-Git-Tag: 1.31.0-rc.0~17902^2 X-Git-Url: http://git.cyclocoop.org/%7B%24www_url%7Dadmin/password.php?a=commitdiff_plain;h=8b07ec5abae63c5d479d2983d97e12936dedc757;p=lhc%2Fweb%2Fwiklou.git Further expand Status unit tests When writing these I came accross a case that doesnt quite seem right (I have left room for the test case with a comment explaining) Status now only has 4 untested methods Change-Id: I61acf141de9f786793e8413d2d2ebb95e27e004d --- diff --git a/tests/phpunit/includes/StatusTest.php b/tests/phpunit/includes/StatusTest.php index 4f64e4f555..21d0b02b3e 100644 --- a/tests/phpunit/includes/StatusTest.php +++ b/tests/phpunit/includes/StatusTest.php @@ -245,7 +245,7 @@ class StatusTest extends MediaWikiTestCase { } /** - * @dataProvider provideGetWikiText + * @dataProvider provideGetWikiTextAndHtml * @covers Status::getWikiText * @todo test long and short context messages generated through this method * this can not really be done now due to use of wfMessage()->plain() @@ -255,12 +255,23 @@ class StatusTest extends MediaWikiTestCase { $this->assertEquals( $expected, $status->getWikiText() ); } + /** + * @dataProvider provideGetWikiTextAndHtml + * @covers Status::getHtml + * @todo test long and short context messages generated through this method + * this can not really be done now due to use of $this->getWikiText using wfMessage()->plain() + * It is possible to mock such methods but only if namespaces are used + */ + public function testGetHtml( Status $status, $expected ) { + $this->assertEquals( $expected, $status->getHTML() ); + } + /** * @return array of arrays with values; * 0 => status object * 1 => expected string (with no context) */ - public static function provideGetWikiText() { + public static function provideGetWikiTextAndHtml() { $testCases = array(); $testCases[ 'GoodStatus' ] = array( @@ -308,12 +319,96 @@ class StatusTest extends MediaWikiTestCase { return $testCases; } - //todo test getMessage + /** + * @dataProvider provideGetMessage + * @covers Status::getMessage + * @todo test long and short context messages generated through this method + */ + public function testGetMessage( Status $status, $expectedParams = array(), $expectedKey ) { + $message = $status->getMessage(); + $this->assertInstanceOf( 'Message', $message ); + $this->assertEquals( $expectedParams, $message->getParams() ); + $this->assertEquals( $expectedKey, $message->getKey() ); + } + + /** + * @return array of arrays with values; + * 0 => status object + * 1 => expected Message Params (with no context) + */ + public static function provideGetMessage() { + $testCases = array(); + + $testCases[ 'GoodStatus' ] = array( + new Status(), + array( "Status::getMessage called for a good result, this is incorrect\n" ), + 'internalerror_info' + ); + + $status = new Status(); + $status->ok = false; + $testCases[ 'GoodButNoError' ] = array( + $status, + array( "Status::getMessage: Invalid result object: no error text but not OK\n" ), + 'internalerror_info' + ); + + $status = new Status(); + $status->warning( 'fooBar!' ); + $testCases[ '1StringWarning' ] = array( + $status, + array(), + "fooBar!" + ); + + //NOTE: this seems to return a string instead of a Message object... +// $status = new Status(); +// $status->warning( 'fooBar!' ); +// $status->warning( 'fooBar2!' ); +// $testCases[ '2StringWarnings' ] = array( +// $status, +// array(), +// '' +// ); + + $status = new Status(); + $status->warning( new Message( 'fooBar!', array( 'foo', 'bar' ) ) ); + $testCases[ '1MessageWarning' ] = array( + $status, + array( 'foo', 'bar' ), + "fooBar!", + ); + + //NOTE: this seems to return a string instead of a Message object... +// $status = new Status(); +// $status->warning( new Message( 'fooBar!', array( 'foo', 'bar' ) ) ); +// $status->warning( new Message( 'fooBar2!' ) ); +// $testCases[ '2MessageWarnings' ] = array( +// $status, +// array(), +// "", +// ); + + return $testCases; + } + + /** + * @covers Status::replaceMessage + */ + public function testReplaceMessage() { + $status = new Status(); + $message = new Message( 'key1', array( 'foo1', 'bar1' ) ); + $status->error( $message ); + $newMessage = new Message( 'key2', array( 'foo2', 'bar2' ) ); + + $status->replaceMessage( $message, $newMessage ); + + $this->assertEquals( $newMessage, $status->errors[0]['message'] ); + } + //todo test getErrorMessage - //todo test getHTML //todo test getErrorMessageArray //todo test getStatusArray //todo test getErrorsByType - //todo test replaceMessage }