3 use Wikimedia\TestingAccessWrapper;
4 use Wikimedia\ScopedCallback;
13 $wrap->defaults =
null;
14 $wrap->lazyOptions = [
20 'numberheadings' =>
true,
22 'stubthreshold' =>
true,
33 'wgRenderHashAppend' =>
'',
66 $this->assertSame( $wgUser, $popt->getUser() );
67 $this->assertSame(
$wgLang, $popt->getUserLangObj() );
71 $this->assertSame(
$user, $popt->getUser() );
72 $this->assertSame(
$wgLang, $popt->getUserLangObj() );
76 $this->assertSame( $wgUser, $popt->getUser() );
77 $this->assertSame(
$lang, $popt->getUserLangObj() );
81 $this->assertSame(
$user, $popt->getUser() );
82 $this->assertSame(
$lang, $popt->getUserLangObj() );
86 $this->assertTrue( $popt->getUser()->isAnon() );
87 $this->assertSame( $contLang, $popt->getUserLangObj() );
89 $this->assertSame( $contLang, $popt->getUserLangObj() );
94 $this->assertSame(
$user, $popt->getUser() );
95 $this->assertSame(
$lang, $popt->getUserLangObj() );
97 $this->assertSame(
$lang, $popt->getUserLangObj() );
102 $this->fail(
'Excpected exception not thrown' );
103 }
catch ( InvalidArgumentException $ex ) {
117 $this->assertSame( $expect, $popt->isSafeToCache() );
122 'No overrides' => [
true, [] ],
123 'In-key options are ok' => [
true, [
124 'thumbsize' => 1e100,
125 'printable' =>
false,
127 'Non-in-key options are not ok' => [
false, [
128 'removeComments' =>
false,
130 'Non-in-key options are not ok (2)' => [
false, [
131 'wrapclass' =>
'foobar',
133 'Canonical override, not default (1)' => [
true, [
136 'Canonical override, not default (2)' => [
false, [
151 $usedOptions, $expect,
$options, $globals = [], $hookFunc =
null
160 $this->assertSame( $expect, $popt->optionsHash( $usedOptions ) );
164 $used = [
'thumbsize',
'printable' ];
167 $classWrapper->getDefaults();
168 $allUsableOptions = array_diff(
169 array_keys( $classWrapper->inCacheKey ),
170 array_keys( $classWrapper->lazyOptions )
174 'Canonical options, nothing used' => [ [],
'canonical', [] ],
175 'Canonical options, used some options' => [ $used,
'canonical', [] ],
176 'Used some options, non-default values' => [
178 'printable=1!thumbsize=200',
184 'Canonical options, used all non-lazy options' => [ $allUsableOptions,
'canonical', [] ],
185 'Canonical options, nothing used, but with hooks and $wgRenderHashAppend' => [
187 'canonical!wgRenderHashAppend!onPageRenderingHash',
189 [
'wgRenderHashAppend' =>
'!wgRenderHashAppend' ],
190 [ __CLASS__ .
'::onPageRenderingHash' ],
197 function ( &$defaults, &$inCacheKey, &$lazyOptions ) {
199 ->setMethods( [
'neverCalled',
'calledOnce' ] )
201 $lazyFuncs->expects( $this->never() )->method(
'neverCalled' );
202 $lazyFuncs->expects( $this->once() )->method(
'calledOnce' )->willReturn(
'value' );
214 'opt1' => [ $lazyFuncs,
'calledOnce' ],
215 'opt2' => [ $lazyFuncs,
'neverCalled' ],
216 'opt3' => [ $lazyFuncs,
'neverCalled' ],
224 $popt->registerWatcher(
function () {
225 $this->fail(
'Watcher should not have been called' );
227 $this->assertSame(
'opt1=value', $popt->optionsHash( [
'opt1',
'opt3' ] ) );
230 $this->assertSame(
'opt1=value', $popt->optionsHash( [
'opt1',
'opt3' ] ) );
234 $confstr .=
'!onPageRenderingHash';
243 $popt->getOption(
'bogus' );
252 $popt->setOption(
'bogus',
true );
257 $oldDefaults = $classWrapper->defaults;
258 $oldLazy = $classWrapper->lazyOptions;
259 $reset =
new ScopedCallback(
function ()
use ( $classWrapper, $oldDefaults, $oldLazy ) {
260 $classWrapper->defaults = $oldDefaults;
261 $classWrapper->lazyOptions = $oldLazy;
266 $this->assertTrue( $popt1->matches( $popt2 ) );
268 $popt1->enableLimitReport(
true );
269 $popt2->enableLimitReport(
false );
270 $this->assertTrue( $popt1->matches( $popt2 ) );
272 $popt2->setTidy( !$popt2->getTidy() );
273 $this->assertFalse( $popt1->matches( $popt2 ) );
276 $classWrapper->defaults += [ __METHOD__ => null ];
277 $classWrapper->lazyOptions += [ __METHOD__ =>
function ()
use ( &$ctr ) {
282 $this->assertFalse( $popt1->matches( $popt2 ) );
284 ScopedCallback::consume( $reset );
290 'dateformat',
'numberheadings',
'printable',
'stubthreshold',
291 'thumbsize',
'userlang'
296 $this->
setTemporaryHook(
'ParserOptionsRegister',
function ( &$defaults, &$inCacheKey ) {
308 'dateformat',
'foo',
'numberheadings',
'printable',
'stubthreshold',
309 'thumbsize',
'userlang'
316 $this->assertFalse(
$options->getSpeculativeRevId() );
319 $options->setSpeculativeRevIdCallback(
function ()
use( &$counter ) {
324 $this->assertSame( 1,
$options->getSpeculativeRevId() );
325 $this->assertSame( 1,
$options->getSpeculativeRevId() );