A service for read-only mode
[lhc/web/wiklou.git] / tests / phpunit / includes / GlobalFunctions / GlobalTest.php
index 9f2fdfe..33b6e2f 100644 (file)
@@ -1,6 +1,7 @@
 <?php
 
 /**
+ * @group Database
  * @group GlobalFunctions
  */
 class GlobalTest extends MediaWikiTestCase {
@@ -101,22 +102,28 @@ class GlobalTest extends MediaWikiTestCase {
        }
 
        /**
+        * Intended to cover the relevant bits of ServiceWiring.php, as well as GlobalFunctions.php
         * @covers ::wfReadOnly
         */
        public function testReadOnlyEmpty() {
                global $wgReadOnly;
                $wgReadOnly = null;
 
+               MediaWiki\MediaWikiServices::getInstance()->getReadOnlyMode()->clearCache();
                $this->assertFalse( wfReadOnly() );
                $this->assertFalse( wfReadOnly() );
        }
 
        /**
+        * Intended to cover the relevant bits of ServiceWiring.php, as well as GlobalFunctions.php
         * @covers ::wfReadOnly
         */
        public function testReadOnlySet() {
                global $wgReadOnly, $wgReadOnlyFile;
 
+               $readOnlyMode = MediaWiki\MediaWikiServices::getInstance()->getReadOnlyMode();
+               $readOnlyMode->clearCache();
+
                $f = fopen( $wgReadOnlyFile, "wt" );
                fwrite( $f, 'Message' );
                fclose( $f );
@@ -126,12 +133,23 @@ class GlobalTest extends MediaWikiTestCase {
                $this->assertTrue( wfReadOnly() ); # Check cached
 
                unlink( $wgReadOnlyFile );
-               $wgReadOnly = null; # Clean cache
-
+               $readOnlyMode->clearCache();
                $this->assertFalse( wfReadOnly() );
                $this->assertFalse( wfReadOnly() );
        }
 
+       /**
+        * This behaviour could probably be deprecated. Several extensions rely on it as of 1.29.
+        * @covers ::wfReadOnlyReason
+        */
+       public function testReadOnlyGlobalChange() {
+               $this->assertFalse( wfReadOnlyReason() );
+               $this->setMwGlobals( [
+                       'wgReadOnly' => 'reason'
+               ] );
+               $this->assertSame( 'reason', wfReadOnlyReason() );
+       }
+
        public static function provideArrayToCGI() {
                return [
                        [ [], '' ], // empty
@@ -413,8 +431,8 @@ class GlobalTest extends MediaWikiTestCase {
                );
        }
 
-       /** array( shorthand, expected integer ) */
        public static function provideShorthand() {
+               // Syntax: [ shorthand, expected integer ]
                return [
                        # Null, empty ...
                        [ '', -1 ],