Merge "Define index types as strings"
[lhc/web/wiklou.git] / tests / phpunit / includes / parser / ParserOptionsTest.php
index 8c17780..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,
@@ -283,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( [
@@ -309,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() );
+       }
+
 }