From 8145672cd430b7593a514ed4e346a101e6bfbda9 Mon Sep 17 00:00:00 2001 From: daniel Date: Wed, 16 Apr 2014 21:52:32 +0200 Subject: [PATCH] Allow Status::hasMessage to work with Message objects. Change-Id: I52a468bc33f6c25630665ee8f987a25dc87659ee --- includes/Status.php | 15 ++++++++++----- tests/phpunit/includes/StatusTest.php | 3 +++ 2 files changed, 13 insertions(+), 5 deletions(-) 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' ) ); } -- 2.20.1