Merge "Define index types as strings"
[lhc/web/wiklou.git] / tests / phpunit / includes / parser / ParserOptionsTest.php
index 29f1c8c..01fde35 100644 (file)
@@ -13,6 +13,7 @@ class ParserOptionsTest extends MediaWikiTestCase {
                $wrap->defaults = null;
                $wrap->lazyOptions = [
                        'dateformat' => [ ParserOptions::class, 'initDateFormat' ],
+                       'speculativeRevId' => [ ParserOptions::class, 'initSpeculativeRevId' ],
                ];
                $wrap->inCacheKey = [
                        'dateformat' => true,
@@ -45,9 +46,9 @@ class ParserOptionsTest extends MediaWikiTestCase {
        public function testNewCanonical() {
                $wgUser = $this->getMutableTestUser()->getUser();
                $wgLang = Language::factory( 'fr' );
-               $wgContLang = Language::factory( 'qqx' );
+               $contLang = Language::factory( 'qqx' );
 
-               $this->setContentLang( $wgContLang );
+               $this->setContentLang( $contLang );
                $this->setMwGlobals( [
                        'wgUser' => $wgUser,
                        'wgLang' => $wgLang,
@@ -80,13 +81,12 @@ class ParserOptionsTest extends MediaWikiTestCase {
                $this->assertSame( $user, $popt->getUser() );
                $this->assertSame( $lang, $popt->getUserLangObj() );
 
-               // Passing 'canonical' uses an anon and $wgContLang, and ignores
-               // any passed $userLang
+               // Passing 'canonical' uses an anon and $contLang, and ignores any passed $userLang
                $popt = ParserOptions::newCanonical( 'canonical' );
                $this->assertTrue( $popt->getUser()->isAnon() );
-               $this->assertSame( $wgContLang, $popt->getUserLangObj() );
+               $this->assertSame( $contLang, $popt->getUserLangObj() );
                $popt = ParserOptions::newCanonical( 'canonical', $lang2 );
-               $this->assertSame( $wgContLang, $popt->getUserLangObj() );
+               $this->assertSame( $contLang, $popt->getUserLangObj() );
 
                // Passing an IContextSource uses the user and lang from it, and ignores
                // any passed $userLang
@@ -284,6 +284,31 @@ class ParserOptionsTest extends MediaWikiTestCase {
                ScopedCallback::consume( $reset );
        }
 
+       public function testMatchesForCacheKey() {
+               $cOpts = ParserOptions::newCanonical( null, 'en' );
+
+               $uOpts = ParserOptions::newFromAnon();
+               $this->assertTrue( $cOpts->matchesForCacheKey( $uOpts ) );
+
+               $user = new User();
+               $uOpts = ParserOptions::newFromUser( $user );
+               $this->assertTrue( $cOpts->matchesForCacheKey( $uOpts ) );
+
+               $user = new User();
+               $user->setOption( 'thumbsize', 251 );
+               $uOpts = ParserOptions::newFromUser( $user );
+               $this->assertFalse( $cOpts->matchesForCacheKey( $uOpts ) );
+
+               $user = new User();
+               $user->setOption( 'stubthreshold', 800 );
+               $uOpts = ParserOptions::newFromUser( $user );
+               $this->assertFalse( $cOpts->matchesForCacheKey( $uOpts ) );
+
+               $user = new User();
+               $uOpts = ParserOptions::newFromUserAndLang( $user, Language::factory( 'zh' ) );
+               $this->assertFalse( $cOpts->matchesForCacheKey( $uOpts ) );
+       }
+
        public function testAllCacheVaryingOptions() {
                $this->setTemporaryHook( 'ParserOptionsRegister', null );
                $this->assertSame( [
@@ -310,4 +335,19 @@ class ParserOptionsTest extends MediaWikiTestCase {
                ], ParserOptions::allCacheVaryingOptions() );
        }
 
+       public function testGetSpeculativeRevid() {
+               $options = new ParserOptions();
+
+               $this->assertFalse( $options->getSpeculativeRevId() );
+
+               $counter = 0;
+               $options->setSpeculativeRevIdCallback( function () use( &$counter ) {
+                       return ++$counter;
+               } );
+
+               // make sure the same value is re-used once it is determined
+               $this->assertSame( 1, $options->getSpeculativeRevId() );
+               $this->assertSame( 1, $options->getSpeculativeRevId() );
+       }
+
 }