Add MediaWikiTestCase::checkHasDiff3 and use it
authorumherirrender <umherirrender_de.wp@web.de>
Thu, 22 Nov 2012 16:45:50 +0000 (17:45 +0100)
committerumherirrender <umherirrender_de.wp@web.de>
Thu, 22 Nov 2012 16:45:50 +0000 (17:45 +0100)
Some tests can only passed, when diff3 is enabled on the wiki, when not
the tests should marked as skipped. To avoid code duplicates inside
the test folder for the check, if diff3 is enabled, the new function
MediaWikiTestCase::checkHasDiff3 can be used.

Change-Id: Ie765da49a4a1358da78a3506e38772d61bcd010c

tests/phpunit/MediaWikiTestCase.php
tests/phpunit/includes/EditPageTest.php
tests/phpunit/includes/GlobalFunctions/GlobalTest.php
tests/phpunit/includes/WikiPageTest.php
tests/phpunit/includes/content/WikitextContentHandlerTest.php

index c619dab..99c96f2 100644 (file)
@@ -789,4 +789,24 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase {
                //        But frequently, this is used in fixture setup.
                throw new MWException( "No namespace defaults to wikitext!" );
        }
+
+       /**
+        * Check, if $wgDiff3 is set and ready to merge
+        * Will mark the calling test as skipped, if not ready
+        *
+        * @since 1.21
+        */
+       protected function checkHasDiff3() {
+               global $wgDiff3;
+
+               # This check may also protect against code injection in
+               # case of broken installations.
+               wfSuppressWarnings();
+               $haveDiff3 = $wgDiff3 && file_exists( $wgDiff3 );
+               wfRestoreWarnings();
+
+               if( !$haveDiff3 ) {
+                       $this->markTestSkipped( "Skip test, since diff3 is not configured" );
+               }
+       }
 }
index b02b08a..36fde85 100644 (file)
@@ -356,25 +356,13 @@ hello
                return array_merge( $tests, $testsWithAdam, $testsWithBerta );
        }
 
-       function testHasValidDiff3() {
-               global $wgDiff3;
-
-               if ( !$wgDiff3 ) {
-                       $this->markTestSkipped( "Can't test conflict resolution because \$wgDiff3 is not configured" );
-               } elseif ( !file_exists( $wgDiff3 ) ) {
-                       #XXX: this sucks, since it uses arcane internal knowledge about TextContentHandler::merge3 and wfMerge.
-                       $this->markTestSkipped( "Can't test conflict resolution because \$wgDiff3 is misconfigured: can't find $wgDiff3" );
-               }
-               $this->assertTrue( true );
-       }
-
        /**
-        * @depend testHasValidDiff3
         * @dataProvider provideAutoMerge
         */
        public function testAutoMerge( $baseUser, $text, $adamsEdit, $bertasEdit,
                                $expectedCode, $expectedText, $message = null
        ) {
+               $this->checkHasDiff3();
 
                //create page
                $ns = $this->getDefaultWikitextNS();
index 7304bd9..0dc18a2 100644 (file)
@@ -498,6 +498,8 @@ class GlobalTest extends MediaWikiTestCase {
         * @dataProvider provideMerge()
         */
        public function testMerge( $old, $mine, $yours, $expectedMergeResult, $expectedText ) {
+               $this->checkHasDiff3();
+
                $mergedText = null;
                $isMerged = wfMerge( $old, $mine, $yours, $mergedText );
 
index fb20ce6..cc23d6d 100644 (file)
@@ -704,16 +704,7 @@ more stuff
 
        /* @todo FIXME: fix this!
        public function testGetUndoText() {
-               global $wgDiff3;
-
-               wfSuppressWarnings();
-               $haveDiff3 = $wgDiff3 && file_exists( $wgDiff3 );
-               wfRestoreWarnings();
-
-               if( !$haveDiff3 ) {
-                       $this->markTestSkipped( "diff3 not installed or not found" );
-                       return;
-               }
+               $this->checkHasDiff3();
 
                $text = "one";
                $page = $this->createPage( "WikiPageTest_testGetUndoText", $text );
index d68c3e5..ed4846b 100644 (file)
@@ -103,16 +103,7 @@ class WikitextContentHandlerTest extends MediaWikiLangTestCase {
         * @dataProvider dataMerge3
         */
        public function testMerge3( $old, $mine, $yours, $expected ) {
-               global $wgDiff3;
-
-               if ( !$wgDiff3 ) {
-                       $this->markTestSkipped( "Can't test merge3(), since \$wgDiff3 is not configured" );
-               }
-
-               if ( !file_exists( $wgDiff3 ) ) {
-                       #XXX: this sucks, since it uses arcane internal knowledge about TextContentHandler::merge3 and wfMerge.
-                       $this->markTestSkipped( "Can't test merge3(), since \$wgDiff3 is misconfigured: can't find $wgDiff3" );
-               }
+               $this->checkHasDiff3();
 
                // test merge
                $oldContent = new WikitextContent( $old );