3 use Wikimedia\TestingAccessWrapper;
4 use Wikimedia\ScopedCallback;
10 $wrap->defaults =
null;
11 $wrap->lazyOptions = [
16 'numberheadings' =>
true,
18 'stubthreshold' =>
true,
32 'wgRenderHashAppend' =>
'',
34 'PageRenderingHash' => [],
54 $this->assertSame( $expect, $popt->isSafeToCache() );
59 'No overrides' => [
true, [] ],
60 'In-key options are ok' => [
true, [
64 'Non-in-key options are not ok' => [
false, [
65 'removeComments' =>
false,
67 'Canonical override, not default (1)' => [
true, [
70 'Canonical override, not default (2)' => [
false, [
89 $globals[
'wgHooks'] += [
90 'PageRenderingHash' => [],
98 $this->assertSame( $expect, $popt->optionsHash( $usedOptions ) );
102 $used = [
'wrapclass',
'printable' ];
105 $classWrapper->getDefaults();
106 $allUsableOptions = array_diff(
107 array_keys( $classWrapper->inCacheKey ),
108 array_keys( $classWrapper->lazyOptions )
112 'Canonical options, nothing used' => [ [],
'canonical', [] ],
113 'Canonical options, used some options' => [ $used,
'canonical', [] ],
114 'Used some options, non-default values' => [
116 'printable=1!wrapclass=foobar',
118 'wrapclass' =>
'foobar',
122 'Canonical options, used all non-lazy options' => [ $allUsableOptions,
'canonical', [] ],
123 'Canonical options, nothing used, but with hooks and $wgRenderHashAppend' => [
125 'canonical!wgRenderHashAppend!onPageRenderingHash',
128 'wgRenderHashAppend' =>
'!wgRenderHashAppend',
129 'wgHooks' => [
'PageRenderingHash' => [ [ __CLASS__ .
'::onPageRenderingHash' ] ] ],
136 $confstr .=
'!onPageRenderingHash';
142 $popt->registerWatcher(
function (
$name ) {
143 $this->assertNotEquals(
'editsection',
$name );
146 $this->assertTrue( $popt->getEditSection() );
147 $this->assertSame(
'canonical', $popt->optionsHash( [] ) );
148 $this->assertSame(
'canonical', $popt->optionsHash( [
'editsection' ] ) );
150 $popt->setEditSection(
false );
151 $this->assertFalse( $popt->getEditSection() );
152 $this->assertSame(
'canonical', $popt->optionsHash( [] ) );
153 $this->assertSame(
'editsection=0', $popt->optionsHash( [
'editsection' ] ) );
162 $popt->getOption(
'bogus' );
171 $popt->setOption(
'bogus',
true );
176 $oldDefaults = $classWrapper->defaults;
177 $oldLazy = $classWrapper->lazyOptions;
178 $reset =
new ScopedCallback(
function ()
use ( $classWrapper, $oldDefaults, $oldLazy ) {
179 $classWrapper->defaults = $oldDefaults;
180 $classWrapper->lazyOptions = $oldLazy;
185 $this->assertTrue( $popt1->matches( $popt2 ) );
187 $popt1->enableLimitReport(
true );
188 $popt2->enableLimitReport(
false );
189 $this->assertTrue( $popt1->matches( $popt2 ) );
191 $popt2->setTidy( !$popt2->getTidy() );
192 $this->assertFalse( $popt1->matches( $popt2 ) );
195 $classWrapper->defaults += [ __METHOD__ => null ];
196 $classWrapper->lazyOptions += [ __METHOD__ =>
function ()
use ( &$ctr ) {
201 $this->assertFalse( $popt1->matches( $popt2 ) );
203 ScopedCallback::consume( $reset );
210 $wgHooks[
'ParserOptionsRegister'] = [];
212 'dateformat',
'numberheadings',
'printable',
'stubthreshold',
213 'thumbsize',
'userlang',
'wrapclass',
218 $wgHooks[
'ParserOptionsRegister'][] =
function ( &$defaults, &$inCacheKey ) {
230 'dateformat',
'foo',
'numberheadings',
'printable',
'stubthreshold',
231 'thumbsize',
'userlang',
'wrapclass',