+ '.foo[data-left="x"] { width: 0; }',
+ '.foo[data-left="x"] { width: 0; }'
+ ),
+ );
+ }
+}
diff --git a/tests/phpunit/includes/libs/CSSMinTest.php b/tests/phpunit/includes/libs/CSSMinTest.php
new file mode 100644
index 00000000..a3827756
--- /dev/null
+++ b/tests/phpunit/includes/libs/CSSMinTest.php
@@ -0,0 +1,142 @@
+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;
+
+ parent::tearDown();
+ }
+
+ /**
+ * @dataProvider provideMinifyCases
+ */
+ function testMinify( $code, $expectedOutput ) {
+ $minified = CSSMin::minify( $code );
+
+ $this->assertEquals( $expectedOutput, $minified, 'Minified output should be in the form expected.' );
+ }
+
+ function provideMinifyCases() {
+ return array(
+ // Whitespace
+ array( "\r\t\f \v\n\r", "" ),
+ array( "foo, bar {\n\tprop: value;\n}", "foo,bar{prop:value}" ),
+
+ // Loose comments
+ array( "/* foo */", "" ),
+ array( "/*******\n foo\n *******/", "" ),
+ array( "/*!\n foo\n */", "" ),
+
+ // Inline comments in various different places
+ array( "/* comment */foo, bar {\n\tprop: value;\n}", "foo,bar{prop:value}" ),
+ array( "foo/* comment */, bar {\n\tprop: value;\n}", "foo,bar{prop:value}" ),
+ array( "foo,/* comment */ bar {\n\tprop: value;\n}", "foo,bar{prop:value}" ),
+ array( "foo, bar/* comment */ {\n\tprop: value;\n}", "foo,bar{prop:value}" ),
+ array( "foo, bar {\n\t/* comment */prop: value;\n}", "foo,bar{prop:value}" ),
+ array( "foo, bar {\n\tprop: /* comment */value;\n}", "foo,bar{prop:value}" ),
+ array( "foo, bar {\n\tprop: value /* comment */;\n}", "foo,bar{prop:value }" ),
+ array( "foo, bar {\n\tprop: value; /* comment */\n}", "foo,bar{prop:value; }" ),
+
+ // Keep track of things that aren't as minified as much as they
+ // could be (bug 35493)
+ array( 'foo { prop: value ;}', 'foo{prop:value }' ),
+ array( 'foo { prop : value; }', 'foo{prop :value}' ),
+ array( 'foo { prop: value ; }', 'foo{prop:value }' ),
+ array( 'foo { font-family: "foo" , "bar"; }', 'foo{font-family:"foo" ,"bar"}' ),
+ array( "foo { src:\n\turl('foo') ,\n\turl('bar') ; }", "foo{src:url('foo') ,url('bar') }" ),
+
+ // Interesting cases with string values
+ // - Double quotes, single quotes
+ array( 'foo { content: ""; }', 'foo{content:""}' ),
+ array( "foo { content: ''; }", "foo{content:''}" ),
+ array( 'foo { content: "\'"; }', 'foo{content:"\'"}' ),
+ array( "foo { content: '\"'; }", "foo{content:'\"'}" ),
+ // - Whitespace in string values
+ array( 'foo { content: " "; }', 'foo{content:" "}' ),
+ );
+ }
+
+ /**
+ * @dataProvider provideRemapCases
+ */
+ function testRemap( $message, $params, $expectedOutput ) {
+ $remapped = call_user_func_array( 'CSSMin::remap', $params );
+
+ $messageAdd = " Case: $message";
+ $this->assertEquals( $expectedOutput, $remapped, 'CSSMin::remap should return the expected url form.' . $messageAdd );
+ }
+
+ function provideRemapCases() {
+ // Parameter signature:
+ // CSSMin::remap( $code, $local, $remote, $embedData = true )
+ return array(
+ array(
+ 'Simple case',
+ array( 'foo { prop: url(bar.png); }', false, 'http://example.org', false ),
+ 'foo { prop: url(http://example.org/bar.png); }',
+ ),
+ 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); }',
+ ),
+ 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); }',
+ ),
+ array(
+ 'Guard against stripping double slashes from query',
+ array( 'foo { prop: url(bar.png?corge=//grault); }', false, 'http://example.org/quux/', false ),
+ 'foo { prop: url(http://example.org/quux/bar.png?corge=//grault); }',
+ ),
+ 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); }',
+ ),
+ );
+ }
+
+ /**
+ * Seperated because they are currently broken (bug 35492)
+ *
+ * @group Broken
+ * @dataProvider provideStringCases
+ */
+ function testMinifyWithCSSStringValues( $code, $expectedOutput ) {
+ $this->testMinifyOutput( $code, $expectedOutput );
+ }
+
+ function provideStringCases() {
+ return array(
+ // String values should be respected
+ // - More than one space in a string value
+ array( 'foo { content: " "; }', 'foo{content:" "}' ),
+ // - Using a tab in a string value (turns into a space)
+ array( "foo { content: '\t'; }", "foo{content:'\t'}" ),
+ // - Using css-like syntax in string values
+ array( 'foo::after { content: "{;}"; position: absolute; }', 'foo::after{content:"{;}";position:absolute}' ),
+ );
+ }
+}
diff --git a/tests/phpunit/includes/libs/GenericArrayObjectTest.php b/tests/phpunit/includes/libs/GenericArrayObjectTest.php
new file mode 100644
index 00000000..70fce111
--- /dev/null
+++ b/tests/phpunit/includes/libs/GenericArrayObjectTest.php
@@ -0,0 +1,245 @@
+
+ */
+abstract class GenericArrayObjectTest extends MediaWikiTestCase {
+
+ /**
+ * Returns objects that can serve as elements in the concrete GenericArrayObject deriving class being tested.
+ *
+ * @since 1.20
+ *
+ * @return array
+ */
+ public abstract function elementInstancesProvider();
+
+ /**
+ * Returns the name of the concrete class being tested.
+ *
+ * @since 1.20
+ *
+ * @return string
+ */
+ public abstract function getInstanceClass();
+
+ /**
+ * Provides instances of the concrete class being tested.
+ *
+ * @since 1.20
+ *
+ * @return array
+ */
+ public function instanceProvider() {
+ $instances = array();
+
+ foreach ( $this->elementInstancesProvider() as $elementInstances ) {
+ $instances[] = $this->getNew( $elementInstances );
+ }
+
+ return $this->arrayWrap( $instances );
+ }
+
+ /**
+ * @since 1.20
+ *
+ * @param array $elements
+ *
+ * @return GenericArrayObject
+ */
+ protected function getNew( array $elements = array() ) {
+ $class = $this->getInstanceClass();
+ return new $class( $elements );
+ }
+
+ /**
+ * @dataProvider elementInstancesProvider
+ *
+ * @since 1.20
+ *
+ * @param array $elements
+ */
+ public function testConstructor( array $elements ) {
+ $arrayObject = $this->getNew( $elements );
+
+ $this->assertEquals( count( $elements ), $arrayObject->count() );
+ }
+
+ /**
+ * @dataProvider elementInstancesProvider
+ *
+ * @since 1.20
+ *
+ * @param array $elements
+ */
+ public function testIsEmpty( array $elements ) {
+ $arrayObject = $this->getNew( $elements );
+
+ $this->assertEquals( $elements === array(), $arrayObject->isEmpty() );
+ }
+
+ /**
+ * @dataProvider instanceProvider
+ *
+ * @since 1.20
+ *
+ * @param GenericArrayObject $list
+ */
+ public function testUnset( GenericArrayObject $list ) {
+ if ( !$list->isEmpty() ) {
+ $offset = $list->getIterator()->key();
+ $count = $list->count();
+ $list->offsetUnset( $offset );
+ $this->assertEquals( $count - 1, $list->count() );
+ }
+
+ if ( !$list->isEmpty() ) {
+ $offset = $list->getIterator()->key();
+ $count = $list->count();
+ unset( $list[$offset] );
+ $this->assertEquals( $count - 1, $list->count() );
+ }
+
+ $exception = null;
+ try { $list->offsetUnset( 'sdfsedtgsrdysftu' ); } catch ( \Exception $exception ){}
+ $this->assertInstanceOf( '\Exception', $exception );
+ }
+
+ /**
+ * @dataProvider elementInstancesProvider
+ *
+ * @since 1.20
+ *
+ * @param array $elements
+ */
+ public function testAppend( array $elements ) {
+ $list = $this->getNew();
+
+ $listSize = count( $elements );
+
+ foreach ( $elements as $element ) {
+ $list->append( $element );
+ }
+
+ $this->assertEquals( $listSize, $list->count() );
+
+ $list = $this->getNew();
+
+ foreach ( $elements as $element ) {
+ $list[] = $element;
+ }
+
+ $this->assertEquals( $listSize, $list->count() );
+
+ $this->checkTypeChecks( function( GenericArrayObject $list, $element ) {
+ $list->append( $element );
+ } );
+ }
+
+ /**
+ * @since 1.20
+ *
+ * @param callback $function
+ */
+ protected function checkTypeChecks( $function ) {
+ $excption = null;
+ $list = $this->getNew();
+
+ $elementClass = $list->getObjectType();
+
+ foreach ( array( 42, 'foo', array(), new \stdClass(), 4.2 ) as $element ) {
+ $validValid = $element instanceof $elementClass;
+
+ try{
+ call_user_func( $function, $list, $element );
+ $valid = true;
+ }
+ catch ( InvalidArgumentException $exception ) {
+ $valid = false;
+ }
+
+ $this->assertEquals(
+ $validValid,
+ $valid,
+ 'Object of invalid type got successfully added to a GenericArrayObject'
+ );
+ }
+ }
+
+ /**
+ * @dataProvider elementInstancesProvider
+ *
+ * @since 1.20
+ *
+ * @param array $elements
+ */
+ public function testOffsetSet( array $elements ) {
+ if ( $elements === array() ) {
+ $this->assertTrue( true );
+ return;
+ }
+
+ $list = $this->getNew();
+
+ $element = reset( $elements );
+ $list->offsetSet( 42, $element );
+ $this->assertEquals( $element, $list->offsetGet( 42 ) );
+
+ $list = $this->getNew();
+
+ $element = reset( $elements );
+ $list['oHai'] = $element;
+ $this->assertEquals( $element, $list['oHai'] );
+
+ $list = $this->getNew();
+
+ $element = reset( $elements );
+ $list->offsetSet( 9001, $element );
+ $this->assertEquals( $element, $list[9001] );
+
+ $list = $this->getNew();
+
+ $element = reset( $elements );
+ $list->offsetSet( null, $element );
+ $this->assertEquals( $element, $list[0] );
+
+ $list = $this->getNew();
+ $offset = 0;
+
+ foreach ( $elements as $element ) {
+ $list->offsetSet( null, $element );
+ $this->assertEquals( $element, $list[$offset++] );
+ }
+
+ $this->assertEquals( count( $elements ), $list->count() );
+
+ $this->checkTypeChecks( function( GenericArrayObject $list, $element ) {
+ $list->offsetSet( mt_rand(), $element );
+ } );
+ }
+
+}
diff --git a/tests/phpunit/includes/libs/JavaScriptMinifierTest.php b/tests/phpunit/includes/libs/JavaScriptMinifierTest.php
index d2bfeedf..f121b018 100644
--- a/tests/phpunit/includes/libs/JavaScriptMinifierTest.php
+++ b/tests/phpunit/includes/libs/JavaScriptMinifierTest.php
@@ -4,9 +4,18 @@ class JavaScriptMinifierTest extends MediaWikiTestCase {
function provideCases() {
return array(
- // Basic tokens
+
+ // Basic whitespace and comments that should be stripped entirely
array( "\r\t\f \v\n\r", "" ),
array( "/* Foo *\n*bar\n*/", "" ),
+
+ /**
+ * Slashes used inside block comments (bug 26931).
+ * At some point there was a bug that caused this comment to be ended at '* /',
+ * causing /M... to be left as the beginning of a regex.
+ */
+ array( "/**\n * Foo\n * {\n * 'bar' : {\n * //Multiple rules with configurable operators\n * 'baz' : false\n * }\n */", ""),
+
/**
* ' Foo \' bar \
* baz \' quox ' .
@@ -15,11 +24,13 @@ class JavaScriptMinifierTest extends MediaWikiTestCase {
array( "\" Foo \\\" bar \\\n baz \\\" quox \" .length", "\" Foo \\\" bar \\\n baz \\\" quox \".length" ),
array( "// Foo b/ar baz", "" ),
array( "/ Foo \\/ bar [ / \\] / ] baz / .length", "/ Foo \\/ bar [ / \\] / ] baz /.length" ),
+
// HTML comments
array( " bar", "" ),
array( "--> Foo", "" ),
array( "x --> y", "x-->y" ),
+
// Semicolon insertion
array( "(function(){return\nx;})", "(function(){return\nx;})" ),
array( "throw\nx;", "throw\nx;" ),
@@ -35,12 +46,19 @@ class JavaScriptMinifierTest extends MediaWikiTestCase {
array( "5.\nx;", "5.\nx;" ),
array( "0xFF.\nx;", "0xFF.x;" ),
array( "5.3.\nx;", "5.3.x;" ),
+
+ // Semicolon insertion between an expression having an inline
+ // comment after it, and a statement on the next line (bug 27046).
+ array( "var a = this //foo bar \n for ( b = 0; c < d; b++ ) {}", "var a=this\nfor(b=0;c
assertEquals( $expectedOutput, $minified, "Minified output should be in the form expected." );
}
- /**
- * @dataProvider provideBug32548
- */
- function testBug32548Exponent($num) {
- // Long line breaking was being incorrectly done between the base and
- // exponent part of a number, causing a syntax error. The line should
- // instead break at the start of the number.
- $prefix = 'var longVarName' . str_repeat('_', 973) . '=';
- $suffix = ',shortVarName=0;';
-
- $input = $prefix . $num . $suffix;
- $expected = $prefix . "\n" . $num . $suffix;
-
- $minified = JavaScriptMinifier::minify( $input );
-
- $this->assertEquals( $expected, $minified, "Line breaks must not occur in middle of exponent");
- }
-
function provideBug32548() {
return array(
array(
@@ -145,4 +149,22 @@ class JavaScriptMinifierTest extends MediaWikiTestCase {
),
);
}
+
+ /**
+ * @dataProvider provideBug32548
+ */
+ function testBug32548Exponent( $num ) {
+ // Long line breaking was being incorrectly done between the base and
+ // exponent part of a number, causing a syntax error. The line should
+ // instead break at the start of the number.
+ $prefix = 'var longVarName' . str_repeat( '_', 973 ) . '=';
+ $suffix = ',shortVarName=0;';
+
+ $input = $prefix . $num . $suffix;
+ $expected = $prefix . "\n" . $num . $suffix;
+
+ $minified = JavaScriptMinifier::minify( $input );
+
+ $this->assertEquals( $expected, $minified, "Line breaks must not occur in middle of exponent");
+ }
}
diff --git a/tests/phpunit/includes/media/BitmapMetadataHandlerTest.php b/tests/phpunit/includes/media/BitmapMetadataHandlerTest.php
index f4f52dd8..88f87ef9 100644
--- a/tests/phpunit/includes/media/BitmapMetadataHandlerTest.php
+++ b/tests/phpunit/includes/media/BitmapMetadataHandlerTest.php
@@ -2,7 +2,7 @@
class BitmapMetadataHandlerTest extends MediaWikiTestCase {
public function setUp() {
- $this->filePath = dirname( __FILE__ ) . '/../../data/media/';
+ $this->filePath = __DIR__ . '/../../data/media/';
}
/**
@@ -73,7 +73,8 @@ class BitmapMetadataHandlerTest extends MediaWikiTestCase {
$this->assertEquals( '2020:07:14 01:36:05', $meta['DateTimeDigitized'] );
$this->assertEquals( '1997:03:02 00:01:02', $meta['DateTimeOriginal'] );
}
- /* File has an invalid time (+ one valid but really weird time)
+ /**
+ * File has an invalid time (+ one valid but really weird time)
* that shouldn't be included
*/
public function testIPTCDatesInvalid() {
diff --git a/tests/phpunit/includes/media/ExifRotationTest.php b/tests/phpunit/includes/media/ExifRotationTest.php
index 25149a05..6af52dd1 100644
--- a/tests/phpunit/includes/media/ExifRotationTest.php
+++ b/tests/phpunit/includes/media/ExifRotationTest.php
@@ -5,16 +5,12 @@
*/
class ExifRotationTest extends MediaWikiTestCase {
- /** track directories creations. Content will be deleted. */
- private $createdDirs = array();
-
function setUp() {
parent::setUp();
$this->handler = new BitmapHandler();
- $filePath = dirname( __FILE__ ) . '/../../data/media';
+ $filePath = __DIR__ . '/../../data/media';
- $tmpDir = wfTempDir() . '/exif-test-' . time() . '-' . mt_rand();
- $this->createdDirs[] = $tmpDir;
+ $tmpDir = $this->getNewTempDirectory();
$this->repo = new FSRepo( array(
'name' => 'temp',
@@ -42,17 +38,7 @@ class ExifRotationTest extends MediaWikiTestCase {
$wgShowEXIF = $this->show;
$wgEnableAutoRotation = $this->oldAuto;
- $this->tearDownFiles();
- }
-
- private function tearDownFiles() {
- foreach( $this->createdDirs as $dir ) {
- wfRecursiveRemoveDir( $dir );
- }
- }
-
- function __destruct() {
- $this->tearDownFiles();
+ parent::tearDown();
}
/**
diff --git a/tests/phpunit/includes/media/ExifTest.php b/tests/phpunit/includes/media/ExifTest.php
index b39c15e4..045777d7 100644
--- a/tests/phpunit/includes/media/ExifTest.php
+++ b/tests/phpunit/includes/media/ExifTest.php
@@ -2,22 +2,22 @@
class ExifTest extends MediaWikiTestCase {
public function setUp() {
- $this->mediaPath = dirname( __FILE__ ) . '/../../data/media/';
+ $this->mediaPath = __DIR__ . '/../../data/media/';
if ( !wfDl( 'exif' ) ) {
$this->markTestSkipped( "This test needs the exif extension." );
}
- global $wgShowEXIF;
- $this->showExif = $wgShowEXIF;
- $wgShowEXIF = true;
+ global $wgShowEXIF;
+ $this->showExif = $wgShowEXIF;
+ $wgShowEXIF = true;
}
- public function tearDown() {
- global $wgShowEXIF;
- $wgShowEXIF = $this->showExif;
- }
- public function testGPSExtraction() {
+ public function tearDown() {
+ global $wgShowEXIF;
+ $wgShowEXIF = $this->showExif;
+ }
+ public function testGPSExtraction() {
$filename = $this->mediaPath . 'exif-gps.jpg';
$seg = JpegMetadataExtractor::segmentSplitter( $filename );
$exif = new Exif( $filename, $seg['byteOrder'] );
@@ -25,14 +25,14 @@ class ExifTest extends MediaWikiTestCase {
$expected = array(
'GPSLatitude' => 88.5180555556,
'GPSLongitude' => -21.12357,
- 'GPSAltitude' => -200,
+ 'GPSAltitude' => -3.141592653,
'GPSDOP' => '5/1',
'GPSVersionID' => '2.2.0.0',
);
$this->assertEquals( $expected, $data, '', 0.0000000001 );
}
- public function testUnicodeUserComment() {
+ public function testUnicodeUserComment() {
$filename = $this->mediaPath . 'exif-user-comment.jpg';
$seg = JpegMetadataExtractor::segmentSplitter( $filename );
$exif = new Exif( $filename, $seg['byteOrder'] );
diff --git a/tests/phpunit/includes/media/FormatMetadataTest.php b/tests/phpunit/includes/media/FormatMetadataTest.php
index 8a632f52..6ade6702 100644
--- a/tests/phpunit/includes/media/FormatMetadataTest.php
+++ b/tests/phpunit/includes/media/FormatMetadataTest.php
@@ -4,7 +4,7 @@ class FormatMetadataTest extends MediaWikiTestCase {
if ( !wfDl( 'exif' ) ) {
$this->markTestSkipped( "This test needs the exif extension." );
}
- $filePath = dirname( __FILE__ ) . '/../../data/media';
+ $filePath = __DIR__ . '/../../data/media';
$this->backend = new FSFileBackend( array(
'name' => 'localtesting',
'lockManager' => 'nullLockManager',
diff --git a/tests/phpunit/includes/media/GIFMetadataExtractorTest.php b/tests/phpunit/includes/media/GIFMetadataExtractorTest.php
index 47fc368b..650fdd5c 100644
--- a/tests/phpunit/includes/media/GIFMetadataExtractorTest.php
+++ b/tests/phpunit/includes/media/GIFMetadataExtractorTest.php
@@ -2,7 +2,7 @@
class GIFMetadataExtractorTest extends MediaWikiTestCase {
public function setUp() {
- $this->mediaPath = dirname( __FILE__ ) . '/../../data/media/';
+ $this->mediaPath = __DIR__ . '/../../data/media/';
}
/**
* Put in a file, and see if the metadata coming out is as expected.
diff --git a/tests/phpunit/includes/media/GIFTest.php b/tests/phpunit/includes/media/GIFTest.php
index 36658358..5dcbeee0 100644
--- a/tests/phpunit/includes/media/GIFTest.php
+++ b/tests/phpunit/includes/media/GIFTest.php
@@ -2,7 +2,7 @@
class GIFHandlerTest extends MediaWikiTestCase {
public function setUp() {
- $this->filePath = dirname( __FILE__ ) . '/../../data/media';
+ $this->filePath = __DIR__ . '/../../data/media';
$this->backend = new FSFileBackend( array(
'name' => 'localtesting',
'lockManager' => 'nullLockManager',
diff --git a/tests/phpunit/includes/media/JpegMetadataExtractorTest.php b/tests/phpunit/includes/media/JpegMetadataExtractorTest.php
index f48382a4..41d81190 100644
--- a/tests/phpunit/includes/media/JpegMetadataExtractorTest.php
+++ b/tests/phpunit/includes/media/JpegMetadataExtractorTest.php
@@ -9,7 +9,7 @@
class JpegMetadataExtractorTest extends MediaWikiTestCase {
public function setUp() {
- $this->filePath = dirname( __FILE__ ) . '/../../data/media/';
+ $this->filePath = __DIR__ . '/../../data/media/';
}
/**
diff --git a/tests/phpunit/includes/media/JpegTest.php b/tests/phpunit/includes/media/JpegTest.php
index ddabf5b8..ea007f90 100644
--- a/tests/phpunit/includes/media/JpegTest.php
+++ b/tests/phpunit/includes/media/JpegTest.php
@@ -2,7 +2,7 @@
class JpegTest extends MediaWikiTestCase {
public function setUp() {
- $this->filePath = dirname( __FILE__ ) . '/../../data/media/';
+ $this->filePath = __DIR__ . '/../../data/media/';
if ( !wfDl( 'exif' ) ) {
$this->markTestSkipped( "This test needs the exif extension." );
}
diff --git a/tests/phpunit/includes/media/PNGMetadataExtractorTest.php b/tests/phpunit/includes/media/PNGMetadataExtractorTest.php
index 9f702c50..1b1b2ec3 100644
--- a/tests/phpunit/includes/media/PNGMetadataExtractorTest.php
+++ b/tests/phpunit/includes/media/PNGMetadataExtractorTest.php
@@ -2,7 +2,7 @@
class PNGMetadataExtractorTest extends MediaWikiTestCase {
function setUp() {
- $this->filePath = dirname( __FILE__ ) . '/../../data/media/';
+ $this->filePath = __DIR__ . '/../../data/media/';
}
/**
* Tests zTXt tag (compressed textual metadata)
diff --git a/tests/phpunit/includes/media/PNGTest.php b/tests/phpunit/includes/media/PNGTest.php
index b6f911fd..fe73c9c7 100644
--- a/tests/phpunit/includes/media/PNGTest.php
+++ b/tests/phpunit/includes/media/PNGTest.php
@@ -2,7 +2,7 @@
class PNGHandlerTest extends MediaWikiTestCase {
public function setUp() {
- $this->filePath = dirname( __FILE__ ) . '/../../data/media';
+ $this->filePath = __DIR__ . '/../../data/media';
$this->backend = new FSFileBackend( array(
'name' => 'localtesting',
'lockManager' => 'nullLockManager',
diff --git a/tests/phpunit/includes/media/SVGMetadataExtractorTest.php b/tests/phpunit/includes/media/SVGMetadataExtractorTest.php
index 526beae8..2116554e 100644
--- a/tests/phpunit/includes/media/SVGMetadataExtractorTest.php
+++ b/tests/phpunit/includes/media/SVGMetadataExtractorTest.php
@@ -39,27 +39,33 @@ class SVGMetadataExtractorTest extends MediaWikiTestCase {
}
function providerSvgFiles() {
- $base = dirname( __FILE__ ) . '/../../data/media';
+ $base = __DIR__ . '/../../data/media';
return array(
array(
"$base/Wikimedia-logo.svg",
array(
'width' => 1024,
- 'height' => 1024
+ 'height' => 1024,
+ 'originalWidth' => '1024',
+ 'originalHeight' => '1024',
)
),
array(
"$base/QA_icon.svg",
array(
'width' => 60,
- 'height' => 60
+ 'height' => 60,
+ 'originalWidth' => '60',
+ 'originalHeight' => '60',
)
),
array(
"$base/Gtk-media-play-ltr.svg",
array(
'width' => 60,
- 'height' => 60
+ 'height' => 60,
+ 'originalWidth' => '60.0000000',
+ 'originalHeight' => '60.0000000',
)
),
array(
@@ -67,14 +73,16 @@ class SVGMetadataExtractorTest extends MediaWikiTestCase {
// This file triggered bug 31719, needs entity expansion in the xmlns checks
array(
'width' => 385,
- 'height' => 385
+ 'height' => 385,
+ 'originalWidth' => '385',
+ 'originalHeight' => '385.0004883',
)
)
);
}
function providerSvgFilesWithXMLMetadata() {
- $base = dirname( __FILE__ ) . '/../../data/media';
+ $base = __DIR__ . '/../../data/media';
$metadata =
'
@@ -89,7 +97,9 @@ class SVGMetadataExtractorTest extends MediaWikiTestCase {
array(
'height' => 593,
'metadata' => $metadata,
- 'width' => 959
+ 'width' => 959,
+ 'originalWidth' => '958.69',
+ 'originalHeight' => '592.78998',
)
),
);
diff --git a/tests/phpunit/includes/media/TiffTest.php b/tests/phpunit/includes/media/TiffTest.php
index d4cf503b..4c79f66c 100644
--- a/tests/phpunit/includes/media/TiffTest.php
+++ b/tests/phpunit/includes/media/TiffTest.php
@@ -5,7 +5,7 @@ class TiffTest extends MediaWikiTestCase {
global $wgShowEXIF;
$this->showExif = $wgShowEXIF;
$wgShowEXIF = true;
- $this->filePath = dirname( __FILE__ ) . '/../../data/media/';
+ $this->filePath = __DIR__ . '/../../data/media/';
$this->handler = new TiffHandler;
}
diff --git a/tests/phpunit/includes/media/XMPTest.php b/tests/phpunit/includes/media/XMPTest.php
index c952b23c..8198d3b0 100644
--- a/tests/phpunit/includes/media/XMPTest.php
+++ b/tests/phpunit/includes/media/XMPTest.php
@@ -22,11 +22,11 @@ class XMPTest extends MediaWikiTestCase {
}
$reader = new XMPReader;
$reader->parse( $xmp );
- $this->assertEquals( $expected, $reader->getResults(), $info );
+ $this->assertEquals( $expected, $reader->getResults(), $info, 0.0000000001 );
}
public function dataXMPParse() {
- $xmpPath = dirname( __FILE__ ) . '/../../data/xmp/' ;
+ $xmpPath = __DIR__ . '/../../data/xmp/' ;
$data = array();
// $xmpFiles format: array of arrays with first arg file base name,
@@ -52,6 +52,7 @@ class XMPTest extends MediaWikiTestCase {
array( 'utf32BE', 'UTF-32BE encoding' ),
array( 'utf32LE', 'UTF-32LE encoding' ),
array( 'xmpExt', 'Extended XMP missing second part' ),
+ array( 'gps', 'Handling of exif GPS parameters in XMP' ),
);
foreach( $xmpFiles as $file ) {
$xmp = file_get_contents( $xmpPath . $file[0] . '.xmp' );
@@ -72,7 +73,7 @@ class XMPTest extends MediaWikiTestCase {
* world example file to double check the support for this is right.
*/
function testExtendedXMP() {
- $xmpPath = dirname( __FILE__ ) . '/../../data/xmp/';
+ $xmpPath = __DIR__ . '/../../data/xmp/';
$standardXMP = file_get_contents( $xmpPath . 'xmpExt.xmp' );
$extendedXMP = file_get_contents( $xmpPath . 'xmpExt2.xmp' );
@@ -102,7 +103,7 @@ class XMPTest extends MediaWikiTestCase {
* and thus should only return the StandardXMP, not the ExtendedXMP.
*/
function testExtendedXMPWithWrongGUID() {
- $xmpPath = dirname( __FILE__ ) . '/../../data/xmp/';
+ $xmpPath = __DIR__ . '/../../data/xmp/';
$standardXMP = file_get_contents( $xmpPath . 'xmpExt.xmp' );
$extendedXMP = file_get_contents( $xmpPath . 'xmpExt2.xmp' );
@@ -130,7 +131,7 @@ class XMPTest extends MediaWikiTestCase {
* which should cause it to ignore the ExtendedXMP packet.
*/
function testExtendedXMPMissingPacket() {
- $xmpPath = dirname( __FILE__ ) . '/../../data/xmp/';
+ $xmpPath = __DIR__ . '/../../data/xmp/';
$standardXMP = file_get_contents( $xmpPath . 'xmpExt.xmp' );
$extendedXMP = file_get_contents( $xmpPath . 'xmpExt2.xmp' );
diff --git a/tests/phpunit/includes/mobile/DeviceDetectionTest.php b/tests/phpunit/includes/mobile/DeviceDetectionTest.php
new file mode 100644
index 00000000..0e156532
--- /dev/null
+++ b/tests/phpunit/includes/mobile/DeviceDetectionTest.php
@@ -0,0 +1,40 @@
+assertEquals( $format, $detector->detectFormatName( $userAgent ) );
+ }
+
+ public 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' ),
+ array( 'iphone', 'Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en) AppleWebKit/420.1 (KHTML, like Gecko) Version/3.0 Mobile/3B48b Safari/419.3' ),
+ array( 'nokia', 'Mozilla/5.0 (SymbianOS/9.1; U; [en]; SymbianOS/91 Series60/3.0) AppleWebKit/413 (KHTML, like Gecko) Safari/413' ),
+ array( 'palm_pre', 'Mozilla/5.0 (webOS/1.0; U; en-US) AppleWebKit/525.27.1 (KHTML, like Gecko) Version/1.0 Safari/525.27.1 Pre/1.0' ),
+ array( 'wii', 'Opera/9.00 (Nintendo Wii; U; ; 1309-9; en)' ),
+ array( 'operamini', 'Opera/9.50 (J2ME/MIDP; Opera Mini/4.0.10031/298; U; en)' ),
+ array( 'operamobile', 'Opera/9.51 Beta (Microsoft Windows; PPC; Opera Mobi/1718; U; en)' ),
+ array( 'kindle', 'Mozilla/4.0 (compatible; Linux 2.6.10) NetFront/3.3 Kindle/1.0 (screen 600x800)' ),
+ array( 'kindle2', 'Mozilla/4.0 (compatible; Linux 2.6.22) NetFront/3.4 Kindle/2.0 (screen 824x1200; rotate)' ),
+ array( 'capable', 'Mozilla/5.0 (X11; Linux i686; rv:2.0.1) Gecko/20100101 Firefox/4.0.1' ),
+ array( 'netfront', 'Mozilla/4.08 (Windows; Mobile Content Viewer/1.0) NetFront/3.2' ),
+ array( 'wap2', 'SonyEricssonK608i/R2L/SN356841000828910 Browser/SEMC-Browser/4.2 Profile/MIDP-2.0 Configuration/CLDC-1.1' ),
+ array( 'wap2', 'NokiaN73-2/3.0-630.0.2 Series60/3.0 Profile/MIDP-2.0 Configuration/CLDC-1.1' ),
+ array( 'psp', 'Mozilla/4.0 (PSP (PlayStation Portable); 2.00)' ),
+ array( 'ps3', 'Mozilla/5.0 (PLAYSTATION 3; 1.00)' ),
+ array( 'ie', 'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)' ),
+ array( 'ie', 'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0)' ),
+ array( 'blackberry', 'BlackBerry9300/5.0.0.716 Profile/MIDP-2.1 Configuration/CLDC-1.1 VendorID/133' ),
+ array( 'blackberry-lt5', 'BlackBerry7250/4.0.0 Profile/MIDP-2.0 Configuration/CLDC-1.1' ),
+ );
+ }
+}
diff --git a/tests/phpunit/includes/parser/MediaWikiParserTest.php b/tests/phpunit/includes/parser/MediaWikiParserTest.php
index 816c017a..6a6fded1 100644
--- a/tests/phpunit/includes/parser/MediaWikiParserTest.php
+++ b/tests/phpunit/includes/parser/MediaWikiParserTest.php
@@ -1,5 +1,5 @@
db->selectField( 'image', '1', array( 'img_name' => $image->getName() ) ) ) {
$image->recordUpload2(
'', // archive name
- 'Upload of some lame file',
+ 'Upload of some lame file',
'Some lame file',
array(
'size' => 12345,
@@ -197,7 +197,7 @@ class NewParserTest extends MediaWikiTestCase {
'mime' => 'image/jpeg',
'metadata' => serialize( array() ),
'sha1' => wfBaseConvert( '', 16, 36, 31 ),
- 'fileExists' => true ),
+ 'fileExists' => true ),
$this->db->timestamp( '20010115123500' ), $user
);
}
@@ -207,8 +207,8 @@ class NewParserTest extends MediaWikiTestCase {
if ( !$this->db->selectField( 'image', '1', array( 'img_name' => $image->getName() ) ) ) {
$image->recordUpload2(
'', // archive name
- 'zomgnotcensored',
- 'Borderline image',
+ 'zomgnotcensored',
+ 'Borderline image',
array(
'size' => 12345,
'width' => 320,
@@ -218,7 +218,7 @@ class NewParserTest extends MediaWikiTestCase {
'mime' => 'image/jpeg',
'metadata' => serialize( array() ),
'sha1' => wfBaseConvert( '', 16, 36, 31 ),
- 'fileExists' => true ),
+ 'fileExists' => true ),
$this->db->timestamp( '20010115123500' ), $user
);
}
@@ -326,7 +326,6 @@ class NewParserTest extends MediaWikiTestCase {
'wgExternalLinkTarget' => false,
'wgAlwaysUseTidy' => false,
'wgHtml5' => true,
- 'wgCleanupPresentationalAttributes' => true,
'wgWellFormedXml' => true,
'wgAllowMicrodataAttributes' => true,
'wgAdaptiveMessageCache' => true,
@@ -345,6 +344,9 @@ class NewParserTest extends MediaWikiTestCase {
$this->savedGlobals = array();
+ /** @since 1.20 */
+ wfRunHooks( 'ParserTestGlobals', array( &$settings ) );
+
foreach ( $settings as $var => $val ) {
if ( array_key_exists( $var, $GLOBALS ) ) {
$this->savedGlobals[$var] = $GLOBALS[$var];
@@ -380,7 +382,7 @@ class NewParserTest extends MediaWikiTestCase {
# The entries saved into RepoGroup cache with previous globals will be wrong.
RepoGroup::destroySingleton();
FileBackendGroup::destroySingleton();
- MessageCache::singleton()->destroyInstance();
+ MessageCache::destroyInstance();
return $context;
}
@@ -596,7 +598,7 @@ class NewParserTest extends MediaWikiTestCase {
* Run a fuzz test series
* Draw input from a set of test files
*
- * @todo @fixme Needs some work to not eat memory until the world explodes
+ * @todo fixme Needs some work to not eat memory until the world explodes
*
* @group ParserFuzz
*/
diff --git a/tests/phpunit/includes/parser/ParserMethodsTest.php b/tests/phpunit/includes/parser/ParserMethodsTest.php
new file mode 100644
index 00000000..dea406c3
--- /dev/null
+++ b/tests/phpunit/includes/parser/ParserMethodsTest.php
@@ -0,0 +1,33 @@
+~~~',
+ 'hello \'\'this\'\' is ~~~',
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider dataPreSaveTransform
+ */
+ public function testPreSaveTransform( $text, $expected ) {
+ global $wgParser;
+
+ $title = Title::newFromText( str_replace( '::', '__', __METHOD__ ) );
+ $user = new User();
+ $user->setName( "127.0.0.1" );
+ $popts = ParserOptions::newFromUser( $user );
+ $text = $wgParser->preSaveTransform( $text, $title, $user, $popts );
+
+ $this->assertEquals( $expected, $text );
+ }
+
+ // TODO: Add tests for cleanSig() / cleanSigInSig(), getSection(), replaceSection(), getPreloadText()
+}
+
diff --git a/tests/phpunit/includes/parser/PreprocessorTest.php b/tests/phpunit/includes/parser/PreprocessorTest.php
index 9d3499a0..fee56748 100644
--- a/tests/phpunit/includes/parser/PreprocessorTest.php
+++ b/tests/phpunit/includes/parser/PreprocessorTest.php
@@ -103,7 +103,7 @@ class PreprocessorTest extends MediaWikiTestCase {
array( "{{foo|bar=|}", "{{foo|bar=|}"),
array( "{{Foo|} Bar=", "{{Foo|} Bar="),
array( "{{Foo|} Bar=}}", "Foo} Bar="),
- /* array( file_get_contents( dirname( __FILE__ ) . '/QuoteQuran.txt' ), file_get_contents( dirname( __FILE__ ) . '/QuoteQuranExpanded.txt' ) ), */
+ /* array( file_get_contents( __DIR__ . '/QuoteQuran.txt' ), file_get_contents( __DIR__ . '/QuoteQuranExpanded.txt' ) ), */
);
}
@@ -165,7 +165,7 @@ class PreprocessorTest extends MediaWikiTestCase {
* @dataProvider provideFiles
*/
function testPreprocessorOutputFiles( $filename ) {
- $folder = dirname( __FILE__ ) . "/../../../parser/preprocess";
+ $folder = __DIR__ . "/../../../parser/preprocess";
$wikiText = file_get_contents( "$folder/$filename.txt" );
$output = $this->preprocessToXml( $wikiText );
diff --git a/tests/phpunit/includes/specials/SpecialSearchTest.php b/tests/phpunit/includes/specials/SpecialSearchTest.php
index ea9d5533..20e42a68 100644
--- a/tests/phpunit/includes/specials/SpecialSearchTest.php
+++ b/tests/phpunit/includes/specials/SpecialSearchTest.php
@@ -87,6 +87,14 @@ class SpecialSearchTest extends MediaWikiTestCase {
'advanced', array( 2, 14 ),
'Bug 33583: search with no option should honor User search preferences'
),
+ array(
+ $EMPTY_REQUEST, array_fill_keys( array_map( function( $ns ) {
+ return "searchNs$ns";
+ }, $defaultNS ), 0 ) + array( 'searchNs2' => 1, 'searchNs14' => 1 ),
+ 'advanced', array( 2, 14 ),
+ 'Bug 33583: search with no option should honor User search preferences'
+ . 'and have all other namespace disabled'
+ ),
);
}
diff --git a/tests/phpunit/includes/upload/UploadFromUrlTest.php b/tests/phpunit/includes/upload/UploadFromUrlTest.php
index d56cce31..f66c387b 100644
--- a/tests/phpunit/includes/upload/UploadFromUrlTest.php
+++ b/tests/phpunit/includes/upload/UploadFromUrlTest.php
@@ -20,7 +20,7 @@ class UploadFromUrlTest extends ApiTestCase {
}
}
- protected function doApiRequest( $params, $unused = null, $appendModule = false, $user = null ) {
+ protected function doApiRequest( Array $params, Array $unused = null, $appendModule = false, User $user = null ) {
$sessionId = session_id();
session_write_close();
@@ -228,11 +228,11 @@ class UploadFromUrlTest extends ApiTestCase {
$talk = $this->user->user->getTalkPage();
if ( $talk->exists() ) {
- $a = new Article( $talk );
- $a->doDeleteArticle( '' );
+ $page = WikiPage::factory( $talk );
+ $page->doDeleteArticle( '' );
}
- $this->assertFalse( (bool)$talk->getArticleId( Title::GAID_FOR_UPDATE ), 'User talk does not exist' );
+ $this->assertFalse( (bool)$talk->getArticleID( Title::GAID_FOR_UPDATE ), 'User talk does not exist' );
$data = $this->doApiRequest( array(
'action' => 'upload',
@@ -249,7 +249,7 @@ class UploadFromUrlTest extends ApiTestCase {
$job->run();
$this->assertTrue( wfLocalFile( 'UploadFromUrlTest.png' )->exists() );
- $this->assertTrue( (bool)$talk->getArticleId( Title::GAID_FOR_UPDATE ), 'User talk exists' );
+ $this->assertTrue( (bool)$talk->getArticleID( Title::GAID_FOR_UPDATE ), 'User talk exists' );
$this->deleteFile( 'UploadFromUrlTest.png' );
@@ -341,8 +341,8 @@ class UploadFromUrlTest extends ApiTestCase {
$file = wfFindFile( $name, array( 'ignoreRedirect' => true ) );
$empty = "";
FileDeleteForm::doDelete( $t, $file, $empty, "none", true );
- $a = new Article ( $t );
- $a->doDeleteArticle( "testing" );
+ $page = WikiPage::factory( $t );
+ $page->doDeleteArticle( "testing" );
}
$t = Title::newFromText( $name, NS_FILE );
diff --git a/tests/phpunit/includes/upload/UploadStashTest.php b/tests/phpunit/includes/upload/UploadStashTest.php
index c9dbb138..66fafaaf 100644
--- a/tests/phpunit/includes/upload/UploadStashTest.php
+++ b/tests/phpunit/includes/upload/UploadStashTest.php
@@ -12,17 +12,17 @@ class UploadStashTest extends MediaWikiTestCase {
parent::setUp();
// Setup a file for bug 29408
- $this->bug29408File = dirname( __FILE__ ) . '/bug29408';
+ $this->bug29408File = __DIR__ . '/bug29408';
file_put_contents( $this->bug29408File, "\x00" );
self::$users = array(
- 'sysop' => new ApiTestUser(
+ 'sysop' => new TestUser(
'Uploadstashtestsysop',
'Upload Stash Test Sysop',
'upload_stash_test_sysop@example.com',
array( 'sysop' )
),
- 'uploader' => new ApiTestUser(
+ 'uploader' => new TestUser(
'Uploadstashtestuser',
'Upload Stash Test User',
'upload_stash_test_user@example.com',
diff --git a/tests/phpunit/includes/upload/UploadTest.php b/tests/phpunit/includes/upload/UploadTest.php
index 4293d23b..6948f5b1 100644
--- a/tests/phpunit/includes/upload/UploadTest.php
+++ b/tests/phpunit/includes/upload/UploadTest.php
@@ -12,7 +12,9 @@ class UploadTest extends MediaWikiTestCase {
$this->upload = new UploadTestHandler;
$this->hooks = $wgHooks;
- $wgHooks['InterwikiLoadPrefix'][] = 'MediaWikiTestCase::disableInterwikis';
+ $wgHooks['InterwikiLoadPrefix'][] = function( $prefix, &$data ) {
+ return false;
+ };
}
function tearDown() {
--
cgit v1.2.2