Add getMessage tests with Short and Long Contexts
authoraddshore <addshorewiki@gmail.com>
Sat, 22 Feb 2014 11:43:10 +0000 (12:43 +0100)
committeraddshore <addshorewiki@gmail.com>
Thu, 27 Feb 2014 11:00:26 +0000 (12:00 +0100)
Change-Id: Ib5a1a225b7244490fe9d3a5631d3757614174453

tests/phpunit/includes/StatusTest.php

index 209b54c..4386770 100644 (file)
@@ -371,11 +371,20 @@ class StatusTest extends MediaWikiLangTestCase {
        /**
         * @dataProvider provideGetMessage
         * @covers Status::getMessage
-        * @todo test long and short context messages generated through this method
+        * @todo test with multiple messages at once
         */
-       public function testGetMessage( Status $status, $expectedParams = array(), $expectedKey ) {
-               $message = $status->getMessage();
+       public function testGetMessage( Status $status, $expectedParams = array(), $expectedKey, $shortContext = false, $longContext = false ) {
+               $message = $status->getMessage( $shortContext, $longContext );
                $this->assertInstanceOf( 'Message', $message );
+
+               // Loop through until we get to the appropriate depth for the message
+               $loops = $shortContext ? 1 : ( $longContext ? 2 : 0 );
+               for( $i = 1; $i <= $loops; $i++ ) {
+                       $params = $message->getParams();
+                       $this->assertInstanceOf( 'Message', $params[0] );
+                       $message = $params[0];
+               }
+
                $this->assertEquals( $expectedParams, $message->getParams() );
                $this->assertEquals( $expectedKey, $message->getKey() );
        }
@@ -383,7 +392,7 @@ class StatusTest extends MediaWikiLangTestCase {
        /**
         * @return array of arrays with values;
         *    0 => status object
-        *    1 => expected Message Params (with no context)
+        *    1 => expected Message Params
         */
        public static function provideGetMessage() {
                $testCases = array();
@@ -402,6 +411,21 @@ class StatusTest extends MediaWikiLangTestCase {
                        'internalerror_info'
                );
 
+               $testCases[ 'GoodButNoErrorShortContext' ] = array(
+                       $status,
+                       array( "Status::getMessage: Invalid result object: no error text but not OK\n" ),
+                       'internalerror_info',
+                       true
+               );
+
+               $testCases[ 'GoodButNoErrorLongContext' ] = array(
+                       $status,
+                       array( "Status::getMessage: Invalid result object: no error text but not OK\n" ),
+                       'internalerror_info',
+                       false,
+                       true
+               );
+
                $status = new Status();
                $status->warning( 'fooBar!' );
                $testCases[ '1StringWarning' ] = array(
@@ -438,6 +462,33 @@ class StatusTest extends MediaWikiLangTestCase {
 //                     "",
 //             );
 
+               $status = new Status();
+               $status->error( new Message( 'fooBar!', array( 'foo', 'bar' )  ) );
+               $testCases[ '1MessageError' ] = array(
+                       $status,
+                       array( 'foo', 'bar' ),
+                       "fooBar!",
+               );
+
+               $status = new Status();
+               $status->error( new Message( 'fooBar!', array( 'foo', 'bar' )  ) );
+               $testCases[ '1MessageErrorShortContext' ] = array(
+                       $status,
+                       array( 'foo', 'bar' ),
+                       "fooBar!",
+                       true,
+               );
+
+               $status = new Status();
+               $status->error( new Message( 'fooBar!', array( 'foo', 'bar' )  ) );
+               $testCases[ '1MessageErrorLongContext' ] = array(
+                       $status,
+                       array( 'foo', 'bar' ),
+                       "fooBar!",
+                       false,
+                       true,
+               );
+
                return $testCases;
        }