Merge "Add tablesUsed to RevisionStoreDbTest"
[lhc/web/wiklou.git] / tests / phpunit / includes / parser / ParserOptionsTest.php
index 264e35d..d55372c 100644 (file)
@@ -3,8 +3,46 @@
 use Wikimedia\TestingAccessWrapper;
 use Wikimedia\ScopedCallback;
 
+/**
+ * @covers ParserOptions
+ */
 class ParserOptionsTest extends MediaWikiTestCase {
 
+       private static function clearCache() {
+               $wrap = TestingAccessWrapper::newFromClass( ParserOptions::class );
+               $wrap->defaults = null;
+               $wrap->lazyOptions = [
+                       'dateformat' => [ ParserOptions::class, 'initDateFormat' ],
+               ];
+               $wrap->inCacheKey = [
+                       'dateformat' => true,
+                       'numberheadings' => true,
+                       'thumbsize' => true,
+                       'stubthreshold' => true,
+                       'printable' => true,
+                       'userlang' => true,
+               ];
+       }
+
+       protected function setUp() {
+               global $wgHooks;
+
+               parent::setUp();
+               self::clearCache();
+
+               $this->setMwGlobals( [
+                       'wgRenderHashAppend' => '',
+                       'wgHooks' => [
+                               'PageRenderingHash' => [],
+                       ] + $wgHooks,
+               ] );
+       }
+
+       protected function tearDown() {
+               self::clearCache();
+               parent::tearDown();
+       }
+
        /**
         * @dataProvider provideIsSafeToCache
         * @param bool $expect Expected value
@@ -23,11 +61,14 @@ class ParserOptionsTest extends MediaWikiTestCase {
                        'No overrides' => [ true, [] ],
                        'In-key options are ok' => [ true, [
                                'thumbsize' => 1e100,
-                               'wrapclass' => false,
+                               'printable' => false,
                        ] ],
                        'Non-in-key options are not ok' => [ false, [
                                'removeComments' => false,
                        ] ],
+                       'Non-in-key options are not ok (2)' => [ false, [
+                               'wrapclass' => 'foobar',
+                       ] ],
                        'Canonical override, not default (1)' => [ true, [
                                'tidy' => true,
                        ] ],
@@ -48,7 +89,6 @@ class ParserOptionsTest extends MediaWikiTestCase {
                global $wgHooks;
 
                $globals += [
-                       'wgRenderHashAppend' => '',
                        'wgHooks' => [],
                ];
                $globals['wgHooks'] += [
@@ -64,7 +104,7 @@ class ParserOptionsTest extends MediaWikiTestCase {
        }
 
        public static function provideOptionsHash() {
-               $used = [ 'wrapclass', 'printable' ];
+               $used = [ 'thumbsize', 'printable' ];
 
                $classWrapper = TestingAccessWrapper::newFromClass( ParserOptions::class );
                $classWrapper->getDefaults();
@@ -78,9 +118,9 @@ class ParserOptionsTest extends MediaWikiTestCase {
                        'Canonical options, used some options' => [ $used, 'canonical', [] ],
                        'Used some options, non-default values' => [
                                $used,
-                               'printable=1!wrapclass=foobar',
+                               'printable=1!thumbsize=200',
                                [
-                                       'wrapclass' => 'foobar',
+                                       'thumbsize' => 200,
                                        'printable' => true,
                                ]
                        ],
@@ -103,13 +143,6 @@ class ParserOptionsTest extends MediaWikiTestCase {
 
        // Test weird historical behavior is still weird
        public function testOptionsHashEditSection() {
-               global $wgHooks;
-
-               $this->setMwGlobals( [
-                       'wgRenderHashAppend' => '',
-                       'wgHooks' => [ 'PageRenderingHash' => [] ] + $wgHooks,
-               ] );
-
                $popt = ParserOptions::newCanonical();
                $popt->registerWatcher( function ( $name ) {
                        $this->assertNotEquals( 'editsection', $name );
@@ -175,4 +208,33 @@ class ParserOptionsTest extends MediaWikiTestCase {
                ScopedCallback::consume( $reset );
        }
 
+       public function testAllCacheVaryingOptions() {
+               global $wgHooks;
+
+               // $wgHooks is already saved in self::setUp(), so we can modify it freely here
+               $wgHooks['ParserOptionsRegister'] = [];
+               $this->assertSame( [
+                       'dateformat', 'numberheadings', 'printable', 'stubthreshold',
+                       'thumbsize', 'userlang'
+               ], ParserOptions::allCacheVaryingOptions() );
+
+               self::clearCache();
+
+               $wgHooks['ParserOptionsRegister'][] = function ( &$defaults, &$inCacheKey ) {
+                       $defaults += [
+                               'foo' => 'foo',
+                               'bar' => 'bar',
+                               'baz' => 'baz',
+                       ];
+                       $inCacheKey += [
+                               'foo' => true,
+                               'bar' => false,
+                       ];
+               };
+               $this->assertSame( [
+                       'dateformat', 'foo', 'numberheadings', 'printable', 'stubthreshold',
+                       'thumbsize', 'userlang'
+               ], ParserOptions::allCacheVaryingOptions() );
+       }
+
 }