<?php
class GIFHandlerTest extends MediaWikiTestCase {
+ /** @var FSFileBackend */
+ protected $backend;
+ /** @var GIFHandler */
+ protected $handler;
+ /** @var FSRepo */
+ protected $repo;
+ /** @var string */
+ protected $filePath;
+
protected function setUp() {
parent::setUp();
$this->handler = new GIFHandler();
}
+ /**
+ * @covers GIFHandler::getMetadata
+ */
public function testInvalidFile() {
$res = $this->handler->getMetadata( null, $this->filePath . '/README' );
$this->assertEquals( GIFHandler::BROKEN_FILE, $res );
* @param $filename String basename of the file to check
* @param $expected boolean Expected result.
* @dataProvider provideIsAnimated
+ * @covers GIFHandler::isAnimatedImage
*/
public function testIsAnimanted( $filename, $expected ) {
$file = $this->dataFile( $filename, 'image/gif' );
* @param $filename String
* @param $expected Integer Total image area
* @dataProvider provideGetImageArea
+ * @covers GIFHandler::getImageArea
*/
public function testGetImageArea( $filename, $expected ) {
$file = $this->dataFile( $filename, 'image/gif' );
* @param $metadata String Serialized metadata
* @param $expected Integer One of the class constants of GIFHandler
* @dataProvider provideIsMetadataValid
+ * @covers GIFHandler::isMetadataValid
*/
public function testIsMetadataValid( $metadata, $expected ) {
$actual = $this->handler->isMetadataValid( null, $metadata );
* @param $filename String
* @param $expected String Serialized array
* @dataProvider provideGetMetadata
+ * @covers GIFHandler::getMetadata
*/
public function testGetMetadata( $filename, $expected ) {
$file = $this->dataFile( $filename, 'image/gif' );
);
}
+ /**
+ * @param $filename String
+ * @param $expected String Serialized array
+ * @dataProvider provideGetIndependentMetaArray
+ */
+ public function testGetIndependentMetaArray( $filename, $expected ) {
+ $file = $this->dataFile( $filename, 'image/gif' );
+ $actual = $this->handler->getCommonMetaArray( $file );
+ $this->assertEquals( $expected, $actual );
+ }
+
+ public function provideGetIndependentMetaArray() {
+ return array(
+ array( 'nonanimated.gif', array(
+ 'GIFFileComment' => array(
+ 'GIF test file ⁕ Created with GIMP',
+ ),
+ ) ),
+ array( 'animated-xmp.gif',
+ array(
+ 'Artist' => 'Bawolff',
+ 'ImageDescription' => array(
+ 'x-default' => 'A file to test GIF',
+ '_type' => 'lang',
+ ),
+ 'SublocationDest' => 'The interwebs',
+ 'GIFFileComment' =>
+ array(
+ 'GIƒ·test·file',
+ ),
+ )
+ ),
+ );
+ }
+
private function dataFile( $name, $type ) {
return new UnregisteredLocalFile( false, $this->repo,
"mwstore://localtesting/data/$name", $type );
<?php
+/**
+ * @covers JpegHandler
+ */
class JpegTest extends MediaWikiTestCase {
+ protected $filePath;
+
protected function setUp() {
parent::setUp();
if ( !extension_loaded( 'exif' ) ) {
$this->setMwGlobals( 'wgShowEXIF', true );
+
+ $this->backend = new FSFileBackend( array(
+ 'name' => 'localtesting',
+ 'lockManager' => 'nullLockManager',
+ 'containerPaths' => array( 'data' => $this->filePath )
+ ) );
+ $this->repo = new FSRepo( array(
+ 'name' => 'temp',
+ 'url' => 'http://localhost/thumbtest',
+ 'backend' => $this->backend
+ ) );
+
+ $this->handler = new JpegHandler;
}
public function testInvalidFile() {
- $jpeg = new JpegHandler;
- $res = $jpeg->getMetadata( null, $this->filePath . 'README' );
+ $file = $this->dataFile( 'README', 'image/jpeg' );
+ $res = $this->handler->getMetadata( $file, $this->filePath . 'README' );
$this->assertEquals( ExifBitmapHandler::BROKEN_FILE, $res );
}
public function testJpegMetadataExtraction() {
- $h = new JpegHandler;
- $res = $h->getMetadata( null, $this->filePath . 'test.jpg' );
+ $file = $this->dataFile( 'test.jpg', 'image/jpeg' );
+ $res = $this->handler->getMetadata( $file, $this->filePath . 'test.jpg' );
$expected = 'a:7:{s:16:"ImageDescription";s:9:"Test file";s:11:"XResolution";s:4:"72/1";s:11:"YResolution";s:4:"72/1";s:14:"ResolutionUnit";i:2;s:16:"YCbCrPositioning";i:1;s:15:"JPEGFileComment";a:1:{i:0;s:17:"Created with GIMP";}s:22:"MEDIAWIKI_EXIF_VERSION";i:2;}';
// Unserialize in case serialization format ever changes.
$this->assertEquals( unserialize( $expected ), unserialize( $res ) );
}
+ public function testGetIndependentMetaArray() {
+ $file = $this->dataFile( 'test.jpg', 'image/jpeg' );
+ $res = $this->handler->getCommonMetaArray( $file );
+ $expected = array(
+ 'ImageDescription' => 'Test file',
+ 'XResolution' => '72/1',
+ 'YResolution' => '72/1',
+ 'ResolutionUnit' => 2,
+ 'YCbCrPositioning' => 1,
+ 'JPEGFileComment' => array(
+ 'Created with GIMP',
+ ),
+ );
+
+ $this->assertEquals( $res, $expected );
+ }
+
+ private function dataFile( $name, $type ) {
+ return new UnregisteredLocalFile( false, $this->repo,
+ "mwstore://localtesting/data/$name", $type );
+ }
}
<?php
class PNGHandlerTest extends MediaWikiTestCase {
+ /** @var PNGHandler */
+ protected $handler;
+ /** @var FSRepo */
+ protected $repo;
+ /** @var FSFileBackend */
+ protected $backend;
+ /** @var string */
+ protected $filePath;
+
protected function setUp() {
parent::setUp();
$this->handler = new PNGHandler();
}
+ /**
+ * @covers PNGHandler::getMetadata
+ */
public function testInvalidFile() {
$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.
* @dataProvider provideIsAnimated
+ * @covers PNGHandler::isAnimatedImage
*/
public function testIsAnimanted( $filename, $expected ) {
$file = $this->dataFile( $filename, 'image/png' );
* @param $filename String
* @param $expected Integer Total image area
* @dataProvider provideGetImageArea
+ * @covers PNGHandler::getImageArea
*/
public function testGetImageArea( $filename, $expected ) {
$file = $this->dataFile( $filename, 'image/png' );
* @param $metadata String Serialized metadata
* @param $expected Integer One of the class constants of PNGHandler
* @dataProvider provideIsMetadataValid
+ * @covers PNGHandler::isMetadataValid
*/
public function testIsMetadataValid( $metadata, $expected ) {
$actual = $this->handler->isMetadataValid( null, $metadata );
* @param $filename String
* @param $expected String Serialized array
* @dataProvider provideGetMetadata
+ * @covers PNGHandler::getMetadata
*/
public function testGetMetadata( $filename, $expected ) {
$file = $this->dataFile( $filename, 'image/png' );
);
}
+ /**
+ * @param $filename String
+ * @param $expected Array Expected standard metadata
+ * @dataProvider provideGetIndependentMetaArray
+ */
+ public function testGetIndependentMetaArray( $filename, $expected ) {
+ $file = $this->dataFile( $filename, 'image/png' );
+ $actual = $this->handler->getCommonMetaArray( $file );
+ $this->assertEquals( $expected, $actual );
+ }
+
+ public function provideGetIndependentMetaArray() {
+ return array(
+ array( 'rgb-na-png.png', array() ),
+ array( 'xmp.png',
+ array(
+ 'SerialNumber' => '123456789',
+ )
+ ),
+ );
+ }
+
private function dataFile( $name, $type ) {
return new UnregisteredLocalFile( false, $this->repo,
"mwstore://localtesting/data/$name", $type );
<?php
+/**
+ * @covers SVGMetadataExtractor
+ */
class SVGMetadataExtractorTest extends MediaWikiTestCase {
protected function setUp() {
/**
* @dataProvider provideSvgFiles
*/
- function testGetMetadata( $infile, $expected ) {
+ public function testGetMetadata( $infile, $expected ) {
$this->assertMetadata( $infile, $expected );
}
/**
* @dataProvider provideSvgFilesWithXMLMetadata
*/
- function testGetXMLMetadata( $infile, $expected ) {
+ public function testGetXMLMetadata( $infile, $expected ) {
$r = new XMLReader();
if ( !method_exists( $r, 'readInnerXML' ) ) {
$this->markTestSkipped( 'XMLReader::readInnerXML() does not exist (libxml >2.6.20 needed).' );
'originalWidth' => '385',
'originalHeight' => '385.0004883',
)
+ ),
+ array(
+ "$base/Tux.svg",
+ array(
+ 'width' => 512,
+ 'height' => 594,
+ 'originalWidth' => '100%',
+ 'originalHeight' => '100%',
+ 'title' => 'Tux',
+ 'description' => 'For more information see: http://commons.wikimedia.org/wiki/Image:Tux.svg',
+ )
)
);
}