diff --git a/tests/phpunit/MediaWikiTestCase.php b/tests/phpunit/MediaWikiTestCase.php index c619dab805e..99c96f29167 100644 --- a/tests/phpunit/MediaWikiTestCase.php +++ b/tests/phpunit/MediaWikiTestCase.php @@ -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" ); + } + } } diff --git a/tests/phpunit/includes/EditPageTest.php b/tests/phpunit/includes/EditPageTest.php index b02b08a3cb9..36fde854d7c 100644 --- a/tests/phpunit/includes/EditPageTest.php +++ b/tests/phpunit/includes/EditPageTest.php @@ -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(); diff --git a/tests/phpunit/includes/GlobalFunctions/GlobalTest.php b/tests/phpunit/includes/GlobalFunctions/GlobalTest.php index 7304bd95510..0dc18a2919b 100644 --- a/tests/phpunit/includes/GlobalFunctions/GlobalTest.php +++ b/tests/phpunit/includes/GlobalFunctions/GlobalTest.php @@ -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 ); diff --git a/tests/phpunit/includes/WikiPageTest.php b/tests/phpunit/includes/WikiPageTest.php index fb20ce667d3..cc23d6d5e81 100644 --- a/tests/phpunit/includes/WikiPageTest.php +++ b/tests/phpunit/includes/WikiPageTest.php @@ -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 ); diff --git a/tests/phpunit/includes/content/WikitextContentHandlerTest.php b/tests/phpunit/includes/content/WikitextContentHandlerTest.php index d68c3e5438b..ed4846bed1f 100644 --- a/tests/phpunit/includes/content/WikitextContentHandlerTest.php +++ b/tests/phpunit/includes/content/WikitextContentHandlerTest.php @@ -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 );