From: Timo Tijhof Date: Mon, 8 Oct 2012 10:56:20 +0000 (+0200) Subject: Clean and repair many phpunit tests (+ fix implied configuration) X-Git-Tag: 1.31.0-rc.0~22102^2 X-Git-Url: https://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/exercices/journal.php?a=commitdiff_plain;h=181c7cdc8e9b019ff3c7cfa40452a7791be98dff;p=lhc%2Fweb%2Fwiklou.git Clean and repair many phpunit tests (+ fix implied configuration) This commit depends on the introduction of MediaWikiTestCase::setMwGlobals in change Iccf6ea81f4. Various tests already set their globals, but forgot to restore them afterwards, or forgot to call the parent setUp, tearDown... Either way they won't have to anymore with setMwGlobals. Consistent use of function characteristics: * protected function setUp * protected function tearDown * public static function (provide..) (Matching the function signature with PHPUnit/Framework/TestCase.php) Replaces: * public function (setUp|tearDown)\( * protected function $1( * \tfunction (setUp|tearDown)\( * \tprotected function $1( * \tfunction (data|provide)\( * \tpublic static function $1\( Also renamed a few "data#", "provider#" and "provides#" functions to "provide#" for consistency. This also removes confusion where the /media tests had a few private methods called dataFile(), which were sometimes expected to be data providers. Fixes: TimestampTest often failed due to a previous test setting a different language (it tests "1 hour ago" so need to make sure it is set to English). MWNamespaceTest became a lot cleaner now that it executes with a known context. Though the now-redundant code that was removed didn't work anyway because wgContentNamespaces isn't keyed by namespace id, it had them was values... FileBackendTest: * Fixed: "PHP Fatal: Using $this when not in object context" HttpTest * Added comment about: "PHP Fatal: Call to protected MWHttpRequest::__construct()" (too much unrelated code to fix in this commit) ExternalStoreTest * Add an assertTrue as well, without it the test is useless because regardless of whether wgExternalStores is true or false it only uses it if it is an array. Change-Id: I9d2b148e57bada64afeb7d5a99bec0e58f8e1561 --- diff --git a/includes/ExternalStoreDB.php b/includes/ExternalStoreDB.php index 4f35394086..37b1b9335d 100644 --- a/includes/ExternalStoreDB.php +++ b/includes/ExternalStoreDB.php @@ -100,8 +100,8 @@ class ExternalStoreDB { */ function fetchFromURL( $url ) { $path = explode( '/', $url ); - $cluster = $path[2]; - $id = $path[3]; + $cluster = $path[2]; + $id = $path[3]; if ( isset( $path[4] ) ) { $itemID = $path[4]; } else { diff --git a/tests/phpunit/MediaWikiLangTestCase.php b/tests/phpunit/MediaWikiLangTestCase.php index 6dd8ea35c2..3034601132 100644 --- a/tests/phpunit/MediaWikiLangTestCase.php +++ b/tests/phpunit/MediaWikiLangTestCase.php @@ -4,39 +4,26 @@ * Base class that store and restore the Language objects */ abstract class MediaWikiLangTestCase extends MediaWikiTestCase { - private static $oldLang; - private static $oldContLang; - - public function setUp() { - global $wgLanguageCode, $wgLang, $wgContLang; + protected function setUp() { + global $wgLanguageCode, $wgContLang; parent::setUp(); - self::$oldLang = $wgLang; - self::$oldContLang = $wgContLang; - - if( $wgLanguageCode != $wgContLang->getCode() ) { + if ( $wgLanguageCode != $wgContLang->getCode() ) { throw new MWException("Error in MediaWikiLangTestCase::setUp(): " . "\$wgLanguageCode ('$wgLanguageCode') is different from " . "\$wgContLang->getCode() (" . $wgContLang->getCode() . ")" ); } - $wgLanguageCode = 'en'; # For mainpage to be 'Main Page' + $langCode = 'en'; # For mainpage to be 'Main Page' + $langObj = Language::factory( $langCode ); - $wgContLang = $wgLang = Language::factory( $wgLanguageCode ); - MessageCache::singleton()->disable(); - - } + $this->setMwGlobals( array( + 'wgLanguageCode' => $langCode, + 'wgLang' => $langObj, + 'wgContLang' => $langObj, + ) ); - public function tearDown() { - global $wgContLang, $wgLang, $wgLanguageCode; - $wgLang = self::$oldLang; - - $wgContLang = self::$oldContLang; - $wgLanguageCode = $wgContLang->getCode(); - self::$oldContLang = self::$oldLang = null; - - parent::tearDown(); + MessageCache::singleton()->disable(); } - } diff --git a/tests/phpunit/includes/ArticleTest.php b/tests/phpunit/includes/ArticleTest.php index 846d2b86c2..52d9203180 100644 --- a/tests/phpunit/includes/ArticleTest.php +++ b/tests/phpunit/includes/ArticleTest.php @@ -2,19 +2,25 @@ class ArticleTest extends MediaWikiTestCase { - private $title; // holds a Title object - private $article; // holds an article + /** + * @var Title + */ + private $title; + /** + * @var Article + */ + private $article; /** creates a title object and its article object */ - function setUp() { - $this->title = Title::makeTitle( NS_MAIN, 'SomePage' ); + protected function setUp() { + $this->title = Title::makeTitle( NS_MAIN, 'SomePage' ); $this->article = new Article( $this->title ); } /** cleanup title object and its article object */ - function tearDown() { - $this->title = null; + protected function tearDown() { + $this->title = null; $this->article = null; } diff --git a/tests/phpunit/includes/BlockTest.php b/tests/phpunit/includes/BlockTest.php index 0c95b8d149..5ac05baceb 100644 --- a/tests/phpunit/includes/BlockTest.php +++ b/tests/phpunit/includes/BlockTest.php @@ -11,17 +11,15 @@ class BlockTest extends MediaWikiLangTestCase { /* variable used to save up the blockID we insert in this test suite */ private $blockId; - function setUp() { - global $wgContLang; + protected function setUp() { parent::setUp(); - $wgContLang = Language::factory( 'en' ); + $this->setMwGlobals( 'wgContLang', Language::factory( 'en' ) ); } function addDBData() { - //$this->dumpBlocks(); $user = User::newFromName( 'UTBlockee' ); - if( $user->getID() == 0 ) { + if ( $user->getID() == 0 ) { $user->addToDatabase(); $user->setPassword( 'UTBlockeePassword' ); @@ -45,7 +43,7 @@ class BlockTest extends MediaWikiLangTestCase { // its value might change depending on the order the tests are run. // ApiBlockTest insert its own blocks! $newBlockId = $this->block->getId(); - if ($newBlockId) { + if ( $newBlockId ) { $this->blockId = $newBlockId; } else { throw new MWException( "Failed to insert block for BlockTest; old leftover block remaining?" ); @@ -88,7 +86,7 @@ class BlockTest extends MediaWikiLangTestCase { * * This stopped working with r84475 and friends: regression being fixed for bug 29116. * - * @dataProvider dataBug29116 + * @dataProvider provideBug29116Data */ function testBug29116LoadWithEmptyIp( $vagueTarget ) { $this->hideDeprecated( 'Block::load' ); @@ -108,14 +106,14 @@ class BlockTest extends MediaWikiLangTestCase { * because the new function didn't accept empty strings like Block::load() * had. Regression bug 29116. * - * @dataProvider dataBug29116 + * @dataProvider provideBug29116Data */ function testBug29116NewFromTargetWithEmptyIp( $vagueTarget ) { $block = Block::newFromTarget('UTBlockee', $vagueTarget); $this->assertTrue( $this->block->equals( $block ), "newFromTarget() returns the same block as the one that was made when given empty vagueTarget param " . var_export( $vagueTarget, true ) ); } - function dataBug29116() { + public static function provideBug29116Data() { return array( array( null ), array( '' ), diff --git a/tests/phpunit/includes/CdbTest.php b/tests/phpunit/includes/CdbTest.php index b5418dd74f..97fffda03e 100644 --- a/tests/phpunit/includes/CdbTest.php +++ b/tests/phpunit/includes/CdbTest.php @@ -6,7 +6,7 @@ class CdbTest extends MediaWikiTestCase { - public function setUp() { + protected function setUp() { if ( !CdbReader::haveExtension() ) { $this->markTestSkipped( 'Native CDB support is not available' ); } diff --git a/tests/phpunit/includes/DiffHistoryBlobTest.php b/tests/phpunit/includes/DiffHistoryBlobTest.php index cdb6ed2f72..d46e683e1a 100644 --- a/tests/phpunit/includes/DiffHistoryBlobTest.php +++ b/tests/phpunit/includes/DiffHistoryBlobTest.php @@ -1,7 +1,7 @@ markTestSkipped( 'The xdiff extension is not available' ); return; @@ -28,7 +28,7 @@ class DiffHistoryBlobTest extends MediaWikiTestCase { "Hash of " . addcslashes( $input, "\0..\37!@\@\177..\377" ) ); } - function provideXdiffAdler32() { + public static function provideXdiffAdler32() { return array( array( '', 'Empty string' ), array( "\0", 'Null' ), diff --git a/tests/phpunit/includes/EditPageTest.php b/tests/phpunit/includes/EditPageTest.php index 8ecfd7e5b3..eee5f37c44 100644 --- a/tests/phpunit/includes/EditPageTest.php +++ b/tests/phpunit/includes/EditPageTest.php @@ -6,14 +6,14 @@ class EditPageTest extends MediaWikiTestCase { /** - * @dataProvider dataExtractSectionTitle + * @dataProvider provideExtractSectionTitle */ function testExtractSectionTitle( $section, $title ) { $extracted = EditPage::extractSectionTitle( $section ); $this->assertEquals( $title, $extracted ); } - function dataExtractSectionTitle() { + public static function provideExtractSectionTitle() { return array( array( "== Test ==\n\nJust a test section.", diff --git a/tests/phpunit/includes/ExternalStoreTest.php b/tests/phpunit/includes/ExternalStoreTest.php index 92ec7344ac..fe6c60d305 100644 --- a/tests/phpunit/includes/ExternalStoreTest.php +++ b/tests/phpunit/includes/ExternalStoreTest.php @@ -4,29 +4,78 @@ */ class ExternalStoreTest extends MediaWikiTestCase { - private $saved_wgExternalStores; - function setUp() { - global $wgExternalStores; - $this->saved_wgExternalStores = $wgExternalStores ; - } + function testExternalFetchFromURL() { + $this->setMwGlobals( 'wgExternalStores', false ); - function tearDown() { - global $wgExternalStores; - $wgExternalStores = $this->saved_wgExternalStores ; - } + $this->assertFalse( + ExternalStore::fetchFromURL( 'FOO://cluster1/200' ), + 'Deny if wgExternalStores is not set to a non-empty array' + ); - function testExternalStoreDoesNotFetchIncorrectURL() { - global $wgExternalStores; - $wgExternalStores = true; + $this->setMwGlobals( 'wgExternalStores', array( 'FOO' ) ); + $this->assertEquals( + ExternalStore::fetchFromURL( 'FOO://cluster1/200' ), + 'Hello', + 'Allow FOO://cluster1/200' + ); + $this->assertEquals( + ExternalStore::fetchFromURL( 'FOO://cluster1/300/0' ), + 'Hello', + 'Allow FOO://cluster1/300/0' + ); # Assertions for r68900 $this->assertFalse( - ExternalStore::fetchFromURL( 'http://' ) ); + ExternalStore::fetchFromURL( 'ftp.example.org' ), + 'Deny domain ftp.example.org' + ); $this->assertFalse( - ExternalStore::fetchFromURL( 'ftp.wikimedia.org' ) ); + ExternalStore::fetchFromURL( '/example.txt' ), + 'Deny path /example.txt' + ); $this->assertFalse( - ExternalStore::fetchFromURL( '/super.txt' ) ); + ExternalStore::fetchFromURL( 'http://' ), + 'Deny protocol http://' + ); } } +class ExternalStoreFOO { + + protected $data = array( + 'cluster1' => array( + '200' => 'Hello', + '300' => array( + 'Hello', 'World', + ), + ), + ); + + /** + * Fetch data from given URL + * @param $url String: an url of the form FOO://cluster/id or FOO://cluster/id/itemid. + * @return mixed + */ + function fetchFromURL( $url ) { + // Based on ExternalStoreDB + $path = explode( '/', $url ); + $cluster = $path[2]; + $id = $path[3]; + if ( isset( $path[4] ) ) { + $itemID = $path[4]; + } else { + $itemID = false; + } + + if ( !isset( $this->data[$cluster][$id] ) ) { + return null; + } + + if ( $itemID !== false && is_array( $this->data[$cluster][$id] ) && isset( $this->data[$cluster][$id][$itemID] ) ) { + return $this->data[$cluster][$id][$itemID]; + } + + return $this->data[$cluster][$id]; + } +} \ No newline at end of file diff --git a/tests/phpunit/includes/ExtraParserTest.php b/tests/phpunit/includes/ExtraParserTest.php index 903a6d2593..14bc0bb273 100644 --- a/tests/phpunit/includes/ExtraParserTest.php +++ b/tests/phpunit/includes/ExtraParserTest.php @@ -5,18 +5,18 @@ */ class ExtraParserTest extends MediaWikiTestCase { - function setUp() { - global $wgMemc; - global $wgContLang; - global $wgShowDBErrorBacktrace; - global $wgLanguageCode; - global $wgAlwaysUseTidy; + protected function setUp() { + parent::setUp(); - $wgShowDBErrorBacktrace = true; - $wgLanguageCode = 'en'; - $wgContLang = new Language( 'en' ); - $wgMemc = new EmptyBagOStuff; - $wgAlwaysUseTidy = false; + $this->setMwGlobals( array( + 'wgShowDBErrorBacktrace' => true, + 'wgLanguageCode' => 'en', + 'wgContLang' => Language::factory( 'en' ), + 'wgLang' => Language::factory( 'en' ), + 'wgMemc' => new EmptyBagOStuff, + 'wgAlwaysUseTidy' => false, + 'wgCleanSignatures' => true, + ) ); $this->options = new ParserOptions; $this->options->setTemplateCallback( array( __CLASS__, 'statelessFetchTemplate' ) ); @@ -27,11 +27,8 @@ class ExtraParserTest extends MediaWikiTestCase { // Bug 8689 - Long numeric lines kill the parser function testBug8689() { - global $wgLang; global $wgUser; $longLine = '1.' . str_repeat( '1234567890', 100000 ) . "\n"; - - if ( $wgLang === null ) $wgLang = new Language; $t = Title::newFromText( 'Unit test' ); $options = ParserOptions::newFromUser( $wgUser ); @@ -65,14 +62,8 @@ class ExtraParserTest extends MediaWikiTestCase { * cleanSig() makes all templates substs and removes tildes */ function testCleanSig() { - global $wgCleanSignatures; - $oldCleanSignature = $wgCleanSignatures; - $wgCleanSignatures = true; - $title = Title::newFromText( __FUNCTION__ ); $outputText = $this->parser->cleanSig( "{{Foo}} ~~~~" ); - - $wgCleanSignatures = $oldCleanSignature; $this->assertEquals( "{{SUBST:Foo}} ", $outputText ); } @@ -82,13 +73,10 @@ class ExtraParserTest extends MediaWikiTestCase { */ function testCleanSigDisabled() { global $wgCleanSignatures; - $oldCleanSignature = $wgCleanSignatures; $wgCleanSignatures = false; $title = Title::newFromText( __FUNCTION__ ); $outputText = $this->parser->cleanSig( "{{Foo}} ~~~~" ); - - $wgCleanSignatures = $oldCleanSignature; $this->assertEquals( "{{Foo}} ~~~~", $outputText ); } @@ -101,7 +89,7 @@ class ExtraParserTest extends MediaWikiTestCase { $this->assertEquals( Parser::cleanSigInSig( $in), $out ); } - function provideStringsForCleanSigInSig() { + public static function provideStringsForCleanSigInSig() { return array( array( "{{Foo}} ~~~~", "{{Foo}} " ), array( "~~~", "" ), diff --git a/tests/phpunit/includes/FauxResponseTest.php b/tests/phpunit/includes/FauxResponseTest.php index c042004913..35c7f8f42b 100644 --- a/tests/phpunit/includes/FauxResponseTest.php +++ b/tests/phpunit/includes/FauxResponseTest.php @@ -25,7 +25,7 @@ class FauxResponseTest extends MediaWikiTestCase { var $response; - function setUp() { + protected function setUp() { $this->response = new FauxResponse; } diff --git a/tests/phpunit/includes/GlobalFunctions/GlobalTest.php b/tests/phpunit/includes/GlobalFunctions/GlobalTest.php index 9097d301f5..4d53d065d9 100644 --- a/tests/phpunit/includes/GlobalFunctions/GlobalTest.php +++ b/tests/phpunit/includes/GlobalFunctions/GlobalTest.php @@ -1,22 +1,32 @@ originals['wgReadOnlyFile'] = $wgReadOnlyFile; - $this->originals['wgUrlProtocols'] = $wgUrlProtocols; - $wgReadOnlyFile = tempnam( wfTempDir(), "mwtest_readonly" ); - $wgUrlProtocols[] = 'file://'; - unlink( $wgReadOnlyFile ); + protected function setUp() { + parent::setUp(); + + $readOnlyFile = tempnam( wfTempDir(), "mwtest_readonly" ); + unlink( $readOnlyFile ); + + $this->setMwGlobals( array( + 'wgReadOnlyFile' => $readOnlyFile, + 'wgUrlProtocols' => array( + 'http://', + 'https://', + 'mailto:', + '//', + 'file://', # Non-default + ), + ) ); } - function tearDown() { - global $wgReadOnlyFile, $wgUrlProtocols; + protected function tearDown() { + global $wgReadOnlyFile; + if ( file_exists( $wgReadOnlyFile ) ) { unlink( $wgReadOnlyFile ); } - $wgReadOnlyFile = $this->originals['wgReadOnlyFile']; - $wgUrlProtocols = $this->originals['wgUrlProtocols']; + + parent::tearDown(); } /** @dataProvider provideForWfArrayDiff2 */ @@ -27,7 +37,7 @@ class GlobalTest extends MediaWikiTestCase { } // @todo Provide more tests - public function provideForWfArrayDiff2() { + public static function provideForWfArrayDiff2() { // $a $b $expected return array( array( @@ -100,7 +110,7 @@ class GlobalTest extends MediaWikiTestCase { $this->assertTrue( $end > $start, "Time is running backwards!" ); } - function dataArrayToCGI() { + public static function provideArrayToCGI() { return array( array( array(), '' ), // empty array( array( 'foo' => 'bar' ), 'foo=bar' ), // string test @@ -119,7 +129,7 @@ class GlobalTest extends MediaWikiTestCase { } /** - * @dataProvider dataArrayToCGI + * @dataProvider provideArrayToCGI */ function testArrayToCGI( $array, $result ) { $this->assertEquals( $result, wfArrayToCGI( $array ) ); @@ -134,7 +144,7 @@ class GlobalTest extends MediaWikiTestCase { array( 'foo' => 'bar', 'baz' => 'overridden value' ) ) ); } - function dataCgiToArray() { + public static function provideCgiToArray() { return array( array( '', array() ), // empty array( 'foo=bar', array( 'foo' => 'bar' ) ), // string @@ -150,13 +160,13 @@ class GlobalTest extends MediaWikiTestCase { } /** - * @dataProvider dataCgiToArray + * @dataProvider provideCgiToArray */ function testCgiToArray( $cgi, $result ) { $this->assertEquals( $result, wfCgiToArray( $cgi ) ); } - function dataCgiRoundTrip() { + public static function provideCgiRoundTrip() { return array( array( '' ), array( 'foo=bar' ), @@ -170,7 +180,7 @@ class GlobalTest extends MediaWikiTestCase { } /** - * @dataProvider dataCgiRoundTrip + * @dataProvider provideCgiRoundTrip */ function testCgiRoundTrip( $cgi ) { $this->assertEquals( $cgi, wfArrayToCGI( wfCgiToArray( $cgi ) ) ); @@ -437,7 +447,7 @@ class GlobalTest extends MediaWikiTestCase { } /** array( shorthand, expected integer ) */ - public function provideShorthand() { + public static function provideShorthand() { return array( # Null, empty ... array( '', -1), diff --git a/tests/phpunit/includes/GlobalFunctions/wfAssembleUrlTest.php b/tests/phpunit/includes/GlobalFunctions/wfAssembleUrlTest.php index be6c99e753..bed435a64f 100644 --- a/tests/phpunit/includes/GlobalFunctions/wfAssembleUrlTest.php +++ b/tests/phpunit/includes/GlobalFunctions/wfAssembleUrlTest.php @@ -19,7 +19,7 @@ class wfAssembleUrl extends MediaWikiTestCase { * * @return array */ - public function provideURLParts() { + public static function provideURLParts() { $schemes = array( '' => array(), '//' => array( diff --git a/tests/phpunit/includes/GlobalFunctions/wfExpandUrlTest.php b/tests/phpunit/includes/GlobalFunctions/wfExpandUrlTest.php index 8867cd5d4c..cb6e6c4564 100644 --- a/tests/phpunit/includes/GlobalFunctions/wfExpandUrlTest.php +++ b/tests/phpunit/includes/GlobalFunctions/wfExpandUrlTest.php @@ -32,7 +32,7 @@ class wfExpandUrl extends MediaWikiTestCase { * * @return array */ - public function provideExpandableUrls() { + public static function provideExpandableUrls() { $modes = array( 'http', 'https' ); $servers = array( 'http' => 'http://example.com', diff --git a/tests/phpunit/includes/GlobalFunctions/wfRemoveDotSegmentsTest.php b/tests/phpunit/includes/GlobalFunctions/wfRemoveDotSegmentsTest.php index 1cf0e0fb2c..af784bdea0 100644 --- a/tests/phpunit/includes/GlobalFunctions/wfRemoveDotSegmentsTest.php +++ b/tests/phpunit/includes/GlobalFunctions/wfRemoveDotSegmentsTest.php @@ -18,7 +18,7 @@ class wfRemoveDotSegments extends MediaWikiTestCase { * * @return array */ - public function providePaths() { + public static function providePaths() { return array( array( '/a/b/c/./../../g', '/a/g' ), array( 'mid/content=5/../6', 'mid/6' ), diff --git a/tests/phpunit/includes/GlobalFunctions/wfUrlencodeTest.php b/tests/phpunit/includes/GlobalFunctions/wfUrlencodeTest.php index cd1a8dbd24..673702e5f1 100644 --- a/tests/phpunit/includes/GlobalFunctions/wfUrlencodeTest.php +++ b/tests/phpunit/includes/GlobalFunctions/wfUrlencodeTest.php @@ -85,7 +85,7 @@ class wfUrlencodeTest extends MediaWikiTestCase { * If you want to add other HTTP server name, you will have to add a new * testing method much like the testEncodingUrlWith() method above. */ - public function provideURLS() { + public static function provideURLS() { return array( ### RFC 1738 chars // + is not safe diff --git a/tests/phpunit/includes/HttpTest.php b/tests/phpunit/includes/HttpTest.php index 263383f19f..155bd3123a 100644 --- a/tests/phpunit/includes/HttpTest.php +++ b/tests/phpunit/includes/HttpTest.php @@ -17,7 +17,7 @@ class HttpTest extends MediaWikiTestCase { $this->assertEquals( $expected, $ok, $msg ); } - function cookieDomains() { + public static function cookieDomains() { return array( array( false, "org"), array( false, ".org"), @@ -62,7 +62,7 @@ class HttpTest extends MediaWikiTestCase { /** * Feeds URI to test a long regular expression in Http::isValidURI */ - function provideURI() { + public static function provideURI() { /** Format: 'boolean expectation', 'URI to test', 'Optional message' */ return array( array( false, '¿non sens before!! http://a', 'Allow anything before URI' ), @@ -131,6 +131,10 @@ class HttpTest extends MediaWikiTestCase { * handles header reporting on redirect pages, and will need to be * rewritten when bug 29232 is taken care of (high-level handling of * HTTP redirects). + * @group Broken + * MWHttpRequestTester's constructor is private, needs to use + * MWHttpRequestTester::factory instead. However the objects coming + * from that won't have MWHttpRequestTester::setRespHeaders... */ function testRelativeRedirections() { $h = new MWHttpRequestTester( 'http://oldsite/file.ext' ); diff --git a/tests/phpunit/includes/IPTest.php b/tests/phpunit/includes/IPTest.php index f50b2fe9be..c4a6c55c68 100644 --- a/tests/phpunit/includes/IPTest.php +++ b/tests/phpunit/includes/IPTest.php @@ -405,7 +405,7 @@ class IPTest extends MediaWikiTestCase { } /** Provider for testIPIsInRange() */ - function provideIPsAndRanges() { + public static function provideIPsAndRanges() { # Format: (expected boolean, address, range, optional message) return array( # IPv4 @@ -443,7 +443,7 @@ class IPTest extends MediaWikiTestCase { /** * Provider for IP::splitHostAndPort() */ - function provideSplitHostAndPort() { + public static function provideSplitHostAndPort() { return array( array( false, '[', 'Unclosed square bracket' ), array( false, '[::', 'Unclosed square bracket 2' ), @@ -474,7 +474,7 @@ class IPTest extends MediaWikiTestCase { /** * Provider for IP::combineHostAndPort() */ - function provideCombineHostAndPort() { + public static function provideCombineHostAndPort() { return array( array( '[::1]', array( '::1', 2, 2 ), 'IPv6 default port' ), array( '[::1]:2', array( '::1', 2, 3 ), 'IPv6 non-default port' ), @@ -494,7 +494,7 @@ class IPTest extends MediaWikiTestCase { /** * Provider for IP::testSanitizeRange() */ - function provideIPCIDRs() { + public static function provideIPCIDRs() { return array( array( '35.56.31.252/16', '35.56.0.0/16', 'IPv4 range' ), array( '135.16.21.252/24', '135.16.21.0/24', 'IPv4 range' ), @@ -518,7 +518,7 @@ class IPTest extends MediaWikiTestCase { /** * Provider for IP::testPrettifyIP() */ - function provideIPsToPrettify() { + public static function provideIPsToPrettify() { return array( array( '0:0:0:0:0:0:0:0', '::' ), array( '0:0:0::0:0:0', '::' ), diff --git a/tests/phpunit/includes/JsonTest.php b/tests/phpunit/includes/JsonTest.php index 75dd18d52b..9b508f7096 100644 --- a/tests/phpunit/includes/JsonTest.php +++ b/tests/phpunit/includes/JsonTest.php @@ -3,31 +3,25 @@ class JsonTest extends MediaWikiTestCase { function testPhpBug46944Test() { - $this->assertNotEquals( '\ud840\udc00', strtolower( FormatJson::encode( "\xf0\xa0\x80\x80" ) ), 'Test encoding an broken json_encode character (U+20000)' ); - - + } function testDecodeVarTypes() { - $this->assertInternalType( 'object', FormatJson::decode( '{"Name": "Cheeso", "Rank": 7}' ), 'Default to object' ); - + $this->assertInternalType( 'array', FormatJson::decode( '{"Name": "Cheeso", "Rank": 7}', true ), 'Optional array' ); - } - } - diff --git a/tests/phpunit/includes/LanguageConverterTest.php b/tests/phpunit/includes/LanguageConverterTest.php index baf28b07fa..9fc6f4d4da 100644 --- a/tests/phpunit/includes/LanguageConverterTest.php +++ b/tests/phpunit/includes/LanguageConverterTest.php @@ -4,24 +4,28 @@ class LanguageConverterTest extends MediaWikiLangTestCase { protected $lang = null; protected $lc = null; - function setUp() { + protected function setUp() { parent::setUp(); - global $wgMemc, $wgRequest, $wgUser, $wgContLang; - $wgUser = new User; - $wgRequest = new FauxRequest( array() ); - $wgMemc = new EmptyBagOStuff; - $wgContLang = Language::factory( 'tg' ); + $this->setMwGlobals( array( + 'wgContLang' => Language::factory( 'tg' ), + 'wgDefaultLanguageVariant' => false, + 'wgMemc' => new EmptyBagOStuff, + 'wgRequest' => new FauxRequest( array() ), + 'wgUser' => new User, + ) ); + $this->lang = new LanguageToTest(); - $this->lc = new TestConverter( $this->lang, 'tg', - array( 'tg', 'tg-latn' ) ); + $this->lc = new TestConverter( + $this->lang, 'tg', + array( 'tg', 'tg-latn' ) + ); } - function tearDown() { - global $wgMemc; - unset( $wgMemc ); + protected function tearDown() { unset( $this->lc ); unset( $this->lang ); + parent::tearDown(); } @@ -71,7 +75,7 @@ class LanguageConverterTest extends MediaWikiLangTestCase { } function testGetPreferredVariantHeaderUserVsUrl() { - global $wgRequest, $wgUser, $wgContLang; + global $wgContLang, $wgRequest, $wgUser; $wgContLang = Language::factory( 'tg-latn' ); $wgRequest->setVal( 'variant', 'tg' ); diff --git a/tests/phpunit/includes/LinksUpdateTest.php b/tests/phpunit/includes/LinksUpdateTest.php index 8e37b139bd..40bba7e859 100644 --- a/tests/phpunit/includes/LinksUpdateTest.php +++ b/tests/phpunit/includes/LinksUpdateTest.php @@ -25,7 +25,7 @@ class LinksUpdateTest extends MediaWikiTestCase { ); } - function setUp() { + protected function setUp() { $dbw = wfGetDB( DB_MASTER ); $dbw->replace( 'interwiki', diff --git a/tests/phpunit/includes/LocalFileTest.php b/tests/phpunit/includes/LocalFileTest.php index 5b26b89ce3..c5a9dc198e 100644 --- a/tests/phpunit/includes/LocalFileTest.php +++ b/tests/phpunit/includes/LocalFileTest.php @@ -6,10 +6,11 @@ */ class LocalFileTest extends MediaWikiTestCase { - function setUp() { - global $wgCapitalLinks; - $wgCapitalLinks = true; + protected function setUp() { + parent::setUp(); + + $this->setMwGlobals( 'wgCapitalLinks', true ); $info = array( 'name' => 'test', diff --git a/tests/phpunit/includes/MWFunctionTest.php b/tests/phpunit/includes/MWFunctionTest.php index ed5e760296..f7be59f601 100644 --- a/tests/phpunit/includes/MWFunctionTest.php +++ b/tests/phpunit/includes/MWFunctionTest.php @@ -3,7 +3,6 @@ class MWFunctionTest extends MediaWikiTestCase { function testCallUserFuncWorkarounds() { - $this->assertEquals( call_user_func( array( 'MWFunctionTest', 'someMethod' ) ), MWFunction::call( 'MWFunctionTest::someMethod' ) @@ -12,9 +11,7 @@ class MWFunctionTest extends MediaWikiTestCase { call_user_func( array( 'MWFunctionTest', 'someMethod' ), 'foo', 'bar', 'baz' ), MWFunction::call( 'MWFunctionTest::someMethod', 'foo', 'bar', 'baz' ) ); - - - + $this->assertEquals( call_user_func_array( array( 'MWFunctionTest', 'someMethod' ), array() ), MWFunction::callArray( 'MWFunctionTest::someMethod', array() ) @@ -23,38 +20,33 @@ class MWFunctionTest extends MediaWikiTestCase { call_user_func_array( array( 'MWFunctionTest', 'someMethod' ), array( 'foo', 'bar', 'baz' ) ), MWFunction::callArray( 'MWFunctionTest::someMethod', array( 'foo', 'bar', 'baz' ) ) ); - } function testNewObjFunction() { - $arg1 = 'Foo'; $arg2 = 'Bar'; $arg3 = array( 'Baz' ); $arg4 = new ExampleObject; - + $args = array( $arg1, $arg2, $arg3, $arg4 ); - + $newObject = new MWBlankClass( $arg1, $arg2, $arg3, $arg4 ); - $this->assertEquals( MWFunction::newObj( 'MWBlankClass', $args )->args, $newObject->args ); - + $this->assertEquals( MWFunction::newObj( 'MWBlankClass', $args, true )->args, $newObject->args, 'Works even with PHP version < 5.1.3' ); - } /** * @expectedException MWException */ function testCallingParentFails() { - MWFunction::call( 'parent::foo' ); } @@ -62,7 +54,6 @@ class MWFunctionTest extends MediaWikiTestCase { * @expectedException MWException */ function testCallingSelfFails() { - MWFunction::call( 'self::foo' ); } @@ -73,13 +64,12 @@ class MWFunctionTest extends MediaWikiTestCase { } class MWBlankClass { - + public $args = array(); - + function __construct( $arg1, $arg2, $arg3, $arg4 ) { $this->args = array( $arg1, $arg2, $arg3, $arg4 ); } - } class ExampleObject { diff --git a/tests/phpunit/includes/MWNamespaceTest.php b/tests/phpunit/includes/MWNamespaceTest.php index 3b05d675d7..5de5cc95da 100644 --- a/tests/phpunit/includes/MWNamespaceTest.php +++ b/tests/phpunit/includes/MWNamespaceTest.php @@ -11,21 +11,22 @@ * */ class MWNamespaceTest extends MediaWikiTestCase { - /** - * Sets up the fixture, for example, opens a network connection. - * This method is called before a test is executed. - */ protected function setUp() { - } + parent::setUp(); - /** - * Tears down the fixture, for example, closes a network connection. - * This method is called after a test is executed. - */ - protected function tearDown() { + $this->setMwGlobals( array( + 'wgContentNamespaces' => array( NS_MAIN ), + 'wgNamespacesWithSubpages' => array( + NS_TALK => true, + NS_USER => true, + NS_USER_TALK => true, + ), + 'wgCapitalLinks' => true, + 'wgCapitalLinkOverrides' => array(), + 'wgNonincludableNamespaces' => array(), + ) ); } - #### START OF TESTS ######################################################### /** @@ -268,77 +269,36 @@ class MWNamespaceTest extends MediaWikiTestCase { public function testIsContent() { // NS_MAIN is a content namespace per DefaultSettings.php // and per function definition. - $this->assertIsContent( NS_MAIN ); - global $wgContentNamespaces; - - $saved = $wgContentNamespaces; - - $wgContentNamespaces[] = NS_MAIN; $this->assertIsContent( NS_MAIN ); // Other namespaces which are not expected to be content - if ( isset( $wgContentNamespaces[NS_MEDIA] ) ) { - unset( $wgContentNamespaces[NS_MEDIA] ); - } - $this->assertIsNotContent( NS_MEDIA ); - if ( isset( $wgContentNamespaces[NS_SPECIAL] ) ) { - unset( $wgContentNamespaces[NS_SPECIAL] ); - } + $this->assertIsNotContent( NS_MEDIA ); $this->assertIsNotContent( NS_SPECIAL ); - - if ( isset( $wgContentNamespaces[NS_TALK] ) ) { - unset( $wgContentNamespaces[NS_TALK] ); - } $this->assertIsNotContent( NS_TALK ); - - if ( isset( $wgContentNamespaces[NS_USER] ) ) { - unset( $wgContentNamespaces[NS_USER] ); - } $this->assertIsNotContent( NS_USER ); - - if ( isset( $wgContentNamespaces[NS_CATEGORY] ) ) { - unset( $wgContentNamespaces[NS_CATEGORY] ); - } $this->assertIsNotContent( NS_CATEGORY ); - - if ( isset( $wgContentNamespaces[100] ) ) { - unset( $wgContentNamespaces[100] ); - } $this->assertIsNotContent( 100 ); - - $wgContentNamespaces = $saved; } /** * Similar to testIsContent() but alters the $wgContentNamespaces * global variable. */ - public function testIsContentWithAdditionsInWgContentNamespaces() { - // NS_MAIN is a content namespace per DefaultSettings.php - // and per function definition. - $this->assertIsContent( NS_MAIN ); + public function testIsContentAdvanced() { + global $wgContentNamespaces; - // Tests that user defined namespace #252 is not content: + // Test that user defined namespace #252 is not content $this->assertIsNotContent( 252 ); - # @todo FIXME: Is global saving really required for PHPUnit? // Bless namespace # 252 as a content namespace - global $wgContentNamespaces; - $savedGlobal = $wgContentNamespaces; $wgContentNamespaces[] = 252; + $this->assertIsContent( 252 ); // Makes sure NS_MAIN was not impacted $this->assertIsContent( NS_MAIN ); - - // Restore global - $wgContentNamespaces = $savedGlobal; - - // Verify namespaces after global restauration - $this->assertIsContent( NS_MAIN ); - $this->assertIsNotContent( 252 ); } public function testIsWatchable() { @@ -356,31 +316,21 @@ class MWNamespaceTest extends MediaWikiTestCase { } public function testHasSubpages() { + global $wgNamespacesWithSubpages; + // Special namespaces: $this->assertHasNotSubpages( NS_MEDIA ); $this->assertHasNotSubpages( NS_SPECIAL ); - // namespaces without subpages - # save up global - global $wgNamespacesWithSubpages; - $saved = null; - if( array_key_exists( NS_MAIN, $wgNamespacesWithSubpages ) ) { - $saved = $wgNamespacesWithSubpages[NS_MAIN]; - unset( $wgNamespacesWithSubpages[NS_MAIN] ); - } - + // Namespaces without subpages $this->assertHasNotSubpages( NS_MAIN ); $wgNamespacesWithSubpages[NS_MAIN] = true; $this->assertHasSubpages( NS_MAIN ); + $wgNamespacesWithSubpages[NS_MAIN] = false; $this->assertHasNotSubpages( NS_MAIN ); - # restore global - if( $saved !== null ) { - $wgNamespacesWithSubpages[NS_MAIN] = $saved; - } - // Some namespaces with subpages $this->assertHasSubpages( NS_TALK ); $this->assertHasSubpages( NS_USER ); @@ -390,22 +340,25 @@ class MWNamespaceTest extends MediaWikiTestCase { /** */ public function testGetContentNamespaces() { + global $wgContentNamespaces; + $this->assertEquals( array( NS_MAIN ), MWNamespace::getcontentNamespaces(), '$wgContentNamespaces is an array with only NS_MAIN by default' ); - global $wgContentNamespaces; - $saved = $wgContentNamespaces; # test !is_array( $wgcontentNamespaces ) $wgContentNamespaces = ''; $this->assertEquals( NS_MAIN, MWNamespace::getcontentNamespaces() ); + $wgContentNamespaces = false; $this->assertEquals( NS_MAIN, MWNamespace::getcontentNamespaces() ); + $wgContentNamespaces = null; $this->assertEquals( NS_MAIN, MWNamespace::getcontentNamespaces() ); + $wgContentNamespaces = 5; $this->assertEquals( NS_MAIN, MWNamespace::getcontentNamespaces() ); @@ -433,8 +386,6 @@ class MWNamespaceTest extends MediaWikiTestCase { array( NS_MAIN, NS_USER, NS_CATEGORY ), MWNamespace::getcontentNamespaces() ); - - $wgContentNamespaces = $saved; } /** @@ -504,24 +455,20 @@ class MWNamespaceTest extends MediaWikiTestCase { */ public function testIsCapitalizedWithWgCapitalLinks() { global $wgCapitalLinks; - // Save the global to easily reset to MediaWiki default settings - $savedGlobal = $wgCapitalLinks; - $wgCapitalLinks = true; $this->assertIsCapitalized( NS_PROJECT ); $this->assertIsCapitalized( NS_PROJECT_TALK ); $wgCapitalLinks = false; + // hardcoded namespaces (see above function) are still capitalized: $this->assertIsCapitalized( NS_SPECIAL ); $this->assertIsCapitalized( NS_USER ); $this->assertIsCapitalized( NS_MEDIAWIKI ); + // setting is correctly applied $this->assertIsNotCapitalized( NS_PROJECT ); $this->assertIsNotCapitalized( NS_PROJECT_TALK ); - - // reset global state: - $wgCapitalLinks = $savedGlobal; } /** @@ -532,12 +479,11 @@ class MWNamespaceTest extends MediaWikiTestCase { */ public function testIsCapitalizedWithWgCapitalLinkOverrides() { global $wgCapitalLinkOverrides; - // Save the global to easily reset to MediaWiki default settings - $savedGlobal = $wgCapitalLinkOverrides; // Test default settings $this->assertIsCapitalized( NS_PROJECT ); $this->assertIsCapitalized( NS_PROJECT_TALK ); + // hardcoded namespaces (see above function) are capitalized: $this->assertIsCapitalized( NS_SPECIAL ); $this->assertIsCapitalized( NS_USER ); @@ -547,20 +493,19 @@ class MWNamespaceTest extends MediaWikiTestCase { $wgCapitalLinkOverrides[NS_SPECIAL] = false; $wgCapitalLinkOverrides[NS_USER] = false; $wgCapitalLinkOverrides[NS_MEDIAWIKI] = false; + $this->assertIsCapitalized( NS_SPECIAL ); $this->assertIsCapitalized( NS_USER ); $this->assertIsCapitalized( NS_MEDIAWIKI ); - $wgCapitalLinkOverrides = $savedGlobal; $wgCapitalLinkOverrides[NS_PROJECT] = false; $this->assertIsNotCapitalized( NS_PROJECT ); + $wgCapitalLinkOverrides[NS_PROJECT] = true ; $this->assertIsCapitalized( NS_PROJECT ); - unset( $wgCapitalLinkOverrides[NS_PROJECT] ); - $this->assertIsCapitalized( NS_PROJECT ); - // reset global state: - $wgCapitalLinkOverrides = $savedGlobal; + unset( $wgCapitalLinkOverrides[NS_PROJECT] ); + $this->assertIsCapitalized( NS_PROJECT ); } public function testHasGenderDistinction() { @@ -578,10 +523,10 @@ class MWNamespaceTest extends MediaWikiTestCase { public function testIsNonincludable() { global $wgNonincludableNamespaces; + $wgNonincludableNamespaces = array( NS_USER ); $this->assertTrue( MWNamespace::isNonincludable( NS_USER ) ); - $this->assertFalse( MWNamespace::isNonincludable( NS_TEMPLATE ) ); } diff --git a/tests/phpunit/includes/MessageTest.php b/tests/phpunit/includes/MessageTest.php index 20181fd457..22450dc431 100644 --- a/tests/phpunit/includes/MessageTest.php +++ b/tests/phpunit/includes/MessageTest.php @@ -1,6 +1,14 @@ setMwGlobals( array( + 'wgLang' => Language::factory( 'en' ), + 'wgForceUIMsgAsContentMsg' => array(), + ) ); + } function testExists() { $this->assertTrue( wfMessage( 'mainpage' )->exists() ); @@ -43,16 +51,11 @@ class MessageTest extends MediaWikiLangTestCase { function testInContentLanguage() { global $wgLang, $wgForceUIMsgAsContentMsg; - $oldLang = $wgLang; $wgLang = Language::factory( 'fr' ); $this->assertEquals( 'Main Page', wfMessage( 'mainpage' )->inContentLanguage()->plain(), 'ForceUIMsg disabled' ); $wgForceUIMsgAsContentMsg['testInContentLanguage'] = 'mainpage'; $this->assertEquals( 'Accueil', wfMessage( 'mainpage' )->inContentLanguage()->plain(), 'ForceUIMsg enabled' ); - - /* Restore globals */ - $wgLang = $oldLang; - unset( $wgForceUIMsgAsContentMsg['testInContentLanguage'] ); } /** diff --git a/tests/phpunit/includes/ParserOptionsTest.php b/tests/phpunit/includes/ParserOptionsTest.php index 59c955fe89..5b2adaf9fd 100644 --- a/tests/phpunit/includes/ParserOptionsTest.php +++ b/tests/phpunit/includes/ParserOptionsTest.php @@ -5,15 +5,19 @@ class ParserOptionsTest extends MediaWikiTestCase { private $popts; private $pcache; - function setUp() { - global $wgContLang, $wgUser, $wgLanguageCode; - $wgContLang = Language::factory( $wgLanguageCode ); - $this->popts = ParserOptions::newFromUserAndLang( $wgUser, $wgContLang ); - $this->pcache = ParserCache::singleton(); - } + protected function setUp() { + global $wgLanguageCode, $wgUser; + parent::setUp(); + + $langObj = Language::factory( $wgLanguageCode ); + + $this->setMwGlobals( array( + 'wgContLang' => $langObj, + 'wgUseDynamicDates' => true, + ) ); - function tearDown() { - parent::tearDown(); + $this->popts = ParserOptions::newFromUserAndLang( $wgUser, $langObj ); + $this->pcache = ParserCache::singleton(); } /** @@ -21,14 +25,12 @@ class ParserOptionsTest extends MediaWikiTestCase { * @group Database */ function testGetParserCacheKeyWithDynamicDates() { - global $wgUseDynamicDates; - $wgUseDynamicDates = true; - $title = Title::newFromText( "Some test article" ); $page = WikiPage::factory( $title ); $pcacheKeyBefore = $this->pcache->getKey( $page, $this->popts ); $this->assertNotNull( $this->popts->getDateFormat() ); + $pcacheKeyAfter = $this->pcache->getKey( $page, $this->popts ); $this->assertEquals( $pcacheKeyBefore, $pcacheKeyAfter ); } diff --git a/tests/phpunit/includes/PathRouterTest.php b/tests/phpunit/includes/PathRouterTest.php index f62745841d..4487210a50 100644 --- a/tests/phpunit/includes/PathRouterTest.php +++ b/tests/phpunit/includes/PathRouterTest.php @@ -5,7 +5,7 @@ class PathRouterTest extends MediaWikiTestCase { - public function setUp() { + protected function setUp() { $router = new PathRouter; $router->add("/wiki/$1"); $this->basicRouter = $router; @@ -182,7 +182,7 @@ class PathRouterTest extends MediaWikiTestCase { $this->assertEquals( $matches, array( 'title' => "Title_With Space" ) ); } - public function dataRegexpChars() { + public static function provideRegexpChars() { return array( array( "$" ), array( "$1" ), @@ -193,7 +193,7 @@ class PathRouterTest extends MediaWikiTestCase { /** * Make sure the router doesn't break on special characters like $ used in regexp replacements - * @dataProvider dataRegexpChars + * @dataProvider provideRegexpChars */ public function testRegexpChars( $char ) { $matches = $this->basicRouter->parse( "/wiki/$char" ); diff --git a/tests/phpunit/includes/PreferencesTest.php b/tests/phpunit/includes/PreferencesTest.php index 0e12317791..1a8a4cc79d 100644 --- a/tests/phpunit/includes/PreferencesTest.php +++ b/tests/phpunit/includes/PreferencesTest.php @@ -7,7 +7,6 @@ class PreferencesTest extends MediaWikiTestCase { function __construct() { parent::__construct(); - global $wgEnableEmail; $this->prefUsers['noemail'] = new User; @@ -23,9 +22,12 @@ class PreferencesTest extends MediaWikiTestCase { $this->context = new RequestContext; $this->context->setTitle( Title::newFromText('PreferencesTest') ); + } + + protected function setUp() { + parent::setUp(); - //some tests depends on email setting - $wgEnableEmail = true; + $this->setMwGlobals( 'wgEnableEmail', true ); } /** diff --git a/tests/phpunit/includes/RecentChangeTest.php b/tests/phpunit/includes/RecentChangeTest.php index fbf271cc5c..a1f808c68b 100644 --- a/tests/phpunit/includes/RecentChangeTest.php +++ b/tests/phpunit/includes/RecentChangeTest.php @@ -220,7 +220,8 @@ class RecentChangeTest extends MediaWikiTestCase { * @todo: Emulate these edits somehow and extract * raw edit summary from RecentChange object * -- - + */ +/* function testIrcMsgForBlankingAES() { // $this->context->msg( 'autosumm-blank', .. ); } @@ -237,8 +238,7 @@ class RecentChangeTest extends MediaWikiTestCase { // $this->context->msg( 'undo-summary', .. ); } - * -- - */ +*/ /** * @param $expected String Expected IRC text without colors codes diff --git a/tests/phpunit/includes/ResourceLoaderTest.php b/tests/phpunit/includes/ResourceLoaderTest.php index ab70483900..893d2600a7 100644 --- a/tests/phpunit/includes/ResourceLoaderTest.php +++ b/tests/phpunit/includes/ResourceLoaderTest.php @@ -15,7 +15,7 @@ class ResourceLoaderTest extends MediaWikiTestCase { } /* Provider Methods */ - public function provideValidModules() { + public static function provideValidModules() { return array( array( 'TEST.validModule1', new ResourceLoaderTestModule() ), ); @@ -61,7 +61,7 @@ class ResourceLoaderTest extends MediaWikiTestCase { $this->assertEquals( $modules, ResourceLoaderContext::expandModuleNames( $packed ), $desc ); } - public function providePackedModules() { + public static function providePackedModules() { return array( array( 'Example from makePackedModulesString doc comment', diff --git a/tests/phpunit/includes/RevisionStorageTest.php b/tests/phpunit/includes/RevisionStorageTest.php index 8a7facece4..d2ecc55ee8 100644 --- a/tests/phpunit/includes/RevisionStorageTest.php +++ b/tests/phpunit/includes/RevisionStorageTest.php @@ -34,7 +34,7 @@ class RevisionStorageTest extends MediaWikiTestCase { 'iwlinks' ) ); } - public function setUp() { + protected function setUp() { if ( !$this->the_page ) { $this->the_page = $this->createPage( 'RevisionStorageTest_the_page', "just a dummy page" ); } @@ -310,7 +310,7 @@ class RevisionStorageTest extends MediaWikiTestCase { $this->assertEquals( 'some testing text', $rev->getText() ); } - public function dataUserWasLastToEdit() { + public static function provideUserWasLastToEdit() { return array( array( #0 3, true, # actually the last edit @@ -328,7 +328,7 @@ class RevisionStorageTest extends MediaWikiTestCase { } /** - * @dataProvider dataUserWasLastToEdit + * @dataProvider provideUserWasLastToEdit */ public function testUserWasLastToEdit( $sinceIdx, $expectedLast ) { $userA = \User::newFromName( "RevisionStorageTest_userA" ); diff --git a/tests/phpunit/includes/RevisionTest.php b/tests/phpunit/includes/RevisionTest.php index d7654db9f2..e8f298b0b8 100644 --- a/tests/phpunit/includes/RevisionTest.php +++ b/tests/phpunit/includes/RevisionTest.php @@ -1,25 +1,14 @@ setMwGlobals( array( + 'wgContLang' => Language::factory( 'en' ), 'wgLegacyEncoding' => false, 'wgCompressRevisions' => false, - ); - foreach ( $globalSet as $var => $data ) { - $this->saveGlobals[$var] = $GLOBALS[$var]; - $GLOBALS[$var] = $data; - } - } - - function tearDown() { - foreach ( $this->saveGlobals as $var => $data ) { - $GLOBALS[$var] = $data; - } + ) ); } function testGetRevisionText() { @@ -107,7 +96,10 @@ class RevisionTest extends MediaWikiTestCase { } function testCompressRevisionTextUtf8Gzip() { - $GLOBALS['wgCompressRevisions'] = true; + global $wgCompressRevisions; + + $wgCompressRevisions = true; + $row = new stdClass; $row->old_text = "Wiki est l'\xc3\xa9cole superieur !"; $row->old_flags = Revision::compressRevisionText( $row->old_text ); diff --git a/tests/phpunit/includes/SampleTest.php b/tests/phpunit/includes/SampleTest.php index 59ba0a047e..2f55de4da3 100644 --- a/tests/phpunit/includes/SampleTest.php +++ b/tests/phpunit/includes/SampleTest.php @@ -5,18 +5,23 @@ class TestSample extends MediaWikiLangTestCase { /** * Anything that needs to happen before your tests should go here. */ - function setUp() { - global $wgContLang; + protected function setUp() { + // Be sure to do call the parent setup and teardown functions. + // This makes sure that all the various cleanup and restorations + // happen as they should (including the restoration for setMwGlobals). parent::setUp(); - /* For example, we need to set $wgContLang for creating a new Title */ - $wgContLang = Language::factory( 'en' ); + // This sets the globals and will restore them automatically + // after each test. + $this->setMwGlobals( array( + 'wgContLang' => Language::factory( 'en' ), + ) ); } /** * Anything cleanup you need to do should go here. */ - function tearDown() { + protected function tearDown() { parent::tearDown(); } @@ -40,8 +45,10 @@ class TestSample extends MediaWikiLangTestCase { /** * If you want to run a the same test with a variety of data. use a data provider. * see: http://www.phpunit.de/manual/3.4/en/writing-tests-for-phpunit.html + * + * Note: Data providers are always called statically and outside setUp/tearDown! */ - public function provideTitles() { + public static function provideTitles() { return array( array( 'Text', NS_MEDIA, 'Media:Text' ), array( 'Text', null, 'Text' ), @@ -78,6 +85,7 @@ class TestSample extends MediaWikiLangTestCase { * example) as arguments to the next method (e.g. $title in * testTitleDepends is whatever testInitialCreatiion returned.) */ + /** * @depends testSetUpMainPageTitleForNextTest * See http://www.phpunit.de/manual/3.4/en/appendixes.annotations.html#appendixes.annotations.depends diff --git a/tests/phpunit/includes/SanitizerTest.php b/tests/phpunit/includes/SanitizerTest.php index ac9971e290..c593d2f1bf 100644 --- a/tests/phpunit/includes/SanitizerTest.php +++ b/tests/phpunit/includes/SanitizerTest.php @@ -2,7 +2,11 @@ class SanitizerTest extends MediaWikiTestCase { - function setUp() { + protected function setUp() { + parent::setUp(); + + $this->setMwGlobals( 'wgCleanupPresentationalAttributes', true ); + AutoLoader::loadClass( 'Sanitizer' ); } @@ -110,20 +114,22 @@ class SanitizerTest extends MediaWikiTestCase { $this->assertEquals( Sanitizer::decodeTagAttributes( 'foo=&foobar;' ), array( 'foo' => '&foobar;' ), 'Entity-like items are accepted' ); } - function testDeprecatedAttributesDisabled() { - $GLOBALS['wgCleanupPresentationalAttributes'] = false; - $this->assertEquals( ' clear="left"', Sanitizer::fixTagAttributes( 'clear="left"', 'br' ), 'Deprecated attributes are not converted to styles when enabled.' ); - } - /** * @dataProvider provideDeprecatedAttributes */ function testDeprecatedAttributes( $input, $tag, $expected, $message = null ) { - $GLOBALS['wgCleanupPresentationalAttributes'] = true; $this->assertEquals( $expected, Sanitizer::fixTagAttributes( $input, $tag ), $message ); } - function provideDeprecatedAttributes() { + function testDeprecatedAttributesDisabled() { + global $wgCleanupPresentationalAttributes; + + $wgCleanupPresentationalAttributes = false; + + $this->assertEquals( ' clear="left"', Sanitizer::fixTagAttributes( 'clear="left"', 'br' ), 'Deprecated attributes are not converted to styles when enabled.' ); + } + + public static function provideDeprecatedAttributes() { return array( array( 'clear="left"', 'br', ' style="clear: left;"', 'Deprecated attributes are converted to styles when enabled.' ), array( 'clear="all"', 'br', ' style="clear: both;"', 'clear=all is converted to clear: both; not clear: all;' ), @@ -170,7 +176,7 @@ class SanitizerTest extends MediaWikiTestCase { ); } - function provideCssCommentsFixtures() { + public static function provideCssCommentsFixtures() { /** array( , , [message] ) */ return array( array( ' ', '/**/' ), diff --git a/tests/phpunit/includes/SeleniumConfigurationTest.php b/tests/phpunit/includes/SeleniumConfigurationTest.php index 8589c188a4..8f6aafa36a 100644 --- a/tests/phpunit/includes/SeleniumConfigurationTest.php +++ b/tests/phpunit/includes/SeleniumConfigurationTest.php @@ -99,7 +99,8 @@ testBrowser = "firefox" private $testSuites1 = null; - public function setUp() { + protected function setUp() { + parent::setUp(); if ( !defined( 'SELENIUMTEST' ) ) { define( 'SELENIUMTEST', true ); } @@ -108,7 +109,7 @@ testBrowser = "firefox" /** * Clean up the temporary file used to store the selenium settings. */ - public function tearDown() { + protected function tearDown() { if ( strlen( $this->tempFileName ) > 0 ) { unlink( $this->tempFileName ); unset( $this->tempFileName ); diff --git a/tests/phpunit/includes/SiteConfigurationTest.php b/tests/phpunit/includes/SiteConfigurationTest.php index 57d3532a5b..4e0d2f42a7 100644 --- a/tests/phpunit/includes/SiteConfigurationTest.php +++ b/tests/phpunit/includes/SiteConfigurationTest.php @@ -25,7 +25,7 @@ function getSiteParams( $conf, $wiki ) { class SiteConfigurationTest extends MediaWikiTestCase { var $mConf; - function setUp() { + protected function setUp() { $this->mConf = new SiteConfiguration; $this->mConf->suffixes = array( 'wiki' ); diff --git a/tests/phpunit/includes/TimeAdjustTest.php b/tests/phpunit/includes/TimeAdjustTest.php index cd027c5b84..db4162fa07 100644 --- a/tests/phpunit/includes/TimeAdjustTest.php +++ b/tests/phpunit/includes/TimeAdjustTest.php @@ -1,28 +1,21 @@ iniSet( 'precision', 15 ); - } + $this->setMwGlobals( array( + 'wgLocalTZoffset' => null, + 'wgContLang' => Language::factory( 'en' ), + ) ); - public function tearDown() { - global $wgLocalTZoffset; - $wgLocalTZoffset = self::$offset; - parent::tearDown(); + $this->iniSet( 'precision', 15 ); } # Test offset usage for a given language::userAdjust function testUserAdjust() { global $wgLocalTZoffset, $wgContLang; - $wgContLang = $en = Language::factory( 'en' ); - #  Collection of parameters for Language_t_Offset. # Format: date to be formatted, localTZoffset value, expected date $userAdjust_tests = array( @@ -43,7 +36,7 @@ class TimeAdjustTest extends MediaWikiLangTestCase { $this->assertEquals( strval( $data[2] ), - strval( $en->userAdjust( $data[0], '' ) ), + strval( $wgContLang->userAdjust( $data[0], '' ) ), "User adjust {$data[0]} by {$data[1]} minutes should give {$data[2]}" ); } diff --git a/tests/phpunit/includes/TimestampTest.php b/tests/phpunit/includes/TimestampTest.php index 231228f55f..53d0424276 100644 --- a/tests/phpunit/includes/TimestampTest.php +++ b/tests/phpunit/includes/TimestampTest.php @@ -4,6 +4,16 @@ * Tests timestamp parsing and output. */ class TimestampTest extends MediaWikiTestCase { + + protected function setUp() { + parent::setUp(); + + $this->setMwGlobals( array( + 'wgLanguageCode' => 'en', + 'wgContLang' => Language::factory( 'en' ), + 'wgLang' => Language::factory( 'en' ), + ) ); + } /** * Test parsing of valid timestamps and outputing to MW format. * @dataProvider provideValidTimestamps @@ -51,7 +61,7 @@ class TimestampTest extends MediaWikiTestCase { * Returns a list of valid timestamps in the format: * array( type, timestamp_of_type, timestamp_in_MW ) */ - function provideValidTimestamps() { + public static function provideValidTimestamps() { return array( // Various formats array( TS_UNIX, '1343761268', '20120731190108' ), diff --git a/tests/phpunit/includes/TitleMethodsTest.php b/tests/phpunit/includes/TitleMethodsTest.php index aed658baa3..5a540b83e2 100644 --- a/tests/phpunit/includes/TitleMethodsTest.php +++ b/tests/phpunit/includes/TitleMethodsTest.php @@ -2,7 +2,7 @@ class TitleMethodsTest extends MediaWikiTestCase { - public function dataEquals() { + public static function provideEquals() { return array( array( 'Main Page', 'Main Page', true ), array( 'Main Page', 'Not The Main Page', false ), @@ -15,7 +15,7 @@ class TitleMethodsTest extends MediaWikiTestCase { } /** - * @dataProvider dataEquals + * @dataProvider provideEquals */ public function testEquals( $titleA, $titleB, $expectedBool ) { $titleA = Title::newFromText( $titleA ); @@ -25,7 +25,7 @@ class TitleMethodsTest extends MediaWikiTestCase { $this->assertEquals( $expectedBool, $titleB->equals( $titleA ) ); } - public function dataInNamespace() { + public static function provideInNamespace() { return array( array( 'Main Page', NS_MAIN, true ), array( 'Main Page', NS_TALK, false ), @@ -39,7 +39,7 @@ class TitleMethodsTest extends MediaWikiTestCase { } /** - * @dataProvider dataInNamespace + * @dataProvider provideInNamespace */ public function testInNamespace( $title, $ns, $expectedBool ) { $title = Title::newFromText( $title ); @@ -54,7 +54,7 @@ class TitleMethodsTest extends MediaWikiTestCase { $this->assertFalse( $mainpage->inNamespaces( array( NS_PROJECT, NS_TEMPLATE ) ) ); } - public function dataHasSubjectNamespace() { + public static function provideHasSubjectNamespace() { return array( array( 'Main Page', NS_MAIN, true ), array( 'Main Page', NS_TALK, true ), @@ -68,14 +68,14 @@ class TitleMethodsTest extends MediaWikiTestCase { } /** - * @dataProvider dataHasSubjectNamespace + * @dataProvider provideHasSubjectNamespace */ public function testHasSubjectNamespace( $title, $ns, $expectedBool ) { $title = Title::newFromText( $title ); $this->assertEquals( $expectedBool, $title->hasSubjectNamespace( $ns ) ); } - public function dataIsCssOrJsPage() { + public static function provideIsCssOrJsPage() { return array( array( 'Foo', false ), array( 'Foo.js', false ), @@ -96,7 +96,7 @@ class TitleMethodsTest extends MediaWikiTestCase { } /** - * @dataProvider dataIsCssOrJsPage + * @dataProvider provideIsCssOrJsPage */ public function testIsCssOrJsPage( $title, $expectedBool ) { $title = Title::newFromText( $title ); @@ -104,7 +104,7 @@ class TitleMethodsTest extends MediaWikiTestCase { } - public function dataIsCssJsSubpage() { + public static function provideIsCssJsSubpage() { return array( array( 'Foo', false ), array( 'Foo.js', false ), @@ -123,14 +123,14 @@ class TitleMethodsTest extends MediaWikiTestCase { } /** - * @dataProvider dataIsCssJsSubpage + * @dataProvider provideIsCssJsSubpage */ public function testIsCssJsSubpage( $title, $expectedBool ) { $title = Title::newFromText( $title ); $this->assertEquals( $expectedBool, $title->isCssJsSubpage() ); } - public function dataIsCssSubpage() { + public static function provideIsCssSubpage() { return array( array( 'Foo', false ), array( 'Foo.css', false ), @@ -143,14 +143,14 @@ class TitleMethodsTest extends MediaWikiTestCase { } /** - * @dataProvider dataIsCssSubpage + * @dataProvider provideIsCssSubpage */ public function testIsCssSubpage( $title, $expectedBool ) { $title = Title::newFromText( $title ); $this->assertEquals( $expectedBool, $title->isCssSubpage() ); } - public function dataIsJsSubpage() { + public static function provideIsJsSubpage() { return array( array( 'Foo', false ), array( 'Foo.css', false ), @@ -163,14 +163,14 @@ class TitleMethodsTest extends MediaWikiTestCase { } /** - * @dataProvider dataIsJsSubpage + * @dataProvider provideIsJsSubpage */ public function testIsJsSubpage( $title, $expectedBool ) { $title = Title::newFromText( $title ); $this->assertEquals( $expectedBool, $title->isJsSubpage() ); } - public function dataIsWikitextPage() { + public static function provideIsWikitextPage() { return array( array( 'Foo', true ), array( 'Foo.js', true ), @@ -191,7 +191,7 @@ class TitleMethodsTest extends MediaWikiTestCase { } /** - * @dataProvider dataIsWikitextPage + * @dataProvider provideIsWikitextPage */ public function testIsWikitextPage( $title, $expectedBool ) { $title = Title::newFromText( $title ); diff --git a/tests/phpunit/includes/TitlePermissionTest.php b/tests/phpunit/includes/TitlePermissionTest.php index f62ac5dd72..5df8fe1b1c 100644 --- a/tests/phpunit/includes/TitlePermissionTest.php +++ b/tests/phpunit/includes/TitlePermissionTest.php @@ -4,31 +4,44 @@ * @group Database */ class TitlePermissionTest extends MediaWikiLangTestCase { - protected $title; /** - * @var User + * @var string */ - protected $user, $anonUser, $userUser, $altUser; + protected $userName, $altUserName; /** - * @var string + * @var Title */ - protected $userName, $altUserName; + protected $title; - function setUp() { - global $wgLocaltimezone, $wgLocalTZoffset, $wgMemc, $wgContLang, $wgLang; - parent::setUp(); + /** + * @var User + */ + protected $user, $anonUser, $userUser, $altUser; - if(!$wgMemc) { - $wgMemc = new EmptyBagOStuff; - } - $wgContLang = $wgLang = Language::factory( 'en' ); + protected function setUp() { + parent::setUp(); - $this->userName = "Useruser"; - $this->altUserName = "Altuseruser"; - date_default_timezone_set( $wgLocaltimezone ); - $wgLocalTZoffset = date( "Z" ) / 60; + $langObj = Language::factory( 'en' ); + $localZone = 'UTC'; + $localOffset = date( 'Z' ) / 60; + + $this->setMwGlobals( array( + 'wgMemc' => new EmptyBagOStuff, + 'wgContLang' => $langObj, + 'wgLang' => $langObj, + 'wgLocaltimezone' => $localZone, + 'wgLocalTZoffset' => $localOffset, + 'wgNamespaceProtection' => array( + NS_MEDIAWIKI => 'editinterface', + ), + 'wgUser' => null, + ) ); + + $this->userName = 'Useruser'; + $this->altUserName = 'Altuseruser'; + date_default_timezone_set( $localZone ); $this->title = Title::makeTitle( NS_MAIN, "Main Page" ); if ( !isset( $this->userUser ) || !( $this->userUser instanceOf User ) ) { @@ -53,10 +66,7 @@ class TitlePermissionTest extends MediaWikiLangTestCase { $this->user = $this->userUser; } - } - function tearDown() { - parent::tearDown(); } function setUserPerm( $perm ) { @@ -74,6 +84,8 @@ class TitlePermissionTest extends MediaWikiLangTestCase { } function setUser( $userName = null ) { + global $wgUser; + if ( $userName === 'anon' ) { $this->user = $this->anonUser; } elseif ( $userName === null || $userName === $this->userName ) { @@ -82,7 +94,6 @@ class TitlePermissionTest extends MediaWikiLangTestCase { $this->user = $this->altUser; } - global $wgUser; $wgUser = $this->user; } @@ -338,9 +349,8 @@ class TitlePermissionTest extends MediaWikiLangTestCase { } function testSpecialsAndNSPermissions() { + global $wgNamespaceProtection; $this->setUser( $this->userName ); - global $wgUser; - $wgUser = $this->user; $this->setTitle( NS_SPECIAL ); @@ -359,8 +369,8 @@ class TitlePermissionTest extends MediaWikiLangTestCase { $this->assertEquals( array( array( 'badaccess-group0' ) ), $this->title->getUserPermissionsErrors( 'bogus', $this->user ) ); - global $wgNamespaceProtection; - $wgNamespaceProtection[NS_USER] = array ( 'bogus' ); + $wgNamespaceProtection[NS_USER] = array( 'bogus' ); + $this->setTitle( NS_USER ); $this->setUserPerm( '' ); $this->assertEquals( array( array( 'badaccess-group0' ), array( 'namespaceprotected', 'User' ) ), @@ -377,6 +387,7 @@ class TitlePermissionTest extends MediaWikiLangTestCase { $this->title->getUserPermissionsErrors( 'bogus', $this->user ) ); $wgNamespaceProtection = null; + $this->setUserPerm( 'bogus' ); $this->assertEquals( array( ), $this->title->getUserPermissionsErrors( 'bogus', $this->user ) ); @@ -392,8 +403,6 @@ class TitlePermissionTest extends MediaWikiLangTestCase { function testCssAndJavascriptPermissions() { $this->setUser( $this->userName ); - global $wgUser; - $wgUser = $this->user; $this->setTitle( NS_USER, $this->altUserName . '/test.js' ); $this->runCSSandJSPermissions( diff --git a/tests/phpunit/includes/TitleTest.php b/tests/phpunit/includes/TitleTest.php index c74daae1df..8c22269fd8 100644 --- a/tests/phpunit/includes/TitleTest.php +++ b/tests/phpunit/includes/TitleTest.php @@ -2,6 +2,19 @@ class TitleTest extends MediaWikiTestCase { + protected function setUp() { + parent::setUp(); + + $this->setMwGlobals( array( + 'wgLanguageCode' => 'en', + 'wgContLang' => Language::factory( 'en' ), + // User language + 'wgLang' => Language::factory( 'en' ), + 'wgAllowUserJs' => false, + 'wgDefaultLanguageVariant' => false, + ) ); + } + function testLegalChars() { $titlechars = Title::legalChars(); @@ -16,7 +29,7 @@ class TitleTest extends MediaWikiTestCase { } /** - * @dataProvider dataBug31100 + * @dataProvider provideBug31100 */ function testBug31100FixSpecialName( $text, $expectedParam ) { $title = Title::newFromText( $text ); @@ -30,7 +43,7 @@ class TitleTest extends MediaWikiTestCase { $this->assertEquals( $expectedParam, $par, "Bug 31100 regression check: Title->fixSpecialName() should preserve parameter" ); } - function dataBug31100() { + public static function provideBug31100() { return array( array( 'Special:Version', null ), array( 'Special:Version/', '' ), @@ -45,7 +58,7 @@ class TitleTest extends MediaWikiTestCase { * @param string $source * @param string $target * @param array|string|true $expected Required error - * @dataProvider dataTestIsValidMoveOperation + * @dataProvider provideTestIsValidMoveOperation */ function testIsValidMoveOperation( $source, $target, $expected ) { $title = Title::newFromText( $source ); @@ -69,7 +82,7 @@ class TitleTest extends MediaWikiTestCase { return $result; } - function dataTestIsValidMoveOperation() { + public static function provideTestIsValidMoveOperation() { return array( array( 'Test', 'Test', 'selfmove' ), array( 'File:Test.jpg', 'Page', 'imagenocrossnamespace' ) @@ -79,22 +92,15 @@ class TitleTest extends MediaWikiTestCase { /** * @dataProvider provideCasesForGetpageviewlanguage */ - function testGetpageviewlanguage( $expected, $titleText, $contLang, $lang, $variant, $msg='' ) { - // Save globals - global $wgContLang, $wgLang, $wgAllowUserJs, $wgLanguageCode, $wgDefaultLanguageVariant; - $save['wgContLang'] = $wgContLang; - $save['wgLang'] = $wgLang; - $save['wgAllowUserJs'] = $wgAllowUserJs; - $save['wgLanguageCode'] = $wgLanguageCode; - $save['wgDefaultLanguageVariant'] = $wgDefaultLanguageVariant; - - // Setup test environnement: - $wgContLang = Language::factory( $contLang ); - $wgLang = Language::factory( $lang ); - # To test out .js titles: - $wgAllowUserJs = true; + function testGetpageviewlanguage( $expected, $titleText, $contLang, $lang, $variant, $msg = '' ) { + global $wgLanguageCode, $wgContLang, $wgLang, $wgDefaultLanguageVariant, $wgAllowUserJs; + + // Setup environnement for this test $wgLanguageCode = $contLang; + $wgContLang = Language::factory( $contLang ); + $wgLang = Language::factory( $lang ); $wgDefaultLanguageVariant = $variant; + $wgAllowUserJs = true; $title = Title::newFromText( $titleText ); $this->assertInstanceOf( 'Title', $title, @@ -104,13 +110,6 @@ class TitleTest extends MediaWikiTestCase { $title->getPageViewLanguage()->getCode(), $msg ); - - // Restore globals - $wgContLang = $save['wgContLang']; - $wgLang = $save['wgLang']; - $wgAllowUserJs = $save['wgAllowUserJs']; - $wgLanguageCode = $save['wgLanguageCode']; - $wgDefaultLanguageVariant = $save['wgDefaultLanguageVariant']; } function provideCasesForGetpageviewlanguage() { @@ -182,7 +181,7 @@ class TitleTest extends MediaWikiTestCase { ); } - function provideRootTitleCases() { + public static function provideRootTitleCases() { return array( # Title, expected base, optional message array('User:John_Doe/subOne/subTwo', 'John Doe' ), diff --git a/tests/phpunit/includes/UserTest.php b/tests/phpunit/includes/UserTest.php index 7a424aef16..316e6f5a24 100644 --- a/tests/phpunit/includes/UserTest.php +++ b/tests/phpunit/includes/UserTest.php @@ -7,22 +7,26 @@ define( 'NS_UNITTEST_TALK', 5601 ); * @group Database */ class UserTest extends MediaWikiTestCase { - protected $savedGroupPermissions, $savedRevokedPermissions; /** * @var User */ protected $user; - public function setUp() { + protected function setUp() { parent::setUp(); - $this->savedGroupPermissions = $GLOBALS['wgGroupPermissions']; - $this->savedRevokedPermissions = $GLOBALS['wgRevokePermissions']; + $this->setMwGlobals( array( + 'wgGroupPermissions' => array(), + 'wgRevokePermissions' => array(), + ) ); $this->setUpPermissionGlobals(); - $this->setUpUser(); + + $this->user = new User; + $this->user->addGroup( 'unittesters' ); } + private function setUpPermissionGlobals() { global $wgGroupPermissions, $wgRevokePermissions; @@ -38,22 +42,12 @@ class UserTest extends MediaWikiTestCase { 'writetest' => true, 'modifytest' => true, ); + # Data for regular $wgRevokePermissions test $wgRevokePermissions['formertesters'] = array( 'runtest' => true, ); } - private function setUpUser() { - $this->user = new User; - $this->user->addGroup( 'unittesters' ); - } - - public function tearDown() { - parent::tearDown(); - - $GLOBALS['wgGroupPermissions'] = $this->savedGroupPermissions; - $GLOBALS['wgRevokePermissions'] = $this->savedRevokedPermissions; - } public function testGroupPermissions() { $rights = User::getGroupPermissions( array( 'unittesters' ) ); @@ -95,7 +89,7 @@ class UserTest extends MediaWikiTestCase { $this->assertEquals( $expected, $result, "Groups with permission $right" ); } - public function provideGetGroupsWithPermission() { + public static function provideGetGroupsWithPermission() { return array( array( array( 'unittesters', 'testwriters' ), @@ -123,7 +117,7 @@ class UserTest extends MediaWikiTestCase { $this->assertEquals( $this->user->isValidUserName( $username ), $result, $message ); } - public function provideUserNames() { + public static function provideUserNames() { return array( array( '', false, 'Empty string' ), array( ' ', false, 'Blank space' ), diff --git a/tests/phpunit/includes/WebRequestTest.php b/tests/phpunit/includes/WebRequestTest.php index 1fc0b4b340..153ff78700 100644 --- a/tests/phpunit/includes/WebRequestTest.php +++ b/tests/phpunit/includes/WebRequestTest.php @@ -1,14 +1,18 @@ oldServer = $_SERVER; } - function tearDown() { - $_SERVER = self::$oldServer; + protected function tearDown() { + $_SERVER = $this->oldServer; + + parent::tearDown(); } /** @@ -20,7 +24,7 @@ class WebRequestTest extends MediaWikiTestCase { $this->assertEquals( $expected, $result, $description ); } - function provideDetectServer() { + public static function provideDetectServer() { return array( array( 'http://x', @@ -107,7 +111,7 @@ class WebRequestTest extends MediaWikiTestCase { $this->assertEquals( $expected, $result, $description ); } - function provideGetIP() { + public static function provideGetIP() { return array( array( '127.0.0.1', @@ -189,7 +193,7 @@ class WebRequestTest extends MediaWikiTestCase { $request->getIP(); } - function languageProvider() { + public static function provideLanguageData() { return array( array( '', array(), 'Empty Accept-Language header' ), array( 'en', array( 'en' => 1 ), 'One language' ), @@ -206,7 +210,7 @@ class WebRequestTest extends MediaWikiTestCase { } /** - * @dataProvider languageProvider + * @dataProvider provideLanguageData */ function testAcceptLang($acceptLanguageHeader, $expectedLanguages, $description) { $_SERVER = array( 'HTTP_ACCEPT_LANGUAGE' => $acceptLanguageHeader ); diff --git a/tests/phpunit/includes/WikiPageTest.php b/tests/phpunit/includes/WikiPageTest.php index 2949a3af8f..e77a1334a1 100644 --- a/tests/phpunit/includes/WikiPageTest.php +++ b/tests/phpunit/includes/WikiPageTest.php @@ -29,12 +29,12 @@ class WikiPageTest extends MediaWikiLangTestCase { 'iwlinks' ) ); } - public function setUp() { + protected function setUp() { parent::setUp(); $this->pages_to_delete = array(); } - public function tearDown() { + protected function tearDown() { foreach ( $this->pages_to_delete as $p ) { /* @var $p WikiPage */ @@ -220,7 +220,7 @@ class WikiPageTest extends MediaWikiLangTestCase { $this->assertFalse( $page->exists() ); } - public function dataHasViewableContent() { + public static function provideHasViewableContent() { return array( array( 'WikiPageTest_testHasViewableContent', false, true ), array( 'Special:WikiPageTest_testHasViewableContent', false ), @@ -231,7 +231,7 @@ class WikiPageTest extends MediaWikiLangTestCase { } /** - * @dataProvider dataHasViewableContent + * @dataProvider provideHasViewableContent */ public function testHasViewableContent( $title, $viewable, $create = false ) { $page = $this->newPage( $title ); @@ -246,7 +246,7 @@ class WikiPageTest extends MediaWikiLangTestCase { } } - public function dataGetRedirectTarget() { + public static function provideGetRedirectTarget() { return array( array( 'WikiPageTest_testGetRedirectTarget_1', "hello world", null ), array( 'WikiPageTest_testGetRedirectTarget_2', "#REDIRECT [[hello world]]", "Hello world" ), @@ -254,7 +254,7 @@ class WikiPageTest extends MediaWikiLangTestCase { } /** - * @dataProvider dataGetRedirectTarget + * @dataProvider provideGetRedirectTarget */ public function testGetRedirectTarget( $title, $text, $target ) { $page = $this->createPage( $title, $text ); @@ -265,14 +265,14 @@ class WikiPageTest extends MediaWikiLangTestCase { } /** - * @dataProvider dataGetRedirectTarget + * @dataProvider provideGetRedirectTarget */ public function testIsRedirect( $title, $text, $target ) { $page = $this->createPage( $title, $text ); $this->assertEquals( !is_null( $target ), $page->isRedirect() ); } - public function dataIsCountable() { + public static function provideIsCountable() { return array( // any @@ -366,7 +366,7 @@ class WikiPageTest extends MediaWikiLangTestCase { /** - * @dataProvider dataIsCountable + * @dataProvider provideIsCountable */ public function testIsCountable( $title, $text, $mode, $expected ) { global $wgArticleCountMethod; @@ -388,7 +388,7 @@ class WikiPageTest extends MediaWikiLangTestCase { . " instead of " . var_export( $expected, true ) . " in mode `$mode` for text \"$text\"" ); } - public function dataGetParserOutput() { + public static function provideGetParserOutput() { return array( array("hello ''world''\n", "

hello world

"), // @todo: more...? @@ -396,7 +396,7 @@ class WikiPageTest extends MediaWikiLangTestCase { } /** - * @dataProvider dataGetParserOutput + * @dataProvider provideGetParserOutput */ public function testGetParserOutput( $text, $expectedHtml ) { $page = $this->createPage( 'WikiPageTest_testGetParserOutput', $text ); @@ -427,7 +427,7 @@ more stuff "; - public function dataReplaceSection() { + public static function provideReplaceSection() { return array( array( 'WikiPageTest_testReplaceSection', WikiPageTest::$sections, @@ -468,7 +468,7 @@ more stuff } /** - * @dataProvider dataReplaceSection + * @dataProvider provideReplaceSection */ public function testReplaceSection( $title, $text, $section, $with, $sectionTitle, $expected ) { $page = $this->createPage( $title, $text ); @@ -613,7 +613,7 @@ more stuff $this->assertEquals( "one", $page->getText() ); } - public function dataGetAutosummary( ) { + public static function provideGetAutosummary( ) { return array( array( 'Hello there, world!', @@ -655,7 +655,7 @@ more stuff } /** - * @dataProvider dataGetAutoSummary + * @dataProvider provideGetAutoSummary */ public function testGetAutosummary( $old, $new, $flags, $expected ) { $page = $this->newPage( "WikiPageTest_testGetAutosummary" ); @@ -665,7 +665,7 @@ more stuff $this->assertTrue( (bool)preg_match( $expected, $summary ), "Autosummary didn't match expected pattern $expected: $summary" ); } - public function dataGetAutoDeleteReason( ) { + public static function provideGetAutoDeleteReason( ) { return array( array( array(), @@ -724,7 +724,7 @@ more stuff } /** - * @dataProvider dataGetAutoDeleteReason + * @dataProvider provideGetAutoDeleteReason */ public function testGetAutoDeleteReason( $edits, $expectedResult, $expectedHistory ) { global $wgUser; @@ -754,7 +754,7 @@ more stuff $page->doDeleteArticle( "done" ); } - public function dataPreSaveTransform() { + public static function providePreSaveTransform() { return array( array( 'hello this is ~~~', "hello this is [[Special:Contributions/127.0.0.1|127.0.0.1]]", @@ -766,7 +766,7 @@ more stuff } /** - * @dataProvider dataPreSaveTransform + * @dataProvider providePreSaveTransform */ public function testPreSaveTransform( $text, $expected ) { $this->hideDeprecated( 'WikiPage::preSaveTransform' ); diff --git a/tests/phpunit/includes/XmlSelectTest.php b/tests/phpunit/includes/XmlSelectTest.php index 2407c15171..75bd9222c1 100644 --- a/tests/phpunit/includes/XmlSelectTest.php +++ b/tests/phpunit/includes/XmlSelectTest.php @@ -35,7 +35,7 @@ class XmlSelectTest extends MediaWikiTestCase { * Provides a fourth parameters representing the expected HTML output * */ - public function provideConstructionParameters() { + public static function provideConstructionParameters() { return array( /** * Values are set following a 3-bit Gray code where two successive diff --git a/tests/phpunit/includes/XmlTest.php b/tests/phpunit/includes/XmlTest.php index 74c48f212b..3cc542214a 100644 --- a/tests/phpunit/includes/XmlTest.php +++ b/tests/phpunit/includes/XmlTest.php @@ -4,7 +4,7 @@ class XmlTest extends MediaWikiTestCase { private static $oldLang; private static $oldNamespaces; - public function setUp() { + protected function setUp() { parent::setUp(); $langObj = Language::factory( 'en' ); diff --git a/tests/phpunit/includes/ZipDirectoryReaderTest.php b/tests/phpunit/includes/ZipDirectoryReaderTest.php index d90a695095..81b32c2b99 100644 --- a/tests/phpunit/includes/ZipDirectoryReaderTest.php +++ b/tests/phpunit/includes/ZipDirectoryReaderTest.php @@ -3,7 +3,7 @@ class ZipDirectoryReaderTest extends MediaWikiTestCase { var $zipDir, $entries; - function setUp() { + protected function setUp() { $this->zipDir = __DIR__ . '/../data/zip'; } diff --git a/tests/phpunit/includes/api/ApiBlockTest.php b/tests/phpunit/includes/api/ApiBlockTest.php index 5dfceee8cd..52f1d28dd3 100644 --- a/tests/phpunit/includes/api/ApiBlockTest.php +++ b/tests/phpunit/includes/api/ApiBlockTest.php @@ -6,7 +6,7 @@ */ class ApiBlockTest extends ApiTestCase { - function setUp() { + protected function setUp() { parent::setUp(); $this->doLogin(); } diff --git a/tests/phpunit/includes/api/ApiEditPageTest.php b/tests/phpunit/includes/api/ApiEditPageTest.php index 5297d6daa7..dbf772145e 100644 --- a/tests/phpunit/includes/api/ApiEditPageTest.php +++ b/tests/phpunit/includes/api/ApiEditPageTest.php @@ -10,7 +10,7 @@ */ class ApiEditPageTest extends ApiTestCase { - function setUp() { + protected function setUp() { parent::setUp(); $this->doLogin(); } diff --git a/tests/phpunit/includes/api/ApiOptionsTest.php b/tests/phpunit/includes/api/ApiOptionsTest.php index d54d7dfc67..4684c55782 100644 --- a/tests/phpunit/includes/api/ApiOptionsTest.php +++ b/tests/phpunit/includes/api/ApiOptionsTest.php @@ -9,7 +9,7 @@ class ApiOptionsTest extends MediaWikiLangTestCase { private static $Success = array( 'options' => 'success' ); - function setUp() { + protected function setUp() { parent::setUp(); $this->mUserMock = $this->getMockBuilder( 'User' ) diff --git a/tests/phpunit/includes/api/ApiPurgeTest.php b/tests/phpunit/includes/api/ApiPurgeTest.php index 2566c6cd11..d903714924 100644 --- a/tests/phpunit/includes/api/ApiPurgeTest.php +++ b/tests/phpunit/includes/api/ApiPurgeTest.php @@ -6,7 +6,7 @@ */ class ApiPurgeTest extends ApiTestCase { - function setUp() { + protected function setUp() { parent::setUp(); $this->doLogin(); } diff --git a/tests/phpunit/includes/api/ApiQueryTest.php b/tests/phpunit/includes/api/ApiQueryTest.php index a4b9dc70ba..dbf02f7d8f 100644 --- a/tests/phpunit/includes/api/ApiQueryTest.php +++ b/tests/phpunit/includes/api/ApiQueryTest.php @@ -6,7 +6,7 @@ */ class ApiQueryTest extends ApiTestCase { - function setUp() { + protected function setUp() { parent::setUp(); $this->doLogin(); } diff --git a/tests/phpunit/includes/api/ApiTestCase.php b/tests/phpunit/includes/api/ApiTestCase.php index 3ca674194a..de521752c1 100644 --- a/tests/phpunit/includes/api/ApiTestCase.php +++ b/tests/phpunit/includes/api/ApiTestCase.php @@ -8,7 +8,7 @@ abstract class ApiTestCase extends MediaWikiLangTestCase { */ protected $apiContext; - function setUp() { + protected function setUp() { global $wgContLang, $wgAuth, $wgMemc, $wgRequest, $wgUser, $wgServer; parent::setUp(); diff --git a/tests/phpunit/includes/api/ApiTestCaseUpload.php b/tests/phpunit/includes/api/ApiTestCaseUpload.php index 39c7954773..9f281bd6db 100644 --- a/tests/phpunit/includes/api/ApiTestCaseUpload.php +++ b/tests/phpunit/includes/api/ApiTestCaseUpload.php @@ -8,19 +8,23 @@ abstract class ApiTestCaseUpload extends ApiTestCase { /** * Fixture -- run before every test */ - public function setUp() { - global $wgEnableUploads, $wgEnableAPI; + protected function setUp() { parent::setUp(); - $wgEnableUploads = true; - $wgEnableAPI = true; + $this->setMwGlobals( array( + 'wgEnableUploads' => true, + 'wgEnableAPI' => true, + ) ); + wfSetupSession(); $this->clearFakeUploads(); } - public function tearDown() { + protected function tearDown() { $this->clearTempUpload(); + + parent::tearDown(); } /** @@ -54,7 +58,6 @@ abstract class ApiTestCaseUpload extends ApiTestCase { return $this->deleteFileByTitle( Title::newFromText( $fileName, NS_FILE ) ); } - /** * Helper function -- given a file on the filesystem, find matching content in the db (and associated articles) and remove them. * @param $filePath String: path to file on the filesystem @@ -104,6 +107,7 @@ abstract class ApiTestCaseUpload extends ApiTestCase { return true; } + function fakeUploadChunk( $fieldName, $fileName, $type, & $chunkData ){ $tmpName = tempnam( wfTempDir(), "" ); // copy the chunk data to temp location: @@ -142,7 +146,4 @@ abstract class ApiTestCaseUpload extends ApiTestCase { $_FILES = array(); } - - - } diff --git a/tests/phpunit/includes/api/ApiWatchTest.php b/tests/phpunit/includes/api/ApiWatchTest.php index d2e98152d1..cc6c587f58 100644 --- a/tests/phpunit/includes/api/ApiWatchTest.php +++ b/tests/phpunit/includes/api/ApiWatchTest.php @@ -7,7 +7,7 @@ */ class ApiWatchTest extends ApiTestCase { - function setUp() { + protected function setUp() { parent::setUp(); $this->doLogin(); } diff --git a/tests/phpunit/includes/cache/GenderCacheTest.php b/tests/phpunit/includes/cache/GenderCacheTest.php index a8b987e2d2..52cdc78c5e 100644 --- a/tests/phpunit/includes/cache/GenderCacheTest.php +++ b/tests/phpunit/includes/cache/GenderCacheTest.php @@ -6,7 +6,7 @@ */ class GenderCacheTest extends MediaWikiLangTestCase { - function setUp() { + protected function setUp() { global $wgDefaultUserOptions; parent::setUp(); //ensure the correct default gender @@ -45,7 +45,7 @@ class GenderCacheTest extends MediaWikiLangTestCase { /** * test usernames * - * @dataProvider dataUserName + * @dataProvider provideUserGenders */ function testUserName( $username, $expectedGender ) { $genderCache = GenderCache::singleton(); @@ -56,7 +56,7 @@ class GenderCacheTest extends MediaWikiLangTestCase { /** * genderCache should work with user objects, too * - * @dataProvider dataUserName + * @dataProvider provideUserGenders */ function testUserObjects( $username, $expectedGender ) { $genderCache = GenderCache::singleton(); @@ -65,7 +65,7 @@ class GenderCacheTest extends MediaWikiLangTestCase { $this->assertEquals( $gender, $expectedGender, "GenderCache normal" ); } - function dataUserName() { + public static function provideUserGenders() { return array( array( 'UTMale', 'male' ), array( 'UTFemale', 'female' ), @@ -81,7 +81,7 @@ class GenderCacheTest extends MediaWikiLangTestCase { * test strip of subpages to avoid unnecessary queries * against the never existing username * - * @dataProvider dataStripSubpages + * @dataProvider provideStripSubpages */ function testStripSubpages( $pageWithSubpage, $expectedGender ) { $genderCache = GenderCache::singleton(); @@ -89,7 +89,7 @@ class GenderCacheTest extends MediaWikiLangTestCase { $this->assertEquals( $gender, $expectedGender, "GenderCache must strip of subpages" ); } - function dataStripSubpages() { + public static function provideStripSubpages() { return array( array( 'UTMale/subpage', 'male' ), array( 'UTFemale/subpage', 'female' ), diff --git a/tests/phpunit/includes/cache/ProcessCacheLRUTest.php b/tests/phpunit/includes/cache/ProcessCacheLRUTest.php index 30bfb12475..1c081b8e5a 100644 --- a/tests/phpunit/includes/cache/ProcessCacheLRUTest.php +++ b/tests/phpunit/includes/cache/ProcessCacheLRUTest.php @@ -76,7 +76,7 @@ class ProcessCacheLRUTest extends MediaWikiTestCase { /** * Value which are forbidden by the constructor */ - function provideInvalidConstructorArg() { + public static function provideInvalidConstructorArg() { return array( array( null ), array( array() ), @@ -131,7 +131,7 @@ class ProcessCacheLRUTest extends MediaWikiTestCase { /** * Provider for testFillingCache */ - function provideCacheFilling() { + public static function provideCacheFilling() { // ($cacheMaxEntries, $entryToFill, $msg='') return array( array( 1, 0 ), diff --git a/tests/phpunit/includes/db/DatabaseSQLTest.php b/tests/phpunit/includes/db/DatabaseSQLTest.php index e37cd445fa..0c9f7495a7 100644 --- a/tests/phpunit/includes/db/DatabaseSQLTest.php +++ b/tests/phpunit/includes/db/DatabaseSQLTest.php @@ -8,15 +8,15 @@ */ class DatabaseSQLTest extends MediaWikiTestCase { - public function setUp() { + protected function setUp() { // TODO support other DBMS or find another way to do it - if( $this->db->getType() !== 'mysql' ) { + if ( $this->db->getType() !== 'mysql' ) { $this->markTestSkipped( 'No mysql database' ); } } /** - * @dataProvider dataSelectSQLText + * @dataProvider provideSelectSQLText */ function testSelectSQLText( $sql, $sqlText ) { $this->assertEquals( trim( $this->db->selectSQLText( @@ -29,7 +29,7 @@ class DatabaseSQLTest extends MediaWikiTestCase { ) ), $sqlText ); } - function dataSelectSQLText() { + public static function provideSelectSQLText() { return array( array( array( @@ -106,7 +106,7 @@ class DatabaseSQLTest extends MediaWikiTestCase { } /** - * @dataProvider dataConditional + * @dataProvider provideConditional */ function testConditional( $sql, $sqlText ) { $this->assertEquals( trim( $this->db->conditional( @@ -116,7 +116,7 @@ class DatabaseSQLTest extends MediaWikiTestCase { ) ), $sqlText ); } - function dataConditional() { + public static function provideConditional() { return array( array( array( diff --git a/tests/phpunit/includes/db/DatabaseSqliteTest.php b/tests/phpunit/includes/db/DatabaseSqliteTest.php index d226598bf5..216de8424f 100644 --- a/tests/phpunit/includes/db/DatabaseSqliteTest.php +++ b/tests/phpunit/includes/db/DatabaseSqliteTest.php @@ -24,7 +24,9 @@ class MockDatabaseSqlite extends DatabaseSqliteStandalone { class DatabaseSqliteTest extends MediaWikiTestCase { var $db; - public function setUp() { + protected function setUp() { + parent::setUp(); + if ( !Sqlite::isPresent() ) { $this->markTestSkipped( 'No SQLite support detected' ); } diff --git a/tests/phpunit/includes/db/DatabaseTest.php b/tests/phpunit/includes/db/DatabaseTest.php index dc12ba5f42..a8a6b48a89 100644 --- a/tests/phpunit/includes/db/DatabaseTest.php +++ b/tests/phpunit/includes/db/DatabaseTest.php @@ -7,11 +7,11 @@ class DatabaseTest extends MediaWikiTestCase { var $db, $functionTest = false; - function setUp() { + protected function setUp() { $this->db = wfGetDB( DB_MASTER ); } - function tearDown() { + protected function tearDown() { if ( $this->functionTest ) { $this->dropFunctions(); $this->functionTest = false; diff --git a/tests/phpunit/includes/db/TestORMRowTest.php b/tests/phpunit/includes/db/TestORMRowTest.php index afd1cb803f..c7bea3bbc2 100644 --- a/tests/phpunit/includes/db/TestORMRowTest.php +++ b/tests/phpunit/includes/db/TestORMRowTest.php @@ -58,7 +58,7 @@ class TestORMRowTest extends ORMRowTest { return TestORMTable::singleton(); } - public function setUp() { + protected function setUp() { parent::setUp(); $dbw = wfGetDB( DB_MASTER ); diff --git a/tests/phpunit/includes/debug/MWDebugTest.php b/tests/phpunit/includes/debug/MWDebugTest.php index 246b2918cf..4f338d31bf 100644 --- a/tests/phpunit/includes/debug/MWDebugTest.php +++ b/tests/phpunit/includes/debug/MWDebugTest.php @@ -3,7 +3,7 @@ class MWDebugTest extends MediaWikiTestCase { - function setUp() { + protected function setUp() { // Make sure MWDebug class is enabled static $MWDebugEnabled = false; if( !$MWDebugEnabled ) { @@ -15,7 +15,7 @@ class MWDebugTest extends MediaWikiTestCase { wfSuppressWarnings(); } - function tearDown() { + protected function tearDown() { wfRestoreWarnings(); } diff --git a/tests/phpunit/includes/filerepo/FileBackendTest.php b/tests/phpunit/includes/filerepo/FileBackendTest.php index cb54bb66b7..2303c788f4 100644 --- a/tests/phpunit/includes/filerepo/FileBackendTest.php +++ b/tests/phpunit/includes/filerepo/FileBackendTest.php @@ -10,7 +10,7 @@ class FileBackendTest extends MediaWikiTestCase { private $filesToPrune = array(); private static $backendToUse; - function setUp() { + protected function setUp() { global $wgFileBackends; parent::setUp(); $tmpPrefix = wfTempDir() . '/filebackend-unittest-' . time() . '-' . mt_rand(); @@ -72,7 +72,7 @@ class FileBackendTest extends MediaWikiTestCase { $this->filesToPrune = array(); } - private function baseStorePath() { + private static function baseStorePath() { return 'mwstore://localtesting'; } @@ -183,7 +183,7 @@ class FileBackendTest extends MediaWikiTestCase { "FileBackend::extensionFromPath on path '$path'" ); } - function provider_testExtensionFromPath() { + public static function provider_testExtensionFromPath() { return array( array( 'mwstore://backend/container/path.txt', 'txt' ), array( 'mwstore://backend/container/path.svg.png', 'png' ), @@ -248,11 +248,11 @@ class FileBackendTest extends MediaWikiTestCase { $this->assertBackendPathsConsistent( array( $dest ) ); } - public function provider_testStore() { + public static function provider_testStore() { $cases = array(); $tmpName = TempFSFile::factory( "unittests_", 'txt' )->getPath(); - $toPath = $this->baseStorePath() . '/unittest-cont1/e/fun/obj1.txt'; + $toPath = self::baseStorePath() . '/unittest-cont1/e/fun/obj1.txt'; $op = array( 'op' => 'store', 'src' => $tmpName, 'dst' => $toPath ); $cases[] = array( $op, // operation @@ -337,11 +337,11 @@ class FileBackendTest extends MediaWikiTestCase { $this->assertBackendPathsConsistent( array( $source, $dest ) ); } - public function provider_testCopy() { + public static function provider_testCopy() { $cases = array(); - $source = $this->baseStorePath() . '/unittest-cont1/e/file.txt'; - $dest = $this->baseStorePath() . '/unittest-cont2/a/fileMoved.txt'; + $source = self::baseStorePath() . '/unittest-cont1/e/file.txt'; + $dest = self::baseStorePath() . '/unittest-cont2/a/fileMoved.txt'; $op = array( 'op' => 'copy', 'src' => $source, 'dst' => $dest ); $cases[] = array( @@ -428,11 +428,11 @@ class FileBackendTest extends MediaWikiTestCase { $this->assertBackendPathsConsistent( array( $source, $dest ) ); } - public function provider_testMove() { + public static function provider_testMove() { $cases = array(); - $source = $this->baseStorePath() . '/unittest-cont1/e/file.txt'; - $dest = $this->baseStorePath() . '/unittest-cont2/a/fileMoved.txt'; + $source = self::baseStorePath() . '/unittest-cont1/e/file.txt'; + $dest = self::baseStorePath() . '/unittest-cont2/a/fileMoved.txt'; $op = array( 'op' => 'move', 'src' => $source, 'dst' => $dest ); $cases[] = array( @@ -515,10 +515,10 @@ class FileBackendTest extends MediaWikiTestCase { $this->assertBackendPathsConsistent( array( $source ) ); } - public function provider_testDelete() { + public static function provider_testDelete() { $cases = array(); - $source = $this->baseStorePath() . '/unittest-cont1/e/myfacefile.txt'; + $source = self::baseStorePath() . '/unittest-cont1/e/myfacefile.txt'; $op = array( 'op' => 'delete', 'src' => $source ); $cases[] = array( @@ -611,10 +611,10 @@ class FileBackendTest extends MediaWikiTestCase { /** * @dataProvider provider_testCreate */ - public function provider_testCreate() { + public static function provider_testCreate() { $cases = array(); - $dest = $this->baseStorePath() . '/unittest-cont2/a/myspacefile.txt'; + $dest = self::baseStorePath() . '/unittest-cont2/a/myspacefile.txt'; $op = array( 'op' => 'create', 'content' => 'test test testing', 'dst' => $dest ); $cases[] = array( @@ -678,7 +678,7 @@ class FileBackendTest extends MediaWikiTestCase { private function doTestDoQuickOperations() { $backendName = $this->backendClass(); - $base = $this->baseStorePath(); + $base = self::baseStorePath(); $files = array( "$base/unittest-cont1/e/fileA.a", "$base/unittest-cont1/e/fileB.a", @@ -800,16 +800,16 @@ class FileBackendTest extends MediaWikiTestCase { $rand = mt_rand( 0, 2000000000 ) . time(); $dest = wfTempDir() . "/randomfile!$rand.txt"; $srcs = array( - $this->baseStorePath() . '/unittest-cont1/e/file1.txt', - $this->baseStorePath() . '/unittest-cont1/e/file2.txt', - $this->baseStorePath() . '/unittest-cont1/e/file3.txt', - $this->baseStorePath() . '/unittest-cont1/e/file4.txt', - $this->baseStorePath() . '/unittest-cont1/e/file5.txt', - $this->baseStorePath() . '/unittest-cont1/e/file6.txt', - $this->baseStorePath() . '/unittest-cont1/e/file7.txt', - $this->baseStorePath() . '/unittest-cont1/e/file8.txt', - $this->baseStorePath() . '/unittest-cont1/e/file9.txt', - $this->baseStorePath() . '/unittest-cont1/e/file10.txt' + self::baseStorePath() . '/unittest-cont1/e/file1.txt', + self::baseStorePath() . '/unittest-cont1/e/file2.txt', + self::baseStorePath() . '/unittest-cont1/e/file3.txt', + self::baseStorePath() . '/unittest-cont1/e/file4.txt', + self::baseStorePath() . '/unittest-cont1/e/file5.txt', + self::baseStorePath() . '/unittest-cont1/e/file6.txt', + self::baseStorePath() . '/unittest-cont1/e/file7.txt', + self::baseStorePath() . '/unittest-cont1/e/file8.txt', + self::baseStorePath() . '/unittest-cont1/e/file9.txt', + self::baseStorePath() . '/unittest-cont1/e/file10.txt' ); $content = array( 'egfage', @@ -911,7 +911,7 @@ class FileBackendTest extends MediaWikiTestCase { function provider_testGetFileStat() { $cases = array(); - $base = $this->baseStorePath(); + $base = self::baseStorePath(); $cases[] = array( "$base/unittest-cont1/e/b/z/some_file.txt", "some file contents", true ); $cases[] = array( "$base/unittest-cont1/e/b/some-other_file.txt", "", true ); $cases[] = array( "$base/unittest-cont1/e/b/some-diff_file.txt", null, false ); @@ -966,7 +966,7 @@ class FileBackendTest extends MediaWikiTestCase { function provider_testGetFileContents() { $cases = array(); - $base = $this->baseStorePath(); + $base = self::baseStorePath(); $cases[] = array( "$base/unittest-cont1/e/b/z/some_file.txt", "some file contents" ); $cases[] = array( "$base/unittest-cont1/e/b/some-other_file.txt", "more file contents" ); $cases[] = array( @@ -1031,7 +1031,7 @@ class FileBackendTest extends MediaWikiTestCase { function provider_testGetLocalCopy() { $cases = array(); - $base = $this->baseStorePath(); + $base = self::baseStorePath(); $cases[] = array( "$base/unittest-cont1/e/a/z/some_file.txt", "some file contents" ); $cases[] = array( "$base/unittest-cont1/e/a/some-other_file.txt", "more file contents" ); $cases[] = array( "$base/unittest-cont1/e/a/\$odd&.txt", "test file contents" ); @@ -1097,7 +1097,7 @@ class FileBackendTest extends MediaWikiTestCase { function provider_testGetLocalReference() { $cases = array(); - $base = $this->baseStorePath(); + $base = self::baseStorePath(); $cases[] = array( "$base/unittest-cont1/e/a/z/some_file.txt", "some file contents" ); $cases[] = array( "$base/unittest-cont1/e/a/some-other_file.txt", "more file contents" ); $cases[] = array( "$base/unittest-cont1/e/a/\$odd&.txt", "test file contents" ); @@ -1124,7 +1124,7 @@ class FileBackendTest extends MediaWikiTestCase { } function provider_testPrepareAndClean() { - $base = $this->baseStorePath(); + $base = self::baseStorePath(); return array( array( "$base/unittest-cont1/e/a/z/some_file1.txt", true ), array( "$base/unittest-cont2/a/z/some_file2.txt", true ), @@ -1172,7 +1172,7 @@ class FileBackendTest extends MediaWikiTestCase { private function doTestRecursiveClean() { $backendName = $this->backendClass(); - $base = $this->baseStorePath(); + $base = self::baseStorePath(); $dirs = array( "$base/unittest-cont1/e/a", "$base/unittest-cont1/e/a/b", @@ -1226,7 +1226,7 @@ class FileBackendTest extends MediaWikiTestCase { } private function doTestDoOperations() { - $base = $this->baseStorePath(); + $base = self::baseStorePath(); $fileA = "$base/unittest-cont1/e/a/b/fileA.txt"; $fileAContents = '3tqtmoeatmn4wg4qe-mg3qt3 tq'; @@ -1312,7 +1312,7 @@ class FileBackendTest extends MediaWikiTestCase { // concurrency orientated private function doTestDoOperationsPipeline() { - $base = $this->baseStorePath(); + $base = self::baseStorePath(); $fileAContents = '3tqtmoeatmn4wg4qe-mg3qt3 tq'; $fileBContents = 'g-jmq3gpqgt3qtg q3GT '; @@ -1410,7 +1410,7 @@ class FileBackendTest extends MediaWikiTestCase { } private function doTestDoOperationsFailing() { - $base = $this->baseStorePath(); + $base = self::baseStorePath(); $fileA = "$base/unittest-cont2/a/b/fileA.txt"; $fileAContents = '3tqtmoeatmn4wg4qe-mg3qt3 tq'; @@ -1485,7 +1485,7 @@ class FileBackendTest extends MediaWikiTestCase { private function doTestGetFileList() { $backendName = $this->backendClass(); - $base = $this->baseStorePath(); + $base = self::baseStorePath(); // Should have no errors $iter = $this->backend->getFileList( array( 'dir' => "$base/unittest-cont-notexists" ) ); @@ -1642,7 +1642,7 @@ class FileBackendTest extends MediaWikiTestCase { private function doTestGetDirectoryList() { $backendName = $this->backendClass(); - $base = $this->baseStorePath(); + $base = self::baseStorePath(); $files = array( "$base/unittest-cont1/e/test1.txt", "$base/unittest-cont1/e/test2.txt", @@ -1901,7 +1901,7 @@ class FileBackendTest extends MediaWikiTestCase { } private function deleteFiles( $container ) { - $base = $this->baseStorePath(); + $base = self::baseStorePath(); $iter = $this->backend->getFileList( array( 'dir' => "$base/$container" ) ); if ( $iter ) { foreach ( $iter as $file ) { @@ -1921,8 +1921,4 @@ class FileBackendTest extends MediaWikiTestCase { function assertGoodStatus( $status, $msg ) { $this->assertEquals( print_r( array(), 1 ), print_r( $status->errors, 1 ), $msg ); } - - function tearDown() { - parent::tearDown(); - } } diff --git a/tests/phpunit/includes/filerepo/StoreBatchTest.php b/tests/phpunit/includes/filerepo/StoreBatchTest.php index 3ab56af870..7d815e9a67 100644 --- a/tests/phpunit/includes/filerepo/StoreBatchTest.php +++ b/tests/phpunit/includes/filerepo/StoreBatchTest.php @@ -5,7 +5,7 @@ */ class StoreBatchTest extends MediaWikiTestCase { - public function setUp() { + protected function setUp() { global $wgFileBackends; parent::setUp(); @@ -43,6 +43,17 @@ class StoreBatchTest extends MediaWikiTestCase { $this->createdFiles = array(); } + protected function tearDown() { + $this->repo->cleanupBatch( $this->createdFiles ); // delete files + foreach ( $this->createdFiles as $tmp ) { // delete dirs + $tmp = $this->repo->resolveVirtualUrl( $tmp ); + while ( $tmp = FileBackend::parentStoragePath( $tmp ) ) { + $this->repo->getBackend()->clean( array( 'dir' => $tmp ) ); + } + } + parent::tearDown(); + } + /** * Store a file or virtual URL source into a media file name. * @@ -109,15 +120,4 @@ class StoreBatchTest extends MediaWikiTestCase { $this->storecohort( "Test1.png", "$IP/skins/monobook/wiki.png", "$IP/skins/monobook/video.png", false ); $this->storecohort( "Test2.png", "$IP/skins/monobook/wiki.png", "$IP/skins/monobook/video.png", true ); } - - public function tearDown() { - $this->repo->cleanupBatch( $this->createdFiles ); // delete files - foreach ( $this->createdFiles as $tmp ) { // delete dirs - $tmp = $this->repo->resolveVirtualUrl( $tmp ); - while ( $tmp = FileBackend::parentStoragePath( $tmp ) ) { - $this->repo->getBackend()->clean( array( 'dir' => $tmp ) ); - } - } - parent::tearDown(); - } } diff --git a/tests/phpunit/includes/libs/CSSMinTest.php b/tests/phpunit/includes/libs/CSSMinTest.php index a38277569b..57017a84ea 100644 --- a/tests/phpunit/includes/libs/CSSMinTest.php +++ b/tests/phpunit/includes/libs/CSSMinTest.php @@ -6,25 +6,16 @@ */ class CSSMinTest extends MediaWikiTestCase { - protected $oldServer = null, $oldCanServer = null; - function setUp() { + protected function setUp() { parent::setUp(); - // Fake $wgServer and $wgCanonicalServer - global $wgServer, $wgCanonicalServer; - $this->oldServer = $wgServer; - $this->oldCanServer = $wgCanonicalServer; - $wgServer = $wgCanonicalServer = 'http://wiki.example.org'; - } - - function tearDown() { - // Restore $wgServer and $wgCanonicalServer - global $wgServer, $wgCanonicalServer; - $wgServer = $this->oldServer; - $wgCanonicalServer = $this->oldCanServer; + $server = 'http://doc.example.org'; - parent::tearDown(); + $this->setMwGlobals( array( + 'wgServer' => $server, + 'wgCanonicalServer' => $server, + ) ); } /** @@ -113,7 +104,7 @@ class CSSMinTest extends MediaWikiTestCase { array( 'Expand absolute paths', array( 'foo { prop: url(/w/skin/images/bar.png); }', false, 'http://example.org/quux', false ), - 'foo { prop: url(http://wiki.example.org/w/skin/images/bar.png); }', + 'foo { prop: url(http://doc.example.org/w/skin/images/bar.png); }', ), ); } diff --git a/tests/phpunit/includes/media/BitmapMetadataHandlerTest.php b/tests/phpunit/includes/media/BitmapMetadataHandlerTest.php index 88f87ef9e3..cfd75d8642 100644 --- a/tests/phpunit/includes/media/BitmapMetadataHandlerTest.php +++ b/tests/phpunit/includes/media/BitmapMetadataHandlerTest.php @@ -1,7 +1,11 @@ setMwGlobals( 'wgShowEXIF', false ); + $this->filePath = __DIR__ . '/../../data/media/'; } @@ -14,14 +18,15 @@ class BitmapMetadataHandlerTest extends MediaWikiTestCase { * translation (to en) where XMP should win. */ public function testMultilingualCascade() { + global $wgShowEXIF; + if ( !wfDl( 'exif' ) ) { $this->markTestSkipped( "This test needs the exif extension." ); } if ( !wfDl( 'xml' ) ) { $this->markTestSkipped( "This test needs the xml extension." ); } - global $wgShowEXIF; - $oldExif = $wgShowEXIF; + $wgShowEXIF = true; $meta = BitmapMetadataHandler::Jpeg( $this->filePath . @@ -37,8 +42,6 @@ class BitmapMetadataHandlerTest extends MediaWikiTestCase { 'Did not extract any ImageDescription info?!' ); $this->assertEquals( $expected, $meta['ImageDescription'] ); - - $wgShowEXIF = $oldExif; } /** @@ -73,6 +76,7 @@ class BitmapMetadataHandlerTest extends MediaWikiTestCase { $this->assertEquals( '2020:07:14 01:36:05', $meta['DateTimeDigitized'] ); $this->assertEquals( '1997:03:02 00:01:02', $meta['DateTimeOriginal'] ); } + /** * File has an invalid time (+ one valid but really weird time) * that shouldn't be included @@ -131,12 +135,14 @@ class BitmapMetadataHandlerTest extends MediaWikiTestCase { ); $this->assertEquals( $expected, $result ); } + public function testPNGNative() { $handler = new BitmapMetadataHandler(); $result = $handler->png( $this->filePath . 'Png-native-test.png' ); $expected = 'http://example.com/url'; $this->assertEquals( $expected, $result['metadata']['Identifier']['x-default'] ); } + public function testTiffByteOrder() { $handler = new BitmapMetadataHandler(); $res = $handler->getTiffByteOrder( $this->filePath . 'test.tiff' ); diff --git a/tests/phpunit/includes/media/BitmapScalingTest.php b/tests/phpunit/includes/media/BitmapScalingTest.php index 11d9dc47c3..eb1a536472 100644 --- a/tests/phpunit/includes/media/BitmapScalingTest.php +++ b/tests/phpunit/includes/media/BitmapScalingTest.php @@ -2,18 +2,15 @@ class BitmapScalingTest extends MediaWikiTestCase { - function setUp() { - global $wgMaxImageArea, $wgCustomConvertCommand; - $this->oldMaxImageArea = $wgMaxImageArea; - $this->oldCustomConvertCommand = $wgCustomConvertCommand; - $wgMaxImageArea = 1.25e7; // 3500x3500 - $wgCustomConvertCommand = 'dummy'; // Set so that we don't get client side rendering - } - function tearDown() { - global $wgMaxImageArea, $wgCustomConvertCommand; - $wgMaxImageArea = $this->oldMaxImageArea; - $wgCustomConvertCommand = $this->oldCustomConvertCommand; + protected function setUp() { + parent::setUp(); + + $this->setMwGlobals( array( + 'wgMaxImageArea' => 1.25e7, // 3500x3500 + 'wgCustomConvertCommand' => 'dummy', // Set so that we don't get client side rendering + ) ); } + /** * @dataProvider provideNormaliseParams */ @@ -103,7 +100,8 @@ class BitmapScalingTest extends MediaWikiTestCase { 'Bigger than max image size but doesn\'t need scaling', ), ); - } + } + function testTooBigImage() { $file = new FakeDimensionFile( array( 4000, 4000 ) ); $handler = new BitmapHandler; @@ -111,6 +109,7 @@ class BitmapScalingTest extends MediaWikiTestCase { $this->assertEquals( 'TransformParameterError', get_class( $handler->doTransform( $file, 'dummy path', '', $params ) ) ); } + function testTooBigMustRenderImage() { $file = new FakeDimensionFile( array( 4000, 4000 ) ); $file->mustRender = true; diff --git a/tests/phpunit/includes/media/ExifBitmapTest.php b/tests/phpunit/includes/media/ExifBitmapTest.php index b2f6b7bac8..dd223218d5 100644 --- a/tests/phpunit/includes/media/ExifBitmapTest.php +++ b/tests/phpunit/includes/media/ExifBitmapTest.php @@ -2,43 +2,44 @@ class ExifBitmapTest extends MediaWikiTestCase { - public function setUp() { - global $wgShowEXIF; - $this->showExif = $wgShowEXIF; - $wgShowEXIF = true; + protected function setUp() { + parent::setUp(); + + $this->setMwGlobals( 'wgShowEXIF', true ); + $this->handler = new ExifBitmapHandler; if ( !wfDl( 'exif' ) ) { $this->markTestSkipped( "This test needs the exif extension." ); } } - public function tearDown() { - global $wgShowEXIF; - $wgShowEXIF = $this->showExif; - } - public function testIsOldBroken() { $res = $this->handler->isMetadataValid( null, ExifBitmapHandler::OLD_BROKEN_FILE ); $this->assertEquals( ExifBitmapHandler::METADATA_COMPATIBLE, $res ); } + public function testIsBrokenFile() { $res = $this->handler->isMetadataValid( null, ExifBitmapHandler::BROKEN_FILE ); $this->assertEquals( ExifBitmapHandler::METADATA_GOOD, $res ); } + public function testIsInvalid() { $res = $this->handler->isMetadataValid( null, 'Something Invalid Here.' ); $this->assertEquals( ExifBitmapHandler::METADATA_BAD, $res ); } + public function testGoodMetadata() { $meta = 'a:16:{s:10:"ImageWidth";i:20;s:11:"ImageLength";i:20;s:13:"BitsPerSample";a:3:{i:0;i:8;i:1;i:8;i:2;i:8;}s:11:"Compression";i:5;s:25:"PhotometricInterpretation";i:2;s:16:"ImageDescription";s:17:"Created with GIMP";s:12:"StripOffsets";i:8;s:11:"Orientation";i:1;s:15:"SamplesPerPixel";i:3;s:12:"RowsPerStrip";i:64;s:15:"StripByteCounts";i:238;s:11:"XResolution";s:19:"1207959552/16777216";s:11:"YResolution";s:19:"1207959552/16777216";s:19:"PlanarConfiguration";i:1;s:14:"ResolutionUnit";i:2;s:22:"MEDIAWIKI_EXIF_VERSION";i:2;}'; $res = $this->handler->isMetadataValid( null, $meta ); $this->assertEquals( ExifBitmapHandler::METADATA_GOOD, $res ); } + public function testIsOldGood() { $meta = 'a:16:{s:10:"ImageWidth";i:20;s:11:"ImageLength";i:20;s:13:"BitsPerSample";a:3:{i:0;i:8;i:1;i:8;i:2;i:8;}s:11:"Compression";i:5;s:25:"PhotometricInterpretation";i:2;s:16:"ImageDescription";s:17:"Created with GIMP";s:12:"StripOffsets";i:8;s:11:"Orientation";i:1;s:15:"SamplesPerPixel";i:3;s:12:"RowsPerStrip";i:64;s:15:"StripByteCounts";i:238;s:11:"XResolution";s:19:"1207959552/16777216";s:11:"YResolution";s:19:"1207959552/16777216";s:19:"PlanarConfiguration";i:1;s:14:"ResolutionUnit";i:2;s:22:"MEDIAWIKI_EXIF_VERSION";i:1;}'; $res = $this->handler->isMetadataValid( null, $meta ); $this->assertEquals( ExifBitmapHandler::METADATA_COMPATIBLE, $res ); } + // Handle metadata from paged tiff handler (gotten via instant commons) // gracefully. public function testPagedTiffHandledGracefully() { @@ -55,6 +56,7 @@ class ExifBitmapTest extends MediaWikiTestCase { $res = $this->handler->convertMetadataVersion( $metadata, 2 ); $this->assertEquals( $metadata, $res ); } + function testConvertMetadataToOld() { $metadata = array( 'foo' => array( 'First', 'Second', '_type' => 'ol' ), @@ -73,6 +75,7 @@ class ExifBitmapTest extends MediaWikiTestCase { $res = $this->handler->convertMetadataVersion( $metadata, 1 ); $this->assertEquals( $expected, $res ); } + function testConvertMetadataSoftware() { $metadata = array( 'Software' => array( array('GIMP', '1.1' ) ), @@ -85,6 +88,7 @@ class ExifBitmapTest extends MediaWikiTestCase { $res = $this->handler->convertMetadataVersion( $metadata, 1 ); $this->assertEquals( $expected, $res ); } + function testConvertMetadataSoftwareNormal() { $metadata = array( 'Software' => array( "GIMP 1.2", "vim" ), diff --git a/tests/phpunit/includes/media/ExifRotationTest.php b/tests/phpunit/includes/media/ExifRotationTest.php index 6af52dd10d..692a5f9c56 100644 --- a/tests/phpunit/includes/media/ExifRotationTest.php +++ b/tests/phpunit/includes/media/ExifRotationTest.php @@ -5,7 +5,7 @@ */ class ExifRotationTest extends MediaWikiTestCase { - function setUp() { + protected function setUp() { parent::setUp(); $this->handler = new BitmapHandler(); $filePath = __DIR__ . '/../../data/media'; @@ -33,7 +33,7 @@ class ExifRotationTest extends MediaWikiTestCase { $wgEnableAutoRotation = true; } - public function tearDown() { + protected function tearDown() { global $wgShowEXIF, $wgEnableAutoRotation; $wgShowEXIF = $this->show; $wgEnableAutoRotation = $this->oldAuto; @@ -43,7 +43,7 @@ class ExifRotationTest extends MediaWikiTestCase { /** * - * @dataProvider providerFiles + * @dataProvider provideFiles */ function testMetadata( $name, $type, $info ) { if ( !BitmapHandler::canRotate() ) { @@ -56,7 +56,7 @@ class ExifRotationTest extends MediaWikiTestCase { /** * - * @dataProvider providerFiles + * @dataProvider provideFiles */ function testRotationRendering( $name, $type, $info, $thumbs ) { if ( !BitmapHandler::canRotate() ) { @@ -94,12 +94,13 @@ class ExifRotationTest extends MediaWikiTestCase { } } + /* Utility function */ private function dataFile( $name, $type ) { return new UnregisteredLocalFile( false, $this->repo, "mwstore://localtesting/data/$name", $type ); } - function providerFiles() { + public static function provideFiles() { return array( array( 'landscape-plain.jpg', @@ -134,7 +135,7 @@ class ExifRotationTest extends MediaWikiTestCase { /** * Same as before, but with auto-rotation disabled. - * @dataProvider providerFilesNoAutoRotate + * @dataProvider provideFilesNoAutoRotate */ function testMetadataNoAutoRotate( $name, $type, $info ) { global $wgEnableAutoRotation; @@ -149,7 +150,7 @@ class ExifRotationTest extends MediaWikiTestCase { /** * - * @dataProvider providerFilesNoAutoRotate + * @dataProvider provideFilesNoAutoRotate */ function testRotationRenderingNoAutoRotate( $name, $type, $info, $thumbs ) { global $wgEnableAutoRotation; @@ -188,7 +189,7 @@ class ExifRotationTest extends MediaWikiTestCase { $wgEnableAutoRotation = true; } - function providerFilesNoAutoRotate() { + public static function provideFilesNoAutoRotate() { return array( array( 'landscape-plain.jpg', diff --git a/tests/phpunit/includes/media/ExifTest.php b/tests/phpunit/includes/media/ExifTest.php index 045777d771..7cc56f6b42 100644 --- a/tests/phpunit/includes/media/ExifTest.php +++ b/tests/phpunit/includes/media/ExifTest.php @@ -1,20 +1,16 @@ mediaPath = __DIR__ . '/../../data/media/'; if ( !wfDl( 'exif' ) ) { $this->markTestSkipped( "This test needs the exif extension." ); } - global $wgShowEXIF; - $this->showExif = $wgShowEXIF; - $wgShowEXIF = true; - } - public function tearDown() { - global $wgShowEXIF; - $wgShowEXIF = $this->showExif; + $this->setMwGlobals( 'wgShowEXIF', true ); } public function testGPSExtraction() { diff --git a/tests/phpunit/includes/media/FormatMetadataTest.php b/tests/phpunit/includes/media/FormatMetadataTest.php index 6ade67027c..4dadde56cf 100644 --- a/tests/phpunit/includes/media/FormatMetadataTest.php +++ b/tests/phpunit/includes/media/FormatMetadataTest.php @@ -1,6 +1,9 @@ markTestSkipped( "This test needs the exif extension." ); } @@ -15,13 +18,8 @@ class FormatMetadataTest extends MediaWikiTestCase { 'url' => 'http://localhost/thumbtest', 'backend' => $this->backend ) ); - global $wgShowEXIF; - $this->show = $wgShowEXIF; - $wgShowEXIF = true; - } - public function tearDown() { - global $wgShowEXIF; - $wgShowEXIF = $this->show; + + $this->setMwGlobals( 'wgShowEXIF', true ); } public function testInvalidDate() { diff --git a/tests/phpunit/includes/media/GIFMetadataExtractorTest.php b/tests/phpunit/includes/media/GIFMetadataExtractorTest.php index 650fdd5c7c..3a750aa2b2 100644 --- a/tests/phpunit/includes/media/GIFMetadataExtractorTest.php +++ b/tests/phpunit/includes/media/GIFMetadataExtractorTest.php @@ -1,20 +1,22 @@ mediaPath = __DIR__ . '/../../data/media/'; } /** * Put in a file, and see if the metadata coming out is as expected. * @param $filename String * @param $expected Array The extracted metadata. - * @dataProvider dataGetMetadata + * @dataProvider provideGetMetadata */ public function testGetMetadata( $filename, $expected ) { $actual = GIFMetadataExtractor::getMetadata( $this->mediaPath . $filename ); $this->assertEquals( $expected, $actual ); } - public function dataGetMetadata() { + public static function provideGetMetadata() { $xmpNugget = << diff --git a/tests/phpunit/includes/media/GIFTest.php b/tests/phpunit/includes/media/GIFTest.php index 5dcbeee03f..9ffc764d66 100644 --- a/tests/phpunit/includes/media/GIFTest.php +++ b/tests/phpunit/includes/media/GIFTest.php @@ -1,7 +1,9 @@ filePath = __DIR__ . '/../../data/media'; $this->backend = new FSFileBackend( array( 'name' => 'localtesting', @@ -20,17 +22,18 @@ class GIFHandlerTest extends MediaWikiTestCase { $res = $this->handler->getMetadata( null, $this->filePath . '/README' ); $this->assertEquals( GIFHandler::BROKEN_FILE, $res ); } + /** * @param $filename String basename of the file to check * @param $expected boolean Expected result. - * @dataProvider dataIsAnimated + * @dataProvider provideIsAnimated */ public function testIsAnimanted( $filename, $expected ) { $file = $this->dataFile( $filename, 'image/gif' ); $actual = $this->handler->isAnimatedImage( $file ); $this->assertEquals( $expected, $actual ); } - public function dataIsAnimated() { + public static function provideIsAnimated() { return array( array( 'animated.gif', true ), array( 'nonanimated.gif', false ), @@ -40,14 +43,14 @@ class GIFHandlerTest extends MediaWikiTestCase { /** * @param $filename String * @param $expected Integer Total image area - * @dataProvider dataGetImageArea + * @dataProvider provideGetImageArea */ public function testGetImageArea( $filename, $expected ) { $file = $this->dataFile( $filename, 'image/gif' ); $actual = $this->handler->getImageArea( $file, $file->getWidth(), $file->getHeight() ); $this->assertEquals( $expected, $actual ); } - public function dataGetImageArea() { + public static function provideGetImageArea() { return array( array( 'animated.gif', 5400 ), array( 'nonanimated.gif', 1350 ), @@ -57,13 +60,13 @@ class GIFHandlerTest extends MediaWikiTestCase { /** * @param $metadata String Serialized metadata * @param $expected Integer One of the class constants of GIFHandler - * @dataProvider dataIsMetadataValid + * @dataProvider provideIsMetadataValid */ public function testIsMetadataValid( $metadata, $expected ) { $actual = $this->handler->isMetadataValid( null, $metadata ); $this->assertEquals( $expected, $actual ); } - public function dataIsMetadataValid() { + public static function provideIsMetadataValid() { return array( array( GIFHandler::BROKEN_FILE, GIFHandler::METADATA_GOOD ), array( '', GIFHandler::METADATA_BAD ), @@ -76,7 +79,7 @@ class GIFHandlerTest extends MediaWikiTestCase { /** * @param $filename String * @param $expected String Serialized array - * @dataProvider dataGetMetadata + * @dataProvider provideGetMetadata */ public function testGetMetadata( $filename, $expected ) { $file = $this->dataFile( $filename, 'image/gif' ); @@ -84,7 +87,7 @@ class GIFHandlerTest extends MediaWikiTestCase { $this->assertEquals( unserialize( $expected ), unserialize( $actual ) ); } - public function dataGetMetadata() { + public static function provideGetMetadata() { return array( array( 'nonanimated.gif', 'a:4:{s:10:"frameCount";i:1;s:6:"looped";b:0;s:8:"duration";d:0.1000000000000000055511151231257827021181583404541015625;s:8:"metadata";a:2:{s:14:"GIFFileComment";a:1:{i:0;s:35:"GIF test file ⁕ Created with GIMP";}s:15:"_MW_GIF_VERSION";i:1;}}' ), array( 'animated-xmp.gif', 'a:4:{s:10:"frameCount";i:4;s:6:"looped";b:1;s:8:"duration";d:2.399999999999999911182158029987476766109466552734375;s:8:"metadata";a:5:{s:6:"Artist";s:7:"Bawolff";s:16:"ImageDescription";a:2:{s:9:"x-default";s:18:"A file to test GIF";s:5:"_type";s:4:"lang";}s:15:"SublocationDest";s:13:"The interwebs";s:14:"GIFFileComment";a:1:{i:0;s:16:"GIƒ·test·file";}s:15:"_MW_GIF_VERSION";i:1;}}' ), diff --git a/tests/phpunit/includes/media/JpegMetadataExtractorTest.php b/tests/phpunit/includes/media/JpegMetadataExtractorTest.php index 41d811902c..6e1c0af117 100644 --- a/tests/phpunit/includes/media/JpegMetadataExtractorTest.php +++ b/tests/phpunit/includes/media/JpegMetadataExtractorTest.php @@ -8,7 +8,9 @@ */ class JpegMetadataExtractorTest extends MediaWikiTestCase { - public function setUp() { + protected function setUp() { + parent::setUp(); + $this->filePath = __DIR__ . '/../../data/media/'; } @@ -18,13 +20,13 @@ class JpegMetadataExtractorTest extends MediaWikiTestCase { * * @param $file filename * - * @dataProvider dataUtf8Comment + * @dataProvider provideUtf8Comment */ public function testUtf8Comment( $file ) { $res = JpegMetadataExtractor::segmentSplitter( $this->filePath . $file ); $this->assertEquals( array( 'UTF-8 JPEG Comment — ¼' ), $res['COM'] ); } - public function dataUtf8Comment() { + public static function provideUtf8Comment() { return array( array( 'jpeg-comment-utf.jpg' ), array( 'jpeg-padding-even.jpg' ), diff --git a/tests/phpunit/includes/media/JpegTest.php b/tests/phpunit/includes/media/JpegTest.php index ea007f9031..05d3661efa 100644 --- a/tests/phpunit/includes/media/JpegTest.php +++ b/tests/phpunit/includes/media/JpegTest.php @@ -1,18 +1,15 @@ filePath = __DIR__ . '/../../data/media/'; if ( !wfDl( 'exif' ) ) { $this->markTestSkipped( "This test needs the exif extension." ); } - global $wgShowEXIF; - $this->show = $wgShowEXIF; - $wgShowEXIF = true; - } - public function tearDown() { - global $wgShowEXIF; - $wgShowEXIF = $this->show; + + $this->setMwGlobals( 'wgShowEXIF', true ); } public function testInvalidFile() { @@ -20,6 +17,7 @@ class JpegTest extends MediaWikiTestCase { $res = $jpeg->getMetadata( null, $this->filePath . 'README' ); $this->assertEquals( ExifBitmapHandler::BROKEN_FILE, $res ); } + public function testJpegMetadataExtraction() { $h = new JpegHandler; $res = $h->getMetadata( null, $this->filePath . 'test.jpg' ); diff --git a/tests/phpunit/includes/media/PNGMetadataExtractorTest.php b/tests/phpunit/includes/media/PNGMetadataExtractorTest.php index 1b1b2ec33a..ee1c6f8216 100644 --- a/tests/phpunit/includes/media/PNGMetadataExtractorTest.php +++ b/tests/phpunit/includes/media/PNGMetadataExtractorTest.php @@ -1,7 +1,7 @@ filePath = __DIR__ . '/../../data/media/'; } /** @@ -60,6 +60,8 @@ class PNGMetadataExtractorTest extends MediaWikiTestCase { /** * Test extraction of pHYs tags, which can tell what the * actual resolution of the image is (aka in dots per meter). + */ +/* function testPngPhysTag () { $meta = PNGMetadataExtractor::getMetadata( $this->filePath . 'Png-native-test.png' ); @@ -71,6 +73,7 @@ class PNGMetadataExtractorTest extends MediaWikiTestCase { $this->assertEquals( '2835/100', $meta['YResolution'] ); $this->assertEquals( 3, $meta['ResolutionUnit'] ); // 3 = cm } +*/ /** * Given a normal static PNG, check the animation metadata returned. diff --git a/tests/phpunit/includes/media/PNGTest.php b/tests/phpunit/includes/media/PNGTest.php index fe73c9c71c..2075758784 100644 --- a/tests/phpunit/includes/media/PNGTest.php +++ b/tests/phpunit/includes/media/PNGTest.php @@ -1,7 +1,9 @@ filePath = __DIR__ . '/../../data/media'; $this->backend = new FSFileBackend( array( 'name' => 'localtesting', @@ -23,14 +25,14 @@ class PNGHandlerTest extends MediaWikiTestCase { /** * @param $filename String basename of the file to check * @param $expected boolean Expected result. - * @dataProvider dataIsAnimated + * @dataProvider provideIsAnimated */ public function testIsAnimanted( $filename, $expected ) { $file = $this->dataFile( $filename, 'image/png' ); $actual = $this->handler->isAnimatedImage( $file ); $this->assertEquals( $expected, $actual ); } - public function dataIsAnimated() { + public static function provideIsAnimated() { return array( array( 'Animated_PNG_example_bouncing_beach_ball.png', true ), array( '1bit-png.png', false ), @@ -40,14 +42,14 @@ class PNGHandlerTest extends MediaWikiTestCase { /** * @param $filename String * @param $expected Integer Total image area - * @dataProvider dataGetImageArea + * @dataProvider provideGetImageArea */ public function testGetImageArea( $filename, $expected ) { $file = $this->dataFile($filename, 'image/png' ); $actual = $this->handler->getImageArea( $file, $file->getWidth(), $file->getHeight() ); $this->assertEquals( $expected, $actual ); } - public function dataGetImageArea() { + public static function provideGetImageArea() { return array( array( '1bit-png.png', 2500 ), array( 'greyscale-png.png', 2500 ), @@ -59,13 +61,13 @@ class PNGHandlerTest extends MediaWikiTestCase { /** * @param $metadata String Serialized metadata * @param $expected Integer One of the class constants of PNGHandler - * @dataProvider dataIsMetadataValid + * @dataProvider provideIsMetadataValid */ public function testIsMetadataValid( $metadata, $expected ) { $actual = $this->handler->isMetadataValid( null, $metadata ); $this->assertEquals( $expected, $actual ); } - public function dataIsMetadataValid() { + public static function provideIsMetadataValid() { return array( array( PNGHandler::BROKEN_FILE, PNGHandler::METADATA_GOOD ), array( '', PNGHandler::METADATA_BAD ), @@ -78,7 +80,7 @@ class PNGHandlerTest extends MediaWikiTestCase { /** * @param $filename String * @param $expected String Serialized array - * @dataProvider dataGetMetadata + * @dataProvider provideGetMetadata */ public function testGetMetadata( $filename, $expected ) { $file = $this->dataFile( $filename, 'image/png' ); @@ -86,7 +88,7 @@ class PNGHandlerTest extends MediaWikiTestCase { // $this->assertEquals( unserialize( $expected ), unserialize( $actual ) ); $this->assertEquals( ( $expected ), ( $actual ) ); } - public function dataGetMetadata() { + public static function provideGetMetadata() { return array( array( 'rgb-na-png.png', 'a:6:{s:10:"frameCount";i:0;s:9:"loopCount";i:1;s:8:"duration";d:0;s:8:"bitDepth";i:8;s:9:"colorType";s:10:"truecolour";s:8:"metadata";a:1:{s:15:"_MW_PNG_VERSION";i:1;}}' ), array( 'xmp.png', 'a:6:{s:10:"frameCount";i:0;s:9:"loopCount";i:1;s:8:"duration";d:0;s:8:"bitDepth";i:1;s:9:"colorType";s:14:"index-coloured";s:8:"metadata";a:2:{s:12:"SerialNumber";s:9:"123456789";s:15:"_MW_PNG_VERSION";i:1;}}' ), diff --git a/tests/phpunit/includes/media/SVGMetadataExtractorTest.php b/tests/phpunit/includes/media/SVGMetadataExtractorTest.php index 2116554eec..007ce46c2c 100644 --- a/tests/phpunit/includes/media/SVGMetadataExtractorTest.php +++ b/tests/phpunit/includes/media/SVGMetadataExtractorTest.php @@ -2,19 +2,19 @@ class SVGMetadataExtractorTest extends MediaWikiTestCase { - function setUp() { + protected function setUp() { AutoLoader::loadClass( 'SVGMetadataExtractorTest' ); } /** - * @dataProvider providerSvgFiles + * @dataProvider provideSvgFiles */ function testGetMetadata( $infile, $expected ) { $this->assertMetadata( $infile, $expected ); } /** - * @dataProvider providerSvgFilesWithXMLMetadata + * @dataProvider provideSvgFilesWithXMLMetadata */ function testGetXMLMetadata( $infile, $expected ) { $r = new XMLReader(); @@ -38,7 +38,7 @@ class SVGMetadataExtractorTest extends MediaWikiTestCase { } } - function providerSvgFiles() { + public static function provideSvgFiles() { $base = __DIR__ . '/../../data/media'; return array( array( @@ -81,7 +81,7 @@ class SVGMetadataExtractorTest extends MediaWikiTestCase { ); } - function providerSvgFilesWithXMLMetadata() { + public static function provideSvgFilesWithXMLMetadata() { $base = __DIR__ . '/../../data/media'; $metadata = ' diff --git a/tests/phpunit/includes/media/TiffTest.php b/tests/phpunit/includes/media/TiffTest.php index 4c79f66c0e..91c35c4b91 100644 --- a/tests/phpunit/includes/media/TiffTest.php +++ b/tests/phpunit/includes/media/TiffTest.php @@ -1,19 +1,15 @@ showExif = $wgShowEXIF; - $wgShowEXIF = true; + protected function setUp() { + parent::setUp(); + + $this->setMwGlobals( 'wgShowEXIF', true ); + $this->filePath = __DIR__ . '/../../data/media/'; $this->handler = new TiffHandler; } - public function tearDown() { - global $wgShowEXIF; - $wgShowEXIF = $this->showExif; - } - public function testInvalidFile() { if ( !wfDl( 'exif' ) ) { $this->markTestIncomplete( "This test needs the exif extension." ); diff --git a/tests/phpunit/includes/media/XMPTest.php b/tests/phpunit/includes/media/XMPTest.php index 8198d3b08b..be02dd71ef 100644 --- a/tests/phpunit/includes/media/XMPTest.php +++ b/tests/phpunit/includes/media/XMPTest.php @@ -1,7 +1,7 @@ markTestSkipped( 'Requires libxml to do XMP parsing' ); } @@ -14,7 +14,7 @@ class XMPTest extends MediaWikiTestCase { * @param $expected Array expected result of parsing the xmp. * @param $info String Short sentence on what's being tested. * - * @dataProvider dataXMPParse + * @dataProvider provideXMPParse */ public function testXMPParse( $xmp, $expected, $info ) { if ( !is_string( $xmp ) || !is_array( $expected ) ) { @@ -25,7 +25,7 @@ class XMPTest extends MediaWikiTestCase { $this->assertEquals( $expected, $reader->getResults(), $info, 0.0000000001 ); } - public function dataXMPParse() { + public static function provideXMPParse() { $xmpPath = __DIR__ . '/../../data/xmp/' ; $data = array(); diff --git a/tests/phpunit/includes/media/XMPValidateTest.php b/tests/phpunit/includes/media/XMPValidateTest.php index e2bb8d8dea..a2b4e1c29a 100644 --- a/tests/phpunit/includes/media/XMPValidateTest.php +++ b/tests/phpunit/includes/media/XMPValidateTest.php @@ -2,7 +2,7 @@ class XMPValidateTest extends MediaWikiTestCase { /** - * @dataProvider providerDate + * @dataProvider provideDates */ function testValidateDate( $value, $expected ) { // The method should modify $value. @@ -10,7 +10,7 @@ class XMPValidateTest extends MediaWikiTestCase { $this->assertEquals( $expected, $value ); } - function providerDate() { + public static function provideDates() { /* For reference valid date formats are: * YYYY * YYYY-MM diff --git a/tests/phpunit/includes/mobile/DeviceDetectionTest.php b/tests/phpunit/includes/mobile/DeviceDetectionTest.php index 0e15653206..2588691469 100644 --- a/tests/phpunit/includes/mobile/DeviceDetectionTest.php +++ b/tests/phpunit/includes/mobile/DeviceDetectionTest.php @@ -13,7 +13,7 @@ $this->assertEquals( $format, $detector->detectFormatName( $userAgent ) ); } - public function provideTestFormatName() { + public static function provideTestFormatName() { return array( array( 'android', 'Mozilla/5.0 (Linux; U; Android 2.1; en-us; Nexus One Build/ERD62) AppleWebKit/530.17 (KHTML, like Gecko) Version/4.0 Mobile Safari/530.17' ), array( 'iphone2', 'Mozilla/5.0 (ipod: U;CPU iPhone OS 2_2 like Mac OS X: es_es) AppleWebKit/525.18.1 (KHTML, like Gecko) Version/3.0 Mobile/3B48b Safari/419.3' ), diff --git a/tests/phpunit/includes/parser/MagicVariableTest.php b/tests/phpunit/includes/parser/MagicVariableTest.php index 31645313b9..46ef5da1d9 100644 --- a/tests/phpunit/includes/parser/MagicVariableTest.php +++ b/tests/phpunit/includes/parser/MagicVariableTest.php @@ -29,9 +29,10 @@ class MagicVariableTest extends MediaWikiTestCase { ); /** setup a basic parser object */ - function setUp() { - global $wgContLang; - $wgContLang = Language::factory( 'en' ); + protected function setUp() { + parent::setUp(); + + $this->setMwGlobals( 'wgContLang', Language::factory( 'en' ) ); $this->testParser = new Parser(); $this->testParser->Options( new ParserOptions() ); @@ -47,8 +48,10 @@ class MagicVariableTest extends MediaWikiTestCase { } /** destroy parser (TODO: is it really neded?)*/ - function tearDown() { + protected function tearDown() { unset( $this->testParser ); + + parent::tearDown(); } ############### TESTS ############################################# diff --git a/tests/phpunit/includes/parser/NewParserTest.php b/tests/phpunit/includes/parser/NewParserTest.php index ff6e472a20..848991ea5b 100644 --- a/tests/phpunit/includes/parser/NewParserTest.php +++ b/tests/phpunit/includes/parser/NewParserTest.php @@ -9,7 +9,7 @@ */ class NewParserTest extends MediaWikiTestCase { static protected $articles = array(); // Array of test articles defined by the tests - /* The dataProvider is run on a different instance than the test, so it must be static + /* The data provider is run on a different instance than the test, so it must be static * When running tests from several files, all tests will see all articles. */ static protected $backendToUse; @@ -31,7 +31,7 @@ class NewParserTest extends MediaWikiTestCase { protected $file = false; - function setUp() { + protected function setUp() { global $wgContLang, $wgNamespaceProtection, $wgNamespaceAliases; global $wgHooks, $IP; $wgContLang = Language::factory( 'en' ); @@ -100,7 +100,7 @@ class NewParserTest extends MediaWikiTestCase { $wgNamespaceAliases['Image_talk'] = NS_FILE_TALK; } - public function tearDown() { + protected function tearDown() { foreach ( $this->savedInitialGlobals as $var => $val ) { $GLOBALS[$var] = $val; } diff --git a/tests/phpunit/includes/parser/ParserMethodsTest.php b/tests/phpunit/includes/parser/ParserMethodsTest.php index dea406c398..e0f95b68cd 100644 --- a/tests/phpunit/includes/parser/ParserMethodsTest.php +++ b/tests/phpunit/includes/parser/ParserMethodsTest.php @@ -2,7 +2,7 @@ class ParserMethodsTest extends MediaWikiLangTestCase { - public function dataPreSaveTransform() { + public static function providePreSaveTransform() { return array( array( 'hello this is ~~~', "hello this is [[Special:Contributions/127.0.0.1|127.0.0.1]]", @@ -14,7 +14,7 @@ class ParserMethodsTest extends MediaWikiLangTestCase { } /** - * @dataProvider dataPreSaveTransform + * @dataProvider providePreSaveTransform */ public function testPreSaveTransform( $text, $expected ) { global $wgParser; diff --git a/tests/phpunit/includes/parser/ParserPreloadTest.php b/tests/phpunit/includes/parser/ParserPreloadTest.php index 0e8ef53078..d537b6e116 100644 --- a/tests/phpunit/includes/parser/ParserPreloadTest.php +++ b/tests/phpunit/includes/parser/ParserPreloadTest.php @@ -8,7 +8,7 @@ class ParserPreloadTest extends MediaWikiTestCase { private $testParserOptions; private $title; - function setUp() { + protected function setUp() { $this->testParserOptions = new ParserOptions(); $this->testParser = new Parser(); @@ -18,7 +18,7 @@ class ParserPreloadTest extends MediaWikiTestCase { $this->title = Title::newFromText( 'Preload Test' ); } - function tearDown() { + protected function tearDown() { unset( $this->testParser ); unset( $this->title ); } diff --git a/tests/phpunit/includes/parser/PreprocessorTest.php b/tests/phpunit/includes/parser/PreprocessorTest.php index fee5674805..d82fc6c09d 100644 --- a/tests/phpunit/includes/parser/PreprocessorTest.php +++ b/tests/phpunit/includes/parser/PreprocessorTest.php @@ -5,7 +5,7 @@ class PreprocessorTest extends MediaWikiTestCase { var $mPPNodeCount = 0; var $mOptions; - function setUp() { + protected function setUp() { global $wgParserConf; $this->mOptions = new ParserOptions(); $name = isset( $wgParserConf['preprocessorClass'] ) ? $wgParserConf['preprocessorClass'] : 'Preprocessor_DOM'; diff --git a/tests/phpunit/includes/search/SearchEngineTest.php b/tests/phpunit/includes/search/SearchEngineTest.php index f019ad6adb..f23f06d4b7 100644 --- a/tests/phpunit/includes/search/SearchEngineTest.php +++ b/tests/phpunit/includes/search/SearchEngineTest.php @@ -7,15 +7,11 @@ class SearchEngineTest extends MediaWikiTestCase { protected $search, $pageList; - function tearDown() { - unset( $this->search ); - } - /** * Checks for database type & version. * Will skip current test if DB does not support search. */ - function setUp() { + protected function setUp() { parent::setUp(); // Search tests require MySQL or SQLite with FTS # Get database type and version @@ -32,6 +28,10 @@ class SearchEngineTest extends MediaWikiTestCase { $this->search = new $searchType( $this->db ); } + protected function tearDown() { + unset( $this->search ); + } + function pageExists( $title ) { return false; } diff --git a/tests/phpunit/includes/search/SearchUpdateTest.php b/tests/phpunit/includes/search/SearchUpdateTest.php index 6e49a9a1c9..7d867bc497 100644 --- a/tests/phpunit/includes/search/SearchUpdateTest.php +++ b/tests/phpunit/includes/search/SearchUpdateTest.php @@ -19,7 +19,11 @@ class MockSearch extends SearchEngine { * @group Search */ class SearchUpdateTest extends MediaWikiTestCase { - static $searchType; + + protected function setUp() { + parent::setUp(); + $this->setMwGlobals( 'wgSearchType', 'MockSearch' ); + } function update( $text, $title = 'Test', $id = 1 ) { $u = new SearchUpdate( $id, $title, $text ); @@ -33,19 +37,6 @@ class SearchUpdateTest extends MediaWikiTestCase { return $resultText; } - function setUp() { - global $wgSearchType; - - self::$searchType = $wgSearchType; - $wgSearchType = 'MockSearch'; - } - - function tearDown() { - global $wgSearchType; - - $wgSearchType = self::$searchType; - } - function testUpdateText() { $this->assertEquals( 'test', diff --git a/tests/phpunit/includes/specials/SpecialRecentchangesTest.php b/tests/phpunit/includes/specials/SpecialRecentchangesTest.php index 2e4f4b09b8..f1023093d2 100644 --- a/tests/phpunit/includes/specials/SpecialRecentchangesTest.php +++ b/tests/phpunit/includes/specials/SpecialRecentchangesTest.php @@ -14,7 +14,7 @@ class SpecialRecentchangesTest extends MediaWikiTestCase { */ protected $rc; - function setUp() { + protected function setUp() { } /** helper to test SpecialRecentchanges::buildMainQueryConds() */ @@ -120,7 +120,7 @@ class SpecialRecentchangesTest extends MediaWikiTestCase { * Provides associated namespaces to test recent changes * namespaces association filtering. */ - public function provideNamespacesAssociations() { + public static function provideNamespacesAssociations() { return array( # (NS => Associated_NS) array( NS_MAIN, NS_TALK), array( NS_TALK, NS_MAIN), diff --git a/tests/phpunit/includes/specials/SpecialSearchTest.php b/tests/phpunit/includes/specials/SpecialSearchTest.php index 20e42a68bd..b2063ebdb8 100644 --- a/tests/phpunit/includes/specials/SpecialSearchTest.php +++ b/tests/phpunit/includes/specials/SpecialSearchTest.php @@ -10,9 +10,6 @@ class SpecialSearchTest extends MediaWikiTestCase { private $search; - function setUp() { } - function tearDown() { } - /** * @covers SpecialSearch::load * @dataProvider provideSearchOptionsTests diff --git a/tests/phpunit/includes/upload/UploadFromUrlTest.php b/tests/phpunit/includes/upload/UploadFromUrlTest.php index 3093334477..59663ba9f5 100644 --- a/tests/phpunit/includes/upload/UploadFromUrlTest.php +++ b/tests/phpunit/includes/upload/UploadFromUrlTest.php @@ -6,7 +6,7 @@ */ class UploadFromUrlTest extends ApiTestCase { - public function setUp() { + protected function setUp() { global $wgEnableUploads, $wgAllowCopyUploads, $wgAllowAsyncCopyUploads; parent::setUp(); diff --git a/tests/phpunit/includes/upload/UploadStashTest.php b/tests/phpunit/includes/upload/UploadStashTest.php index 66fafaaffe..857aef5c80 100644 --- a/tests/phpunit/includes/upload/UploadStashTest.php +++ b/tests/phpunit/includes/upload/UploadStashTest.php @@ -8,7 +8,7 @@ class UploadStashTest extends MediaWikiTestCase { */ public static $users; - public function setUp() { + protected function setUp() { parent::setUp(); // Setup a file for bug 29408 @@ -31,6 +31,18 @@ class UploadStashTest extends MediaWikiTestCase { ); } + protected function tearDown() { + if ( file_exists( $this->bug29408File . "." ) ) { + unlink( $this->bug29408File . "." ); + } + + if ( file_exists( $this->bug29408File ) ) { + unlink( $this->bug29408File ); + } + + parent::tearDown(); + } + public function testBug29408() { global $wgUser; $wgUser = self::$users['uploader']->user; @@ -62,16 +74,4 @@ class UploadStashTest extends MediaWikiTestCase { $request = new FauxRequest( array( 'wpFileKey' => 'testkey-test.test', 'wpSessionKey' => 'foo') ); $this->assertTrue( UploadFromStash::isValidRequest($request), 'Check key precedence' ); } - - public function tearDown() { - parent::tearDown(); - - if( file_exists( $this->bug29408File . "." ) ) { - unlink( $this->bug29408File . "." ); - } - - if( file_exists( $this->bug29408File ) ) { - unlink( $this->bug29408File ); - } - } } diff --git a/tests/phpunit/includes/upload/UploadTest.php b/tests/phpunit/includes/upload/UploadTest.php index 6948f5b19e..d75773467a 100644 --- a/tests/phpunit/includes/upload/UploadTest.php +++ b/tests/phpunit/includes/upload/UploadTest.php @@ -6,7 +6,7 @@ class UploadTest extends MediaWikiTestCase { protected $upload; - function setUp() { + protected function setUp() { global $wgHooks; parent::setUp(); @@ -17,7 +17,7 @@ class UploadTest extends MediaWikiTestCase { }; } - function tearDown() { + protected function tearDown() { global $wgHooks; $wgHooks = $this->hooks; } @@ -27,7 +27,7 @@ class UploadTest extends MediaWikiTestCase { * First checks the return code * of UploadBase::getTitle() and then the actual returned title * - * @dataProvider dataTestTitleValidation + * @dataProvider provideTestTitleValidation */ public function testTitleValidation( $srcFilename, $dstFilename, $code, $msg ) { /* Check the result code */ @@ -46,7 +46,7 @@ class UploadTest extends MediaWikiTestCase { /** * Test various forms of valid and invalid titles that can be supplied. */ - public function dataTestTitleValidation() { + public static function provideTestTitleValidation() { return array( /* Test a valid title */ array( 'ValidTitle.jpg', 'ValidTitle.jpg', UploadBase::OK, diff --git a/tests/phpunit/languages/LanguageAmTest.php b/tests/phpunit/languages/LanguageAmTest.php index 3a648ded5b..26790886b4 100644 --- a/tests/phpunit/languages/LanguageAmTest.php +++ b/tests/phpunit/languages/LanguageAmTest.php @@ -9,10 +9,10 @@ class LanguageAmTest extends MediaWikiTestCase { private $lang; - function setUp() { + protected function setUp() { $this->lang = Language::factory( 'Am' ); } - function tearDown() { + protected function tearDown() { unset( $this->lang ); } diff --git a/tests/phpunit/languages/LanguageArTest.php b/tests/phpunit/languages/LanguageArTest.php index b23e053410..84507c5da8 100644 --- a/tests/phpunit/languages/LanguageArTest.php +++ b/tests/phpunit/languages/LanguageArTest.php @@ -8,10 +8,10 @@ class LanguageArTest extends MediaWikiTestCase { private $lang; - function setUp() { + protected function setUp() { $this->lang = Language::factory( 'Ar' ); } - function tearDown() { + protected function tearDown() { unset( $this->lang ); } diff --git a/tests/phpunit/languages/LanguageBeTest.php b/tests/phpunit/languages/LanguageBeTest.php index 735ccc6372..3135ca8b9a 100644 --- a/tests/phpunit/languages/LanguageBeTest.php +++ b/tests/phpunit/languages/LanguageBeTest.php @@ -9,10 +9,10 @@ class LanguageBeTest extends MediaWikiTestCase { private $lang; - function setUp() { + protected function setUp() { $this->lang = Language::factory( 'Be' ); } - function tearDown() { + protected function tearDown() { unset( $this->lang ); } diff --git a/tests/phpunit/languages/LanguageBe_taraskTest.php b/tests/phpunit/languages/LanguageBe_taraskTest.php index 765cdb8fae..11aacb64c6 100644 --- a/tests/phpunit/languages/LanguageBe_taraskTest.php +++ b/tests/phpunit/languages/LanguageBe_taraskTest.php @@ -3,10 +3,10 @@ class LanguageBeTaraskTest extends MediaWikiTestCase { private $lang; - function setUp() { + protected function setUp() { $this->lang = Language::factory( 'Be-tarask' ); } - function tearDown() { + protected function tearDown() { unset( $this->lang ); } diff --git a/tests/phpunit/languages/LanguageBhTest.php b/tests/phpunit/languages/LanguageBhTest.php index e1e2a13e9a..00f4e13468 100644 --- a/tests/phpunit/languages/LanguageBhTest.php +++ b/tests/phpunit/languages/LanguageBhTest.php @@ -9,10 +9,10 @@ class LanguageBhTest extends MediaWikiTestCase { private $lang; - function setUp() { + protected function setUp() { $this->lang = Language::factory( 'Bh' ); } - function tearDown() { + protected function tearDown() { unset( $this->lang ); } diff --git a/tests/phpunit/languages/LanguageBsTest.php b/tests/phpunit/languages/LanguageBsTest.php index b6631c03d8..39391af603 100644 --- a/tests/phpunit/languages/LanguageBsTest.php +++ b/tests/phpunit/languages/LanguageBsTest.php @@ -9,10 +9,10 @@ class LanguageBsTest extends MediaWikiTestCase { private $lang; - function setUp() { + protected function setUp() { $this->lang = Language::factory( 'Bs' ); } - function tearDown() { + protected function tearDown() { unset( $this->lang ); } diff --git a/tests/phpunit/languages/LanguageCsTest.php b/tests/phpunit/languages/LanguageCsTest.php index dda29f9a5e..862de52513 100644 --- a/tests/phpunit/languages/LanguageCsTest.php +++ b/tests/phpunit/languages/LanguageCsTest.php @@ -9,10 +9,10 @@ class LanguageCsTest extends MediaWikiTestCase { private $lang; - function setUp() { + protected function setUp() { $this->lang = Language::factory( 'cs' ); } - function tearDown() { + protected function tearDown() { unset( $this->lang ); } diff --git a/tests/phpunit/languages/LanguageCuTest.php b/tests/phpunit/languages/LanguageCuTest.php index f8186d7b6a..5d5d60cd4c 100644 --- a/tests/phpunit/languages/LanguageCuTest.php +++ b/tests/phpunit/languages/LanguageCuTest.php @@ -9,10 +9,10 @@ class LanguageCuTest extends MediaWikiTestCase { private $lang; - function setUp() { + protected function setUp() { $this->lang = Language::factory( 'cu' ); } - function tearDown() { + protected function tearDown() { unset( $this->lang ); } diff --git a/tests/phpunit/languages/LanguageCyTest.php b/tests/phpunit/languages/LanguageCyTest.php index e9f9e41058..406a943ee1 100644 --- a/tests/phpunit/languages/LanguageCyTest.php +++ b/tests/phpunit/languages/LanguageCyTest.php @@ -9,10 +9,10 @@ class LanguageCyTest extends MediaWikiTestCase { private $lang; - function setUp() { + protected function setUp() { $this->lang = Language::factory( 'cy' ); } - function tearDown() { + protected function tearDown() { unset( $this->lang ); } diff --git a/tests/phpunit/languages/LanguageDsbTest.php b/tests/phpunit/languages/LanguageDsbTest.php index ab7f9313c6..516b9ee843 100644 --- a/tests/phpunit/languages/LanguageDsbTest.php +++ b/tests/phpunit/languages/LanguageDsbTest.php @@ -9,10 +9,10 @@ class LanguageDsbTest extends MediaWikiTestCase { private $lang; - function setUp() { + protected function setUp() { $this->lang = Language::factory( 'dsb' ); } - function tearDown() { + protected function tearDown() { unset( $this->lang ); } diff --git a/tests/phpunit/languages/LanguageFrTest.php b/tests/phpunit/languages/LanguageFrTest.php index 8538744ec5..0a290289c2 100644 --- a/tests/phpunit/languages/LanguageFrTest.php +++ b/tests/phpunit/languages/LanguageFrTest.php @@ -9,10 +9,10 @@ class LanguageFrTest extends MediaWikiTestCase { private $lang; - function setUp() { + protected function setUp() { $this->lang = Language::factory( 'fr' ); } - function tearDown() { + protected function tearDown() { unset( $this->lang ); } diff --git a/tests/phpunit/languages/LanguageGaTest.php b/tests/phpunit/languages/LanguageGaTest.php index fbd9f11df1..9535cb1515 100644 --- a/tests/phpunit/languages/LanguageGaTest.php +++ b/tests/phpunit/languages/LanguageGaTest.php @@ -9,10 +9,10 @@ class LanguageGaTest extends MediaWikiTestCase { private $lang; - function setUp() { + protected function setUp() { $this->lang = Language::factory( 'ga' ); } - function tearDown() { + protected function tearDown() { unset( $this->lang ); } diff --git a/tests/phpunit/languages/LanguageGdTest.php b/tests/phpunit/languages/LanguageGdTest.php index 24574bda21..e6bfdd7996 100644 --- a/tests/phpunit/languages/LanguageGdTest.php +++ b/tests/phpunit/languages/LanguageGdTest.php @@ -9,10 +9,10 @@ class LanguageGdTest extends MediaWikiTestCase { private $lang; - function setUp() { + protected function setUp() { $this->lang = Language::factory( 'gd' ); } - function tearDown() { + protected function tearDown() { unset( $this->lang ); } diff --git a/tests/phpunit/languages/LanguageGvTest.php b/tests/phpunit/languages/LanguageGvTest.php index 3d298b9b59..18cf225670 100644 --- a/tests/phpunit/languages/LanguageGvTest.php +++ b/tests/phpunit/languages/LanguageGvTest.php @@ -9,10 +9,10 @@ class LanguageGvTest extends MediaWikiTestCase { private $lang; - function setUp() { + protected function setUp() { $this->lang = Language::factory( 'gv' ); } - function tearDown() { + protected function tearDown() { unset( $this->lang ); } diff --git a/tests/phpunit/languages/LanguageHeTest.php b/tests/phpunit/languages/LanguageHeTest.php index 7833da7149..6205320f25 100644 --- a/tests/phpunit/languages/LanguageHeTest.php +++ b/tests/phpunit/languages/LanguageHeTest.php @@ -9,10 +9,10 @@ class LanguageHeTest extends MediaWikiTestCase { private $lang; - function setUp() { + protected function setUp() { $this->lang = Language::factory( 'he' ); } - function tearDown() { + protected function tearDown() { unset( $this->lang ); } diff --git a/tests/phpunit/languages/LanguageHiTest.php b/tests/phpunit/languages/LanguageHiTest.php index ead9e02020..bb3b5faf91 100644 --- a/tests/phpunit/languages/LanguageHiTest.php +++ b/tests/phpunit/languages/LanguageHiTest.php @@ -9,10 +9,10 @@ class LanguageHiTest extends MediaWikiTestCase { private $lang; - function setUp() { + protected function setUp() { $this->lang = Language::factory( 'Hi' ); } - function tearDown() { + protected function tearDown() { unset( $this->lang ); } diff --git a/tests/phpunit/languages/LanguageHrTest.php b/tests/phpunit/languages/LanguageHrTest.php index 4f1c66bfca..6f0ca1b329 100644 --- a/tests/phpunit/languages/LanguageHrTest.php +++ b/tests/phpunit/languages/LanguageHrTest.php @@ -9,10 +9,10 @@ class LanguageHrTest extends MediaWikiTestCase { private $lang; - function setUp() { + protected function setUp() { $this->lang = Language::factory( 'hr' ); } - function tearDown() { + protected function tearDown() { unset( $this->lang ); } diff --git a/tests/phpunit/languages/LanguageHsbTest.php b/tests/phpunit/languages/LanguageHsbTest.php index 803c772184..d336e8174a 100644 --- a/tests/phpunit/languages/LanguageHsbTest.php +++ b/tests/phpunit/languages/LanguageHsbTest.php @@ -9,10 +9,10 @@ class LanguageHsbTest extends MediaWikiTestCase { private $lang; - function setUp() { + protected function setUp() { $this->lang = Language::factory( 'hsb' ); } - function tearDown() { + protected function tearDown() { unset( $this->lang ); } diff --git a/tests/phpunit/languages/LanguageHuTest.php b/tests/phpunit/languages/LanguageHuTest.php index adbd37ecd6..31818687fe 100644 --- a/tests/phpunit/languages/LanguageHuTest.php +++ b/tests/phpunit/languages/LanguageHuTest.php @@ -9,10 +9,10 @@ class LanguageHuTest extends MediaWikiTestCase { private $lang; - function setUp() { + protected function setUp() { $this->lang = Language::factory( 'Hu' ); } - function tearDown() { + protected function tearDown() { unset( $this->lang ); } diff --git a/tests/phpunit/languages/LanguageHyTest.php b/tests/phpunit/languages/LanguageHyTest.php index 7990bdfce2..2885707c6e 100644 --- a/tests/phpunit/languages/LanguageHyTest.php +++ b/tests/phpunit/languages/LanguageHyTest.php @@ -9,10 +9,10 @@ class LanguageHyTest extends MediaWikiTestCase { private $lang; - function setUp() { + protected function setUp() { $this->lang = Language::factory( 'hy' ); } - function tearDown() { + protected function tearDown() { unset( $this->lang ); } diff --git a/tests/phpunit/languages/LanguageKshTest.php b/tests/phpunit/languages/LanguageKshTest.php index ab889464cd..78ff4455ee 100644 --- a/tests/phpunit/languages/LanguageKshTest.php +++ b/tests/phpunit/languages/LanguageKshTest.php @@ -9,10 +9,10 @@ class LanguageKshTest extends MediaWikiTestCase { private $lang; - function setUp() { + protected function setUp() { $this->lang = Language::factory( 'ksh' ); } - function tearDown() { + protected function tearDown() { unset( $this->lang ); } diff --git a/tests/phpunit/languages/LanguageLnTest.php b/tests/phpunit/languages/LanguageLnTest.php index 0fd9167e0e..60b4945128 100644 --- a/tests/phpunit/languages/LanguageLnTest.php +++ b/tests/phpunit/languages/LanguageLnTest.php @@ -9,10 +9,10 @@ class LanguageLnTest extends MediaWikiTestCase { private $lang; - function setUp() { + protected function setUp() { $this->lang = Language::factory( 'ln' ); } - function tearDown() { + protected function tearDown() { unset( $this->lang ); } diff --git a/tests/phpunit/languages/LanguageLtTest.php b/tests/phpunit/languages/LanguageLtTest.php index 0d7c7d3e9f..821e02888a 100644 --- a/tests/phpunit/languages/LanguageLtTest.php +++ b/tests/phpunit/languages/LanguageLtTest.php @@ -9,10 +9,10 @@ class LanguageLtTest extends MediaWikiTestCase { private $lang; - function setUp() { + protected function setUp() { $this->lang = Language::factory( 'Lt' ); } - function tearDown() { + protected function tearDown() { unset( $this->lang ); } diff --git a/tests/phpunit/languages/LanguageLvTest.php b/tests/phpunit/languages/LanguageLvTest.php index 0636da5f52..bb0dc6c82e 100644 --- a/tests/phpunit/languages/LanguageLvTest.php +++ b/tests/phpunit/languages/LanguageLvTest.php @@ -9,10 +9,10 @@ class LanguageLvTest extends MediaWikiTestCase { private $lang; - function setUp() { + protected function setUp() { $this->lang = Language::factory( 'lv' ); } - function tearDown() { + protected function tearDown() { unset( $this->lang ); } diff --git a/tests/phpunit/languages/LanguageMgTest.php b/tests/phpunit/languages/LanguageMgTest.php index 06b5654728..d6ac643efb 100644 --- a/tests/phpunit/languages/LanguageMgTest.php +++ b/tests/phpunit/languages/LanguageMgTest.php @@ -9,10 +9,10 @@ class LanguageMgTest extends MediaWikiTestCase { private $lang; - function setUp() { + protected function setUp() { $this->lang = Language::factory( 'mg' ); } - function tearDown() { + protected function tearDown() { unset( $this->lang ); } diff --git a/tests/phpunit/languages/LanguageMkTest.php b/tests/phpunit/languages/LanguageMkTest.php index cf5ec3d943..21a9e41e01 100644 --- a/tests/phpunit/languages/LanguageMkTest.php +++ b/tests/phpunit/languages/LanguageMkTest.php @@ -9,10 +9,10 @@ class LanguageMkTest extends MediaWikiTestCase { private $lang; - function setUp() { + protected function setUp() { $this->lang = Language::factory( 'mk' ); } - function tearDown() { + protected function tearDown() { unset( $this->lang ); } diff --git a/tests/phpunit/languages/LanguageMlTest.php b/tests/phpunit/languages/LanguageMlTest.php index 8c4b0b2f41..9af2389fd0 100644 --- a/tests/phpunit/languages/LanguageMlTest.php +++ b/tests/phpunit/languages/LanguageMlTest.php @@ -9,10 +9,10 @@ class LanguageMlTest extends MediaWikiTestCase { private $lang; - function setUp() { + protected function setUp() { $this->lang = Language::factory( 'Ml' ); } - function tearDown() { + protected function tearDown() { unset( $this->lang ); } diff --git a/tests/phpunit/languages/LanguageMoTest.php b/tests/phpunit/languages/LanguageMoTest.php index 533e590fab..4f208d994e 100644 --- a/tests/phpunit/languages/LanguageMoTest.php +++ b/tests/phpunit/languages/LanguageMoTest.php @@ -9,10 +9,10 @@ class LanguageMoTest extends MediaWikiTestCase { private $lang; - function setUp() { + protected function setUp() { $this->lang = Language::factory( 'mo' ); } - function tearDown() { + protected function tearDown() { unset( $this->lang ); } diff --git a/tests/phpunit/languages/LanguageMtTest.php b/tests/phpunit/languages/LanguageMtTest.php index 421bb3889e..4d25347d95 100644 --- a/tests/phpunit/languages/LanguageMtTest.php +++ b/tests/phpunit/languages/LanguageMtTest.php @@ -9,10 +9,10 @@ class LanguageMtTest extends MediaWikiTestCase { private $lang; - function setUp() { + protected function setUp() { $this->lang = Language::factory( 'mt' ); } - function tearDown() { + protected function tearDown() { unset( $this->lang ); } diff --git a/tests/phpunit/languages/LanguageNlTest.php b/tests/phpunit/languages/LanguageNlTest.php index cf979cd24c..c8cfbb6674 100644 --- a/tests/phpunit/languages/LanguageNlTest.php +++ b/tests/phpunit/languages/LanguageNlTest.php @@ -9,10 +9,10 @@ class LanguageNlTest extends MediaWikiTestCase { private $lang; - function setUp() { + protected function setUp() { $this->lang = Language::factory( 'Nl' ); } - function tearDown() { + protected function tearDown() { unset( $this->lang ); } diff --git a/tests/phpunit/languages/LanguageNsoTest.php b/tests/phpunit/languages/LanguageNsoTest.php index ea39362832..1e70997898 100644 --- a/tests/phpunit/languages/LanguageNsoTest.php +++ b/tests/phpunit/languages/LanguageNsoTest.php @@ -9,10 +9,10 @@ class LanguageNsoTest extends MediaWikiTestCase { private $lang; - function setUp() { + protected function setUp() { $this->lang = Language::factory( 'nso' ); } - function tearDown() { + protected function tearDown() { unset( $this->lang ); } diff --git a/tests/phpunit/languages/LanguagePlTest.php b/tests/phpunit/languages/LanguagePlTest.php index e56d4b77c9..a5436409c0 100644 --- a/tests/phpunit/languages/LanguagePlTest.php +++ b/tests/phpunit/languages/LanguagePlTest.php @@ -9,10 +9,10 @@ class LanguagePlTest extends MediaWikiTestCase { private $lang; - function setUp() { + protected function setUp() { $this->lang = Language::factory( 'pl' ); } - function tearDown() { + protected function tearDown() { unset( $this->lang ); } diff --git a/tests/phpunit/languages/LanguageRoTest.php b/tests/phpunit/languages/LanguageRoTest.php index 5270f6fee5..9bf01a4906 100644 --- a/tests/phpunit/languages/LanguageRoTest.php +++ b/tests/phpunit/languages/LanguageRoTest.php @@ -9,10 +9,10 @@ class LanguageRoTest extends MediaWikiTestCase { private $lang; - function setUp() { + protected function setUp() { $this->lang = Language::factory( 'ro' ); } - function tearDown() { + protected function tearDown() { unset( $this->lang ); } diff --git a/tests/phpunit/languages/LanguageRuTest.php b/tests/phpunit/languages/LanguageRuTest.php index 7a1f193b79..189a96ce7c 100644 --- a/tests/phpunit/languages/LanguageRuTest.php +++ b/tests/phpunit/languages/LanguageRuTest.php @@ -10,10 +10,10 @@ class LanguageRuTest extends MediaWikiTestCase { private $lang; - function setUp() { + protected function setUp() { $this->lang = Language::factory( 'ru' ); } - function tearDown() { + protected function tearDown() { unset( $this->lang ); } diff --git a/tests/phpunit/languages/LanguageSeTest.php b/tests/phpunit/languages/LanguageSeTest.php index 065ec29ec7..51cfd2f002 100644 --- a/tests/phpunit/languages/LanguageSeTest.php +++ b/tests/phpunit/languages/LanguageSeTest.php @@ -9,10 +9,10 @@ class LanguageSeTest extends MediaWikiTestCase { private $lang; - function setUp() { + protected function setUp() { $this->lang = Language::factory( 'se' ); } - function tearDown() { + protected function tearDown() { unset( $this->lang ); } diff --git a/tests/phpunit/languages/LanguageSgsTest.php b/tests/phpunit/languages/LanguageSgsTest.php index 931c82f0b0..62f2775491 100644 --- a/tests/phpunit/languages/LanguageSgsTest.php +++ b/tests/phpunit/languages/LanguageSgsTest.php @@ -9,10 +9,10 @@ class LanguageSgsTest extends MediaWikiTestCase { private $lang; - function setUp() { + protected function setUp() { $this->lang = Language::factory( 'Sgs' ); } - function tearDown() { + protected function tearDown() { unset( $this->lang ); } diff --git a/tests/phpunit/languages/LanguageShTest.php b/tests/phpunit/languages/LanguageShTest.php index b8169aed86..1d8ae7c316 100644 --- a/tests/phpunit/languages/LanguageShTest.php +++ b/tests/phpunit/languages/LanguageShTest.php @@ -9,10 +9,10 @@ class LanguageShTest extends MediaWikiTestCase { private $lang; - function setUp() { + protected function setUp() { $this->lang = Language::factory( 'sh' ); } - function tearDown() { + protected function tearDown() { unset( $this->lang ); } diff --git a/tests/phpunit/languages/LanguageSkTest.php b/tests/phpunit/languages/LanguageSkTest.php index 4cfd840e50..25823cf4b4 100644 --- a/tests/phpunit/languages/LanguageSkTest.php +++ b/tests/phpunit/languages/LanguageSkTest.php @@ -10,10 +10,10 @@ class LanguageSkTest extends MediaWikiTestCase { private $lang; - function setUp() { + protected function setUp() { $this->lang = Language::factory( 'sk' ); } - function tearDown() { + protected function tearDown() { unset( $this->lang ); } diff --git a/tests/phpunit/languages/LanguageSlTest.php b/tests/phpunit/languages/LanguageSlTest.php index c1f756918f..76de0fcf4f 100644 --- a/tests/phpunit/languages/LanguageSlTest.php +++ b/tests/phpunit/languages/LanguageSlTest.php @@ -10,10 +10,10 @@ class LanguageSlTest extends MediaWikiTestCase { private $lang; - function setUp() { + protected function setUp() { $this->lang = Language::factory( 'sl' ); } - function tearDown() { + protected function tearDown() { unset( $this->lang ); } diff --git a/tests/phpunit/languages/LanguageSmaTest.php b/tests/phpunit/languages/LanguageSmaTest.php index b7e72e971e..cf1447757a 100644 --- a/tests/phpunit/languages/LanguageSmaTest.php +++ b/tests/phpunit/languages/LanguageSmaTest.php @@ -9,10 +9,10 @@ class LanguageSmaTest extends MediaWikiTestCase { private $lang; - function setUp() { + protected function setUp() { $this->lang = Language::factory( 'sma' ); } - function tearDown() { + protected function tearDown() { unset( $this->lang ); } diff --git a/tests/phpunit/languages/LanguageSrTest.php b/tests/phpunit/languages/LanguageSrTest.php index d44ecf8e5b..7be4589c03 100644 --- a/tests/phpunit/languages/LanguageSrTest.php +++ b/tests/phpunit/languages/LanguageSrTest.php @@ -19,10 +19,10 @@ class LanguageSrTest extends MediaWikiTestCase { /* Language object. Initialized before each test */ private $lang; - function setUp() { + protected function setUp() { $this->lang = Language::factory( 'sr' ); } - function tearDown() { + protected function tearDown() { unset( $this->lang ); } diff --git a/tests/phpunit/languages/LanguageTest.php b/tests/phpunit/languages/LanguageTest.php index bfb45c75c6..621c891735 100644 --- a/tests/phpunit/languages/LanguageTest.php +++ b/tests/phpunit/languages/LanguageTest.php @@ -7,10 +7,10 @@ class LanguageTest extends MediaWikiTestCase { */ private $lang; - function setUp() { + protected function setUp() { $this->lang = Language::factory( 'en' ); } - function tearDown() { + protected function tearDown() { unset( $this->lang ); } diff --git a/tests/phpunit/languages/LanguageTiTest.php b/tests/phpunit/languages/LanguageTiTest.php index 4bfaa0097b..175cdb97c0 100644 --- a/tests/phpunit/languages/LanguageTiTest.php +++ b/tests/phpunit/languages/LanguageTiTest.php @@ -9,10 +9,10 @@ class LanguageTiTest extends MediaWikiTestCase { private $lang; - function setUp() { + protected function setUp() { $this->lang = Language::factory( 'Ti' ); } - function tearDown() { + protected function tearDown() { unset( $this->lang ); } diff --git a/tests/phpunit/languages/LanguageTlTest.php b/tests/phpunit/languages/LanguageTlTest.php index a1facd14a2..e03531ffd0 100644 --- a/tests/phpunit/languages/LanguageTlTest.php +++ b/tests/phpunit/languages/LanguageTlTest.php @@ -9,10 +9,10 @@ class LanguageTlTest extends MediaWikiTestCase { private $lang; - function setUp() { + protected function setUp() { $this->lang = Language::factory( 'Tl' ); } - function tearDown() { + protected function tearDown() { unset( $this->lang ); } diff --git a/tests/phpunit/languages/LanguageTrTest.php b/tests/phpunit/languages/LanguageTrTest.php index bda4c9d96e..a3cacc2489 100644 --- a/tests/phpunit/languages/LanguageTrTest.php +++ b/tests/phpunit/languages/LanguageTrTest.php @@ -9,10 +9,10 @@ class LanguageTrTest extends MediaWikiTestCase { private $lang; - function setUp() { + protected function setUp() { $this->lang = Language::factory( 'Tr' ); } - function tearDown() { + protected function tearDown() { unset( $this->lang ); } diff --git a/tests/phpunit/languages/LanguageUkTest.php b/tests/phpunit/languages/LanguageUkTest.php index 60fafb0dd7..2b6f707fba 100644 --- a/tests/phpunit/languages/LanguageUkTest.php +++ b/tests/phpunit/languages/LanguageUkTest.php @@ -10,10 +10,10 @@ class LanguageUkTest extends MediaWikiTestCase { private $lang; - function setUp() { + protected function setUp() { $this->lang = Language::factory( 'Uk' ); } - function tearDown() { + protected function tearDown() { unset( $this->lang ); } diff --git a/tests/phpunit/languages/LanguageUzTest.php b/tests/phpunit/languages/LanguageUzTest.php index 723872836f..0314649107 100644 --- a/tests/phpunit/languages/LanguageUzTest.php +++ b/tests/phpunit/languages/LanguageUzTest.php @@ -19,10 +19,10 @@ class LanguageUzTest extends MediaWikiTestCase { /* Language object. Initialized before each test */ private $lang; - function setUp() { + protected function setUp() { $this->lang = Language::factory( 'uz' ); } - function tearDown() { + protected function tearDown() { unset( $this->lang ); } diff --git a/tests/phpunit/languages/LanguageWaTest.php b/tests/phpunit/languages/LanguageWaTest.php index 172f19b93f..08312ce943 100644 --- a/tests/phpunit/languages/LanguageWaTest.php +++ b/tests/phpunit/languages/LanguageWaTest.php @@ -9,10 +9,10 @@ class LanguageWaTest extends MediaWikiTestCase { private $lang; - function setUp() { + protected function setUp() { $this->lang = Language::factory( 'Wa' ); } - function tearDown() { + protected function tearDown() { unset( $this->lang ); } diff --git a/tests/phpunit/maintenance/DumpTestCase.php b/tests/phpunit/maintenance/DumpTestCase.php index d13443899c..d9b651f30d 100644 --- a/tests/phpunit/maintenance/DumpTestCase.php +++ b/tests/phpunit/maintenance/DumpTestCase.php @@ -72,7 +72,7 @@ abstract class DumpTestCase extends MediaWikiLangTestCase { * * Clears $wgUser, and reports errors from addDBData to PHPUnit */ - public function setUp() { + protected function setUp() { global $wgUser; parent::setUp(); diff --git a/tests/phpunit/maintenance/backupTextPassTest.php b/tests/phpunit/maintenance/backupTextPassTest.php index a0bbadf991..0368b81845 100644 --- a/tests/phpunit/maintenance/backupTextPassTest.php +++ b/tests/phpunit/maintenance/backupTextPassTest.php @@ -74,7 +74,7 @@ class TextPassDumperTest extends DumpTestCase { } - public function setUp() { + protected function setUp() { parent::setUp(); // Since we will restrict dumping by page ranges (to allow diff --git a/tests/phpunit/maintenance/backup_PageTest.php b/tests/phpunit/maintenance/backup_PageTest.php index 925e277d9d..64374f86a3 100644 --- a/tests/phpunit/maintenance/backup_PageTest.php +++ b/tests/phpunit/maintenance/backup_PageTest.php @@ -65,7 +65,7 @@ class BackupDumperPageTest extends DumpTestCase { } - public function setUp() { + protected function setUp() { parent::setUp(); // Since we will restrict dumping by page ranges (to allow diff --git a/tests/phpunit/skins/SideBarTest.php b/tests/phpunit/skins/SideBarTest.php index 912d7602f5..89337f4c6a 100644 --- a/tests/phpunit/skins/SideBarTest.php +++ b/tests/phpunit/skins/SideBarTest.php @@ -33,13 +33,13 @@ class SideBarTest extends MediaWikiLangTestCase { } } - function setUp() { + protected function setUp() { parent::setUp(); $this->initMessagesHref(); $this->skin = new SkinTemplate(); $this->skin->getContext()->setLanguage( Language::factory( 'en' ) ); } - function tearDown() { + protected function tearDown() { parent::tearDown(); $this->skin = null; } diff --git a/tests/phpunit/suites/UploadFromUrlTestSuite.php b/tests/phpunit/suites/UploadFromUrlTestSuite.php index f2638111bb..843aaf9f84 100644 --- a/tests/phpunit/suites/UploadFromUrlTestSuite.php +++ b/tests/phpunit/suites/UploadFromUrlTestSuite.php @@ -15,7 +15,7 @@ class UploadFromUrlTestSuite extends PHPUnit_Framework_TestSuite { return true; } - function setUp() { + protected function setUp() { global $wgParser, $wgParserConf, $IP, $messageMemc, $wgMemc, $wgUser, $wgLang, $wgOut, $wgRequest, $wgStyleDirectory, $wgEnableParserCache, $wgNamespaceAliases, $wgNamespaceProtection, $parserMemc; @@ -79,7 +79,7 @@ class UploadFromUrlTestSuite extends PHPUnit_Framework_TestSuite { FileBackendGroup::destroySingleton(); } - public function tearDown() { + protected function tearDown() { foreach ( $this->savedGlobals as $var => $val ) { $GLOBALS[$var] = $val; }