summaryrefslogtreecommitdiff
path: root/tests/phpunit/includes/libs
diff options
context:
space:
mode:
Diffstat (limited to 'tests/phpunit/includes/libs')
-rw-r--r--tests/phpunit/includes/libs/ArrayUtilsTest.php12
-rw-r--r--tests/phpunit/includes/libs/CSSMinTest.php57
-rw-r--r--tests/phpunit/includes/libs/IEUrlExtensionTest.php33
-rw-r--r--tests/phpunit/includes/libs/IPSetTest.php252
-rw-r--r--tests/phpunit/includes/libs/JavaScriptMinifierTest.php19
-rw-r--r--tests/phpunit/includes/libs/ObjectFactoryTest.php41
-rw-r--r--tests/phpunit/includes/libs/ProcessCacheLRUTest.php2
-rw-r--r--tests/phpunit/includes/libs/SamplingStatsdClientTest.php43
-rw-r--r--tests/phpunit/includes/libs/XhprofTest.php16
-rw-r--r--tests/phpunit/includes/libs/composer/ComposerLockTest.php61
10 files changed, 229 insertions, 307 deletions
diff --git a/tests/phpunit/includes/libs/ArrayUtilsTest.php b/tests/phpunit/includes/libs/ArrayUtilsTest.php
index b5ea7b72..32b150c7 100644
--- a/tests/phpunit/includes/libs/ArrayUtilsTest.php
+++ b/tests/phpunit/includes/libs/ArrayUtilsTest.php
@@ -23,11 +23,11 @@ class ArrayUtilsTest extends PHPUnit_Framework_TestCase {
}
function provideFindLowerBound() {
- $self = $this;
- $indexValueCallback = function ( $size ) use ( $self ) {
- return function ( $val ) use ( $self, $size ) {
- $self->assertTrue( $val >= 0 );
- $self->assertTrue( $val < $size );
+ $that = $this;
+ $indexValueCallback = function ( $size ) use ( $that ) {
+ return function ( $val ) use ( $that, $size ) {
+ $that->assertTrue( $val >= 0 );
+ $that->assertTrue( $val < $size );
return $val;
};
};
@@ -212,7 +212,7 @@ class ArrayUtilsTest extends PHPUnit_Framework_TestCase {
array(),
array( 1 => 1 ),
array( 1 ),
- array( 1 => 1),
+ array( 1 => 1 ),
),
array(
array(),
diff --git a/tests/phpunit/includes/libs/CSSMinTest.php b/tests/phpunit/includes/libs/CSSMinTest.php
index 6142f967..7841f30f 100644
--- a/tests/phpunit/includes/libs/CSSMinTest.php
+++ b/tests/phpunit/includes/libs/CSSMinTest.php
@@ -102,12 +102,12 @@ class CSSMinTest extends MediaWikiTestCase {
array(
'Without trailing slash',
array( 'foo { prop: url(../bar.png); }', false, 'http://example.org/quux', false ),
- 'foo { prop: url(http://example.org/quux/../bar.png); }',
+ 'foo { prop: url(http://example.org/bar.png); }',
),
array(
'With trailing slash on remote (bug 27052)',
array( 'foo { prop: url(../bar.png); }', false, 'http://example.org/quux/', false ),
- 'foo { prop: url(http://example.org/quux/../bar.png); }',
+ 'foo { prop: url(http://example.org/bar.png); }',
),
array(
'Guard against stripping double slashes from query',
@@ -133,12 +133,7 @@ class CSSMinTest extends MediaWikiTestCase {
$remotePath = 'http://localhost/w/';
$realOutput = CSSMin::remap( $input, $localPath, $remotePath );
-
- $this->assertEquals(
- $expectedOutput,
- preg_replace( '/\d+-\d+-\d+T\d+:\d+:\d+Z/', 'timestamp', $realOutput ),
- "CSSMin::remap: $message"
- );
+ $this->assertEquals( $expectedOutput, $realOutput, "CSSMin::remap: $message" );
}
public static function provideIsRemoteUrl() {
@@ -197,7 +192,7 @@ class CSSMinTest extends MediaWikiTestCase {
array(
'Regular file',
'foo { background: url(red.gif); }',
- 'foo { background: url(http://localhost/w/red.gif?timestamp); }',
+ 'foo { background: url(http://localhost/w/red.gif?34ac6); }',
),
array(
'Regular file (missing)',
@@ -242,12 +237,12 @@ class CSSMinTest extends MediaWikiTestCase {
array(
'Embedded file',
'foo { /* @embed */ background: url(red.gif); }',
- "foo { background: url($red); background: url(http://localhost/w/red.gif?timestamp)!ie; }",
+ "foo { background: url($red); background: url(http://localhost/w/red.gif?34ac6)!ie; }",
),
array(
'Embedded file, other comments before the rule',
"foo { /* Bar. */ /* @embed */ background: url(red.gif); }",
- "foo { /* Bar. */ background: url($red); /* Bar. */ background: url(http://localhost/w/red.gif?timestamp)!ie; }",
+ "foo { /* Bar. */ background: url($red); /* Bar. */ background: url(http://localhost/w/red.gif?34ac6)!ie; }",
),
array(
'Can not re-embed data: URIs',
@@ -268,12 +263,12 @@ class CSSMinTest extends MediaWikiTestCase {
'Embedded file (inline @embed)',
'foo { background: /* @embed */ url(red.gif); }',
"foo { background: url($red); "
- . "background: url(http://localhost/w/red.gif?timestamp)!ie; }",
+ . "background: url(http://localhost/w/red.gif?34ac6)!ie; }",
),
array(
'Can not embed large files',
'foo { /* @embed */ background: url(large.png); }',
- "foo { background: url(http://localhost/w/large.png?timestamp); }",
+ "foo { background: url(http://localhost/w/large.png?e3d1f); }",
),
array(
'SVG files are embedded without base64 encoding and unnecessary IE 6 and 7 fallback',
@@ -283,55 +278,55 @@ class CSSMinTest extends MediaWikiTestCase {
array(
'Two regular files in one rule',
'foo { background: url(red.gif), url(green.gif); }',
- 'foo { background: url(http://localhost/w/red.gif?timestamp), '
- . 'url(http://localhost/w/green.gif?timestamp); }',
+ 'foo { background: url(http://localhost/w/red.gif?34ac6), '
+ . 'url(http://localhost/w/green.gif?13651); }',
),
array(
'Two embedded files in one rule',
'foo { /* @embed */ background: url(red.gif), url(green.gif); }',
"foo { background: url($red), url($green); "
- . "background: url(http://localhost/w/red.gif?timestamp), "
- . "url(http://localhost/w/green.gif?timestamp)!ie; }",
+ . "background: url(http://localhost/w/red.gif?34ac6), "
+ . "url(http://localhost/w/green.gif?13651)!ie; }",
),
array(
'Two embedded files in one rule (inline @embed)',
'foo { background: /* @embed */ url(red.gif), /* @embed */ url(green.gif); }',
"foo { background: url($red), url($green); "
- . "background: url(http://localhost/w/red.gif?timestamp), "
- . "url(http://localhost/w/green.gif?timestamp)!ie; }",
+ . "background: url(http://localhost/w/red.gif?34ac6), "
+ . "url(http://localhost/w/green.gif?13651)!ie; }",
),
array(
'Two embedded files in one rule (inline @embed), one too large',
'foo { background: /* @embed */ url(red.gif), /* @embed */ url(large.png); }',
- "foo { background: url($red), url(http://localhost/w/large.png?timestamp); "
- . "background: url(http://localhost/w/red.gif?timestamp), "
- . "url(http://localhost/w/large.png?timestamp)!ie; }",
+ "foo { background: url($red), url(http://localhost/w/large.png?e3d1f); "
+ . "background: url(http://localhost/w/red.gif?34ac6), "
+ . "url(http://localhost/w/large.png?e3d1f)!ie; }",
),
array(
'Practical example with some noise',
'foo { /* @embed */ background: #f9f9f9 url(red.gif) 0 0 no-repeat; }',
"foo { background: #f9f9f9 url($red) 0 0 no-repeat; "
- . "background: #f9f9f9 url(http://localhost/w/red.gif?timestamp) 0 0 no-repeat!ie; }",
+ . "background: #f9f9f9 url(http://localhost/w/red.gif?34ac6) 0 0 no-repeat!ie; }",
),
array(
'Does not mess with other properties',
'foo { color: red; background: url(red.gif); font-size: small; }',
- 'foo { color: red; background: url(http://localhost/w/red.gif?timestamp); font-size: small; }',
+ 'foo { color: red; background: url(http://localhost/w/red.gif?34ac6); font-size: small; }',
),
array(
'Spacing and miscellanea not changed (1)',
'foo { background: url(red.gif); }',
- 'foo { background: url(http://localhost/w/red.gif?timestamp); }',
+ 'foo { background: url(http://localhost/w/red.gif?34ac6); }',
),
array(
'Spacing and miscellanea not changed (2)',
'foo {background:url(red.gif)}',
- 'foo {background:url(http://localhost/w/red.gif?timestamp)}',
+ 'foo {background:url(http://localhost/w/red.gif?34ac6)}',
),
array(
'Spaces within url() parentheses are ignored',
'foo { background: url( red.gif ); }',
- 'foo { background: url(http://localhost/w/red.gif?timestamp); }',
+ 'foo { background: url(http://localhost/w/red.gif?34ac6); }',
),
array(
'@import rule to local file (should we remap this?)',
@@ -351,22 +346,22 @@ class CSSMinTest extends MediaWikiTestCase {
array(
'Simple case with comments after url',
'foo { prop: url(red.gif)/* some {funny;} comment */ ; }',
- 'foo { prop: url(http://localhost/w/red.gif?timestamp)/* some {funny;} comment */ ; }',
+ 'foo { prop: url(http://localhost/w/red.gif?34ac6)/* some {funny;} comment */ ; }',
),
array(
'Embedded file with comment before url',
'foo { /* @embed */ background: /* some {funny;} comment */ url(red.gif); }',
- "foo { background: /* some {funny;} comment */ url($red); background: /* some {funny;} comment */ url(http://localhost/w/red.gif?timestamp)!ie; }",
+ "foo { background: /* some {funny;} comment */ url($red); background: /* some {funny;} comment */ url(http://localhost/w/red.gif?34ac6)!ie; }",
),
array(
'Embedded file with comments inside and outside the rule',
'foo { /* @embed */ background: url(red.gif) /* some {foo;} comment */; /* some {bar;} comment */ }',
- "foo { background: url($red) /* some {foo;} comment */; background: url(http://localhost/w/red.gif?timestamp) /* some {foo;} comment */!ie; /* some {bar;} comment */ }",
+ "foo { background: url($red) /* some {foo;} comment */; background: url(http://localhost/w/red.gif?34ac6) /* some {foo;} comment */!ie; /* some {bar;} comment */ }",
),
array(
'Embedded file with comment outside the rule',
'foo { /* @embed */ background: url(red.gif); /* some {funny;} comment */ }',
- "foo { background: url($red); background: url(http://localhost/w/red.gif?timestamp)!ie; /* some {funny;} comment */ }",
+ "foo { background: url($red); background: url(http://localhost/w/red.gif?34ac6)!ie; /* some {funny;} comment */ }",
),
array(
'Rule with two urls, each with comments',
diff --git a/tests/phpunit/includes/libs/IEUrlExtensionTest.php b/tests/phpunit/includes/libs/IEUrlExtensionTest.php
index e96953ee..57668e50 100644
--- a/tests/phpunit/includes/libs/IEUrlExtensionTest.php
+++ b/tests/phpunit/includes/libs/IEUrlExtensionTest.php
@@ -170,4 +170,37 @@ class IEUrlExtensionTest extends PHPUnit_Framework_TestCase {
'Two dots'
);
}
+
+ /**
+ * @covers IEUrlExtension::findIE6Extension
+ */
+ public function testScriptQuery() {
+ $this->assertEquals(
+ 'php',
+ IEUrlExtension::findIE6Extension( 'example.php?foo=a&bar=b' ),
+ 'Script with query'
+ );
+ }
+
+ /**
+ * @covers IEUrlExtension::findIE6Extension
+ */
+ public function testEscapedScriptQuery() {
+ $this->assertEquals(
+ '',
+ IEUrlExtension::findIE6Extension( 'example%2Ephp?foo=a&bar=b' ),
+ 'Script with urlencoded dot and query'
+ );
+ }
+
+ /**
+ * @covers IEUrlExtension::findIE6Extension
+ */
+ public function testEscapedScriptQueryDot() {
+ $this->assertEquals(
+ 'y',
+ IEUrlExtension::findIE6Extension( 'example%2Ephp?foo=a.x&bar=b.y' ),
+ 'Script with urlencoded dot and query with dot'
+ );
+ }
}
diff --git a/tests/phpunit/includes/libs/IPSetTest.php b/tests/phpunit/includes/libs/IPSetTest.php
deleted file mode 100644
index 5bbacef4..00000000
--- a/tests/phpunit/includes/libs/IPSetTest.php
+++ /dev/null
@@ -1,252 +0,0 @@
-<?php
-
-/**
- * @group IPSet
- */
-class IPSetTest extends PHPUnit_Framework_TestCase {
- /**
- * Provides test cases for IPSetTest::testIPSet
- *
- * Returns an array of test cases. Each case is an array of (description,
- * config, tests). Description is just text output for failure messages,
- * config is an array constructor argument for IPSet, and the tests are
- * an array of IP => expected (boolean) result against the config dataset.
- */
- public static function provideIPSets() {
- return array(
- array(
- 'old_list_subset',
- array(
- '208.80.152.162',
- '10.64.0.123',
- '10.64.0.124',
- '10.64.0.125',
- '10.64.0.126',
- '10.64.0.127',
- '10.64.0.128',
- '10.64.0.129',
- '10.64.32.104',
- '10.64.32.105',
- '10.64.32.106',
- '10.64.32.107',
- '91.198.174.45',
- '91.198.174.46',
- '91.198.174.47',
- '91.198.174.57',
- '2620:0:862:1:A6BA:DBFF:FE30:CFB3',
- '91.198.174.58',
- '2620:0:862:1:A6BA:DBFF:FE38:FFDA',
- '208.80.152.16',
- '208.80.152.17',
- '208.80.152.18',
- '208.80.152.19',
- '91.198.174.102',
- '91.198.174.103',
- '91.198.174.104',
- '91.198.174.105',
- '91.198.174.106',
- '91.198.174.107',
- '91.198.174.81',
- '2620:0:862:1:26B6:FDFF:FEF5:B2D4',
- '91.198.174.82',
- '2620:0:862:1:26B6:FDFF:FEF5:ABB4',
- '10.20.0.113',
- '2620:0:862:102:26B6:FDFF:FEF5:AD9C',
- '10.20.0.114',
- '2620:0:862:102:26B6:FDFF:FEF5:7C38',
- ),
- array(
- '0.0.0.0' => false,
- '255.255.255.255' => false,
- '10.64.0.122' => false,
- '10.64.0.123' => true,
- '10.64.0.124' => true,
- '10.64.0.129' => true,
- '10.64.0.130' => false,
- '91.198.174.81' => true,
- '91.198.174.80' => false,
- '0::0' => false,
- 'ffff:ffff:ffff:ffff:FFFF:FFFF:FFFF:FFFF' => false,
- '2001:db8::1234' => false,
- '2620:0:862:1:26b6:fdff:fef5:abb3' => false,
- '2620:0:862:1:26b6:fdff:fef5:abb4' => true,
- '2620:0:862:1:26b6:fdff:fef5:abb5' => false,
- ),
- ),
- array(
- 'new_cidr_set',
- array(
- '208.80.154.0/26',
- '2620:0:861:1::/64',
- '208.80.154.128/26',
- '2620:0:861:2::/64',
- '208.80.154.64/26',
- '2620:0:861:3::/64',
- '208.80.155.96/27',
- '2620:0:861:4::/64',
- '10.64.0.0/22',
- '2620:0:861:101::/64',
- '10.64.16.0/22',
- '2620:0:861:102::/64',
- '10.64.32.0/22',
- '2620:0:861:103::/64',
- '10.64.48.0/22',
- '2620:0:861:107::/64',
- '91.198.174.0/25',
- '2620:0:862:1::/64',
- '10.20.0.0/24',
- '2620:0:862:102::/64',
- '10.128.0.0/24',
- '2620:0:863:101::/64',
- '10.2.4.26',
- ),
- array(
- '0.0.0.0' => false,
- '255.255.255.255' => false,
- '10.2.4.25' => false,
- '10.2.4.26' => true,
- '10.2.4.27' => false,
- '10.20.0.255' => true,
- '10.128.0.0' => true,
- '10.64.17.55' => true,
- '10.64.20.0' => false,
- '10.64.27.207' => false,
- '10.64.31.255' => false,
- '0::0' => false,
- 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff' => false,
- '2001:DB8::1' => false,
- '2620:0:861:106::45' => false,
- '2620:0:862:103::' => false,
- '2620:0:862:102:10:20:0:113' => true,
- ),
- ),
- array(
- 'empty_set',
- array(),
- array(
- '0.0.0.0' => false,
- '255.255.255.255' => false,
- '10.2.4.25' => false,
- '10.2.4.26' => false,
- '10.2.4.27' => false,
- '10.20.0.255' => false,
- '10.128.0.0' => false,
- '10.64.17.55' => false,
- '10.64.20.0' => false,
- '10.64.27.207' => false,
- '10.64.31.255' => false,
- '0::0' => false,
- 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff' => false,
- '2001:DB8::1' => false,
- '2620:0:861:106::45' => false,
- '2620:0:862:103::' => false,
- '2620:0:862:102:10:20:0:113' => false,
- ),
- ),
- array(
- 'edge_cases',
- array(
- '0.0.0.0',
- '255.255.255.255',
- '::',
- 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff',
- '10.10.10.10/25', // host bits intentional
- ),
- array(
- '0.0.0.0' => true,
- '255.255.255.255' => true,
- '10.2.4.25' => false,
- '10.2.4.26' => false,
- '10.2.4.27' => false,
- '10.20.0.255' => false,
- '10.128.0.0' => false,
- '10.64.17.55' => false,
- '10.64.20.0' => false,
- '10.64.27.207' => false,
- '10.64.31.255' => false,
- '0::0' => true,
- 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff' => true,
- '2001:DB8::1' => false,
- '2620:0:861:106::45' => false,
- '2620:0:862:103::' => false,
- '2620:0:862:102:10:20:0:113' => false,
- '10.10.9.255' => false,
- '10.10.10.0' => true,
- '10.10.10.1' => true,
- '10.10.10.10' => true,
- '10.10.10.126' => true,
- '10.10.10.127' => true,
- '10.10.10.128' => false,
- '10.10.10.177' => false,
- '10.10.10.255' => false,
- '10.10.11.0' => false,
- ),
- ),
- array(
- 'exercise_optimizer',
- array(
- 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:0/112',
- 'ffff:ffff:ffff:ffff:ffff:ffff:fffe:0/112',
- 'ffff:ffff:ffff:ffff:ffff:ffff:fffd:0/112',
- 'ffff:ffff:ffff:ffff:ffff:ffff:fffc:0/112',
- 'ffff:ffff:ffff:ffff:ffff:ffff:fffb:0/112',
- 'ffff:ffff:ffff:ffff:ffff:ffff:fffa:0/112',
- 'ffff:ffff:ffff:ffff:ffff:ffff:fff9:8000/113',
- 'ffff:ffff:ffff:ffff:ffff:ffff:fff9:0/113',
- 'ffff:ffff:ffff:ffff:ffff:ffff:fff8:0/112',
- 'ffff:ffff:ffff:ffff:ffff:ffff:fff7:0/112',
- 'ffff:ffff:ffff:ffff:ffff:ffff:fff6:0/112',
- 'ffff:ffff:ffff:ffff:ffff:ffff:fff5:0/112',
- 'ffff:ffff:ffff:ffff:ffff:ffff:fff4:0/112',
- 'ffff:ffff:ffff:ffff:ffff:ffff:fff3:0/112',
- 'ffff:ffff:ffff:ffff:ffff:ffff:fff2:0/112',
- 'ffff:ffff:ffff:ffff:ffff:ffff:fff1:0/112',
- 'ffff:ffff:ffff:ffff:ffff:ffff:fff0:0/112',
- 'ffff:ffff:ffff:ffff:ffff:ffff:ffef:0/112',
- 'ffff:ffff:ffff:ffff:ffff:ffff:ffee:0/112',
- 'ffff:ffff:ffff:ffff:ffff:ffff:ffec:0/111',
- 'ffff:ffff:ffff:ffff:ffff:ffff:ffeb:0/112',
- 'ffff:ffff:ffff:ffff:ffff:ffff:ffea:0/112',
- 'ffff:ffff:ffff:ffff:ffff:ffff:ffe9:0/112',
- 'ffff:ffff:ffff:ffff:ffff:ffff:ffe8:0/112',
- 'ffff:ffff:ffff:ffff:ffff:ffff:ffe7:0/112',
- 'ffff:ffff:ffff:ffff:ffff:ffff:ffe6:0/112',
- 'ffff:ffff:ffff:ffff:ffff:ffff:ffe5:0/112',
- 'ffff:ffff:ffff:ffff:ffff:ffff:ffe4:0/112',
- 'ffff:ffff:ffff:ffff:ffff:ffff:ffe3:0/112',
- 'ffff:ffff:ffff:ffff:ffff:ffff:ffe2:0/112',
- 'ffff:ffff:ffff:ffff:ffff:ffff:ffe1:0/112',
- 'ffff:ffff:ffff:ffff:ffff:ffff:ffe0:0/110',
- 'ffff:ffff:ffff:ffff:ffff:ffff:ffc0:0/107',
- 'ffff:ffff:ffff:ffff:ffff:ffff:ffa0:0/107',
- ),
- array(
- '0.0.0.0' => false,
- '255.255.255.255' => false,
- '::' => false,
- 'ffff:ffff:ffff:ffff:ffff:ffff:ff9f:ffff' => false,
- 'ffff:ffff:ffff:ffff:ffff:ffff:ffa0:0' => true,
- 'ffff:ffff:ffff:ffff:ffff:ffff:ffc0:1234' => true,
- 'ffff:ffff:ffff:ffff:ffff:ffff:ffed:ffff' => true,
- 'ffff:ffff:ffff:ffff:ffff:ffff:fff4:4444' => true,
- 'ffff:ffff:ffff:ffff:ffff:ffff:fff9:8080' => true,
- 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff' => true,
- ),
- ),
- );
- }
-
- /**
- * Validates IPSet loading and matching code
- *
- * @covers IPSet
- * @dataProvider provideIPSets
- */
- public function testIPSet( $desc, array $cfg, array $tests ) {
- $ipset = new IPSet( $cfg );
- foreach ( $tests as $ip => $expected ) {
- $result = $ipset->match( $ip );
- $this->assertEquals( $expected, $result, "Incorrect match() result for $ip in dataset $desc" );
- }
- }
-}
diff --git a/tests/phpunit/includes/libs/JavaScriptMinifierTest.php b/tests/phpunit/includes/libs/JavaScriptMinifierTest.php
index 149a28c1..d23534ed 100644
--- a/tests/phpunit/includes/libs/JavaScriptMinifierTest.php
+++ b/tests/phpunit/includes/libs/JavaScriptMinifierTest.php
@@ -140,6 +140,13 @@ class JavaScriptMinifierTest extends PHPUnit_Framework_TestCase {
array( "5..toString();", "5..toString();" ),
array( "5...toString();", false ),
array( "5.\n.toString();", '5..toString();' ),
+
+ // Boolean minification (!0 / !1)
+ array( "var a = { b: true };", "var a={b:!0};" ),
+ array( "var a = { true: 12 };", "var a={true:12};", false ),
+ array( "a.true = 12;", "a.true=12;", false ),
+ array( "a.foo = true;", "a.foo=!0;" ),
+ array( "a.foo = false;", "a.foo=!1;" ),
);
}
@@ -147,15 +154,17 @@ class JavaScriptMinifierTest extends PHPUnit_Framework_TestCase {
* @dataProvider provideCases
* @covers JavaScriptMinifier::minify
*/
- public function testJavaScriptMinifierOutput( $code, $expectedOutput ) {
+ public function testJavaScriptMinifierOutput( $code, $expectedOutput, $expectedValid = true ) {
$minified = JavaScriptMinifier::minify( $code );
// JSMin+'s parser will throw an exception if output is not valid JS.
// suppression of warnings needed for stupid crap
- wfSuppressWarnings();
- $parser = new JSParser();
- wfRestoreWarnings();
- $parser->parse( $minified, 'minify-test.js', 1 );
+ if ( $expectedValid ) {
+ MediaWiki\suppressWarnings();
+ $parser = new JSParser();
+ MediaWiki\restoreWarnings();
+ $parser->parse( $minified, 'minify-test.js', 1 );
+ }
$this->assertEquals(
$expectedOutput,
diff --git a/tests/phpunit/includes/libs/ObjectFactoryTest.php b/tests/phpunit/includes/libs/ObjectFactoryTest.php
index 92207325..aea037e0 100644
--- a/tests/phpunit/includes/libs/ObjectFactoryTest.php
+++ b/tests/phpunit/includes/libs/ObjectFactoryTest.php
@@ -26,11 +26,20 @@ class ObjectFactoryTest extends PHPUnit_Framework_TestCase {
public function testClosureExpansionDisabled() {
$obj = ObjectFactory::getObjectFromSpec( array(
'class' => 'ObjectFactoryTest_Fixture',
- 'args' => array( function (){ return 'unwrapped'; }, ),
+ 'args' => array( function() {
+ return 'unwrapped';
+ }, ),
+ 'calls' => array(
+ 'setter' => array( function() {
+ return 'unwrapped';
+ }, ),
+ ),
'closure_expansion' => false,
) );
$this->assertInstanceOf( 'Closure', $obj->args[0] );
$this->assertSame( 'unwrapped', $obj->args[0]() );
+ $this->assertInstanceOf( 'Closure', $obj->setterArgs[0] );
+ $this->assertSame( 'unwrapped', $obj->setterArgs[0]() );
}
/**
@@ -39,22 +48,46 @@ class ObjectFactoryTest extends PHPUnit_Framework_TestCase {
public function testClosureExpansionEnabled() {
$obj = ObjectFactory::getObjectFromSpec( array(
'class' => 'ObjectFactoryTest_Fixture',
- 'args' => array( function (){ return 'unwrapped'; }, ),
+ 'args' => array( function() {
+ return 'unwrapped';
+ }, ),
+ 'calls' => array(
+ 'setter' => array( function() {
+ return 'unwrapped';
+ }, ),
+ ),
'closure_expansion' => true,
) );
$this->assertInternalType( 'string', $obj->args[0] );
$this->assertSame( 'unwrapped', $obj->args[0] );
+ $this->assertInternalType( 'string', $obj->setterArgs[0] );
+ $this->assertSame( 'unwrapped', $obj->setterArgs[0] );
$obj = ObjectFactory::getObjectFromSpec( array(
'class' => 'ObjectFactoryTest_Fixture',
- 'args' => array( function (){ return 'unwrapped'; }, ),
+ 'args' => array( function() {
+ return 'unwrapped';
+ }, ),
+ 'calls' => array(
+ 'setter' => array( function() {
+ return 'unwrapped';
+ }, ),
+ ),
) );
$this->assertInternalType( 'string', $obj->args[0] );
$this->assertSame( 'unwrapped', $obj->args[0] );
+ $this->assertInternalType( 'string', $obj->setterArgs[0] );
+ $this->assertSame( 'unwrapped', $obj->setterArgs[0] );
}
}
class ObjectFactoryTest_Fixture {
public $args;
- public function __construct( /*...*/ ) { $this->args = func_get_args(); }
+ public $setterArgs;
+ public function __construct( /*...*/ ) {
+ $this->args = func_get_args();
+ }
+ public function setter( /*...*/ ) {
+ $this->setterArgs = func_get_args();
+ }
}
diff --git a/tests/phpunit/includes/libs/ProcessCacheLRUTest.php b/tests/phpunit/includes/libs/ProcessCacheLRUTest.php
index 43001979..cec662a9 100644
--- a/tests/phpunit/includes/libs/ProcessCacheLRUTest.php
+++ b/tests/phpunit/includes/libs/ProcessCacheLRUTest.php
@@ -70,7 +70,7 @@ class ProcessCacheLRUTest extends PHPUnit_Framework_TestCase {
/**
* @dataProvider provideInvalidConstructorArg
- * @expectedException UnexpectedValueException
+ * @expectedException Wikimedia\Assert\ParameterAssertionException
* @covers ProcessCacheLRU::__construct
*/
public function testConstructorGivenInvalidValue( $maxSize ) {
diff --git a/tests/phpunit/includes/libs/SamplingStatsdClientTest.php b/tests/phpunit/includes/libs/SamplingStatsdClientTest.php
new file mode 100644
index 00000000..be6732d5
--- /dev/null
+++ b/tests/phpunit/includes/libs/SamplingStatsdClientTest.php
@@ -0,0 +1,43 @@
+<?php
+
+use Liuggio\StatsdClient\Entity\StatsdData;
+
+class SamplingStatsdClientTest extends PHPUnit_Framework_TestCase {
+ /**
+ * @dataProvider samplingDataProvider
+ */
+ public function testSampling( $data, $sampleRate, $seed, $expectWrite ) {
+ $sender = $this->getMock( 'Liuggio\StatsdClient\Sender\SenderInterface' );
+ $sender->expects( $this->any() )->method( 'open' )->will( $this->returnValue( true ) );
+ if ( $expectWrite ) {
+ $sender->expects( $this->once() )->method( 'write' )
+ ->with( $this->anything(), $this->equalTo( $data ) );
+ } else {
+ $sender->expects( $this->never() )->method( 'write' );
+ }
+ mt_srand( $seed );
+ $client = new SamplingStatsdClient( $sender );
+ $client->send( $data, $sampleRate );
+ }
+
+ public function samplingDataProvider() {
+ $unsampled = new StatsdData();
+ $unsampled->setKey( 'foo' );
+ $unsampled->setValue( 1 );
+
+ $sampled = new StatsdData();
+ $sampled->setKey( 'foo' );
+ $sampled->setValue( 1 );
+ $sampled->setSampleRate( '0.1' );
+
+ return array(
+ // $data, $sampleRate, $seed, $expectWrite
+ array( $unsampled, 1, 0 /*0.44*/, $unsampled ),
+ array( $sampled, 1, 0 /*0.44*/, null ),
+ array( $sampled, 1, 4 /*0.03*/, $sampled ),
+ array( $unsampled, 0.1, 4 /*0.03*/, $sampled ),
+ array( $sampled, 0.5, 0 /*0.44*/, null ),
+ array( $sampled, 0.5, 4 /*0.03*/, $sampled ),
+ );
+ }
+}
diff --git a/tests/phpunit/includes/libs/XhprofTest.php b/tests/phpunit/includes/libs/XhprofTest.php
index 2440fc08..77b188cf 100644
--- a/tests/phpunit/includes/libs/XhprofTest.php
+++ b/tests/phpunit/includes/libs/XhprofTest.php
@@ -255,43 +255,43 @@ class XhprofTest extends PHPUnit_Framework_TestCase {
*/
protected function getXhprofFixture( array $opts = array() ) {
$xhprof = new Xhprof( $opts );
- $xhprof->loadRawData( array (
- 'foo==>bar' => array (
+ $xhprof->loadRawData( array(
+ 'foo==>bar' => array(
'ct' => 2,
'wt' => 57,
'cpu' => 92,
'mu' => 1896,
'pmu' => 0,
),
- 'foo==>strlen' => array (
+ 'foo==>strlen' => array(
'ct' => 2,
'wt' => 21,
'cpu' => 141,
'mu' => 752,
'pmu' => 0,
),
- 'bar==>bar@1' => array (
+ 'bar==>bar@1' => array(
'ct' => 1,
'wt' => 18,
'cpu' => 19,
'mu' => 752,
'pmu' => 0,
),
- 'main()==>foo' => array (
+ 'main()==>foo' => array(
'ct' => 1,
'wt' => 304,
'cpu' => 307,
'mu' => 4008,
'pmu' => 0,
),
- 'main()==>xhprof_disable' => array (
+ 'main()==>xhprof_disable' => array(
'ct' => 1,
'wt' => 8,
'cpu' => 10,
'mu' => 768,
'pmu' => 392,
),
- 'main()' => array (
+ 'main()' => array(
'ct' => 1,
'wt' => 353,
'cpu' => 351,
@@ -311,7 +311,7 @@ class XhprofTest extends PHPUnit_Framework_TestCase {
*/
protected function assertArrayStructure( $struct, $actual, $label = null ) {
$this->assertInternalType( 'array', $actual, $label );
- $this->assertCount( count($struct), $actual, $label );
+ $this->assertCount( count( $struct ), $actual, $label );
foreach ( $struct as $key => $type ) {
$this->assertArrayHasKey( $key, $actual );
$this->assertInternalType( $type, $actual[$key] );
diff --git a/tests/phpunit/includes/libs/composer/ComposerLockTest.php b/tests/phpunit/includes/libs/composer/ComposerLockTest.php
index b5fd5f6e..cac3b101 100644
--- a/tests/phpunit/includes/libs/composer/ComposerLockTest.php
+++ b/tests/phpunit/includes/libs/composer/ComposerLockTest.php
@@ -27,34 +27,95 @@ class ComposerLockTest extends MediaWikiTestCase {
'wikimedia/cdb' => array(
'version' => '1.0.1',
'type' => 'library',
+ 'licenses' => array( 'GPL-2.0' ),
+ 'authors' => array(
+ array(
+ 'name' => 'Tim Starling',
+ 'email' => 'tstarling@wikimedia.org',
+ ),
+ array(
+ 'name' => 'Chad Horohoe',
+ 'email' => 'chad@wikimedia.org',
+ ),
+ ),
+ 'description' => 'Constant Database (CDB) wrapper library for PHP. Provides pure-PHP fallback when dba_* functions are absent.',
),
'cssjanus/cssjanus' => array(
'version' => '1.1.1',
'type' => 'library',
+ 'licenses' => array( 'Apache-2.0' ),
+ 'authors' => array(),
+ 'description' => 'Convert CSS stylesheets between left-to-right and right-to-left.',
),
'leafo/lessphp' => array(
'version' => '0.5.0',
'type' => 'library',
+ 'licenses' => array( 'MIT', 'GPL-3.0' ),
+ 'authors' => array(
+ array(
+ 'name' => 'Leaf Corcoran',
+ 'email' => 'leafot@gmail.com',
+ 'homepage' => 'http://leafo.net',
+ ),
+ ),
+ 'description' => 'lessphp is a compiler for LESS written in PHP.',
),
'psr/log' => array(
'version' => '1.0.0',
'type' => 'library',
+ 'licenses' => array( 'MIT' ),
+ 'authors' => array(
+ array(
+ 'name' => 'PHP-FIG',
+ 'homepage' => 'http://www.php-fig.org/',
+ ),
+ ),
+ 'description' => 'Common interface for logging libraries',
),
'oojs/oojs-ui' => array(
'version' => '0.6.0',
'type' => 'library',
+ 'licenses' => array( 'MIT' ),
+ 'authors' => array(),
+ 'description' => '',
),
'composer/installers' => array(
'version' => '1.0.19',
'type' => 'composer-installer',
+ 'licenses' => array( 'MIT' ),
+ 'authors' => array(
+ array(
+ 'name' => 'Kyle Robinson Young',
+ 'email' => 'kyle@dontkry.com',
+ 'homepage' => 'https://github.com/shama',
+ ),
+ ),
+ 'description' => 'A multi-framework Composer library installer',
),
'mediawiki/translate' => array(
'version' => '2014.12',
'type' => 'mediawiki-extension',
+ 'licenses' => array( 'GPL-2.0+' ),
+ 'authors' => array(
+ array(
+ 'name' => 'Niklas Laxström',
+ 'email' => 'niklas.laxstrom@gmail.com',
+ 'role' => 'Lead nitpicker',
+ ),
+ array(
+ 'name' => 'Siebrand Mazeland',
+ 'email' => 's.mazeland@xs4all.nl',
+ 'role' => 'Developer',
+ ),
+ ),
+ 'description' => 'The only standard solution to translate any kind of text with an avant-garde web interface within MediaWiki, including your documentation and software',
),
'mediawiki/universal-language-selector' => array(
'version' => '2014.12',
'type' => 'mediawiki-extension',
+ 'licenses' => array( 'GPL-2.0+', 'MIT' ),
+ 'authors' => array(),
+ 'description' => 'The primary aim is to allow users to select a language and configure its support in an easy way. Main features are language selection, input methods and web fonts.',
),
), $lock->getInstalledDependencies(), false, true );
}