From: umherirrender Date: Thu, 22 Nov 2012 16:45:50 +0000 (+0100) Subject: Add MediaWikiTestCase::checkHasDiff3 and use it X-Git-Tag: 1.31.0-rc.0~21535^2 X-Git-Url: http://git.cyclocoop.org/%24dirpuce/puce%24spip_lang_rtl.gif?a=commitdiff_plain;h=9b3292e31a7dd827d4336c6081d7d8d79a27f2c3;p=lhc%2Fweb%2Fwiklou.git Add MediaWikiTestCase::checkHasDiff3 and use it 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 --- diff --git a/tests/phpunit/MediaWikiTestCase.php b/tests/phpunit/MediaWikiTestCase.php index c619dab805..99c96f2916 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 b02b08a3cb..36fde854d7 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 7304bd9551..0dc18a2919 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 fb20ce667d..cc23d6d5e8 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 d68c3e5438..ed4846bed1 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 );