summaryrefslogtreecommitdiff
path: root/tests/phpunit/includes/GlobalFunctions
diff options
context:
space:
mode:
Diffstat (limited to 'tests/phpunit/includes/GlobalFunctions')
-rw-r--r--tests/phpunit/includes/GlobalFunctions/GlobalTest.php103
-rw-r--r--tests/phpunit/includes/GlobalFunctions/wfArrayPlus2dTest.php94
-rw-r--r--tests/phpunit/includes/GlobalFunctions/wfTimestampTest.php1
-rw-r--r--tests/phpunit/includes/GlobalFunctions/wfUrlencodeTest.php2
4 files changed, 198 insertions, 2 deletions
diff --git a/tests/phpunit/includes/GlobalFunctions/GlobalTest.php b/tests/phpunit/includes/GlobalFunctions/GlobalTest.php
index 1e30273e..e89e36f6 100644
--- a/tests/phpunit/includes/GlobalFunctions/GlobalTest.php
+++ b/tests/phpunit/includes/GlobalFunctions/GlobalTest.php
@@ -666,9 +666,9 @@ class GlobalTest extends MediaWikiTestCase {
public function testWfMkdirParents() {
// Should not return true if file exists instead of directory
$fname = $this->getNewTempFile();
- wfSuppressWarnings();
+ MediaWiki\suppressWarnings();
$ok = wfMkdirParents( $fname );
- wfRestoreWarnings();
+ MediaWiki\restoreWarnings();
$this->assertFalse( $ok );
}
@@ -687,6 +687,105 @@ class GlobalTest extends MediaWikiTestCase {
$this->assertEquals( $expected, $actual, $description );
}
+ public function wfWikiID() {
+ $this->setMwGlobals( array(
+ 'wgDBname' => 'example',
+ 'wgDBprefix' => '',
+ ) );
+ $this->assertEquals(
+ wfWikiID(),
+ 'example'
+ );
+
+ $this->setMwGlobals( array(
+ 'wgDBname' => 'example',
+ 'wgDBprefix' => 'mw_',
+ ) );
+ $this->assertEquals(
+ wfWikiID(),
+ 'example-mw_'
+ );
+ }
+
+ public function testWfMemcKey() {
+ // Just assert the exact output so we can catch unintentional changes to key
+ // construction, which would effectively invalidate all existing cache.
+
+ $this->setMwGlobals( array(
+ 'wgCachePrefix' => false,
+ 'wgDBname' => 'example',
+ 'wgDBprefix' => '',
+ ) );
+ $this->assertEquals(
+ wfMemcKey( 'foo', '123', 'bar' ),
+ 'example:foo:123:bar'
+ );
+
+ $this->setMwGlobals( array(
+ 'wgCachePrefix' => false,
+ 'wgDBname' => 'example',
+ 'wgDBprefix' => 'mw_',
+ ) );
+ $this->assertEquals(
+ wfMemcKey( 'foo', '123', 'bar' ),
+ 'example-mw_:foo:123:bar'
+ );
+
+ $this->setMwGlobals( array(
+ 'wgCachePrefix' => 'custom',
+ 'wgDBname' => 'example',
+ 'wgDBprefix' => 'mw_',
+ ) );
+ $this->assertEquals(
+ wfMemcKey( 'foo', '123', 'bar' ),
+ 'custom:foo:123:bar'
+ );
+ }
+
+ public function testWfForeignMemcKey() {
+ $this->setMwGlobals( array(
+ 'wgCachePrefix' => false,
+ 'wgDBname' => 'example',
+ 'wgDBprefix' => '',
+ ) );
+ $local = wfMemcKey( 'foo', 'bar' );
+
+ $this->setMwGlobals( array(
+ 'wgDBname' => 'other',
+ 'wgDBprefix' => 'mw_',
+ ) );
+ $this->assertEquals(
+ wfForeignMemcKey( 'example', '', 'foo', 'bar' ),
+ $local,
+ 'Match output of wfMemcKey from local wiki'
+ );
+ }
+
+ public function testWfGlobalCacheKey() {
+ $this->setMwGlobals( array(
+ 'wgCachePrefix' => 'ignored',
+ 'wgDBname' => 'example',
+ 'wgDBprefix' => ''
+ ) );
+ $one = wfGlobalCacheKey( 'some', 'thing' );
+ $this->assertEquals(
+ $one,
+ 'global:some:thing'
+ );
+
+ $this->setMwGlobals( array(
+ 'wgDBname' => 'other',
+ 'wgDBprefix' => 'mw_'
+ ) );
+ $two = wfGlobalCacheKey( 'some', 'thing' );
+
+ $this->assertEquals(
+ $one,
+ $two,
+ 'Not fragmented by wiki id'
+ );
+ }
+
public static function provideWfShellWikiCmdList() {
global $wgPhpCli;
diff --git a/tests/phpunit/includes/GlobalFunctions/wfArrayPlus2dTest.php b/tests/phpunit/includes/GlobalFunctions/wfArrayPlus2dTest.php
new file mode 100644
index 00000000..88875bb0
--- /dev/null
+++ b/tests/phpunit/includes/GlobalFunctions/wfArrayPlus2dTest.php
@@ -0,0 +1,94 @@
+<?php
+/**
+ * @group GlobalFunctions
+ * @covers ::wfArrayPlus2d
+ */
+class WfArrayPlus2dTest extends MediaWikiTestCase {
+ /**
+ * @dataProvider provideArrays
+ */
+ public function testWfArrayPlus2d( $baseArray, $newValues, $expected, $testName ) {
+ $this->assertEquals(
+ $expected,
+ wfArrayPlus2d( $baseArray, $newValues ),
+ $testName
+ );
+ }
+
+ /**
+ * Provider for testing wfArrayPlus2d
+ *
+ * @return array
+ */
+ public static function provideArrays() {
+ return array(
+ // target array, new values array, expected result
+ array(
+ array( 0 => '1dArray' ),
+ array( 1 => '1dArray' ),
+ array( 0 => '1dArray', 1 => '1dArray' ),
+ "Test simple union of two arrays with different keys",
+ ),
+ array(
+ array(
+ 0 => array( 0 => '2dArray' ),
+ ),
+ array(
+ 0 => array( 1 => '2dArray' ),
+ ),
+ array(
+ 0 => array( 0 => '2dArray', 1 => '2dArray' ),
+ ),
+ "Test union of 2d arrays with different keys in the value array",
+ ),
+ array(
+ array(
+ 0 => array( 0 => '2dArray' ),
+ ),
+ array(
+ 0 => array( 0 => '1dArray' ),
+ ),
+ array(
+ 0 => array( 0 => '2dArray' ),
+ ),
+ "Test union of 2d arrays with same keys in the value array",
+ ),
+ array(
+ array(
+ 0 => array( 0 => array( 0 => '3dArray' ) ),
+ ),
+ array(
+ 0 => array( 0 => array( 1 => '2dArray' ) ),
+ ),
+ array(
+ 0 => array( 0 => array( 0 => '3dArray' ) ),
+ ),
+ "Test union of 3d array with different keys",
+ ),
+ array(
+ array(
+ 0 => array( 0 => array( 0 => '3dArray' ) ),
+ ),
+ array(
+ 0 => array( 1 => array( 0 => '2dArray' ) ),
+ ),
+ array(
+ 0 => array( 0 => array( 0 => '3dArray' ), 1 => array( 0 => '2dArray' ) ),
+ ),
+ "Test union of 3d array with different keys in the value array",
+ ),
+ array(
+ array(
+ 0 => array( 0 => array( 0 => '3dArray' ) ),
+ ),
+ array(
+ 0 => array( 0 => array( 0 => '2dArray' ) ),
+ ),
+ array(
+ 0 => array( 0 => array( 0 => '3dArray' ) ),
+ ),
+ "Test union of 3d array with same keys in the value array",
+ ),
+ );
+ }
+}
diff --git a/tests/phpunit/includes/GlobalFunctions/wfTimestampTest.php b/tests/phpunit/includes/GlobalFunctions/wfTimestampTest.php
index bea496c4..4ce51c6a 100644
--- a/tests/phpunit/includes/GlobalFunctions/wfTimestampTest.php
+++ b/tests/phpunit/includes/GlobalFunctions/wfTimestampTest.php
@@ -21,6 +21,7 @@ class WfTimestampTest extends MediaWikiTestCase {
array( -30281104, TS_MW, '19690115123456', 'Negative TS_UNIX to TS_MW' ),
array( $t, TS_UNIX, 979562096, 'TS_UNIX to TS_UNIX' ),
array( $t, TS_DB, '2001-01-15 12:34:56', 'TS_UNIX to TS_DB' ),
+ array( $t + .01, TS_MW, '20010115123456', 'TS_UNIX float to TS_MW' ),
array( $t, TS_ISO_8601_BASIC, '20010115T123456Z', 'TS_ISO_8601_BASIC to TS_DB' ),
diff --git a/tests/phpunit/includes/GlobalFunctions/wfUrlencodeTest.php b/tests/phpunit/includes/GlobalFunctions/wfUrlencodeTest.php
index d11668b7..d4df7b00 100644
--- a/tests/phpunit/includes/GlobalFunctions/wfUrlencodeTest.php
+++ b/tests/phpunit/includes/GlobalFunctions/wfUrlencodeTest.php
@@ -112,6 +112,8 @@ class WfUrlencodeTest extends MediaWikiTestCase {
### Other tests
// slash remain unchanged. %2F seems to break things
array( '/', '/' ),
+ // T105265
+ array( '~', '~' ),
// Other 'funnies' chars
array( '[]', '%5B%5D' ),