X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=tests%2Fphpunit%2Fincludes%2Fparser%2FParserOptionsTest.php;h=ad899bd7a9c6b869926a519a667ea9931646c972;hb=13bb844fdfff794525e2cb202176ddee3a23ef06;hp=d6061420e76bd4f54e6f6298f6d63fa0a7f82896;hpb=5604684b4420048b6f0db29daf5b6ae7d600b446;p=lhc%2Fweb%2Fwiklou.git diff --git a/tests/phpunit/includes/parser/ParserOptionsTest.php b/tests/phpunit/includes/parser/ParserOptionsTest.php index d6061420e7..ad899bd7a9 100644 --- a/tests/phpunit/includes/parser/ParserOptionsTest.php +++ b/tests/phpunit/includes/parser/ParserOptionsTest.php @@ -5,6 +5,42 @@ use Wikimedia\ScopedCallback; class ParserOptionsTest extends MediaWikiTestCase { + private static function clearCache() { + $wrap = TestingAccessWrapper::newFromClass( ParserOptions::class ); + $wrap->defaults = null; + $wrap->lazyOptions = [ + 'dateformat' => [ ParserOptions::class, 'initDateFormat' ], + ]; + $wrap->inCacheKey = [ + 'dateformat' => true, + 'numberheadings' => true, + 'thumbsize' => true, + 'stubthreshold' => true, + 'printable' => true, + 'userlang' => true, + 'wrapclass' => true, + ]; + } + + protected function setUp() { + global $wgHooks; + + parent::setUp(); + self::clearCache(); + + $this->setMwGlobals( [ + 'wgRenderHashAppend' => '', + 'wgHooks' => [ + 'PageRenderingHash' => [], + ] + $wgHooks, + ] ); + } + + protected function tearDown() { + self::clearCache(); + parent::tearDown(); + } + /** * @dataProvider provideIsSafeToCache * @param bool $expect Expected value @@ -37,66 +73,6 @@ class ParserOptionsTest extends MediaWikiTestCase { ]; } - /** - * @dataProvider provideOptionsHashPre30 - * @param array $usedOptions Used options - * @param string $expect Expected value - * @param array $options Options to set - * @param array $globals Globals to set - */ - public function testOptionsHashPre30( $usedOptions, $expect, $options, $globals = [] ) { - global $wgHooks; - - $globals += [ - 'wgRenderHashAppend' => '', - 'wgHooks' => [], - ]; - $globals['wgHooks'] += [ - 'PageRenderingHash' => [], - ] + $wgHooks; - $this->setMwGlobals( $globals ); - - $popt = new ParserOptions(); - foreach ( $options as $setter => $value ) { - $popt->$setter( $value ); - } - $this->assertSame( $expect, $popt->optionsHashPre30( $usedOptions ) ); - } - - public static function provideOptionsHashPre30() { - $used = [ 'wrapclass', 'printable' ]; - - return [ - 'Canonical options, nothing used' => [ [], '*!*!*!*!*!*', [] ], - 'Canonical options, used some options' => [ $used, '*!*!*!*!*!*', [] ], - 'Used some options, non-default values' => [ - $used, - '*!*!*!*!*!*!printable=1!wrapclass=foobar', - [ - 'setWrapOutputClass' => 'foobar', - 'setIsPrintable' => true, - ] - ], - 'Canonical options, nothing used, but with hooks and $wgRenderHashAppend' => [ - [], - '*!*!*!*!*!wgRenderHashAppend!*!onPageRenderingHash', - [], - [ - 'wgRenderHashAppend' => '!wgRenderHashAppend', - 'wgHooks' => [ 'PageRenderingHash' => [ [ __CLASS__ . '::onPageRenderingHash' ] ] ], - ] - ], - - // Test weird historical behavior is still weird - 'Canonical options, editsection=true used' => [ [ 'editsection' ], '*!*!*!*!*', [ - 'setEditSection' => true, - ] ], - 'Canonical options, editsection=false used' => [ [ 'editsection' ], '*!*!*!*!*!edit=0', [ - 'setEditSection' => false, - ] ], - ]; - } - /** * @dataProvider provideOptionsHash * @param array $usedOptions Used options @@ -108,7 +84,6 @@ class ParserOptionsTest extends MediaWikiTestCase { global $wgHooks; $globals += [ - 'wgRenderHashAppend' => '', 'wgHooks' => [], ]; $globals['wgHooks'] += [ @@ -163,13 +138,6 @@ class ParserOptionsTest extends MediaWikiTestCase { // Test weird historical behavior is still weird public function testOptionsHashEditSection() { - global $wgHooks; - - $this->setMwGlobals( [ - 'wgRenderHashAppend' => '', - 'wgHooks' => [ 'PageRenderingHash' => [] ] + $wgHooks, - ] ); - $popt = ParserOptions::newCanonical(); $popt->registerWatcher( function ( $name ) { $this->assertNotEquals( 'editsection', $name ); @@ -235,4 +203,33 @@ class ParserOptionsTest extends MediaWikiTestCase { ScopedCallback::consume( $reset ); } + public function testAllCacheVaryingOptions() { + global $wgHooks; + + // $wgHooks is already saved in self::setUp(), so we can modify it freely here + $wgHooks['ParserOptionsRegister'] = []; + $this->assertSame( [ + 'dateformat', 'numberheadings', 'printable', 'stubthreshold', + 'thumbsize', 'userlang', 'wrapclass', + ], ParserOptions::allCacheVaryingOptions() ); + + self::clearCache(); + + $wgHooks['ParserOptionsRegister'][] = function ( &$defaults, &$inCacheKey ) { + $defaults += [ + 'foo' => 'foo', + 'bar' => 'bar', + 'baz' => 'baz', + ]; + $inCacheKey += [ + 'foo' => true, + 'bar' => false, + ]; + }; + $this->assertSame( [ + 'dateformat', 'foo', 'numberheadings', 'printable', 'stubthreshold', + 'thumbsize', 'userlang', 'wrapclass', + ], ParserOptions::allCacheVaryingOptions() ); + } + }