*/
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 {
* 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();
}
-
}
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;
}
/* 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' );
// 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?" );
*
* This stopped working with r84475 and friends: regression being fixed for bug 29116.
*
- * @dataProvider dataBug29116
+ * @dataProvider provideBug29116Data
*/
function testBug29116LoadWithEmptyIp( $vagueTarget ) {
$this->hideDeprecated( 'Block::load' );
* 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( '' ),
class CdbTest extends MediaWikiTestCase {
- public function setUp() {
+ protected function setUp() {
if ( !CdbReader::haveExtension() ) {
$this->markTestSkipped( 'Native CDB support is not available' );
}
<?php
class DiffHistoryBlobTest extends MediaWikiTestCase {
- function setUp() {
+ protected function setUp() {
if ( !extension_loaded( 'xdiff' ) ) {
$this->markTestSkipped( 'The xdiff extension is not available' );
return;
"Hash of " . addcslashes( $input, "\0..\37!@\@\177..\377" ) );
}
- function provideXdiffAdler32() {
+ public static function provideXdiffAdler32() {
return array(
array( '', 'Empty string' ),
array( "\0", 'Null' ),
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.",
*/
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
*/
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' ) );
// 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 );
* 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 );
}
*/
function testCleanSigDisabled() {
global $wgCleanSignatures;
- $oldCleanSignature = $wgCleanSignatures;
$wgCleanSignatures = false;
$title = Title::newFromText( __FUNCTION__ );
$outputText = $this->parser->cleanSig( "{{Foo}} ~~~~" );
-
- $wgCleanSignatures = $oldCleanSignature;
$this->assertEquals( "{{Foo}} ~~~~", $outputText );
}
$this->assertEquals( Parser::cleanSigInSig( $in), $out );
}
- function provideStringsForCleanSigInSig() {
+ public static function provideStringsForCleanSigInSig() {
return array(
array( "{{Foo}} ~~~~", "{{Foo}} " ),
array( "~~~", "" ),
class FauxResponseTest extends MediaWikiTestCase {
var $response;
- function setUp() {
+ protected function setUp() {
$this->response = new FauxResponse;
}
<?php
class GlobalTest extends MediaWikiTestCase {
- function setUp() {
- global $wgReadOnlyFile, $wgUrlProtocols;
- $this->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 */
}
// @todo Provide more tests
- public function provideForWfArrayDiff2() {
+ public static function provideForWfArrayDiff2() {
// $a $b $expected
return array(
array(
$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
}
/**
- * @dataProvider dataArrayToCGI
+ * @dataProvider provideArrayToCGI
*/
function testArrayToCGI( $array, $result ) {
$this->assertEquals( $result, wfArrayToCGI( $array ) );
array( 'foo' => 'bar', 'baz' => 'overridden value' ) ) );
}
- function dataCgiToArray() {
+ public static function provideCgiToArray() {
return array(
array( '', array() ), // empty
array( 'foo=bar', array( 'foo' => 'bar' ) ), // string
}
/**
- * @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' ),
}
/**
- * @dataProvider dataCgiRoundTrip
+ * @dataProvider provideCgiRoundTrip
*/
function testCgiRoundTrip( $cgi ) {
$this->assertEquals( $cgi, wfArrayToCGI( wfCgiToArray( $cgi ) ) );
}
/** array( shorthand, expected integer ) */
- public function provideShorthand() {
+ public static function provideShorthand() {
return array(
# Null, empty ...
array( '', -1),
*
* @return array
*/
- public function provideURLParts() {
+ public static function provideURLParts() {
$schemes = array(
'' => array(),
'//' => array(
*
* @return array
*/
- public function provideExpandableUrls() {
+ public static function provideExpandableUrls() {
$modes = array( 'http', 'https' );
$servers = array(
'http' => 'http://example.com',
*
* @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' ),
* 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
$this->assertEquals( $expected, $ok, $msg );
}
- function cookieDomains() {
+ public static function cookieDomains() {
return array(
array( false, "org"),
array( false, ".org"),
/**
* 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' ),
* 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' );
}
/** Provider for testIPIsInRange() */
- function provideIPsAndRanges() {
+ public static function provideIPsAndRanges() {
# Format: (expected boolean, address, range, optional message)
return array(
# IPv4
/**
* Provider for IP::splitHostAndPort()
*/
- function provideSplitHostAndPort() {
+ public static function provideSplitHostAndPort() {
return array(
array( false, '[', 'Unclosed square bracket' ),
array( false, '[::', 'Unclosed square bracket 2' ),
/**
* 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' ),
/**
* 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' ),
/**
* 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', '::' ),
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'
);
-
}
-
}
-
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();
}
}
function testGetPreferredVariantHeaderUserVsUrl() {
- global $wgRequest, $wgUser, $wgContLang;
+ global $wgContLang, $wgRequest, $wgUser;
$wgContLang = Language::factory( 'tg-latn' );
$wgRequest->setVal( 'variant', 'tg' );
);
}
- function setUp() {
+ protected function setUp() {
$dbw = wfGetDB( DB_MASTER );
$dbw->replace(
'interwiki',
*/
class LocalFileTest extends MediaWikiTestCase {
- function setUp() {
- global $wgCapitalLinks;
- $wgCapitalLinks = true;
+ protected function setUp() {
+ parent::setUp();
+
+ $this->setMwGlobals( 'wgCapitalLinks', true );
$info = array(
'name' => 'test',
class MWFunctionTest extends MediaWikiTestCase {
function testCallUserFuncWorkarounds() {
-
$this->assertEquals(
call_user_func( array( 'MWFunctionTest', 'someMethod' ) ),
MWFunction::call( 'MWFunctionTest::someMethod' )
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() )
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' );
}
* @expectedException MWException
*/
function testCallingSelfFails() {
-
MWFunction::call( 'self::foo' );
}
}
class MWBlankClass {
-
+
public $args = array();
-
+
function __construct( $arg1, $arg2, $arg3, $arg4 ) {
$this->args = array( $arg1, $arg2, $arg3, $arg4 );
}
-
}
class ExampleObject {
*
*/
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 #########################################################
/**
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() {
}
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 );
/**
*/
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() );
array( NS_MAIN, NS_USER, NS_CATEGORY ),
MWNamespace::getcontentNamespaces()
);
-
- $wgContentNamespaces = $saved;
}
/**
*/
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;
}
/**
*/
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 );
$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() {
public function testIsNonincludable() {
global $wgNonincludableNamespaces;
+
$wgNonincludableNamespaces = array( NS_USER );
$this->assertTrue( MWNamespace::isNonincludable( NS_USER ) );
-
$this->assertFalse( MWNamespace::isNonincludable( NS_TEMPLATE ) );
}
<?php
class MessageTest extends MediaWikiLangTestCase {
+ protected function setUp() {
+ parent::setUp();
+
+ $this->setMwGlobals( array(
+ 'wgLang' => Language::factory( 'en' ),
+ 'wgForceUIMsgAsContentMsg' => array(),
+ ) );
+ }
function testExists() {
$this->assertTrue( wfMessage( 'mainpage' )->exists() );
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'] );
}
/**
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();
}
/**
* @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 );
}
class PathRouterTest extends MediaWikiTestCase {
- public function setUp() {
+ protected function setUp() {
$router = new PathRouter;
$router->add("/wiki/$1");
$this->basicRouter = $router;
$this->assertEquals( $matches, array( 'title' => "Title_With Space" ) );
}
- public function dataRegexpChars() {
+ public static function provideRegexpChars() {
return array(
array( "$" ),
array( "$1" ),
/**
* 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" );
function __construct() {
parent::__construct();
- global $wgEnableEmail;
$this->prefUsers['noemail'] = new User;
$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 );
}
/**
* @todo: Emulate these edits somehow and extract
* raw edit summary from RecentChange object
* --
-
+ */
+/*
function testIrcMsgForBlankingAES() {
// $this->context->msg( 'autosumm-blank', .. );
}
// $this->context->msg( 'undo-summary', .. );
}
- * --
- */
+*/
/**
* @param $expected String Expected IRC text without colors codes
}
/* Provider Methods */
- public function provideValidModules() {
+ public static function provideValidModules() {
return array(
array( 'TEST.validModule1', new ResourceLoaderTestModule() ),
);
$this->assertEquals( $modules, ResourceLoaderContext::expandModuleNames( $packed ), $desc );
}
- public function providePackedModules() {
+ public static function providePackedModules() {
return array(
array(
'Example from makePackedModulesString doc comment',
'iwlinks' ) );
}
- public function setUp() {
+ protected function setUp() {
if ( !$this->the_page ) {
$this->the_page = $this->createPage( 'RevisionStorageTest_the_page', "just a dummy page" );
}
$this->assertEquals( 'some testing text', $rev->getText() );
}
- public function dataUserWasLastToEdit() {
+ public static function provideUserWasLastToEdit() {
return array(
array( #0
3, true, # actually the last edit
}
/**
- * @dataProvider dataUserWasLastToEdit
+ * @dataProvider provideUserWasLastToEdit
*/
public function testUserWasLastToEdit( $sinceIdx, $expectedLast ) {
$userA = \User::newFromName( "RevisionStorageTest_userA" );
<?php
class RevisionTest extends MediaWikiTestCase {
- var $saveGlobals = array();
+ protected function setUp() {
+ parent::setUp();
- function setUp() {
- global $wgContLang;
- $wgContLang = Language::factory( 'en' );
- $globalSet = array(
+ $this->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() {
}
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 );
/**
* 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();
}
/**
* 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' ),
* 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
class SanitizerTest extends MediaWikiTestCase {
- function setUp() {
+ protected function setUp() {
+ parent::setUp();
+
+ $this->setMwGlobals( 'wgCleanupPresentationalAttributes', true );
+
AutoLoader::loadClass( 'Sanitizer' );
}
$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;' ),
);
}
- function provideCssCommentsFixtures() {
+ public static function provideCssCommentsFixtures() {
/** array( <expected>, <css>, [message] ) */
return array(
array( ' ', '/**/' ),
private $testSuites1 = null;
- public function setUp() {
+ protected function setUp() {
+ parent::setUp();
if ( !defined( 'SELENIUMTEST' ) ) {
define( 'SELENIUMTEST', true );
}
/**
* 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 );
class SiteConfigurationTest extends MediaWikiTestCase {
var $mConf;
- function setUp() {
+ protected function setUp() {
$this->mConf = new SiteConfiguration;
$this->mConf->suffixes = array( 'wiki' );
<?php
class TimeAdjustTest extends MediaWikiLangTestCase {
- static $offset;
-
- public function setUp() {
+ protected function setUp() {
parent::setUp();
- global $wgLocalTZoffset;
- self::$offset = $wgLocalTZoffset;
- $this->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(
$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]}"
);
}
* 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
* 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' ),
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 ),
}
/**
- * @dataProvider dataEquals
+ * @dataProvider provideEquals
*/
public function testEquals( $titleA, $titleB, $expectedBool ) {
$titleA = Title::newFromText( $titleA );
$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 ),
}
/**
- * @dataProvider dataInNamespace
+ * @dataProvider provideInNamespace
*/
public function testInNamespace( $title, $ns, $expectedBool ) {
$title = Title::newFromText( $title );
$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 ),
}
/**
- * @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 ),
}
/**
- * @dataProvider dataIsCssOrJsPage
+ * @dataProvider provideIsCssOrJsPage
*/
public function testIsCssOrJsPage( $title, $expectedBool ) {
$title = Title::newFromText( $title );
}
- public function dataIsCssJsSubpage() {
+ public static function provideIsCssJsSubpage() {
return array(
array( 'Foo', false ),
array( 'Foo.js', false ),
}
/**
- * @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 ),
}
/**
- * @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 ),
}
/**
- * @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 ),
}
/**
- * @dataProvider dataIsWikitextPage
+ * @dataProvider provideIsWikitextPage
*/
public function testIsWikitextPage( $title, $expectedBool ) {
$title = Title::newFromText( $title );
* @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 ) ) {
$this->user = $this->userUser;
}
- }
- function tearDown() {
- parent::tearDown();
}
function setUserPerm( $perm ) {
}
function setUser( $userName = null ) {
+ global $wgUser;
+
if ( $userName === 'anon' ) {
$this->user = $this->anonUser;
} elseif ( $userName === null || $userName === $this->userName ) {
$this->user = $this->altUser;
}
- global $wgUser;
$wgUser = $this->user;
}
}
function testSpecialsAndNSPermissions() {
+ global $wgNamespaceProtection;
$this->setUser( $this->userName );
- global $wgUser;
- $wgUser = $this->user;
$this->setTitle( NS_SPECIAL );
$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' ) ),
$this->title->getUserPermissionsErrors( 'bogus', $this->user ) );
$wgNamespaceProtection = null;
+
$this->setUserPerm( 'bogus' );
$this->assertEquals( array( ),
$this->title->getUserPermissionsErrors( 'bogus', $this->user ) );
function testCssAndJavascriptPermissions() {
$this->setUser( $this->userName );
- global $wgUser;
- $wgUser = $this->user;
$this->setTitle( NS_USER, $this->altUserName . '/test.js' );
$this->runCSSandJSPermissions(
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();
}
/**
- * @dataProvider dataBug31100
+ * @dataProvider provideBug31100
*/
function testBug31100FixSpecialName( $text, $expectedParam ) {
$title = Title::newFromText( $text );
$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/', '' ),
* @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 );
return $result;
}
- function dataTestIsValidMoveOperation() {
+ public static function provideTestIsValidMoveOperation() {
return array(
array( 'Test', 'Test', 'selfmove' ),
array( 'File:Test.jpg', 'Page', 'imagenocrossnamespace' )
/**
* @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,
$title->getPageViewLanguage()->getCode(),
$msg
);
-
- // Restore globals
- $wgContLang = $save['wgContLang'];
- $wgLang = $save['wgLang'];
- $wgAllowUserJs = $save['wgAllowUserJs'];
- $wgLanguageCode = $save['wgLanguageCode'];
- $wgDefaultLanguageVariant = $save['wgDefaultLanguageVariant'];
}
function provideCasesForGetpageviewlanguage() {
);
}
- function provideRootTitleCases() {
+ public static function provideRootTitleCases() {
return array(
# Title, expected base, optional message
array('User:John_Doe/subOne/subTwo', 'John Doe' ),
* @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;
'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' ) );
$this->assertEquals( $expected, $result, "Groups with permission $right" );
}
- public function provideGetGroupsWithPermission() {
+ public static function provideGetGroupsWithPermission() {
return array(
array(
array( 'unittesters', 'testwriters' ),
$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' ),
<?php
class WebRequestTest extends MediaWikiTestCase {
- static $oldServer;
+ protected $oldServer;
- function setUp() {
- self::$oldServer = $_SERVER;
+ protected function setUp() {
+ parent::setUp();
+
+ $this->oldServer = $_SERVER;
}
- function tearDown() {
- $_SERVER = self::$oldServer;
+ protected function tearDown() {
+ $_SERVER = $this->oldServer;
+
+ parent::tearDown();
}
/**
$this->assertEquals( $expected, $result, $description );
}
- function provideDetectServer() {
+ public static function provideDetectServer() {
return array(
array(
'http://x',
$this->assertEquals( $expected, $result, $description );
}
- function provideGetIP() {
+ public static function provideGetIP() {
return array(
array(
'127.0.0.1',
$request->getIP();
}
- function languageProvider() {
+ public static function provideLanguageData() {
return array(
array( '', array(), 'Empty Accept-Language header' ),
array( 'en', array( 'en' => 1 ), 'One language' ),
}
/**
- * @dataProvider languageProvider
+ * @dataProvider provideLanguageData
*/
function testAcceptLang($acceptLanguageHeader, $expectedLanguages, $description) {
$_SERVER = array( 'HTTP_ACCEPT_LANGUAGE' => $acceptLanguageHeader );
'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 */
$this->assertFalse( $page->exists() );
}
- public function dataHasViewableContent() {
+ public static function provideHasViewableContent() {
return array(
array( 'WikiPageTest_testHasViewableContent', false, true ),
array( 'Special:WikiPageTest_testHasViewableContent', false ),
}
/**
- * @dataProvider dataHasViewableContent
+ * @dataProvider provideHasViewableContent
*/
public function testHasViewableContent( $title, $viewable, $create = false ) {
$page = $this->newPage( $title );
}
}
- 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" ),
}
/**
- * @dataProvider dataGetRedirectTarget
+ * @dataProvider provideGetRedirectTarget
*/
public function testGetRedirectTarget( $title, $text, $target ) {
$page = $this->createPage( $title, $text );
}
/**
- * @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
/**
- * @dataProvider dataIsCountable
+ * @dataProvider provideIsCountable
*/
public function testIsCountable( $title, $text, $mode, $expected ) {
global $wgArticleCountMethod;
. " 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", "<p>hello <i>world</i></p>"),
// @todo: more...?
}
/**
- * @dataProvider dataGetParserOutput
+ * @dataProvider provideGetParserOutput
*/
public function testGetParserOutput( $text, $expectedHtml ) {
$page = $this->createPage( 'WikiPageTest_testGetParserOutput', $text );
";
- public function dataReplaceSection() {
+ public static function provideReplaceSection() {
return array(
array( 'WikiPageTest_testReplaceSection',
WikiPageTest::$sections,
}
/**
- * @dataProvider dataReplaceSection
+ * @dataProvider provideReplaceSection
*/
public function testReplaceSection( $title, $text, $section, $with, $sectionTitle, $expected ) {
$page = $this->createPage( $title, $text );
$this->assertEquals( "one", $page->getText() );
}
- public function dataGetAutosummary( ) {
+ public static function provideGetAutosummary( ) {
return array(
array(
'Hello there, world!',
}
/**
- * @dataProvider dataGetAutoSummary
+ * @dataProvider provideGetAutoSummary
*/
public function testGetAutosummary( $old, $new, $flags, $expected ) {
$page = $this->newPage( "WikiPageTest_testGetAutosummary" );
$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(),
}
/**
- * @dataProvider dataGetAutoDeleteReason
+ * @dataProvider provideGetAutoDeleteReason
*/
public function testGetAutoDeleteReason( $edits, $expectedResult, $expectedHistory ) {
global $wgUser;
$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]]",
}
/**
- * @dataProvider dataPreSaveTransform
+ * @dataProvider providePreSaveTransform
*/
public function testPreSaveTransform( $text, $expected ) {
$this->hideDeprecated( 'WikiPage::preSaveTransform' );
* 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
private static $oldLang;
private static $oldNamespaces;
- public function setUp() {
+ protected function setUp() {
parent::setUp();
$langObj = Language::factory( 'en' );
class ZipDirectoryReaderTest extends MediaWikiTestCase {
var $zipDir, $entries;
- function setUp() {
+ protected function setUp() {
$this->zipDir = __DIR__ . '/../data/zip';
}
*/
class ApiBlockTest extends ApiTestCase {
- function setUp() {
+ protected function setUp() {
parent::setUp();
$this->doLogin();
}
*/
class ApiEditPageTest extends ApiTestCase {
- function setUp() {
+ protected function setUp() {
parent::setUp();
$this->doLogin();
}
private static $Success = array( 'options' => 'success' );
- function setUp() {
+ protected function setUp() {
parent::setUp();
$this->mUserMock = $this->getMockBuilder( 'User' )
*/
class ApiPurgeTest extends ApiTestCase {
- function setUp() {
+ protected function setUp() {
parent::setUp();
$this->doLogin();
}
*/
class ApiQueryTest extends ApiTestCase {
- function setUp() {
+ protected function setUp() {
parent::setUp();
$this->doLogin();
}
*/
protected $apiContext;
- function setUp() {
+ protected function setUp() {
global $wgContLang, $wgAuth, $wgMemc, $wgRequest, $wgUser, $wgServer;
parent::setUp();
/**
* 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();
}
/**
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
return true;
}
+
function fakeUploadChunk( $fieldName, $fileName, $type, & $chunkData ){
$tmpName = tempnam( wfTempDir(), "" );
// copy the chunk data to temp location:
$_FILES = array();
}
-
-
-
}
*/
class ApiWatchTest extends ApiTestCase {
- function setUp() {
+ protected function setUp() {
parent::setUp();
$this->doLogin();
}
*/
class GenderCacheTest extends MediaWikiLangTestCase {
- function setUp() {
+ protected function setUp() {
global $wgDefaultUserOptions;
parent::setUp();
//ensure the correct default gender
/**
* test usernames
*
- * @dataProvider dataUserName
+ * @dataProvider provideUserGenders
*/
function testUserName( $username, $expectedGender ) {
$genderCache = GenderCache::singleton();
/**
* genderCache should work with user objects, too
*
- * @dataProvider dataUserName
+ * @dataProvider provideUserGenders
*/
function testUserObjects( $username, $expectedGender ) {
$genderCache = GenderCache::singleton();
$this->assertEquals( $gender, $expectedGender, "GenderCache normal" );
}
- function dataUserName() {
+ public static function provideUserGenders() {
return array(
array( 'UTMale', 'male' ),
array( 'UTFemale', 'female' ),
* test strip of subpages to avoid unnecessary queries
* against the never existing username
*
- * @dataProvider dataStripSubpages
+ * @dataProvider provideStripSubpages
*/
function testStripSubpages( $pageWithSubpage, $expectedGender ) {
$genderCache = GenderCache::singleton();
$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' ),
/**
* Value which are forbidden by the constructor
*/
- function provideInvalidConstructorArg() {
+ public static function provideInvalidConstructorArg() {
return array(
array( null ),
array( array() ),
/**
* Provider for testFillingCache
*/
- function provideCacheFilling() {
+ public static function provideCacheFilling() {
// ($cacheMaxEntries, $entryToFill, $msg='')
return array(
array( 1, 0 ),
*/
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(
) ), $sqlText );
}
- function dataSelectSQLText() {
+ public static function provideSelectSQLText() {
return array(
array(
array(
}
/**
- * @dataProvider dataConditional
+ * @dataProvider provideConditional
*/
function testConditional( $sql, $sqlText ) {
$this->assertEquals( trim( $this->db->conditional(
) ), $sqlText );
}
- function dataConditional() {
+ public static function provideConditional() {
return array(
array(
array(
class DatabaseSqliteTest extends MediaWikiTestCase {
var $db;
- public function setUp() {
+ protected function setUp() {
+ parent::setUp();
+
if ( !Sqlite::isPresent() ) {
$this->markTestSkipped( 'No SQLite support detected' );
}
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;
return TestORMTable::singleton();
}
- public function setUp() {
+ protected function setUp() {
parent::setUp();
$dbw = wfGetDB( DB_MASTER );
class MWDebugTest extends MediaWikiTestCase {
- function setUp() {
+ protected function setUp() {
// Make sure MWDebug class is enabled
static $MWDebugEnabled = false;
if( !$MWDebugEnabled ) {
wfSuppressWarnings();
}
- function tearDown() {
+ protected function tearDown() {
wfRestoreWarnings();
}
private $filesToPrune = array();
private static $backendToUse;
- function setUp() {
+ protected function setUp() {
global $wgFileBackends;
parent::setUp();
$tmpPrefix = wfTempDir() . '/filebackend-unittest-' . time() . '-' . mt_rand();
$this->filesToPrune = array();
}
- private function baseStorePath() {
+ private static function baseStorePath() {
return 'mwstore://localtesting';
}
"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' ),
$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
$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(
$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(
$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(
/**
* @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(
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",
$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',
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 );
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(
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" );
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" );
}
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 ),
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",
}
private function doTestDoOperations() {
- $base = $this->baseStorePath();
+ $base = self::baseStorePath();
$fileA = "$base/unittest-cont1/e/a/b/fileA.txt";
$fileAContents = '3tqtmoeatmn4wg4qe-mg3qt3 tq';
// concurrency orientated
private function doTestDoOperationsPipeline() {
- $base = $this->baseStorePath();
+ $base = self::baseStorePath();
$fileAContents = '3tqtmoeatmn4wg4qe-mg3qt3 tq';
$fileBContents = 'g-jmq3gpqgt3qtg q3GT ';
}
private function doTestDoOperationsFailing() {
- $base = $this->baseStorePath();
+ $base = self::baseStorePath();
$fileA = "$base/unittest-cont2/a/b/fileA.txt";
$fileAContents = '3tqtmoeatmn4wg4qe-mg3qt3 tq';
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" ) );
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",
}
private function deleteFiles( $container ) {
- $base = $this->baseStorePath();
+ $base = self::baseStorePath();
$iter = $this->backend->getFileList( array( 'dir' => "$base/$container" ) );
if ( $iter ) {
foreach ( $iter as $file ) {
function assertGoodStatus( $status, $msg ) {
$this->assertEquals( print_r( array(), 1 ), print_r( $status->errors, 1 ), $msg );
}
-
- function tearDown() {
- parent::tearDown();
- }
}
*/
class StoreBatchTest extends MediaWikiTestCase {
- public function setUp() {
+ protected function setUp() {
global $wgFileBackends;
parent::setUp();
$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.
*
$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();
- }
}
*/
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,
+ ) );
}
/**
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); }',
),
);
}
<?php
class BitmapMetadataHandlerTest extends MediaWikiTestCase {
- public function setUp() {
+ protected function setUp() {
+ parent::setUp();
+
+ $this->setMwGlobals( 'wgShowEXIF', false );
+
$this->filePath = __DIR__ . '/../../data/media/';
}
* 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 .
'Did not extract any ImageDescription info?!' );
$this->assertEquals( $expected, $meta['ImageDescription'] );
-
- $wgShowEXIF = $oldExif;
}
/**
$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
);
$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' );
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
*/
'Bigger than max image size but doesn\'t need scaling',
),
);
- }
+ }
+
function testTooBigImage() {
$file = new FakeDimensionFile( array( 4000, 4000 ) );
$handler = new BitmapHandler;
$this->assertEquals( 'TransformParameterError',
get_class( $handler->doTransform( $file, 'dummy path', '', $params ) ) );
}
+
function testTooBigMustRenderImage() {
$file = new FakeDimensionFile( array( 4000, 4000 ) );
$file->mustRender = true;
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() {
$res = $this->handler->convertMetadataVersion( $metadata, 2 );
$this->assertEquals( $metadata, $res );
}
+
function testConvertMetadataToOld() {
$metadata = array(
'foo' => array( 'First', 'Second', '_type' => 'ol' ),
$res = $this->handler->convertMetadataVersion( $metadata, 1 );
$this->assertEquals( $expected, $res );
}
+
function testConvertMetadataSoftware() {
$metadata = array(
'Software' => array( array('GIMP', '1.1' ) ),
$res = $this->handler->convertMetadataVersion( $metadata, 1 );
$this->assertEquals( $expected, $res );
}
+
function testConvertMetadataSoftwareNormal() {
$metadata = array(
'Software' => array( "GIMP 1.2", "vim" ),
*/
class ExifRotationTest extends MediaWikiTestCase {
- function setUp() {
+ protected function setUp() {
parent::setUp();
$this->handler = new BitmapHandler();
$filePath = __DIR__ . '/../../data/media';
$wgEnableAutoRotation = true;
}
- public function tearDown() {
+ protected function tearDown() {
global $wgShowEXIF, $wgEnableAutoRotation;
$wgShowEXIF = $this->show;
$wgEnableAutoRotation = $this->oldAuto;
/**
*
- * @dataProvider providerFiles
+ * @dataProvider provideFiles
*/
function testMetadata( $name, $type, $info ) {
if ( !BitmapHandler::canRotate() ) {
/**
*
- * @dataProvider providerFiles
+ * @dataProvider provideFiles
*/
function testRotationRendering( $name, $type, $info, $thumbs ) {
if ( !BitmapHandler::canRotate() ) {
}
}
+ /* 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',
/**
* Same as before, but with auto-rotation disabled.
- * @dataProvider providerFilesNoAutoRotate
+ * @dataProvider provideFilesNoAutoRotate
*/
function testMetadataNoAutoRotate( $name, $type, $info ) {
global $wgEnableAutoRotation;
/**
*
- * @dataProvider providerFilesNoAutoRotate
+ * @dataProvider provideFilesNoAutoRotate
*/
function testRotationRenderingNoAutoRotate( $name, $type, $info, $thumbs ) {
global $wgEnableAutoRotation;
$wgEnableAutoRotation = true;
}
- function providerFilesNoAutoRotate() {
+ public static function provideFilesNoAutoRotate() {
return array(
array(
'landscape-plain.jpg',
<?php
class ExifTest extends MediaWikiTestCase {
- public function setUp() {
+ protected function setUp() {
+ parent::setUp();
+
$this->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() {
<?php
class FormatMetadataTest extends MediaWikiTestCase {
- public function setUp() {
+
+ protected function setUp() {
+ parent::setUp();
+
if ( !wfDl( 'exif' ) ) {
$this->markTestSkipped( "This test needs the exif extension." );
}
'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() {
<?php
class GIFMetadataExtractorTest extends MediaWikiTestCase {
- public function setUp() {
+ protected function setUp() {
+ parent::setUp();
+
$this->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 = <<<EOF
<?xpacket begin='' id='W5M0MpCehiHzreSzNTczkc9d'?>
<?php
class GIFHandlerTest extends MediaWikiTestCase {
- public function setUp() {
+ protected function setUp() {
+ parent::setUp();
+
$this->filePath = __DIR__ . '/../../data/media';
$this->backend = new FSFileBackend( array(
'name' => 'localtesting',
$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 ),
/**
* @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 ),
/**
* @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 ),
/**
* @param $filename String
* @param $expected String Serialized array
- * @dataProvider dataGetMetadata
+ * @dataProvider provideGetMetadata
*/
public function testGetMetadata( $filename, $expected ) {
$file = $this->dataFile( $filename, 'image/gif' );
$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;}}' ),
*/
class JpegMetadataExtractorTest extends MediaWikiTestCase {
- public function setUp() {
+ protected function setUp() {
+ parent::setUp();
+
$this->filePath = __DIR__ . '/../../data/media/';
}
*
* @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' ),
<?php
class JpegTest extends MediaWikiTestCase {
- public function setUp() {
+ protected function setUp() {
+ parent::setUp();
+
$this->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() {
$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' );
<?php
class PNGMetadataExtractorTest extends MediaWikiTestCase {
- function setUp() {
+ protected function setUp() {
$this->filePath = __DIR__ . '/../../data/media/';
}
/**
/**
* 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' );
$this->assertEquals( '2835/100', $meta['YResolution'] );
$this->assertEquals( 3, $meta['ResolutionUnit'] ); // 3 = cm
}
+*/
/**
* Given a normal static PNG, check the animation metadata returned.
<?php
class PNGHandlerTest extends MediaWikiTestCase {
- public function setUp() {
+ protected function setUp() {
+ parent::setUp();
+
$this->filePath = __DIR__ . '/../../data/media';
$this->backend = new FSFileBackend( array(
'name' => 'localtesting',
/**
* @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 ),
/**
* @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 ),
/**
* @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 ),
/**
* @param $filename String
* @param $expected String Serialized array
- * @dataProvider dataGetMetadata
+ * @dataProvider provideGetMetadata
*/
public function testGetMetadata( $filename, $expected ) {
$file = $this->dataFile( $filename, 'image/png' );
// $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;}}' ),
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();
}
}
- function providerSvgFiles() {
+ public static function provideSvgFiles() {
$base = __DIR__ . '/../../data/media';
return array(
array(
);
}
- function providerSvgFilesWithXMLMetadata() {
+ public static function provideSvgFilesWithXMLMetadata() {
$base = __DIR__ . '/../../data/media';
$metadata =
'<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<?php
class TiffTest extends MediaWikiTestCase {
- public function setUp() {
- global $wgShowEXIF;
- $this->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." );
<?php
class XMPTest extends MediaWikiTestCase {
- function setUp() {
+ protected function setUp() {
if ( !wfDl( 'xml' ) ) {
$this->markTestSkipped( 'Requires libxml to do XMP parsing' );
}
* @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 ) ) {
$this->assertEquals( $expected, $reader->getResults(), $info, 0.0000000001 );
}
- public function dataXMPParse() {
+ public static function provideXMPParse() {
$xmpPath = __DIR__ . '/../../data/xmp/' ;
$data = array();
class XMPValidateTest extends MediaWikiTestCase {
/**
- * @dataProvider providerDate
+ * @dataProvider provideDates
*/
function testValidateDate( $value, $expected ) {
// The method should modify $value.
$this->assertEquals( $expected, $value );
}
- function providerDate() {
+ public static function provideDates() {
/* For reference valid date formats are:
* YYYY
* YYYY-MM
$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' ),
);
/** 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() );
}
/** destroy parser (TODO: is it really neded?)*/
- function tearDown() {
+ protected function tearDown() {
unset( $this->testParser );
+
+ parent::tearDown();
}
############### TESTS #############################################
*/
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;
protected $file = false;
- function setUp() {
+ protected function setUp() {
global $wgContLang, $wgNamespaceProtection, $wgNamespaceAliases;
global $wgHooks, $IP;
$wgContLang = Language::factory( 'en' );
$wgNamespaceAliases['Image_talk'] = NS_FILE_TALK;
}
- public function tearDown() {
+ protected function tearDown() {
foreach ( $this->savedInitialGlobals as $var => $val ) {
$GLOBALS[$var] = $val;
}
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]]",
}
/**
- * @dataProvider dataPreSaveTransform
+ * @dataProvider providePreSaveTransform
*/
public function testPreSaveTransform( $text, $expected ) {
global $wgParser;
private $testParserOptions;
private $title;
- function setUp() {
+ protected function setUp() {
$this->testParserOptions = new ParserOptions();
$this->testParser = new Parser();
$this->title = Title::newFromText( 'Preload Test' );
}
- function tearDown() {
+ protected function tearDown() {
unset( $this->testParser );
unset( $this->title );
}
var $mPPNodeCount = 0;
var $mOptions;
- function setUp() {
+ protected function setUp() {
global $wgParserConf;
$this->mOptions = new ParserOptions();
$name = isset( $wgParserConf['preprocessorClass'] ) ? $wgParserConf['preprocessorClass'] : 'Preprocessor_DOM';
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
$this->search = new $searchType( $this->db );
}
+ protected function tearDown() {
+ unset( $this->search );
+ }
+
function pageExists( $title ) {
return false;
}
* @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 );
return $resultText;
}
- function setUp() {
- global $wgSearchType;
-
- self::$searchType = $wgSearchType;
- $wgSearchType = 'MockSearch';
- }
-
- function tearDown() {
- global $wgSearchType;
-
- $wgSearchType = self::$searchType;
- }
-
function testUpdateText() {
$this->assertEquals(
'test',
*/
protected $rc;
- function setUp() {
+ protected function setUp() {
}
/** helper to test SpecialRecentchanges::buildMainQueryConds() */
* 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),
class SpecialSearchTest extends MediaWikiTestCase {
private $search;
- function setUp() { }
- function tearDown() { }
-
/**
* @covers SpecialSearch::load
* @dataProvider provideSearchOptionsTests
*/
class UploadFromUrlTest extends ApiTestCase {
- public function setUp() {
+ protected function setUp() {
global $wgEnableUploads, $wgAllowCopyUploads, $wgAllowAsyncCopyUploads;
parent::setUp();
*/
public static $users;
- public function setUp() {
+ protected function setUp() {
parent::setUp();
// Setup a file for bug 29408
);
}
+ 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;
$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 );
- }
- }
}
protected $upload;
- function setUp() {
+ protected function setUp() {
global $wgHooks;
parent::setUp();
};
}
- function tearDown() {
+ protected function tearDown() {
global $wgHooks;
$wgHooks = $this->hooks;
}
* 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 */
/**
* 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,
class LanguageAmTest extends MediaWikiTestCase {
private $lang;
- function setUp() {
+ protected function setUp() {
$this->lang = Language::factory( 'Am' );
}
- function tearDown() {
+ protected function tearDown() {
unset( $this->lang );
}
class LanguageArTest extends MediaWikiTestCase {
private $lang;
- function setUp() {
+ protected function setUp() {
$this->lang = Language::factory( 'Ar' );
}
- function tearDown() {
+ protected function tearDown() {
unset( $this->lang );
}
class LanguageBeTest extends MediaWikiTestCase {
private $lang;
- function setUp() {
+ protected function setUp() {
$this->lang = Language::factory( 'Be' );
}
- function tearDown() {
+ protected function tearDown() {
unset( $this->lang );
}
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 );
}
class LanguageBhTest extends MediaWikiTestCase {
private $lang;
- function setUp() {
+ protected function setUp() {
$this->lang = Language::factory( 'Bh' );
}
- function tearDown() {
+ protected function tearDown() {
unset( $this->lang );
}
class LanguageBsTest extends MediaWikiTestCase {
private $lang;
- function setUp() {
+ protected function setUp() {
$this->lang = Language::factory( 'Bs' );
}
- function tearDown() {
+ protected function tearDown() {
unset( $this->lang );
}
class LanguageCsTest extends MediaWikiTestCase {
private $lang;
- function setUp() {
+ protected function setUp() {
$this->lang = Language::factory( 'cs' );
}
- function tearDown() {
+ protected function tearDown() {
unset( $this->lang );
}
class LanguageCuTest extends MediaWikiTestCase {
private $lang;
- function setUp() {
+ protected function setUp() {
$this->lang = Language::factory( 'cu' );
}
- function tearDown() {
+ protected function tearDown() {
unset( $this->lang );
}
class LanguageCyTest extends MediaWikiTestCase {
private $lang;
- function setUp() {
+ protected function setUp() {
$this->lang = Language::factory( 'cy' );
}
- function tearDown() {
+ protected function tearDown() {
unset( $this->lang );
}
class LanguageDsbTest extends MediaWikiTestCase {
private $lang;
- function setUp() {
+ protected function setUp() {
$this->lang = Language::factory( 'dsb' );
}
- function tearDown() {
+ protected function tearDown() {
unset( $this->lang );
}
class LanguageFrTest extends MediaWikiTestCase {
private $lang;
- function setUp() {
+ protected function setUp() {
$this->lang = Language::factory( 'fr' );
}
- function tearDown() {
+ protected function tearDown() {
unset( $this->lang );
}
class LanguageGaTest extends MediaWikiTestCase {
private $lang;
- function setUp() {
+ protected function setUp() {
$this->lang = Language::factory( 'ga' );
}
- function tearDown() {
+ protected function tearDown() {
unset( $this->lang );
}
class LanguageGdTest extends MediaWikiTestCase {
private $lang;
- function setUp() {
+ protected function setUp() {
$this->lang = Language::factory( 'gd' );
}
- function tearDown() {
+ protected function tearDown() {
unset( $this->lang );
}
class LanguageGvTest extends MediaWikiTestCase {
private $lang;
- function setUp() {
+ protected function setUp() {
$this->lang = Language::factory( 'gv' );
}
- function tearDown() {
+ protected function tearDown() {
unset( $this->lang );
}
class LanguageHeTest extends MediaWikiTestCase {
private $lang;
- function setUp() {
+ protected function setUp() {
$this->lang = Language::factory( 'he' );
}
- function tearDown() {
+ protected function tearDown() {
unset( $this->lang );
}
class LanguageHiTest extends MediaWikiTestCase {
private $lang;
- function setUp() {
+ protected function setUp() {
$this->lang = Language::factory( 'Hi' );
}
- function tearDown() {
+ protected function tearDown() {
unset( $this->lang );
}
class LanguageHrTest extends MediaWikiTestCase {
private $lang;
- function setUp() {
+ protected function setUp() {
$this->lang = Language::factory( 'hr' );
}
- function tearDown() {
+ protected function tearDown() {
unset( $this->lang );
}
class LanguageHsbTest extends MediaWikiTestCase {
private $lang;
- function setUp() {
+ protected function setUp() {
$this->lang = Language::factory( 'hsb' );
}
- function tearDown() {
+ protected function tearDown() {
unset( $this->lang );
}
class LanguageHuTest extends MediaWikiTestCase {
private $lang;
- function setUp() {
+ protected function setUp() {
$this->lang = Language::factory( 'Hu' );
}
- function tearDown() {
+ protected function tearDown() {
unset( $this->lang );
}
class LanguageHyTest extends MediaWikiTestCase {
private $lang;
- function setUp() {
+ protected function setUp() {
$this->lang = Language::factory( 'hy' );
}
- function tearDown() {
+ protected function tearDown() {
unset( $this->lang );
}
class LanguageKshTest extends MediaWikiTestCase {
private $lang;
- function setUp() {
+ protected function setUp() {
$this->lang = Language::factory( 'ksh' );
}
- function tearDown() {
+ protected function tearDown() {
unset( $this->lang );
}
class LanguageLnTest extends MediaWikiTestCase {
private $lang;
- function setUp() {
+ protected function setUp() {
$this->lang = Language::factory( 'ln' );
}
- function tearDown() {
+ protected function tearDown() {
unset( $this->lang );
}
class LanguageLtTest extends MediaWikiTestCase {
private $lang;
- function setUp() {
+ protected function setUp() {
$this->lang = Language::factory( 'Lt' );
}
- function tearDown() {
+ protected function tearDown() {
unset( $this->lang );
}
class LanguageLvTest extends MediaWikiTestCase {
private $lang;
- function setUp() {
+ protected function setUp() {
$this->lang = Language::factory( 'lv' );
}
- function tearDown() {
+ protected function tearDown() {
unset( $this->lang );
}
class LanguageMgTest extends MediaWikiTestCase {
private $lang;
- function setUp() {
+ protected function setUp() {
$this->lang = Language::factory( 'mg' );
}
- function tearDown() {
+ protected function tearDown() {
unset( $this->lang );
}
class LanguageMkTest extends MediaWikiTestCase {
private $lang;
- function setUp() {
+ protected function setUp() {
$this->lang = Language::factory( 'mk' );
}
- function tearDown() {
+ protected function tearDown() {
unset( $this->lang );
}
class LanguageMlTest extends MediaWikiTestCase {
private $lang;
- function setUp() {
+ protected function setUp() {
$this->lang = Language::factory( 'Ml' );
}
- function tearDown() {
+ protected function tearDown() {
unset( $this->lang );
}
class LanguageMoTest extends MediaWikiTestCase {
private $lang;
- function setUp() {
+ protected function setUp() {
$this->lang = Language::factory( 'mo' );
}
- function tearDown() {
+ protected function tearDown() {
unset( $this->lang );
}
class LanguageMtTest extends MediaWikiTestCase {
private $lang;
- function setUp() {
+ protected function setUp() {
$this->lang = Language::factory( 'mt' );
}
- function tearDown() {
+ protected function tearDown() {
unset( $this->lang );
}
class LanguageNlTest extends MediaWikiTestCase {
private $lang;
- function setUp() {
+ protected function setUp() {
$this->lang = Language::factory( 'Nl' );
}
- function tearDown() {
+ protected function tearDown() {
unset( $this->lang );
}
class LanguageNsoTest extends MediaWikiTestCase {
private $lang;
- function setUp() {
+ protected function setUp() {
$this->lang = Language::factory( 'nso' );
}
- function tearDown() {
+ protected function tearDown() {
unset( $this->lang );
}
class LanguagePlTest extends MediaWikiTestCase {
private $lang;
- function setUp() {
+ protected function setUp() {
$this->lang = Language::factory( 'pl' );
}
- function tearDown() {
+ protected function tearDown() {
unset( $this->lang );
}
class LanguageRoTest extends MediaWikiTestCase {
private $lang;
- function setUp() {
+ protected function setUp() {
$this->lang = Language::factory( 'ro' );
}
- function tearDown() {
+ protected function tearDown() {
unset( $this->lang );
}
class LanguageRuTest extends MediaWikiTestCase {
private $lang;
- function setUp() {
+ protected function setUp() {
$this->lang = Language::factory( 'ru' );
}
- function tearDown() {
+ protected function tearDown() {
unset( $this->lang );
}
class LanguageSeTest extends MediaWikiTestCase {
private $lang;
- function setUp() {
+ protected function setUp() {
$this->lang = Language::factory( 'se' );
}
- function tearDown() {
+ protected function tearDown() {
unset( $this->lang );
}
class LanguageSgsTest extends MediaWikiTestCase {
private $lang;
- function setUp() {
+ protected function setUp() {
$this->lang = Language::factory( 'Sgs' );
}
- function tearDown() {
+ protected function tearDown() {
unset( $this->lang );
}
class LanguageShTest extends MediaWikiTestCase {
private $lang;
- function setUp() {
+ protected function setUp() {
$this->lang = Language::factory( 'sh' );
}
- function tearDown() {
+ protected function tearDown() {
unset( $this->lang );
}
class LanguageSkTest extends MediaWikiTestCase {
private $lang;
- function setUp() {
+ protected function setUp() {
$this->lang = Language::factory( 'sk' );
}
- function tearDown() {
+ protected function tearDown() {
unset( $this->lang );
}
class LanguageSlTest extends MediaWikiTestCase {
private $lang;
- function setUp() {
+ protected function setUp() {
$this->lang = Language::factory( 'sl' );
}
- function tearDown() {
+ protected function tearDown() {
unset( $this->lang );
}
class LanguageSmaTest extends MediaWikiTestCase {
private $lang;
- function setUp() {
+ protected function setUp() {
$this->lang = Language::factory( 'sma' );
}
- function tearDown() {
+ protected function tearDown() {
unset( $this->lang );
}
/* 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 );
}
*/
private $lang;
- function setUp() {
+ protected function setUp() {
$this->lang = Language::factory( 'en' );
}
- function tearDown() {
+ protected function tearDown() {
unset( $this->lang );
}
class LanguageTiTest extends MediaWikiTestCase {
private $lang;
- function setUp() {
+ protected function setUp() {
$this->lang = Language::factory( 'Ti' );
}
- function tearDown() {
+ protected function tearDown() {
unset( $this->lang );
}
class LanguageTlTest extends MediaWikiTestCase {
private $lang;
- function setUp() {
+ protected function setUp() {
$this->lang = Language::factory( 'Tl' );
}
- function tearDown() {
+ protected function tearDown() {
unset( $this->lang );
}
class LanguageTrTest extends MediaWikiTestCase {
private $lang;
- function setUp() {
+ protected function setUp() {
$this->lang = Language::factory( 'Tr' );
}
- function tearDown() {
+ protected function tearDown() {
unset( $this->lang );
}
class LanguageUkTest extends MediaWikiTestCase {
private $lang;
- function setUp() {
+ protected function setUp() {
$this->lang = Language::factory( 'Uk' );
}
- function tearDown() {
+ protected function tearDown() {
unset( $this->lang );
}
/* 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 );
}
class LanguageWaTest extends MediaWikiTestCase {
private $lang;
- function setUp() {
+ protected function setUp() {
$this->lang = Language::factory( 'Wa' );
}
- function tearDown() {
+ protected function tearDown() {
unset( $this->lang );
}
*
* Clears $wgUser, and reports errors from addDBData to PHPUnit
*/
- public function setUp() {
+ protected function setUp() {
global $wgUser;
parent::setUp();
}
- public function setUp() {
+ protected function setUp() {
parent::setUp();
// Since we will restrict dumping by page ranges (to allow
}
- public function setUp() {
+ protected function setUp() {
parent::setUp();
// Since we will restrict dumping by page ranges (to allow
}
}
- 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;
}
return true;
}
- function setUp() {
+ protected function setUp() {
global $wgParser, $wgParserConf, $IP, $messageMemc, $wgMemc,
$wgUser, $wgLang, $wgOut, $wgRequest, $wgStyleDirectory, $wgEnableParserCache,
$wgNamespaceAliases, $wgNamespaceProtection, $parserMemc;
FileBackendGroup::destroySingleton();
}
- public function tearDown() {
+ protected function tearDown() {
foreach ( $this->savedGlobals as $var => $val ) {
$GLOBALS[$var] = $val;
}