Allow Status::hasMessage to work with Message objects.
authordaniel <daniel.kinzler@wikimedia.de>
Wed, 16 Apr 2014 19:52:32 +0000 (21:52 +0200)
committerThiemo Mättig <thiemo.maettig@wikimedia.de>
Tue, 22 Apr 2014 18:19:04 +0000 (20:19 +0200)
Change-Id: I52a468bc33f6c25630665ee8f987a25dc87659ee

includes/Status.php
tests/phpunit/includes/StatusTest.php

index 0244c8a..77bf4a8 100644 (file)
@@ -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;
                        }
                }
index 9d42d1c..8281073 100644 (file)
@@ -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' ) );
        }