*/
class StatusTest extends MediaWikiTestCase {
- public function testCanConstruct(){
+ public function testCanConstruct() {
new Status();
$this->assertTrue( true );
}
* @dataProvider provideValues
* @covers Status::newGood
*/
- public function testNewGood( $value = null ){
+ public function testNewGood( $value = null ) {
$status = Status::newGood( $value );
$this->assertTrue( $status->isGood() );
$this->assertTrue( $status->isOK() );
$this->assertEquals( $value, $status->getValue() );
}
- public static function provideValues(){
+ public static function provideValues() {
return array(
array(),
array( 'foo' ),
* @dataProvider provideMockMessageDetails
* @covers Status::warning
* @covers Status::getWarningsArray
+ * @covers Status::getStatusArray
*/
public function testWarningWithMessage( $mockDetails ) {
$status = new Status();
$messages = $this->getMockMessages( $mockDetails );
- foreach( $messages as $message ){
+ foreach ( $messages as $message ) {
$status->warning( $message );
}
$warnings = $status->getWarningsArray();
$this->assertEquals( count( $messages ), count( $warnings ) );
- foreach( $messages as $key => $message ) {
+ foreach ( $messages as $key => $message ) {
$expectedArray = array_merge( array( $message->getKey() ), $message->getParams() );
$this->assertEquals( $warnings[$key], $expectedArray );
}
* @dataProvider provideMockMessageDetails
* @covers Status::error
* @covers Status::getErrorsArray
+ * @covers Status::getStatusArray
*/
public function testErrorWithMessage( $mockDetails ) {
$status = new Status();
$messages = $this->getMockMessages( $mockDetails );
- foreach( $messages as $message ){
+ foreach ( $messages as $message ) {
$status->error( $message );
}
$errors = $status->getErrorsArray();
$this->assertEquals( count( $messages ), count( $errors ) );
- foreach( $messages as $key => $message ) {
+ foreach ( $messages as $key => $message ) {
$expectedArray = array_merge( array( $message->getKey() ), $message->getParams() );
$this->assertEquals( $errors[$key], $expectedArray );
}
* @param array $messageDetails eg. array( 'KEY' => array(/PARAMS/) )
* @return Message[]
*/
- protected function getMockMessages( $messageDetails ){
+ protected function getMockMessages( $messageDetails ) {
$messages = array();
- foreach( $messageDetails as $key => $paramsArray ){
+ foreach ( $messageDetails as $key => $paramsArray ) {
$messages[] = $this->getMockMessage( $key, $paramsArray );
}
return $messages;
}
- public static function provideMockMessageDetails(){
+ public static function provideMockMessageDetails() {
return array(
array( array( 'key1' => array( 'foo' => 'bar' ) ) ),
array( array( 'key1' => array( 'foo' => 'bar' ), 'key2' => array( 'foo2' => 'bar2' ) ) ),
* @covers Status::merge
* @todo test merge with $overwriteValue true
*/
- public function testMerge(){
+ public function testMerge() {
$status1 = new Status();
$status2 = new Status();
$message1 = $this->getMockMessage( 'warn1' );
*/
public function testCleanParams( $cleanCallback, $params, $expected ) {
$method = new ReflectionMethod( 'Status', 'cleanParams' );
- $method->setAccessible(TRUE);
+ $method->setAccessible( true );
$status = new Status();
$status->cleanCallback = $cleanCallback;
$this->assertEquals( $newMessage, $status->errors[0]['message'] );
}
- //todo test getErrorMessage
- //todo test getErrorMessageArray
- //todo test getStatusArray
- //todo test getErrorsByType
+ /**
+ * @covers Status::getErrorMessage
+ */
+ public function testGetErrorMessage() {
+ $method = new ReflectionMethod( 'Status', 'getErrorMessage' );
+ $method->setAccessible(true);
+ $status = new Status();
+ $key = 'foo';
+ $params = array( 'bar' );
+
+ /** @var Message $message */
+ $message = $method->invoke( $status, array_merge( array( $key ), $params ) );
+ $this->assertInstanceOf( 'Message', $message );
+ $this->assertEquals( $key, $message->getKey() );
+ $this->assertEquals( $params, $message->getParams() );
+ }
+
+ /**
+ * @covers Status::getErrorMessageArray
+ */
+ public function testGetErrorMessageArray() {
+ $method = new ReflectionMethod( 'Status', 'getErrorMessageArray' );
+ $method->setAccessible(true);
+ $status = new Status();
+ $key = 'foo';
+ $params = array( 'bar' );
+
+ /** @var Message[] $messageArray */
+ $messageArray = $method->invoke(
+ $status,
+ array(
+ array_merge( array( $key ), $params ),
+ array_merge( array( $key ), $params )
+ )
+ );
+
+ $this->assertInternalType( 'array', $messageArray );
+ $this->assertCount( 2, $messageArray );
+ foreach( $messageArray as $message ) {
+ $this->assertInstanceOf( 'Message', $message );
+ $this->assertEquals( $key, $message->getKey() );
+ $this->assertEquals( $params, $message->getParams() );
+ }
+ }
+
+ /**
+ * @covers Status::getErrorsByType
+ */
+ public function testGetErrorsByType() {
+ $status = new Status();
+ $warning = new Message( 'warning111' );
+ $error = new Message( 'error111' );
+ $status->warning( $warning );
+ $status->error( $error );
+
+ $warnings = $status->getErrorsByType( 'warning' );
+ $errors = $status->getErrorsByType( 'error' );
+
+ $this->assertCount( 1, $warnings );
+ $this->assertCount( 1, $errors );
+ $this->assertEquals( $warning, $warnings[0]['message'] );
+ $this->assertEquals( $error, $errors[0]['message'] );
+ }
}