5 of n.
Change-Id: I811ca957b6588085d67606ebc0cd4033a1e53839
function testFileRepoConstructionOptionCanNotBeNull() {
$f = new FileRepo();
}
+
/**
* @expectedException MWException
*/
function testFileRepoConstructionOptionCanNotBeAnEmptyArray() {
$f = new FileRepo( array() );
}
+
/**
* @expectedException MWException
*/
'backend' => 'foobar'
) );
}
+
/**
* @expectedException MWException
*/
function testFileRepoConstructionWithRequiredOptions() {
$f = new FileRepo( array(
- 'name' => 'FileRepoTestRepository',
+ 'name' => 'FileRepoTestRepository',
'backend' => new FSFileBackend( array(
- 'name' => 'local-testing',
- 'lockManager' => 'nullLockManager',
+ 'name' => 'local-testing',
+ 'lockManager' => 'nullLockManager',
'containerPaths' => array()
) )
) );
$backend = new $class( $useConfig );
} else {
$backend = new FSFileBackend( array(
- 'name' => 'local-testing',
+ 'name' => 'local-testing',
'lockManager' => 'nullLockManager',
'containerPaths' => array(
- 'unittests-public' => "{$tmpPrefix}-public",
- 'unittests-thumb' => "{$tmpPrefix}-thumb",
- 'unittests-temp' => "{$tmpPrefix}-temp",
+ 'unittests-public' => "{$tmpPrefix}-public",
+ 'unittests-thumb' => "{$tmpPrefix}-thumb",
+ 'unittests-temp' => "{$tmpPrefix}-temp",
'unittests-deleted' => "{$tmpPrefix}-deleted",
)
) );
}
$this->repo = new FileRepo( array(
- 'name' => 'unittests',
+ 'name' => 'unittests',
'backend' => $backend
) );
* @param $srcPath string The filepath or virtual URL
* @param $flags integer Flags to pass into repo::store().
*/
- private function storeit($originalName, $srcPath, $flags) {
+ private function storeit( $originalName, $srcPath, $flags ) {
$hashPath = $this->repo->getHashPath( $originalName );
$dstRel = "$hashPath{$this->date}!$originalName";
$dstUrlRel = $hashPath . $this->date . '!' . rawurlencode( $originalName );
* @param $otherfn string The name of the different file (in the filesystem)
* @param $fromrepo logical 'true' if we want to copy from a virtual URL out of the Repo.
*/
- private function storecohort($fn, $infn, $otherfn, $fromrepo) {
+ private function storecohort( $fn, $infn, $otherfn, $fromrepo ) {
$f = $this->storeit( $fn, $infn, 0 );
$this->assertTrue( $f->isOK(), 'failed to store a new file' );
$this->assertEquals( $f->failCount, 0, "counts wrong {$f->successCount} {$f->failCount}" );
$this->assertEquals( $f->successCount, 1, "counts wrong {$f->successCount} {$f->failCount}" );
if ( $fromrepo ) {
- $f = $this->storeit( "Other-$fn", $infn, FileRepo::OVERWRITE);
+ $f = $this->storeit( "Other-$fn", $infn, FileRepo::OVERWRITE );
$infn = $f->value;
}
// This should work because we're allowed to overwrite
$this->assertEquals( $f->successCount, 1, "counts wrong {$f->successCount} {$f->failCount}" );
// This should fail because we're overwriting different content.
if ( $fromrepo ) {
- $f = $this->storeit( "Other-$fn", $otherfn, FileRepo::OVERWRITE);
+ $f = $this->storeit( "Other-$fn", $otherfn, FileRepo::OVERWRITE );
$otherfn = $f->value;
}
$f = $this->storeit( $fn, $otherfn, FileRepo::OVERWRITE_SAME );
# Format: (expected string, unformattedText string, optional message)
return array(
# Escape some wikitext
- array( 'Install <tag>' , 'Install <tag>', 'Escaping <' ),
- array( 'Install {{template}}' , 'Install {{template}}', 'Escaping [[' ),
- array( 'Install [[page]]' , 'Install [[page]]', 'Escaping {{' ),
- array( 'Install ' , "Install \r", 'Removing \r' ),
+ array( 'Install <tag>', 'Install <tag>', 'Escaping <' ),
+ array( 'Install {{template}}', 'Install {{template}}', 'Escaping [[' ),
+ array( 'Install [[page]]', 'Install [[page]]', 'Escaping {{' ),
+ array( 'Install ', "Install \r", 'Removing \r' ),
# Transform \t{1,2} into :{1,2}
array( ':One indentation', "\tOne indentation", 'Replacing a single \t' ),
array( '::Two indentations', "\t\tTwo indentations", 'Replacing 2 x \t' ),
# Transform 'bug 123' links
- array(
+ array(
'<span class="config-plainlink">[https://bugzilla.wikimedia.org/123 bug 123]</span>',
'bug 123', 'Testing bug 123 links' ),
array(
array(
'<span class="config-plainlink">[http://www.mediawiki.org/wiki/Manual:$wgFoo_Bar $wgFoo_Bar]</span>',
'$wgFoo_Bar', 'Testing $wgFoo_Bar (with underscore)' ),
-
+
# Icky variables that shouldn't link
array( '$myAwesomeVariable', '$myAwesomeVariable', 'Testing $myAwesomeVariable (not starting with $wg)' ),
array( '$()not!a&Var', '$()not!a&Var', 'Testing $()not!a&Var (obviously not a variable)' ),
foreach ( array( 'queueRand', 'queueRandTTL', 'queueFifo', 'queueFifoTTL' ) as $q ) {
do {
$job = $this->$q->pop();
- if ( $job ) $this->$q->ack( $job );
+ if ( $job ) {
+ $this->$q->ack( $job );
+ }
} while ( $job );
}
$this->queueRand = null;
$this->assertEquals( 0, $queue->getAcquiredCount(), "Queue is empty ($desc)" );
$this->assertTrue( $queue->batchPush(
- array( $this->newDedupedJob(), $this->newDedupedJob(), $this->newDedupedJob() ) ),
+ array( $this->newDedupedJob(), $this->newDedupedJob(), $this->newDedupedJob() ) ),
"Push worked ($desc)" );
$this->assertFalse( $queue->isEmpty(), "Queue is not empty ($desc)" );
$this->assertEquals( 0, $queue->getAcquiredCount(), "No jobs active ($desc)" );
$this->assertTrue( $queue->batchPush(
- array( $this->newDedupedJob(), $this->newDedupedJob(), $this->newDedupedJob() ) ),
+ array( $this->newDedupedJob(), $this->newDedupedJob(), $this->newDedupedJob() ) ),
"Push worked ($desc)" );
$this->assertFalse( $queue->isEmpty(), "Queue is not empty ($desc)" );
$id = wfRandomString( 32 );
$root1 = Job::newRootJobParams( "nulljobspam:$id" ); // task ID/timestamp
- for ( $i=0; $i<5; ++$i ) {
+ for ( $i = 0; $i < 5; ++$i ) {
$this->assertTrue( $queue->push( $this->newJob( 0, $root1 ) ), "Push worked ($desc)" );
}
$queue->deduplicateRootJob( $this->newJob( 0, $root1 ) );
$root2 = Job::newRootJobParams( "nulljobspam:$id" ); // task ID/timestamp
$this->assertNotEquals( $root1['rootJobTimestamp'], $root2['rootJobTimestamp'],
"Root job signatures have different timestamps." );
- for ( $i=0; $i<5; ++$i ) {
+ for ( $i = 0; $i < 5; ++$i ) {
$this->assertTrue( $queue->push( $this->newJob( 0, $root2 ) ), "Push worked ($desc)" );
}
$queue->deduplicateRootJob( $this->newJob( 0, $root2 ) );
$jobs[] = $job;
$queue->ack( $job );
}
- if ( $job instanceof DuplicateJob ) ++$dupcount;
+ if ( $job instanceof DuplicateJob ) {
+ ++$dupcount;
+ }
} while ( $job );
$this->assertEquals( 10, count( $jobs ), "Correct number of jobs popped ($desc)" );
$this->assertEquals( 0, $queue->getSize(), "Queue is empty ($desc)" );
$this->assertEquals( 0, $queue->getAcquiredCount(), "Queue is empty ($desc)" );
- for ( $i=0; $i<10; ++$i ) {
+ for ( $i = 0; $i < 10; ++$i ) {
$this->assertTrue( $queue->push( $this->newJob( $i ) ), "Push worked ($desc)" );
}
- for ( $i=0; $i<10; ++$i ) {
+ for ( $i = 0; $i < 10; ++$i ) {
$job = $queue->pop();
$this->assertTrue( $job instanceof Job, "Jobs popped from queue ($desc)" );
$params = $job->getParams();
if ( !function_exists( 'json_encode' ) ) {
$this->markTestIncomplete( 'No PHP json support, unable to test' );
return;
- } elseif( strtolower( json_encode( "\xf0\xa0\x80\x80" ) ) != '"\ud840\udc00"' ) {
+ } elseif ( strtolower( json_encode( "\xf0\xa0\x80\x80" ) ) != '"\ud840\udc00"' ) {
$this->markTestIncomplete( 'Have buggy PHP json support, unable to test' );
return;
} else {
$transformedB = CSSJanus::transform( $cssB );
$this->assertEquals( $transformedB, $cssA, 'Test B-A transformation' );
-
- // If no B version is provided, it means
- // the output should equal the input.
} else {
+ // If no B version is provided, it means
+ // the output should equal the input.
$transformedA = CSSJanus::transform( $cssA );
$this->assertEquals( $transformedA, $cssA, 'Nothing was flipped' );
}
$flipped = CSSJanus::transform( $code, $swapLtrRtlInURL, $swapLeftRightInURL );
$this->assertEquals( $expectedOutput, $flipped,
- 'Test flipping, options: url-ltr-rtl=' . ($swapLtrRtlInURL ? 'true' : 'false')
- . ' url-left-right=' . ($swapLeftRightInURL ? 'true' : 'false')
+ 'Test flipping, options: url-ltr-rtl=' . ( $swapLtrRtlInURL ? 'true' : 'false' )
+ . ' url-left-right=' . ( $swapLeftRightInURL ? 'true' : 'false' )
);
}
+
/**
* @dataProvider provideTransformBrokenCases
* @group Broken
public function testUnset( GenericArrayObject $list ) {
if ( $list->isEmpty() ) {
$this->assertTrue( true ); // We cannot test unset if there are no elements
- }
- else {
+ } else {
$offset = $list->getIterator()->key();
$count = $list->count();
$list->offsetUnset( $offset );
$this->assertEquals( $listSize, $list->count() );
- $this->checkTypeChecks( function( GenericArrayObject $list, $element ) {
+ $this->checkTypeChecks( function ( GenericArrayObject $list, $element ) {
$list->append( $element );
} );
}
foreach ( array( 42, 'foo', array(), new stdClass(), 4.2 ) as $element ) {
$validValid = $element instanceof $elementClass;
- try{
+ try {
call_user_func( $function, $list, $element );
$valid = true;
- }
- catch ( InvalidArgumentException $exception ) {
+ } catch ( InvalidArgumentException $exception ) {
$valid = false;
}
$this->assertEquals( count( $elements ), $list->count() );
- $this->checkTypeChecks( function( GenericArrayObject $list, $element ) {
+ $this->checkTypeChecks( function ( GenericArrayObject $list, $element ) {
$list->offsetSet( mt_rand(), $element );
} );
}
*/
class IEUrlExtensionTest extends MediaWikiTestCase {
function testSimple() {
- $this->assertEquals(
+ $this->assertEquals(
'y',
IEUrlExtension::findIE6Extension( 'x.y' ),
'Simple extension'
* 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 */", ""),
+ array( "/**\n * Foo\n * {\n * 'bar' : {\n * //Multiple rules with configurable operators\n * 'baz' : false\n * }\n */", "" ),
/**
* ' Foo \' bar \
array( "switch(x){case y?z:{}/ x/g:{}/ x/g;}", "switch(x){case y?z:{}/x/g:{}/ x/g;}" ),
array( "function x(){}/ x/g", "function x(){}/ x/g" ),
array( "+function x(){}/ x/g", "+function x(){}/x/g" ),
-
+
// Multiline quoted string
array( "var foo=\"\\\nblah\\\n\";", "var foo=\"\\\nblah\\\n\";" ),
// Division vs. regex nastiness
array( "alert( (10+10) / '/'.charCodeAt( 0 ) + '//' );", "alert((10+10)/'/'.charCodeAt(0)+'//');" ),
array( "if(1)/a /g.exec('Pa ss');", "if(1)/a /g.exec('Pa ss');" ),
-
+
// newline insertion after 1000 chars: break after the "++", not before
array( str_repeat( ';', 996 ) . "if(x++);", str_repeat( ';', 996 ) . "if(x++\n);" ),
// Unicode letter characters should pass through ok in identifiers (bug 31187)
- array( "var KaŝSkatolVal = {}", 'var KaŝSkatolVal={}'),
+ array( "var KaŝSkatolVal = {}", 'var KaŝSkatolVal={}' ),
// Per spec unicode char escape values should work in identifiers,
// as long as it's a valid char. In future it might get normalized.
- array( "var Ka\\u015dSkatolVal = {}", 'var Ka\\u015dSkatolVal={}'),
+ array( "var Ka\\u015dSkatolVal = {}", 'var Ka\\u015dSkatolVal={}' ),
// Some structures that might look invalid at first sight
array( "var a = 5.;", "var a=5.;" ),
array(
// This one gets interpreted all together by the prior code;
// no break at the 'E' happens.
- '1.23456789E55',
+ '1.23456789E55',
),
array(
// This one breaks under the bad code; splits between 'E' and '+'
$minified = JavaScriptMinifier::minify( $input );
- $this->assertEquals( $expected, $minified, "Line breaks must not occur in middle of exponent");
+ $this->assertEquals( $expected, $minified, "Line breaks must not occur in middle of exponent" );
}
}
'wgLogActionsHandlers' => array( 'phpunit/test' => 'LogFormatter',
'phpunit/param' => 'LogFormatter' ),
'wgUser' => User::newFromName( 'Testuser' ),
- 'wgExtensionMessagesFiles' => array( 'LogTests' => __DIR__.'/LogTests.i18n.php' ),
+ 'wgExtensionMessagesFiles' => array( 'LogTests' => __DIR__ . '/LogTests.i18n.php' ),
) );
$wgLang->getLocalisationCache()->recache( $wgLang->getCode() );
$messages = array();
$messages['en'] = array(
- 'log-name-phpunit' => 'PHPUnit-log',
+ 'log-name-phpunit' => 'PHPUnit-log',
'log-description-phpunit' => 'Log for PHPUnit-tests',
- 'logentry-phpunit-test' => '$1 {{GENDER:$2|tests}} with page $3',
- 'logentry-phpunit-param' => '$4',
+ 'logentry-phpunit-test' => '$1 {{GENDER:$2|tests}} with page $3',
+ 'logentry-phpunit-param' => '$4',
);
$expected = array(
'x-default' => 'right(iptc)',
- 'en' => 'right translation',
- '_type' => 'lang'
+ 'en' => 'right translation',
+ '_type' => 'lang'
);
-
+
$this->assertArrayHasKey( 'ImageDescription', $meta,
'Did not extract any ImageDescription info?!' );
}
$handler = new BitmapMetadataHandler();
$result = $handler->png( $this->filePath . 'xmp.png' );
- $expected = array (
+ $expected = array(
'frameCount' => 0,
'loopCount' => 1,
'duration' => 0,
'bitDepth' => 1,
'colorType' => 'index-coloured',
- 'metadata' => array (
+ 'metadata' => array(
'SerialNumber' => '123456789',
'_MW_PNG_VERSION' => 1,
),
);
- $this->assertEquals( $expected, $result );
+ $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'] );
+ $this->assertEquals( $expected, $result['metadata']['Identifier']['x-default'] );
}
public function testTiffByteOrder() {
$this->assertTrue( $valid );
$this->assertEquals( $expectedParams, $params, $msg );
}
-
+
function provideNormaliseParams() {
return array(
- /* Regular resize operations */
+ /* Regular resize operations */
array(
array( 1024, 768 ),
- array(
- 'width' => 512, 'height' => 384,
+ array(
+ 'width' => 512, 'height' => 384,
'physicalWidth' => 512, 'physicalHeight' => 384,
'page' => 1,
),
),
array(
array( 1024, 768 ),
- array(
- 'width' => 512, 'height' => 384,
+ array(
+ 'width' => 512, 'height' => 384,
'physicalWidth' => 512, 'physicalHeight' => 384,
- 'page' => 1,
+ 'page' => 1,
),
array( 'width' => 512, 'height' => 768 ),
'Resizing with height set too high',
),
array(
array( 1024, 768 ),
- array(
- 'width' => 512, 'height' => 384,
+ array(
+ 'width' => 512, 'height' => 384,
'physicalWidth' => 512, 'physicalHeight' => 384,
- 'page' => 1,
+ 'page' => 1,
),
array( 'width' => 1024, 'height' => 384 ),
'Resizing with height set',
),
-
+
/* Very tall images */
array(
array( 1000, 100 ),
- array(
+ array(
'width' => 5, 'height' => 1,
'physicalWidth' => 5, 'physicalHeight' => 1,
- 'page' => 1,
+ 'page' => 1,
),
array( 'width' => 5 ),
'Very wide image',
),
-
+
array(
array( 100, 1000 ),
- array(
+ array(
'width' => 1, 'height' => 10,
'physicalWidth' => 1, 'physicalHeight' => 10,
- 'page' => 1,
+ 'page' => 1,
),
array( 'width' => 1 ),
'Very high image',
),
array(
array( 100, 1000 ),
- array(
+ array(
'width' => 1, 'height' => 5,
'physicalWidth' => 1, 'physicalHeight' => 10,
- 'page' => 1,
+ 'page' => 1,
),
array( 'width' => 10, 'height' => 5 ),
'Very high image with height set',
/* Max image area */
array(
array( 4000, 4000 ),
- array(
+ array(
'width' => 5000, 'height' => 5000,
'physicalWidth' => 4000, 'physicalHeight' => 4000,
- 'page' => 1,
+ 'page' => 1,
),
array( 'width' => 5000 ),
'Bigger than max image size but doesn\'t need scaling',
$file = new FakeDimensionFile( array( 4000, 4000 ) );
$handler = new BitmapHandler;
$params = array( 'width' => '3700' ); // Still bigger than max size.
- $this->assertEquals( 'TransformParameterError',
+ $this->assertEquals( 'TransformParameterError',
get_class( $handler->doTransform( $file, 'dummy path', '', $params ) ) );
}
$file->mustRender = true;
$handler = new BitmapHandler;
$params = array( 'width' => '5000' ); // Still bigger than max size.
- $this->assertEquals( 'TransformParameterError',
+ $this->assertEquals( 'TransformParameterError',
get_class( $handler->doTransform( $file, 'dummy path', '', $params ) ) );
}
-
+
function testImageArea() {
$file = new FakeDimensionFile( array( 7, 9 ) );
$handler = new BitmapHandler;
public $mustRender = false;
public function __construct( $dimensions ) {
- parent::__construct( Title::makeTitle( NS_FILE, 'Test' ),
+ parent::__construct( Title::makeTitle( NS_FILE, 'Test' ),
new NullRepo( null ) );
-
+
$this->dimensions = $dimensions;
}
+
public function getWidth( $page = 1 ) {
return $this->dimensions[0];
}
+
public function getHeight( $page = 1 ) {
return $this->dimensions[1];
}
+
public function mustRender() {
return $this->mustRender;
}
+
public function getPath() {
return '';
}
function testConvertMetadataLatest() {
$metadata = array(
- 'foo' => array( 'First', 'Second', '_type' => 'ol' ),
- 'MEDIAWIKI_EXIF_VERSION' => 2
- );
+ 'foo' => array( 'First', 'Second', '_type' => 'ol' ),
+ 'MEDIAWIKI_EXIF_VERSION' => 2
+ );
$res = $this->handler->convertMetadataVersion( $metadata, 2 );
$this->assertEquals( $metadata, $res );
}
function testConvertMetadataSoftware() {
$metadata = array(
- 'Software' => array( array('GIMP', '1.1' ) ),
+ 'Software' => array( array( 'GIMP', '1.1' ) ),
'MEDIAWIKI_EXIF_VERSION' => 2,
);
$expected = array(
$tmpDir = $this->getNewTempDirectory();
$this->repo = new FSRepo( array(
- 'name' => 'temp',
- 'url' => 'http://localhost/thumbtest',
- 'backend' => new FSFileBackend( array(
- 'name' => 'localtesting',
- 'lockManager' => 'nullLockManager',
+ 'name' => 'temp',
+ 'url' => 'http://localhost/thumbtest',
+ 'backend' => new FSFileBackend( array(
+ 'name' => 'localtesting',
+ 'lockManager' => 'nullLockManager',
'containerPaths' => array( 'temp-thumb' => $tmpDir, 'data' => $filePath )
) )
) );
if ( !BitmapHandler::canRotate() ) {
$this->markTestSkipped( "This test needs a rasterizer that can auto-rotate." );
}
- foreach( $thumbs as $size => $out ) {
- if( preg_match('/^(\d+)px$/', $size, $matches ) ) {
+ foreach ( $thumbs as $size => $out ) {
+ if ( preg_match( '/^(\d+)px$/', $size, $matches ) ) {
$params = array(
'width' => $matches[1],
);
'height' => $matches[2]
);
} else {
- throw new MWException('bogus test data format ' . $size);
+ throw new MWException( 'bogus test data format ' . $size );
}
$file = $this->dataFile( $name, $type );
$this->assertEquals( $out[1], $thumb->getHeight(), "$name: thumb reported height check for $size" );
$gis = getimagesize( $thumb->getLocalCopyPath() );
- if ($out[0] > $info['width']) {
+ if ( $out[0] > $info['width'] ) {
// Physical image won't be scaled bigger than the original.
- $this->assertEquals( $info['width'], $gis[0], "$name: thumb actual width check for $size");
- $this->assertEquals( $info['height'], $gis[1], "$name: thumb actual height check for $size");
+ $this->assertEquals( $info['width'], $gis[0], "$name: thumb actual width check for $size" );
+ $this->assertEquals( $info['height'], $gis[1], "$name: thumb actual height check for $size" );
} else {
- $this->assertEquals( $out[0], $gis[0], "$name: thumb actual width check for $size");
- $this->assertEquals( $out[1], $gis[1], "$name: thumb actual height check for $size");
+ $this->assertEquals( $out[0], $gis[0], "$name: thumb actual width check for $size" );
+ $this->assertEquals( $out[1], $gis[1], "$name: thumb actual height check for $size" );
}
}
}
global $wgEnableAutoRotation;
$wgEnableAutoRotation = false;
- foreach( $thumbs as $size => $out ) {
- if( preg_match('/^(\d+)px$/', $size, $matches ) ) {
+ foreach ( $thumbs as $size => $out ) {
+ if ( preg_match( '/^(\d+)px$/', $size, $matches ) ) {
$params = array(
'width' => $matches[1],
);
'height' => $matches[2]
);
} else {
- throw new MWException('bogus test data format ' . $size);
+ throw new MWException( 'bogus test data format ' . $size );
}
$file = $this->dataFile( $name, $type );
$this->assertEquals( $out[1], $thumb->getHeight(), "$name: thumb reported height check for $size" );
$gis = getimagesize( $thumb->getLocalCopyPath() );
- if ($out[0] > $info['width']) {
+ if ( $out[0] > $info['width'] ) {
// Physical image won't be scaled bigger than the original.
- $this->assertEquals( $info['width'], $gis[0], "$name: thumb actual width check for $size");
- $this->assertEquals( $info['height'], $gis[1], "$name: thumb actual height check for $size");
+ $this->assertEquals( $info['width'], $gis[0], "$name: thumb actual width check for $size" );
+ $this->assertEquals( $info['height'], $gis[1], "$name: thumb actual height check for $size" );
} else {
- $this->assertEquals( $out[0], $gis[0], "$name: thumb actual width check for $size");
- $this->assertEquals( $out[1], $gis[1], "$name: thumb actual height check for $size");
+ $this->assertEquals( $out[0], $gis[0], "$name: thumb actual width check for $size" );
+ $this->assertEquals( $out[1], $gis[1], "$name: thumb actual height check for $size" );
}
}
$wgEnableAutoRotation = true;
*/
function testBitmapExtractPreRotationDimensions( $rotation, $expected ) {
$result = $this->handler->extractPreRotationDimensions( array(
- 'physicalWidth' => self::TEST_WIDTH,
- 'physicalHeight' => self::TEST_HEIGHT,
- ), $rotation );
+ 'physicalWidth' => self::TEST_WIDTH,
+ 'physicalHeight' => self::TEST_HEIGHT,
+ ), $rotation );
$this->assertEquals( $expected, $result );
}
public function testGPSExtraction() {
$filename = $this->mediaPath . 'exif-gps.jpg';
- $seg = JpegMetadataExtractor::segmentSplitter( $filename );
+ $seg = JpegMetadataExtractor::segmentSplitter( $filename );
$exif = new Exif( $filename, $seg['byteOrder'] );
$data = $exif->getFilteredData();
$expected = array(
public function testUnicodeUserComment() {
$filename = $this->mediaPath . 'exif-user-comment.jpg';
- $seg = JpegMetadataExtractor::segmentSplitter( $filename );
+ $seg = JpegMetadataExtractor::segmentSplitter( $filename );
$exif = new Exif( $filename, $seg['byteOrder'] );
$data = $exif->getFilteredData();
if ( !wfDl( 'exif' ) ) {
$this->markTestSkipped( "This test needs the exif extension." );
}
- $filePath = __DIR__ . '/../../data/media';
+ $filePath = __DIR__ . '/../../data/media';
$this->backend = new FSFileBackend( array(
- 'name' => 'localtesting',
- 'lockManager' => 'nullLockManager',
+ 'name' => 'localtesting',
+ 'lockManager' => 'nullLockManager',
'containerPaths' => array( 'data' => $filePath )
) );
$this->repo = new FSRepo( array(
- 'name' => 'temp',
- 'url' => 'http://localhost/thumbtest',
+ 'name' => 'temp',
+ 'url' => 'http://localhost/thumbtest',
'backend' => $this->backend
) );
public function testInvalidDate() {
$file = $this->dataFile( 'broken_exif_date.jpg', 'image/jpeg' );
-
+
// Throws an error if bug hit
$meta = $file->formatMetadata();
$this->assertNotEquals( false, $meta, 'Valid metadata extracted' );
-
+
// Find date exif entry
$this->assertArrayHasKey( 'visible', $meta );
$dateIndex = null;
}
}
$this->assertNotNull( $dateIndex, 'Date entry exists in metadata' );
- $this->assertEquals( '0000:01:00 00:02:27',
+ $this->assertEquals( '0000:01:00 00:02:27',
$meta['visible'][$dateIndex]['value'],
'File with invalid date metadata (bug 29471)' );
}
$this->mediaPath = __DIR__ . '/../../data/media/';
}
+
/**
* Put in a file, and see if the metadata coming out is as expected.
* @param $filename String
$actual = GIFMetadataExtractor::getMetadata( $this->mediaPath . $filename );
$this->assertEquals( $expected, $actual );
}
+
public static function provideGetMetadata() {
$xmpNugget = <<<EOF
$xmpNugget = str_replace( "\r", '', $xmpNugget ); // Windows compat
return array(
- array( 'nonanimated.gif', array(
- 'comment' => array( 'GIF test file ⁕ Created with GIMP' ),
- 'duration' => 0.1,
- 'frameCount' => 1,
- 'looped' => false,
- 'xmp' => '',
+ array(
+ 'nonanimated.gif',
+ array(
+ 'comment' => array( 'GIF test file ⁕ Created with GIMP' ),
+ 'duration' => 0.1,
+ 'frameCount' => 1,
+ 'looped' => false,
+ 'xmp' => '',
)
),
- array( 'animated.gif', array(
- 'comment' => array( 'GIF test file . Created with GIMP' ),
- 'duration' => 2.4,
- 'frameCount' => 4,
- 'looped' => true,
- 'xmp' => '',
+ array(
+ 'animated.gif',
+ array(
+ 'comment' => array( 'GIF test file . Created with GIMP' ),
+ 'duration' => 2.4,
+ 'frameCount' => 4,
+ 'looped' => true,
+ 'xmp' => '',
)
),
- array( 'animated-xmp.gif', array(
- 'xmp' => $xmpNugget,
- 'duration' => 2.4,
- 'frameCount' => 4,
- 'looped' => true,
- 'comment' => array( 'GIƒ·test·file' ),
+ array(
+ 'animated-xmp.gif',
+ array(
+ 'xmp' => $xmpNugget,
+ 'duration' => 2.4,
+ 'frameCount' => 4,
+ 'looped' => true,
+ 'comment' => array( 'GIƒ·test·file' ),
)
),
);
protected function setUp() {
parent::setUp();
- $this->filePath = __DIR__ . '/../../data/media';
+ $this->filePath = __DIR__ . '/../../data/media';
$this->backend = new FSFileBackend( array(
- 'name' => 'localtesting',
- 'lockManager' => 'nullLockManager',
+ 'name' => 'localtesting',
+ 'lockManager' => 'nullLockManager',
'containerPaths' => array( 'data' => $this->filePath )
) );
$this->repo = new FSRepo( array(
- 'name' => 'temp',
- 'url' => 'http://localhost/thumbtest',
+ 'name' => 'temp',
+ 'url' => 'http://localhost/thumbtest',
'backend' => $this->backend
) );
$this->handler = new GIFHandler();
$actual = $this->handler->isAnimatedImage( $file );
$this->assertEquals( $expected, $actual );
}
+
public static function provideIsAnimated() {
return array(
array( 'animated.gif', true ),
$actual = $this->handler->getImageArea( $file, $file->getWidth(), $file->getHeight() );
$this->assertEquals( $expected, $actual );
}
+
public static function provideGetImageArea() {
return array(
array( 'animated.gif', 5400 ),
$actual = $this->handler->isMetadataValid( null, $metadata );
$this->assertEquals( $expected, $actual );
}
+
public static function provideIsMetadataValid() {
return array(
array( GIFHandler::BROKEN_FILE, GIFHandler::METADATA_GOOD ),
$res = IPTC::Parse( $iptcData );
$this->assertEquals( array( '¼' ), $res['Keywords'] );
}
+
/* This one contains a sequence that's valid iso 8859-1 but not valid utf8 */
/* \xC3 = Ã, \xB8 = ¸ */
public function testIPTCParseNoCharset88591b() {
$res = IPTC::Parse( $iptcData );
$this->assertEquals( array( 'ÃÃø' ), $res['Keywords'] );
}
+
/* Same as testIPTCParseNoCharset88591b, but forcing the charset to utf-8.
* What should happen is the first "\xC3\xC3" should be dropped as invalid,
* leaving \xC3\xB8, which is ø
$res = IPTC::Parse( $iptcData );
$this->assertEquals( array( 'ø' ), $res['Keywords'] );
}
+
public function testIPTCParseNoCharsetUTF8() {
$iptcData = "Photoshop 3.0\08BIM\4\4\0\0\0\0\0\x07\x1c\x02\x19\x00\x02¼";
$res = IPTC::Parse( $iptcData );
$this->assertEquals( array( '¼' ), $res['Keywords'] );
}
+
// Testing something that has 2 values for keyword
public function testIPTCParseMulti() {
$iptcData = /* identifier */ "Photoshop 3.0\08BIM\4\4"
$res = IPTC::Parse( $iptcData );
$this->assertEquals( array( '¼', '¼½' ), $res['Keywords'] );
}
+
public function testIPTCParseUTF8() {
// This has the magic "\x1c\x01\x5A\x00\x03\x1B\x25\x47" which marks content as UTF8.
$iptcData = "Photoshop 3.0\08BIM\4\4\0\0\0\0\0\x0F\x1c\x02\x19\x00\x02¼\x1c\x01\x5A\x00\x03\x1B\x25\x47";
$res = JpegMetadataExtractor::segmentSplitter( $this->filePath . $file );
$this->assertEquals( array( 'UTF-8 JPEG Comment — ¼' ), $res['COM'] );
}
+
public static function provideUtf8Comment() {
return array(
array( 'jpeg-comment-utf.jpg' ),
array( 'jpeg-padding-odd.jpg' ),
);
}
+
/** The file is iso-8859-1, but it should get auto converted */
public function testIso88591Comment() {
$res = JpegMetadataExtractor::segmentSplitter( $this->filePath . 'jpeg-comment-iso8859-1.jpg' );
$this->assertEquals( array( 'ISO-8859-1 JPEG Comment - ¼' ), $res['COM'] );
}
+
/** Comment values that are non-textual (random binary junk) should not be shown.
* The example test file has a comment with a 0x5 byte in it which is a control character
* and considered binary junk for our purposes.
$res = JpegMetadataExtractor::segmentSplitter( $this->filePath . 'jpeg-comment-binary.jpg' );
$this->assertEmpty( $res['COM'] );
}
+
/* Very rarely a file can have multiple comments.
* Order of comments is based on order inside the file.
*/
$res = JpegMetadataExtractor::segmentSplitter( $this->filePath . 'jpeg-comment-multiple.jpg' );
$this->assertEquals( array( 'foo', 'bar' ), $res['COM'] );
}
+
public function testXMPExtraction() {
$res = JpegMetadataExtractor::segmentSplitter( $this->filePath . 'jpeg-xmp-psir.jpg' );
$expected = file_get_contents( $this->filePath . 'jpeg-xmp-psir.xmp' );
$this->assertEquals( $expected, $res['XMP'] );
}
+
public function testPSIRExtraction() {
$res = JpegMetadataExtractor::segmentSplitter( $this->filePath . 'jpeg-xmp-psir.jpg' );
$expected = '50686f746f73686f7020332e30003842494d04040000000000181c02190004746573741c02190003666f6f1c020000020004';
$this->assertEquals( $expected, bin2hex( $res['PSIR'][0] ) );
}
+
public function testXMPExtractionAltAppId() {
$res = JpegMetadataExtractor::segmentSplitter( $this->filePath . 'jpeg-xmp-alt.jpg' );
$expected = file_get_contents( $this->filePath . 'jpeg-xmp-psir.xmp' );
$this->assertEquals( 'iptc-no-hash', $res );
}
+
public function testIPTCHashComparisionBadHash() {
$segments = JpegMetadataExtractor::segmentSplitter( $this->filePath . 'jpeg-iptc-bad-hash.jpg' );
$res = JpegMetadataExtractor::doPSIR( $segments['PSIR'][0] );
$this->assertEquals( 'iptc-bad-hash', $res );
}
+
public function testIPTCHashComparisionGoodHash() {
$segments = JpegMetadataExtractor::segmentSplitter( $this->filePath . 'jpeg-iptc-good-hash.jpg' );
$res = JpegMetadataExtractor::doPSIR( $segments['PSIR'][0] );
$this->assertEquals( 'iptc-good-hash', $res );
}
+
public function testExifByteOrder() {
$res = JpegMetadataExtractor::segmentSplitter( $this->filePath . 'exif-user-comment.jpg' );
$expected = 'BE';
parent::setUp();
$this->filePath = __DIR__ . '/../../data/media/';
}
+
/**
- * Tests zTXt tag (compressed textual metadata)
+ * Tests zTXt tag (compressed textual metadata)
*/
function testPngNativetZtxt() {
$this->checkPHPExtension( 'zlib' );
* 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.
$this->assertEquals( 8, $meta['bitDepth'] );
}
+
function testPngBitDepth1() {
$meta = PNGMetadataExtractor::getMetadata( $this->filePath .
'1bit-png.png' );
$this->assertEquals( 'index-coloured', $meta['colorType'] );
}
+
function testPngRgbColour() {
$meta = PNGMetadataExtractor::getMetadata( $this->filePath .
'rgb-png.png' );
$this->assertEquals( 'truecolour-alpha', $meta['colorType'] );
}
+
function testPngRgbNoAlphaColour() {
$meta = PNGMetadataExtractor::getMetadata( $this->filePath .
'rgb-na-png.png' );
$this->assertEquals( 'truecolour', $meta['colorType'] );
}
+
function testPngGreyscaleColour() {
$meta = PNGMetadataExtractor::getMetadata( $this->filePath .
'greyscale-png.png' );
$this->assertEquals( 'greyscale-alpha', $meta['colorType'] );
}
+
function testPngGreyscaleNoAlphaColour() {
$meta = PNGMetadataExtractor::getMetadata( $this->filePath .
'greyscale-na-png.png' );
protected function setUp() {
parent::setUp();
- $this->filePath = __DIR__ . '/../../data/media';
+ $this->filePath = __DIR__ . '/../../data/media';
$this->backend = new FSFileBackend( array(
- 'name' => 'localtesting',
- 'lockManager' => 'nullLockManager',
+ 'name' => 'localtesting',
+ 'lockManager' => 'nullLockManager',
'containerPaths' => array( 'data' => $this->filePath )
) );
$this->repo = new FSRepo( array(
- 'name' => 'temp',
- 'url' => 'http://localhost/thumbtest',
+ 'name' => 'temp',
+ 'url' => 'http://localhost/thumbtest',
'backend' => $this->backend
) );
$this->handler = new PNGHandler();
$res = $this->handler->getMetadata( null, $this->filePath . '/README' );
$this->assertEquals( PNGHandler::BROKEN_FILE, $res );
}
+
/**
* @param $filename String basename of the file to check
* @param $expected boolean Expected result.
$actual = $this->handler->isAnimatedImage( $file );
$this->assertEquals( $expected, $actual );
}
+
public static function provideIsAnimated() {
return array(
array( 'Animated_PNG_example_bouncing_beach_ball.png', true ),
* @dataProvider provideGetImageArea
*/
public function testGetImageArea( $filename, $expected ) {
- $file = $this->dataFile($filename, 'image/png' );
+ $file = $this->dataFile( $filename, 'image/png' );
$actual = $this->handler->getImageArea( $file, $file->getWidth(), $file->getHeight() );
$this->assertEquals( $expected, $actual );
}
+
public static function provideGetImageArea() {
return array(
array( '1bit-png.png', 2500 ),
$actual = $this->handler->isMetadataValid( null, $metadata );
$this->assertEquals( $expected, $actual );
}
+
public static function provideIsMetadataValid() {
return array(
array( PNGHandler::BROKEN_FILE, PNGHandler::METADATA_GOOD ),
// $this->assertEquals( unserialize( $expected ), unserialize( $actual ) );
$this->assertEquals( ( $expected ), ( $actual ) );
}
+
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;}}' ),
+ 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;}}' ),
);
}
function testGetMetadata( $infile, $expected ) {
$this->assertMetadata( $infile, $expected );
}
-
+
/**
* @dataProvider provideSvgFilesWithXMLMetadata
*/
function testGetXMLMetadata( $infile, $expected ) {
$r = new XMLReader();
- if( !method_exists( $r, 'readInnerXML' ) ) {
+ if ( !method_exists( $r, 'readInnerXML' ) ) {
$this->markTestSkipped( 'XMLReader::readInnerXML() does not exist (libxml >2.6.20 needed).' );
return;
}
public static function provideSvgFilesWithXMLMetadata() {
$base = __DIR__ . '/../../data/media';
- $metadata =
- '<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
+ $metadata = '<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<ns4:Work xmlns:ns4="http://creativecommons.org/ns#" rdf:about="">
<ns5:format xmlns:ns5="http://purl.org/dc/elements/1.1/">image/svg+xml</ns5:format>
<ns5:type xmlns:ns5="http://purl.org/dc/elements/1.1/" rdf:resource="http://purl.org/dc/dcmitype/StillImage"/>
}
public static function provideXMPParse() {
- $xmpPath = __DIR__ . '/../../data/xmp/' ;
+ $xmpPath = __DIR__ . '/../../data/xmp/';
$data = array();
// $xmpFiles format: array of arrays with first arg file base name,
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 ) {
+ );
+
+ foreach ( $xmpFiles as $file ) {
$xmp = file_get_contents( $xmpPath . $file[0] . '.xmp' );
// I'm not sure if this is the best way to handle getting the
// result array, but it seems kind of big to put directly in the test
$reader->parseExtended( $extendedPacket );
$actual = $reader->getResults();
- $expected = array( 'xmp-exif' =>
- array(
+ $expected = array(
+ 'xmp-exif' => array(
'DigitalZoomRatio' => '0/10',
'Flash' => 9,
'FNumber' => '2/10',
$reader->parseExtended( $extendedPacket );
$actual = $reader->getResults();
- $expected = array( 'xmp-exif' =>
- array(
+ $expected = array(
+ 'xmp-exif' => array(
'DigitalZoomRatio' => '0/10',
'Flash' => 9,
)
$this->assertEquals( $expected, $actual );
}
+
/**
* Have a high offset to simulate a missing packet,
* which should cause it to ignore the ExtendedXMP packet.
$reader->parseExtended( $extendedPacket );
$actual = $reader->getResults();
- $expected = array( 'xmp-exif' =>
- array(
+ $expected = array(
+ 'xmp-exif' => array(
'DigitalZoomRatio' => '0/10',
'Flash' => 9,
)