/**
* @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() );
}
/**
* @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();
'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 = 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;
}