From: daniel Date: Wed, 16 Apr 2014 19:52:32 +0000 (+0200) Subject: Allow Status::hasMessage to work with Message objects. X-Git-Tag: 1.31.0-rc.0~16080^2 X-Git-Url: http://git.cyclocoop.org/%27%20.%20url_absolue%28%24favicon%29%20.%20?a=commitdiff_plain;h=8145672cd430b7593a514ed4e346a101e6bfbda9;p=lhc%2Fweb%2Fwiklou.git Allow Status::hasMessage to work with Message objects. Change-Id: I52a468bc33f6c25630665ee8f987a25dc87659ee --- diff --git a/includes/Status.php b/includes/Status.php index 0244c8ae02..77bf4a8592 100644 --- a/includes/Status.php +++ b/includes/Status.php @@ -405,15 +405,20 @@ class Status { /** * Returns true if the specified message is present as a warning or error * - * Note, due to the lack of tools for comparing Message objects, this - * function will not work when using a Message object as a parameter. + * @param string|Message $message Message key or object to search for * - * @param string $msg Message name * @return bool */ - public function hasMessage( $msg ) { + public function hasMessage( $message ) { + if ( $message instanceof Message ) { + $message = $message->getKey(); + } foreach ( $this->errors as $error ) { - if ( $error['message'] === $msg ) { + if ( $error['message'] instanceof Message + && $error['message']->getKey() === $message + ) { + return true; + } elseif ( $error['message'] === $message ) { return true; } } diff --git a/tests/phpunit/includes/StatusTest.php b/tests/phpunit/includes/StatusTest.php index 9d42d1c505..8281073083 100644 --- a/tests/phpunit/includes/StatusTest.php +++ b/tests/phpunit/includes/StatusTest.php @@ -259,7 +259,10 @@ class StatusTest extends MediaWikiLangTestCase { 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' ) ); }