}
public static function provideValues() {
- return array(
- array(),
- array( 'foo' ),
- array( array( 'foo' => 'bar' ) ),
- array( new Exception() ),
- array( 1234 ),
- );
+ return [
+ [],
+ [ 'foo' ],
+ [ [ 'foo' => 'bar' ] ],
+ [ new Exception() ],
+ [ 1234 ],
+ ];
}
/**
$status = Status::newFatal( 'foo', 1, 2 );
$this->assertFalse( $status->ok );
$this->assertArrayEquals(
- array(
- array(
+ [
+ [
'type' => 'error',
'message' => 'foo',
- 'params' => array( 1, 2 )
- )
- ),
+ 'params' => [ 1, 2 ]
+ ]
+ ],
$status->errors
);
}
}
public static function provideSetResult() {
- return array(
- array( true ),
- array( false ),
- array( true, 'value' ),
- array( false, 'value' ),
- );
+ return [
+ [ true ],
+ [ false ],
+ [ true, 'value' ],
+ [ false, 'value' ],
+ ];
}
/**
}
public static function provideIsOk() {
- return array(
- array( true ),
- array( false ),
- );
+ return [
+ [ true ],
+ [ false ],
+ ];
}
/**
}
public static function provideIsGood() {
- return array(
- array( true, array(), true ),
- array( true, array( 'foo' ), false ),
- array( false, array(), false ),
- array( false, array( 'foo' ), false ),
- );
+ return [
+ [ true, [], true ],
+ [ true, [ 'foo' ], false ],
+ [ false, [], false ],
+ [ false, [ 'foo' ], false ],
+ ];
}
/**
$this->assertEquals( count( $messages ), count( $warnings ) );
foreach ( $messages as $key => $message ) {
- $expectedArray = array_merge( array( $message->getKey() ), $message->getParams() );
+ $expectedArray = array_merge( [ $message->getKey() ], $message->getParams() );
$this->assertEquals( $warnings[$key], $expectedArray );
}
}
$this->assertEquals( count( $messages ), count( $errors ) );
foreach ( $messages as $key => $message ) {
- $expectedArray = array_merge( array( $message->getKey() ), $message->getParams() );
+ $expectedArray = array_merge( [ $message->getKey() ], $message->getParams() );
$this->assertEquals( $errors[$key], $expectedArray );
}
}
$this->assertEquals( count( $messages ), count( $errors ) );
foreach ( $messages as $key => $message ) {
- $expectedArray = array_merge( array( $message->getKey() ), $message->getParams() );
+ $expectedArray = array_merge( [ $message->getKey() ], $message->getParams() );
$this->assertEquals( $errors[$key], $expectedArray );
}
$this->assertFalse( $status->isOK() );
}
- protected function getMockMessage( $key = 'key', $params = array() ) {
+ protected function getMockMessage( $key = 'key', $params = [] ) {
$message = $this->getMockBuilder( 'Message' )
->disableOriginalConstructor()
->getMock();
* @return Message[]
*/
protected function getMockMessages( $messageDetails ) {
- $messages = array();
+ $messages = [];
foreach ( $messageDetails as $key => $paramsArray ) {
$messages[] = $this->getMockMessage( $key, $paramsArray );
}
}
public static function provideMockMessageDetails() {
- return array(
- array( array( 'key1' => array( 'foo' => 'bar' ) ) ),
- array( array( 'key1' => array( 'foo' => 'bar' ), 'key2' => array( 'foo2' => 'bar2' ) ) ),
- );
+ return [
+ [ [ 'key1' => [ 'foo' => 'bar' ] ] ],
+ [ [ 'key1' => [ 'foo' => 'bar' ], 'key2' => [ 'foo2' => 'bar2' ] ] ],
+ ];
}
/**
return '-' . $value . '-';
};
- return array(
- array( false, array( 'foo' => 'bar' ), array( 'foo' => 'bar' ) ),
- array( $cleanCallback, array( 'foo' => 'bar' ), array( 'foo' => '-bar-' ) ),
- );
+ return [
+ [ false, [ 'foo' => 'bar' ], [ 'foo' => 'bar' ] ],
+ [ $cleanCallback, [ 'foo' => 'bar' ], [ 'foo' => '-bar-' ] ],
+ ];
}
/**
* @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()
- * It is possible to mock such methods but only if namespaces are used
*/
- public function testGetWikiText( Status $status, $wikitext, $html ) {
+ public function testGetWikiText(
+ Status $status, $wikitext, $wrappedWikitext, $html, $wrappedHtml
+ ) {
$this->assertEquals( $wikitext, $status->getWikiText() );
+
+ $this->assertEquals( $wrappedWikitext, $status->getWikiText( 'wrap-short', 'wrap-long', 'qqx' ) );
}
/**
* @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, $wikitext, $html ) {
+ public function testGetHtml(
+ Status $status, $wikitext, $wrappedWikitext, $html, $wrappedHtml
+ ) {
$this->assertEquals( $html, $status->getHTML() );
+
+ $this->assertEquals( $wrappedHtml, $status->getHTML( 'wrap-short', 'wrap-long', 'qqx' ) );
}
/**
* 1 => expected string (with no context)
*/
public static function provideGetWikiTextAndHtml() {
- $testCases = array();
+ $testCases = [];
- $testCases['GoodStatus'] = array(
+ $testCases['GoodStatus'] = [
new Status(),
"Internal error: Status::getWikiText called for a good result, this is incorrect\n",
+ "(wrap-short: (internalerror_info: Status::getWikiText called for a good result, " .
+ "this is incorrect\n))",
"<p>Internal error: Status::getWikiText called for a good result, this is incorrect\n</p>",
- );
+ "<p>(wrap-short: (internalerror_info: Status::getWikiText called for a good result, " .
+ "this is incorrect\n))\n</p>",
+ ];
$status = new Status();
$status->ok = false;
- $testCases['GoodButNoError'] = array(
+ $testCases['GoodButNoError'] = [
$status,
"Internal error: Status::getWikiText: Invalid result object: no error text but not OK\n",
+ "(wrap-short: (internalerror_info: Status::getWikiText: Invalid result object: " .
+ "no error text but not OK\n))",
"<p>Internal error: Status::getWikiText: Invalid result object: no error text but not OK\n</p>",
- );
+ "<p>(wrap-short: (internalerror_info: Status::getWikiText: Invalid result object: " .
+ "no error text but not OK\n))\n</p>",
+ ];
$status = new Status();
$status->warning( 'fooBar!' );
- $testCases['1StringWarning'] = array(
+ $testCases['1StringWarning'] = [
$status,
"<fooBar!>",
+ "(wrap-short: (fooBar!))",
"<p><fooBar!>\n</p>",
- );
+ "<p>(wrap-short: (fooBar!))\n</p>",
+ ];
$status = new Status();
$status->warning( 'fooBar!' );
$status->warning( 'fooBar2!' );
- $testCases['2StringWarnings'] = array(
+ $testCases['2StringWarnings'] = [
$status,
"* <fooBar!>\n* <fooBar2!>\n",
+ "(wrap-long: * (fooBar!)\n* (fooBar2!)\n)",
"<ul><li> <fooBar!></li>\n<li> <fooBar2!></li></ul>\n",
- );
+ "<p>(wrap-long: * (fooBar!)\n</p>\n<ul><li> (fooBar2!)</li></ul>\n<p>)\n</p>",
+ ];
$status = new Status();
- $status->warning( new Message( 'fooBar!', array( 'foo', 'bar' ) ) );
- $testCases['1MessageWarning'] = array(
+ $status->warning( new Message( 'fooBar!', [ 'foo', 'bar' ] ) );
+ $testCases['1MessageWarning'] = [
$status,
"<fooBar!>",
+ "(wrap-short: (fooBar!: foo, bar))",
"<p><fooBar!>\n</p>",
- );
+ "<p>(wrap-short: (fooBar!: foo, bar))\n</p>",
+ ];
$status = new Status();
- $status->warning( new Message( 'fooBar!', array( 'foo', 'bar' ) ) );
+ $status->warning( new Message( 'fooBar!', [ 'foo', 'bar' ] ) );
$status->warning( new Message( 'fooBar2!' ) );
- $testCases['2MessageWarnings'] = array(
+ $testCases['2MessageWarnings'] = [
$status,
"* <fooBar!>\n* <fooBar2!>\n",
+ "(wrap-long: * (fooBar!: foo, bar)\n* (fooBar2!)\n)",
"<ul><li> <fooBar!></li>\n<li> <fooBar2!></li></ul>\n",
- );
+ "<p>(wrap-long: * (fooBar!: foo, bar)\n</p>\n<ul><li> (fooBar2!)</li></ul>\n<p>)\n</p>",
+ ];
return $testCases;
}
+ private static function sanitizedMessageParams( Message $message ) {
+ return array_map( function ( $p ) {
+ return $p instanceof Message
+ ? [
+ 'key' => $p->getKey(),
+ 'params' => self::sanitizedMessageParams( $p ),
+ 'lang' => $p->getLanguage()->getCode(),
+ ]
+ : $p;
+ }, $message->getParams() );
+ }
+
/**
* @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();
+ public function testGetMessage(
+ Status $status, $expectedParams = [], $expectedKey, $expectedWrapper
+ ) {
+ $message = $status->getMessage( null, null, 'qqx' );
$this->assertInstanceOf( 'Message', $message );
- $this->assertEquals( $expectedParams, $message->getParams(), 'Message::getParams' );
+ $this->assertEquals( $expectedParams, self::sanitizedMessageParams( $message ),
+ 'Message::getParams' );
$this->assertEquals( $expectedKey, $message->getKey(), 'Message::getKey' );
+
+ $message = $status->getMessage( 'wrapper-short', 'wrapper-long' );
+ $this->assertInstanceOf( 'Message', $message );
+ $this->assertEquals( $expectedWrapper, $message->getKey(), 'Message::getKey with wrappers' );
+ $this->assertCount( 1, $message->getParams(), 'Message::getParams with wrappers' );
+
+ $message = $status->getMessage( 'wrapper' );
+ $this->assertInstanceOf( 'Message', $message );
+ $this->assertEquals( 'wrapper', $message->getKey(), 'Message::getKey with wrappers' );
+ $this->assertCount( 1, $message->getParams(), 'Message::getParams with wrappers' );
+
+ $message = $status->getMessage( false, 'wrapper' );
+ $this->assertInstanceOf( 'Message', $message );
+ $this->assertEquals( 'wrapper', $message->getKey(), 'Message::getKey with wrappers' );
+ $this->assertCount( 1, $message->getParams(), 'Message::getParams with wrappers' );
}
/**
* 2 => expected Message key
*/
public static function provideGetMessage() {
- $testCases = array();
+ $testCases = [];
- $testCases['GoodStatus'] = array(
+ $testCases['GoodStatus'] = [
new Status(),
- array( "Status::getMessage called for a good result, this is incorrect\n" ),
- 'internalerror_info'
- );
+ [ "Status::getMessage called for a good result, this is incorrect\n" ],
+ 'internalerror_info',
+ 'wrapper-short'
+ ];
$status = new Status();
$status->ok = false;
- $testCases['GoodButNoError'] = array(
+ $testCases['GoodButNoError'] = [
$status,
- array( "Status::getMessage: Invalid result object: no error text but not OK\n" ),
- 'internalerror_info'
- );
+ [ "Status::getMessage: Invalid result object: no error text but not OK\n" ],
+ 'internalerror_info',
+ 'wrapper-short'
+ ];
$status = new Status();
$status->warning( 'fooBar!' );
- $testCases['1StringWarning'] = array(
+ $testCases['1StringWarning'] = [
$status,
- array(),
- 'fooBar!'
- );
+ [],
+ 'fooBar!',
+ 'wrapper-short'
+ ];
- // 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( new Message( 'fooBar!' ), new Message( 'fooBar2!' ) ),
-// "* \$1\n* \$2"
-// );
+ $status = new Status();
+ $status->warning( 'fooBar!' );
+ $status->warning( 'fooBar2!' );
+ $testCases[ '2StringWarnings' ] = [
+ $status,
+ [
+ [ 'key' => 'fooBar!', 'params' => [], 'lang' => 'qqx' ],
+ [ 'key' => 'fooBar2!', 'params' => [], 'lang' => 'qqx' ]
+ ],
+ "* \$1\n* \$2",
+ 'wrapper-long'
+ ];
$status = new Status();
- $status->warning( new Message( 'fooBar!', array( 'foo', 'bar' ) ) );
- $testCases['1MessageWarning'] = array(
+ $status->warning( new Message( 'fooBar!', [ 'foo', 'bar' ] ) );
+ $testCases['1MessageWarning'] = [
$status,
- array( 'foo', 'bar' ),
- 'fooBar!'
- );
+ [ 'foo', 'bar' ],
+ 'fooBar!',
+ 'wrapper-short'
+ ];
$status = new Status();
- $status->warning( new Message( 'fooBar!', array( 'foo', 'bar' ) ) );
+ $status->warning( new Message( 'fooBar!', [ 'foo', 'bar' ] ) );
$status->warning( new Message( 'fooBar2!' ) );
- $testCases['2MessageWarnings'] = array(
+ $testCases['2MessageWarnings'] = [
$status,
- array( new Message( 'fooBar!', array( 'foo', 'bar' ) ), new Message( 'fooBar2!' ) ),
- "* \$1\n* \$2"
- );
+ [
+ [ 'key' => 'fooBar!', 'params' => [ 'foo', 'bar' ], 'lang' => 'qqx' ],
+ [ 'key' => 'fooBar2!', 'params' => [], 'lang' => 'qqx' ]
+ ],
+ "* \$1\n* \$2",
+ 'wrapper-long'
+ ];
return $testCases;
}
*/
public function testReplaceMessage() {
$status = new Status();
- $message = new Message( 'key1', array( 'foo1', 'bar1' ) );
+ $message = new Message( 'key1', [ 'foo1', 'bar1' ] );
$status->error( $message );
- $newMessage = new Message( 'key2', array( 'foo2', 'bar2' ) );
+ $newMessage = new Message( 'key2', [ 'foo2', 'bar2' ] );
$status->replaceMessage( $message, $newMessage );
$method->setAccessible( true );
$status = new Status();
$key = 'foo';
- $params = array( 'bar' );
+ $params = [ 'bar' ];
/** @var Message $message */
- $message = $method->invoke( $status, array_merge( array( $key ), $params ) );
+ $message = $method->invoke( $status, array_merge( [ $key ], $params ) );
$this->assertInstanceOf( 'Message', $message );
$this->assertEquals( $key, $message->getKey() );
$this->assertEquals( $params, $message->getParams() );
$method->setAccessible( true );
$status = new Status();
$key = 'foo';
- $params = array( 'bar' );
+ $params = [ 'bar' ];
/** @var Message[] $messageArray */
$messageArray = $method->invoke(
$status,
- array(
- array_merge( array( $key ), $params ),
- array_merge( array( $key ), $params )
- )
+ [
+ array_merge( [ $key ], $params ),
+ array_merge( [ $key ], $params )
+ ]
);
$this->assertInternalType( 'array', $messageArray );
}
public static function provideNonObjectMessages() {
- return array(
- array( array( 'ImaString', array( 'param1' => 'value1' ) ) ),
- array( array( 'ImaString' ) ),
- );
+ return [
+ [ [ 'ImaString', [ 'param1' => 'value1' ] ] ],
+ [ [ 'ImaString' ] ],
+ ];
}
}