48 $wgLang = Language::factory(
'fr' );
49 $contLang = Language::factory(
'qqx' );
58 $lang = Language::factory(
'de' );
59 $lang2 = Language::factory(
'bug' );
65 $popt = ParserOptions::newCanonical();
66 $this->assertSame( $wgUser, $popt->getUser() );
67 $this->assertSame(
$wgLang, $popt->getUserLangObj() );
70 $popt = ParserOptions::newCanonical( $user );
71 $this->assertSame( $user, $popt->getUser() );
72 $this->assertSame(
$wgLang, $popt->getUserLangObj() );
75 $popt = ParserOptions::newCanonical(
null,
$lang );
76 $this->assertSame( $wgUser, $popt->getUser() );
77 $this->assertSame(
$lang, $popt->getUserLangObj() );
80 $popt = ParserOptions::newCanonical( $user,
$lang );
81 $this->assertSame( $user, $popt->getUser() );
82 $this->assertSame(
$lang, $popt->getUserLangObj() );
85 $popt = ParserOptions::newCanonical(
'canonical' );
86 $this->assertTrue( $popt->getUser()->isAnon() );
87 $this->assertSame( $contLang, $popt->getUserLangObj() );
88 $popt = ParserOptions::newCanonical(
'canonical', $lang2 );
89 $this->assertSame( $contLang, $popt->getUserLangObj() );
93 $popt = ParserOptions::newCanonical(
$context );
94 $this->assertSame( $user, $popt->getUser() );
95 $this->assertSame(
$lang, $popt->getUserLangObj() );
96 $popt = ParserOptions::newCanonical(
$context, $lang2 );
97 $this->assertSame(
$lang, $popt->getUserLangObj() );
101 $popt = ParserOptions::newCanonical(
'bogus' );
102 $this->fail(
'Excpected exception not thrown' );
103 }
catch ( InvalidArgumentException $ex ) {
164 $used = [
'thumbsize',
'printable' ];
166 $classWrapper = TestingAccessWrapper::newFromClass( ParserOptions::class );
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 ) {
198 $lazyFuncs = $this->getMockBuilder( stdClass::class )
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' ],
223 $popt = ParserOptions::newCanonical();
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' ] ) );
256 $classWrapper = TestingAccessWrapper::newFromClass( ParserOptions::class );
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;
264 $popt1 = ParserOptions::newCanonical();
265 $popt2 = ParserOptions::newCanonical();
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 ) {
280 $popt1 = ParserOptions::newCanonical();
281 $popt2 = ParserOptions::newCanonical();
282 $this->assertFalse( $popt1->matches( $popt2 ) );
284 ScopedCallback::consume( $reset );