Ensure OutputPageTest works when Translate extension is loaded
authorC. Scott Ananian <cscott@cscott.net>
Thu, 27 Sep 2018 21:36:19 +0000 (17:36 -0400)
committerC. Scott Ananian <cananian@wikimedia.org>
Fri, 28 Sep 2018 01:05:46 +0000 (01:05 +0000)
The translate extension registers the LanguageLinks hook which is run by
OutputPage::addParserOutputMetadata with a Title as an argument.  If
our mock doesn't provide a valid Title, then
PageTranslationHooks::addLanguageLinks() in Translate will throw a
TypeError in OutputPageTest::testParserOutputCategoryLinks().

Change-Id: I495c51731670f841e5ab752a3a1e014c86ef643d

tests/phpunit/includes/OutputPageTest.php

index 283e99f..054636e 100644 (file)
@@ -1020,9 +1020,14 @@ class OutputPageTest extends MediaWikiTestCase {
 
                $op = $this->getMockBuilder( OutputPage::class )
                        ->setConstructorArgs( [ new RequestContext() ] )
-                       ->setMethods( [ 'addCategoryLinksToLBAndGetResult' ] )
+                                  ->setMethods( [ 'addCategoryLinksToLBAndGetResult', 'getTitle' ] )
                        ->getMock();
 
+               $title = Title::newFromText( 'My test page' );
+               $op->expects( $this->any() )
+                       ->method( 'getTitle' )
+                       ->will( $this->returnValue( $title ) );
+
                $op->expects( $this->any() )
                        ->method( 'addCategoryLinksToLBAndGetResult' )
                        ->will( $this->returnCallback( function ( array $categories ) use ( $fakeResults ) {