Mwalker has submitted this change and it was merged.
Change subject: Further expand Status unit tests
......................................................................
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
---
M tests/phpunit/includes/StatusTest.php
1 file changed, 100 insertions(+), 5 deletions(-)
Approvals:
Mwalker: Looks good to me, approved
jenkins-bot: Verified
diff --git a/tests/phpunit/includes/StatusTest.php
b/tests/phpunit/includes/StatusTest.php
index 4f64e4f..21d0b02 100644
--- a/tests/phpunit/includes/StatusTest.php
+++ b/tests/phpunit/includes/StatusTest.php
@@ -245,7 +245,7 @@
}
/**
- * @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()
@@ -256,11 +256,22 @@
}
/**
+ * @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 @@
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
}
--
To view, visit https://gerrit.wikimedia.org/r/95770
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I61acf141de9f786793e8413d2d2ebb95e27e004d
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Addshore <[email protected]>
Gerrit-Reviewer: Aude <[email protected]>
Gerrit-Reviewer: Hashar <[email protected]>
Gerrit-Reviewer: Mwalker <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits