Merge "SpecialPages: Add ul { margin-top: 0; margin-bottom: 0 } for multicolumn"
[lhc/web/wiklou.git] / tests / phpunit / includes / GlobalFunctions / GlobalTest.php
index 2206fbd..d961e41 100644 (file)
@@ -102,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 );
@@ -127,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
@@ -345,7 +362,6 @@ class GlobalTest extends MediaWikiTestCase {
         * @covers ::wfClientAcceptsGzip
         */
        public function testClientAcceptsGzipTest() {
-
                $settings = [
                        'gzip' => true,
                        'bzip' => false,
@@ -379,7 +395,6 @@ class GlobalTest extends MediaWikiTestCase {
         * @covers ::wfPercent
         */
        public function testWfPercentTest() {
-
                $pcts = [
                        [ 6 / 7, '0.86%', 2, false ],
                        [ 3 / 3, '1%' ],
@@ -458,26 +473,46 @@ class GlobalTest extends MediaWikiTestCase {
                ];
        }
 
+       /**
+        * @covers ::wfMerge
+        */
+       public function testMerge_worksWithLessParameters() {
+               $this->markTestSkippedIfNoDiff3();
+
+               $mergedText = null;
+               $successfulMerge = wfMerge( "old1\n\nold2", "old1\n\nnew2", "new1\n\nold2", $mergedText );
+
+               $mergedText = null;
+               $conflictingMerge = wfMerge( 'old', 'old and mine', 'old and yours', $mergedText );
+
+               $this->assertEquals( true, $successfulMerge );
+               $this->assertEquals( false, $conflictingMerge );
+       }
+
        /**
         * @param string $old Text as it was in the database
         * @param string $mine Text submitted while user was editing
         * @param string $yours Text submitted by the user
         * @param bool $expectedMergeResult Whether the merge should be a success
         * @param string $expectedText Text after merge has been completed
+        * @param string $expectedMergeAttemptResult Diff3 output if conflicts occur
         *
         * @dataProvider provideMerge()
         * @group medium
         * @covers ::wfMerge
         */
-       public function testMerge( $old, $mine, $yours, $expectedMergeResult, $expectedText ) {
+       public function testMerge( $old, $mine, $yours, $expectedMergeResult, $expectedText,
+                                                          $expectedMergeAttemptResult ) {
                $this->markTestSkippedIfNoDiff3();
 
                $mergedText = null;
-               $isMerged = wfMerge( $old, $mine, $yours, $mergedText );
+               $attemptMergeResult = null;
+               $isMerged = wfMerge( $old, $mine, $yours, $mergedText, $mergeAttemptResult );
 
                $msg = 'Merge should be a ';
                $msg .= $expectedMergeResult ? 'success' : 'failure';
                $this->assertEquals( $expectedMergeResult, $isMerged, $msg );
+               $this->assertEquals( $expectedMergeAttemptResult, $mergeAttemptResult );
 
                if ( $isMerged ) {
                        // Verify the merged text
@@ -515,6 +550,9 @@ class GlobalTest extends MediaWikiTestCase {
                                "one one one ONE ONE\n" .
                                        "\n" .
                                        "two two TWO TWO\n", // note: will always end in a newline
+
+                               // mergeAttemptResult:
+                               "",
                        ],
 
                        // #1: conflict, fail
@@ -537,6 +575,13 @@ class GlobalTest extends MediaWikiTestCase {
 
                                // result:
                                null,
+
+                               // mergeAttemptResult:
+                               "1,3c\n" .
+                               "one one one\n" .
+                               "\n" .
+                               "two two\n" .
+                               ".\n",
                        ],
                ];
        }