public function testHasMessage() {
$status = new Status();
$status->fatal( 'bad' );
+ $status->fatal( wfMessage( 'bad-msg' ) );
$this->assertTrue( $status->hasMessage( 'bad' ) );
+ $this->assertTrue( $status->hasMessage( 'bad-msg' ) );
+ $this->assertTrue( $status->hasMessage( wfMessage( 'bad-msg' ) ) );
$this->assertFalse( $status->hasMessage( 'good' ) );
}
/**
* @dataProvider provideGetMessage
* @covers Status::getMessage
- * @todo test with multiple messages at once
+ * @todo test long and short context messages generated through this method
*/
- public function testGetMessage( Status $status, $expectedParams = array(), $expectedKey, $shortContext = false, $longContext = false ) {
- $message = $status->getMessage( $shortContext, $longContext );
+ public function testGetMessage( Status $status, $expectedParams = array(), $expectedKey ) {
+ $message = $status->getMessage();
$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() );
+ $this->assertEquals( $expectedParams, $message->getParams(), 'Message::getParams' );
+ $this->assertEquals( $expectedKey, $message->getKey(), 'Message::getKey' );
}
/**
* @return array of arrays with values;
* 0 => status object
- * 1 => expected Message Params
+ * 1 => expected Message parameters (with no context)
+ * 2 => expected Message key
*/
public static function provideGetMessage() {
$testCases = array();
'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(
$status,
array(),
- "fooBar!"
+ 'fooBar!'
);
- //NOTE: this seems to return a string instead of a Message object...
+ // FIXME: Assertion tries to compare a StubUserLang with a Language object, because
+ // "data providers are executed before both the call to the setUpBeforeClass static method
+ // and the first call to the setUp method. Because of that you can't access any variables
+ // you create there from within a data provider."
+ // http://phpunit.de/manual/3.7/en/writing-tests-for-phpunit.html
// $status = new Status();
// $status->warning( 'fooBar!' );
// $status->warning( 'fooBar2!' );
// $testCases[ '2StringWarnings' ] = array(
// $status,
-// array(),
-// ''
+// array( new Message( 'fooBar!' ), new Message( 'fooBar2!' ) ),
+// "* \$1\n* \$2"
// );
$status = new Status();
$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(),
-// "",
-// );
-
- $status = new Status();
- $status->error( new Message( 'fooBar!', array( 'foo', 'bar' ) ) );
- $testCases[ '1MessageError' ] = array(
- $status,
- array( 'foo', 'bar' ),
- "fooBar!",
+ '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->warning( new Message( 'fooBar!', array( 'foo', 'bar' ) ) );
+ $status->warning( new Message( 'fooBar2!' ) );
+ $testCases[ '2MessageWarnings' ] = array(
$status,
- array( 'foo', 'bar' ),
- "fooBar!",
- false,
- true,
+ array( new Message( 'fooBar!', array( 'foo', 'bar' ) ), new Message( 'fooBar2!' ) ),
+ "* \$1\n* \$2"
);
return $testCases;
*/
public function testGetStatusArrayWithNonObjectMessages( $nonObjMsg ) {
$status = new Status();
- if( !array_key_exists( 1, $nonObjMsg ) ) {
+ if ( !array_key_exists( 1, $nonObjMsg ) ) {
$status->warning( $nonObjMsg[0] );
} else {
$status->warning( $nonObjMsg[0], $nonObjMsg[1] );