Merge "Add canonical id to header on action=info"
[lhc/web/wiklou.git] / tests / phpunit / includes / GlobalFunctions / GlobalTest.php
index 1d48d08..5e54b8d 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
@@ -344,7 +362,6 @@ class GlobalTest extends MediaWikiTestCase {
         * @covers ::wfClientAcceptsGzip
         */
        public function testClientAcceptsGzipTest() {
-
                $settings = [
                        'gzip' => true,
                        'bzip' => false,
@@ -378,7 +395,6 @@ class GlobalTest extends MediaWikiTestCase {
         * @covers ::wfPercent
         */
        public function testWfPercentTest() {
-
                $pcts = [
                        [ 6 / 7, '0.86%', 2, false ],
                        [ 3 / 3, '1%' ],