summaryrefslogtreecommitdiff
path: root/tests/phpunit/includes/GlobalFunctions/GlobalTest.php
diff options
context:
space:
mode:
authorPierre Schmitz <pierre@archlinux.de>2013-12-08 09:55:49 +0100
committerPierre Schmitz <pierre@archlinux.de>2013-12-08 09:55:49 +0100
commit4ac9fa081a7c045f6a9f1cfc529d82423f485b2e (patch)
treeaf68743f2f4a47d13f2b0eb05f5c4aaf86d8ea37 /tests/phpunit/includes/GlobalFunctions/GlobalTest.php
parentaf4da56f1ad4d3ef7b06557bae365da2ea27a897 (diff)
Update to MediaWiki 1.22.0
Diffstat (limited to 'tests/phpunit/includes/GlobalFunctions/GlobalTest.php')
-rw-r--r--tests/phpunit/includes/GlobalFunctions/GlobalTest.php201
1 files changed, 87 insertions, 114 deletions
diff --git a/tests/phpunit/includes/GlobalFunctions/GlobalTest.php b/tests/phpunit/includes/GlobalFunctions/GlobalTest.php
index 24fc47cf..6154df1d 100644
--- a/tests/phpunit/includes/GlobalFunctions/GlobalTest.php
+++ b/tests/phpunit/includes/GlobalFunctions/GlobalTest.php
@@ -29,7 +29,10 @@ class GlobalTest extends MediaWikiTestCase {
parent::tearDown();
}
- /** @dataProvider provideForWfArrayDiff2 */
+ /**
+ * @dataProvider provideForWfArrayDiff2
+ * @covers ::wfArrayDiff2
+ */
public function testWfArrayDiff2( $a, $b, $expected ) {
$this->assertEquals(
wfArrayDiff2( $a, $b ), $expected
@@ -53,25 +56,37 @@ class GlobalTest extends MediaWikiTestCase {
);
}
- function testRandom() {
+ /**
+ * @covers ::wfRandom
+ */
+ public function testRandom() {
# This could hypothetically fail, but it shouldn't ;)
$this->assertFalse(
wfRandom() == wfRandom() );
}
- function testUrlencode() {
+ /**
+ * @covers ::wfUrlencode
+ */
+ public function testUrlencode() {
$this->assertEquals(
"%E7%89%B9%E5%88%A5:Contributions/Foobar",
wfUrlencode( "\xE7\x89\xB9\xE5\x88\xA5:Contributions/Foobar" ) );
}
- function testExpandIRI() {
+ /**
+ * @covers ::wfExpandIRI
+ */
+ public function testExpandIRI() {
$this->assertEquals(
"https://te.wikibooks.org/wiki/ఉబుంటు_వాడుకరి_మార్గదర్శని",
wfExpandIRI( "https://te.wikibooks.org/wiki/%E0%B0%89%E0%B0%AC%E0%B1%81%E0%B0%82%E0%B0%9F%E0%B1%81_%E0%B0%B5%E0%B0%BE%E0%B0%A1%E0%B1%81%E0%B0%95%E0%B0%B0%E0%B0%BF_%E0%B0%AE%E0%B0%BE%E0%B0%B0%E0%B1%8D%E0%B0%97%E0%B0%A6%E0%B0%B0%E0%B1%8D%E0%B0%B6%E0%B0%A8%E0%B0%BF" ) );
}
- function testReadOnlyEmpty() {
+ /**
+ * @covers ::wfReadOnly
+ */
+ public function testReadOnlyEmpty() {
global $wgReadOnly;
$wgReadOnly = null;
@@ -79,7 +94,10 @@ class GlobalTest extends MediaWikiTestCase {
$this->assertFalse( wfReadOnly() );
}
- function testReadOnlySet() {
+ /**
+ * @covers ::wfReadOnly
+ */
+ public function testReadOnlySet() {
global $wgReadOnly, $wgReadOnlyFile;
$f = fopen( $wgReadOnlyFile, "wt" );
@@ -97,19 +115,6 @@ class GlobalTest extends MediaWikiTestCase {
$this->assertFalse( wfReadOnly() );
}
- function testQuotedPrintable() {
- $this->assertEquals(
- "=?UTF-8?Q?=C4=88u=20legebla=3F?=",
- UserMailer::quotedPrintable( "\xc4\x88u legebla?", "UTF-8" ) );
- }
-
- function testTime() {
- $start = wfTime();
- $this->assertInternalType( 'float', $start );
- $end = wfTime();
- $this->assertTrue( $end > $start, "Time is running backwards!" );
- }
-
public static function provideArrayToCGI() {
return array(
array( array(), '' ), // empty
@@ -130,13 +135,17 @@ class GlobalTest extends MediaWikiTestCase {
/**
* @dataProvider provideArrayToCGI
+ * @covers ::wfArrayToCgi
*/
- function testArrayToCGI( $array, $result ) {
+ public function testArrayToCGI( $array, $result ) {
$this->assertEquals( $result, wfArrayToCgi( $array ) );
}
- function testArrayToCGI2() {
+ /**
+ * @covers ::testWfArrayDiff2
+ */
+ public function testArrayToCGI2() {
$this->assertEquals(
"baz=bar&foo=bar",
wfArrayToCgi(
@@ -161,8 +170,9 @@ class GlobalTest extends MediaWikiTestCase {
/**
* @dataProvider provideCgiToArray
+ * @covers ::wfCgiToArray
*/
- function testCgiToArray( $cgi, $result ) {
+ public function testCgiToArray( $cgi, $result ) {
$this->assertEquals( $result, wfCgiToArray( $cgi ) );
}
@@ -181,12 +191,16 @@ class GlobalTest extends MediaWikiTestCase {
/**
* @dataProvider provideCgiRoundTrip
+ * @covers ::wfArrayToCgi
*/
- function testCgiRoundTrip( $cgi ) {
+ public function testCgiRoundTrip( $cgi ) {
$this->assertEquals( $cgi, wfArrayToCgi( wfCgiToArray( $cgi ) ) );
}
- function testMimeTypeMatch() {
+ /**
+ * @covers ::mimeTypeMatch
+ */
+ public function testMimeTypeMatch() {
$this->assertEquals(
'text/html',
mimeTypeMatch( 'text/html',
@@ -208,7 +222,10 @@ class GlobalTest extends MediaWikiTestCase {
'image/svg+xml' => 0.5 ) ) );
}
- function testNegotiateType() {
+ /**
+ * @covers ::wfNegotiateType
+ */
+ public function testNegotiateType() {
$this->assertEquals(
'text/html',
wfNegotiateType(
@@ -249,77 +266,11 @@ class GlobalTest extends MediaWikiTestCase {
array( 'application/xhtml+xml' => 1.0 ) ) );
}
- function testFallbackMbstringFunctions() {
-
- if ( !extension_loaded( 'mbstring' ) ) {
- $this->markTestSkipped( "The mb_string functions must be installed to test the fallback functions" );
- }
-
- $sampleUTF = "Östergötland_coat_of_arms.png";
-
-
- //mb_substr
- $substr_params = array(
- array( 0, 0 ),
- array( 5, -4 ),
- array( 33 ),
- array( 100, -5 ),
- array( -8, 10 ),
- array( 1, 1 ),
- array( 2, -1 )
- );
-
- foreach ( $substr_params as $param_set ) {
- $old_param_set = $param_set;
- array_unshift( $param_set, $sampleUTF );
-
- $this->assertEquals(
- MWFunction::callArray( 'mb_substr', $param_set ),
- MWFunction::callArray( 'Fallback::mb_substr', $param_set ),
- 'Fallback mb_substr with params ' . implode( ', ', $old_param_set )
- );
- }
-
-
- //mb_strlen
- $this->assertEquals(
- mb_strlen( $sampleUTF ),
- Fallback::mb_strlen( $sampleUTF ),
- 'Fallback mb_strlen'
- );
-
-
- //mb_str(r?)pos
- $strpos_params = array(
- //array( 'ter' ),
- //array( 'Ö' ),
- //array( 'Ö', 3 ),
- //array( 'oat_', 100 ),
- //array( 'c', -10 ),
- //Broken for now
- );
-
- foreach ( $strpos_params as $param_set ) {
- $old_param_set = $param_set;
- array_unshift( $param_set, $sampleUTF );
-
- $this->assertEquals(
- MWFunction::callArray( 'mb_strpos', $param_set ),
- MWFunction::callArray( 'Fallback::mb_strpos', $param_set ),
- 'Fallback mb_strpos with params ' . implode( ', ', $old_param_set )
- );
-
- $this->assertEquals(
- MWFunction::callArray( 'mb_strrpos', $param_set ),
- MWFunction::callArray( 'Fallback::mb_strrpos', $param_set ),
- 'Fallback mb_strrpos with params ' . implode( ', ', $old_param_set )
- );
- }
-
- }
-
-
- function testDebugFunctionTest() {
+ /**
+ * @covers ::wfDebug
+ * @covers ::wfDebugMem
+ */
+ public function testDebugFunctionTest() {
global $wgDebugLogFile, $wgDebugTimestamps;
@@ -329,7 +280,6 @@ class GlobalTest extends MediaWikiTestCase {
$old_wgDebugTimestamps = $wgDebugTimestamps;
$wgDebugTimestamps = false;
-
wfDebug( "This is a normal string" );
$this->assertEquals( "This is a normal string", file_get_contents( $wgDebugLogFile ) );
unlink( $wgDebugLogFile );
@@ -338,7 +288,6 @@ class GlobalTest extends MediaWikiTestCase {
$this->assertEquals( "This is nöt an ASCII string", file_get_contents( $wgDebugLogFile ) );
unlink( $wgDebugLogFile );
-
wfDebug( "\00305This has böth UTF and control chars\003" );
$this->assertEquals( " 05This has böth UTF and control chars ", file_get_contents( $wgDebugLogFile ) );
unlink( $wgDebugLogFile );
@@ -351,12 +300,14 @@ class GlobalTest extends MediaWikiTestCase {
$this->assertGreaterThan( 5000000, preg_replace( '/\D/', '', file_get_contents( $wgDebugLogFile ) ) );
unlink( $wgDebugLogFile );
-
$wgDebugLogFile = $old_log_file;
$wgDebugTimestamps = $old_wgDebugTimestamps;
}
- function testClientAcceptsGzipTest() {
+ /**
+ * @covers ::wfClientAcceptsGzip
+ */
+ public function testClientAcceptsGzipTest() {
$settings = array(
'gzip' => true,
@@ -387,7 +338,10 @@ class GlobalTest extends MediaWikiTestCase {
}
}
- function testSwapVarsTest() {
+ /**
+ * @covers ::swap
+ */
+ public function testSwapVarsTest() {
$var1 = 1;
$var2 = 2;
@@ -398,10 +352,12 @@ class GlobalTest extends MediaWikiTestCase {
$this->assertEquals( $var1, 2, 'var1 is swapped' );
$this->assertEquals( $var2, 1, 'var2 is swapped' );
-
}
- function testWfPercentTest() {
+ /**
+ * @covers ::wfPercent
+ */
+ public function testWfPercentTest() {
$pcts = array(
array( 6 / 7, '0.86%', 2, false ),
@@ -429,6 +385,7 @@ class GlobalTest extends MediaWikiTestCase {
/**
* test @see wfShorthandToInteger()
* @dataProvider provideShorthand
+ * @covers ::wfShorthandToInteger
*/
public function testWfShorthandToInteger( $shorthand, $expected ) {
$this->assertEquals( $expected,
@@ -439,7 +396,7 @@ class GlobalTest extends MediaWikiTestCase {
/** array( shorthand, expected integer ) */
public static function provideShorthand() {
return array(
- # Null, empty ...
+ # Null, empty ...
array( '', -1 ),
array( ' ', -1 ),
array( null, -1 ),
@@ -489,6 +446,7 @@ class GlobalTest extends MediaWikiTestCase {
*
* @dataProvider provideMerge()
* @group medium
+ * @covers ::wfMerge
*/
public function testMerge( $old, $mine, $yours, $expectedMergeResult, $expectedText ) {
$this->checkHasDiff3();
@@ -564,13 +522,14 @@ class GlobalTest extends MediaWikiTestCase {
/**
* @dataProvider provideMakeUrlIndexes()
+ * @covers ::wfMakeUrlIndexes
*/
- function testMakeUrlIndexes( $url, $expected ) {
+ public function testMakeUrlIndexes( $url, $expected ) {
$index = wfMakeUrlIndexes( $url );
$this->assertEquals( $expected, $index, "wfMakeUrlIndexes(\"$url\")" );
}
- function provideMakeUrlIndexes() {
+ public static function provideMakeUrlIndexes() {
return array(
array(
// just a regular :)
@@ -621,13 +580,14 @@ class GlobalTest extends MediaWikiTestCase {
/**
* @dataProvider provideWfMatchesDomainList
+ * @covers ::wfMatchesDomainList
*/
- function testWfMatchesDomainList( $url, $domains, $expected, $description ) {
+ public function testWfMatchesDomainList( $url, $domains, $expected, $description ) {
$actual = wfMatchesDomainList( $url, $domains );
$this->assertEquals( $expected, $actual, $description );
}
- function provideWfMatchesDomainList() {
+ public static function provideWfMatchesDomainList() {
$a = array();
$protocols = array( 'HTTP' => 'http:', 'HTTPS' => 'https:', 'protocol-relative' => '' );
foreach ( $protocols as $pDesc => $p ) {
@@ -638,18 +598,30 @@ class GlobalTest extends MediaWikiTestCase {
array( "$p//www.example2.com", array( 'www.example.com', 'www.example2.com', 'www.example3.com' ), true, "Exact match with other domains in array, $pDesc URL" ),
array( "$p//www.example2.com", array( 'example.com', 'example2.com', 'example3,com' ), true, "Match without subdomain with other domains in array, $pDesc URL" ),
array( "$p//www.example4.com", array( 'example.com', 'example2.com', 'example3,com' ), false, "Domain not in array, $pDesc URL" ),
-
- // FIXME: This is a bug in wfMatchesDomainList(). If and when this is fixed, update this test case
- array( "$p//nds-nl.wikipedia.org", array( 'nl.wikipedia.org' ), true, "Substrings of domains match while they shouldn't, $pDesc URL" ),
+ array( "$p//nds-nl.wikipedia.org", array( 'nl.wikipedia.org' ), false, "Non-matching substring of domain, $pDesc URL" ),
) );
}
+
return $a;
}
/**
+ * @covers ::wfMkdirParents
+ */
+ public function testWfMkdirParents() {
+ // Should not return true if file exists instead of directory
+ $fname = $this->getNewTempFile();
+ wfSuppressWarnings();
+ $ok = wfMkdirParents( $fname );
+ wfRestoreWarnings();
+ $this->assertFalse( $ok );
+ }
+
+ /**
* @dataProvider provideWfShellMaintenanceCmdList
+ * @covers ::wfShellMaintenanceCmd
*/
- function testWfShellMaintenanceCmd( $script, $parameters, $options, $expected, $description ) {
+ public function testWfShellMaintenanceCmd( $script, $parameters, $options, $expected, $description ) {
if ( wfIsWindows() ) {
// Approximation that's good enough for our purposes just now
$expected = str_replace( "'", '"', $expected );
@@ -658,8 +630,9 @@ class GlobalTest extends MediaWikiTestCase {
$this->assertEquals( $expected, $actual, $description );
}
- function provideWfShellMaintenanceCmdList() {
+ public static function provideWfShellMaintenanceCmdList() {
global $wgPhpCli;
+
return array(
array( 'eval.php', array( '--help', '--test' ), array(),
"'$wgPhpCli' 'eval.php' '--help' '--test'",
@@ -675,5 +648,5 @@ class GlobalTest extends MediaWikiTestCase {
"Called eval.php --help --test with wrapper and php option" ),
);
}
- /* TODO: many more! */
+ /* @TODO many more! */
}