From dcb6ad0097612b537990c76393fa2c3f48c69aa3 Mon Sep 17 00:00:00 2001 From: umherirrender Date: Sun, 14 Oct 2012 21:34:26 +0200 Subject: [PATCH] Use ParserOptions::newFromUserAndLang in tests This avoids using $wgUser and $wgLang for the ParserOption, which is not needed in the tests Change-Id: Iea07e9a0f0898ec5f8eb98a40000f5d33b279c9e --- tests/phpunit/includes/ExtraParserTest.php | 5 +++-- tests/phpunit/includes/WikiPageTest.php | 2 +- .../includes/parser/MagicVariableTest.php | 5 +++-- .../includes/parser/ParserPreloadTest.php | 5 +++-- .../phpunit/includes/parser/PreprocessorTest.php | 4 ++-- tests/phpunit/includes/parser/TagHooksTest.php | 16 ++++++++-------- 6 files changed, 20 insertions(+), 17 deletions(-) diff --git a/tests/phpunit/includes/ExtraParserTest.php b/tests/phpunit/includes/ExtraParserTest.php index 14bc0bb273..ca1615e3c7 100644 --- a/tests/phpunit/includes/ExtraParserTest.php +++ b/tests/phpunit/includes/ExtraParserTest.php @@ -8,17 +8,18 @@ class ExtraParserTest extends MediaWikiTestCase { protected function setUp() { parent::setUp(); + $contLang = Language::factory( 'en' ); $this->setMwGlobals( array( 'wgShowDBErrorBacktrace' => true, 'wgLanguageCode' => 'en', - 'wgContLang' => Language::factory( 'en' ), + 'wgContLang' => $contLang, 'wgLang' => Language::factory( 'en' ), 'wgMemc' => new EmptyBagOStuff, 'wgAlwaysUseTidy' => false, 'wgCleanSignatures' => true, ) ); - $this->options = new ParserOptions; + $this->options = ParserOptions::newFromUserAndLang( new User, $contLang ); $this->options->setTemplateCallback( array( __CLASS__, 'statelessFetchTemplate' ) ); $this->parser = new Parser; diff --git a/tests/phpunit/includes/WikiPageTest.php b/tests/phpunit/includes/WikiPageTest.php index e98f5a770c..6dc1568397 100644 --- a/tests/phpunit/includes/WikiPageTest.php +++ b/tests/phpunit/includes/WikiPageTest.php @@ -579,7 +579,7 @@ class WikiPageTest extends MediaWikiLangTestCase { public function testGetParserOutput( $model, $text, $expectedHtml ) { $page = $this->createPage( 'WikiPageTest_testGetParserOutput', $text, $model ); - $opt = new ParserOptions(); + $opt = $page->makeParserOptions( 'canonical' ); $po = $page->getParserOutput( $opt ); $text = $po->getText(); diff --git a/tests/phpunit/includes/parser/MagicVariableTest.php b/tests/phpunit/includes/parser/MagicVariableTest.php index 46ef5da1d9..611a45a043 100644 --- a/tests/phpunit/includes/parser/MagicVariableTest.php +++ b/tests/phpunit/includes/parser/MagicVariableTest.php @@ -32,10 +32,11 @@ class MagicVariableTest extends MediaWikiTestCase { protected function setUp() { parent::setUp(); - $this->setMwGlobals( 'wgContLang', Language::factory( 'en' ) ); + $contLang = Language::factory( 'en' ); + $this->setMwGlobals( 'wgContLang', $contLang ); $this->testParser = new Parser(); - $this->testParser->Options( new ParserOptions() ); + $this->testParser->Options( ParserOptions::newFromUserAndLang( new User, $contLang ) ); # initialize parser output $this->testParser->clearState(); diff --git a/tests/phpunit/includes/parser/ParserPreloadTest.php b/tests/phpunit/includes/parser/ParserPreloadTest.php index cb5588b11f..8c22c593c3 100644 --- a/tests/phpunit/includes/parser/ParserPreloadTest.php +++ b/tests/phpunit/includes/parser/ParserPreloadTest.php @@ -9,9 +9,10 @@ class ParserPreloadTest extends MediaWikiTestCase { private $title; protected function setUp() { - parent::setUp(); + global $wgContLang; - $this->testParserOptions = new ParserOptions(); + parent::setUp(); + $this->testParserOptions = ParserOptions::newFromUserAndLang( new User, $wgContLang ); $this->testParser = new Parser(); $this->testParser->Options( $this->testParserOptions ); diff --git a/tests/phpunit/includes/parser/PreprocessorTest.php b/tests/phpunit/includes/parser/PreprocessorTest.php index 0e2bbabf3e..362d9f7426 100644 --- a/tests/phpunit/includes/parser/PreprocessorTest.php +++ b/tests/phpunit/includes/parser/PreprocessorTest.php @@ -6,9 +6,9 @@ class PreprocessorTest extends MediaWikiTestCase { var $mOptions; protected function setUp() { - global $wgParserConf; + global $wgParserConf, $wgContLang; parent::setUp(); - $this->mOptions = new ParserOptions(); + $this->mOptions = ParserOptions::newFromUserAndLang( new User, $wgContLang ); $name = isset( $wgParserConf['preprocessorClass'] ) ? $wgParserConf['preprocessorClass'] : 'Preprocessor_DOM'; $this->mPreprocessor = new $name( $this ); diff --git a/tests/phpunit/includes/parser/TagHooksTest.php b/tests/phpunit/includes/parser/TagHooksTest.php index 713ce846de..d089affced 100644 --- a/tests/phpunit/includes/parser/TagHooksTest.php +++ b/tests/phpunit/includes/parser/TagHooksTest.php @@ -17,11 +17,11 @@ class TagHookTest extends MediaWikiTestCase { * @dataProvider provideValidNames */ function testTagHooks( $tag ) { - global $wgParserConf; + global $wgParserConf, $wgContLang; $parser = new Parser( $wgParserConf ); $parser->setHook( $tag, array( $this, 'tagCallback' ) ); - $parserOutput = $parser->parse( "Foo<$tag>BarBaz", Title::newFromText( 'Test' ), new ParserOptions ); + $parserOutput = $parser->parse( "Foo<$tag>BarBaz", Title::newFromText( 'Test' ), ParserOptions::newFromUserAndLang( new User, $wgContLang ) ); $this->assertEquals( "

FooOneBaz\n

", $parserOutput->getText() ); $parser->mPreprocessor = null; # Break the Parser <-> Preprocessor cycle @@ -32,11 +32,11 @@ class TagHookTest extends MediaWikiTestCase { * @expectedException MWException */ function testBadTagHooks( $tag ) { - global $wgParserConf; + global $wgParserConf, $wgContLang; $parser = new Parser( $wgParserConf ); $parser->setHook( $tag, array( $this, 'tagCallback' ) ); - $parser->parse( "Foo<$tag>BarBaz", Title::newFromText( 'Test' ), new ParserOptions ); + $parser->parse( "Foo<$tag>BarBaz", Title::newFromText( 'Test' ), ParserOptions::newFromUserAndLang( new User, $wgContLang ) ); $this->fail('Exception not thrown.'); } @@ -44,11 +44,11 @@ class TagHookTest extends MediaWikiTestCase { * @dataProvider provideValidNames */ function testFunctionTagHooks( $tag ) { - global $wgParserConf; + global $wgParserConf, $wgContLang; $parser = new Parser( $wgParserConf ); $parser->setFunctionTagHook( $tag, array( $this, 'functionTagCallback' ), 0 ); - $parserOutput = $parser->parse( "Foo<$tag>BarBaz", Title::newFromText( 'Test' ), new ParserOptions ); + $parserOutput = $parser->parse( "Foo<$tag>BarBaz", Title::newFromText( 'Test' ), ParserOptions::newFromUserAndLang( new User, $wgContLang ) ); $this->assertEquals( "

FooOneBaz\n

", $parserOutput->getText() ); $parser->mPreprocessor = null; # Break the Parser <-> Preprocessor cycle @@ -59,11 +59,11 @@ class TagHookTest extends MediaWikiTestCase { * @expectedException MWException */ function testBadFunctionTagHooks( $tag ) { - global $wgParserConf; + global $wgParserConf, $wgContLang; $parser = new Parser( $wgParserConf ); $parser->setFunctionTagHook( $tag, array( $this, 'functionTagCallback' ), SFH_OBJECT_ARGS ); - $parser->parse( "Foo<$tag>BarBaz", Title::newFromText( 'Test' ), new ParserOptions ); + $parser->parse( "Foo<$tag>BarBaz", Title::newFromText( 'Test' ), ParserOptions::newFromUserAndLang( new User, $wgContLang ) ); $this->fail('Exception not thrown.'); } -- 2.20.1