Merge "Permit case independent unit test directories"
[lhc/web/wiklou.git] / tests / phpunit / MediaWikiUnitTestCase.php
index ccf3357..bb018aa 100644 (file)
@@ -40,7 +40,7 @@ abstract class MediaWikiUnitTestCase extends TestCase {
                parent::setUp();
                $reflection = new ReflectionClass( $this );
                $dirSeparator = DIRECTORY_SEPARATOR;
-               if ( strpos( $reflection->getFilename(), "${dirSeparator}unit${dirSeparator}" ) === false ) {
+               if ( stripos( $reflection->getFilename(), "${dirSeparator}unit${dirSeparator}" ) === false ) {
                        $this->fail( 'This unit test needs to be in "tests/phpunit/unit"!' );
                }
                $this->unitGlobals = $GLOBALS;
@@ -72,4 +72,34 @@ abstract class MediaWikiUnitTestCase extends TestCase {
                global $wgHooks;
                $wgHooks[$hookName] = [ $handler ];
        }
+
+       protected function getMockMessage( $text, ...$params ) {
+               if ( isset( $params[0] ) && is_array( $params[0] ) ) {
+                       $params = $params[0];
+               }
+
+               $msg = $this->getMockBuilder( Message::class )
+                       ->disableOriginalConstructor()
+                       ->setMethods( [] )
+                       ->getMock();
+
+               $msg->method( 'toString' )->willReturn( $text );
+               $msg->method( '__toString' )->willReturn( $text );
+               $msg->method( 'text' )->willReturn( $text );
+               $msg->method( 'parse' )->willReturn( $text );
+               $msg->method( 'plain' )->willReturn( $text );
+               $msg->method( 'parseAsBlock' )->willReturn( $text );
+               $msg->method( 'escaped' )->willReturn( $text );
+
+               $msg->method( 'title' )->willReturn( $msg );
+               $msg->method( 'inLanguage' )->willReturn( $msg );
+               $msg->method( 'inContentLanguage' )->willReturn( $msg );
+               $msg->method( 'useDatabase' )->willReturn( $msg );
+               $msg->method( 'setContext' )->willReturn( $msg );
+
+               $msg->method( 'exists' )->willReturn( true );
+               $msg->method( 'content' )->willReturn( new MessageContent( $msg ) );
+
+               return $msg;
+       }
 }