test: coverage recording now needs to be explicit
[mediawiki.git] / tests / phpunit / includes / media / GIFTest.php
blob7ea6b7ef9d940ed1a77da0264d1cafb1adb2eeab
1 <?php
2 class GIFHandlerTest extends MediaWikiTestCase {
4 protected function setUp() {
5 parent::setUp();
7 $this->filePath = __DIR__ . '/../../data/media';
8 $this->backend = new FSFileBackend( array(
9 'name' => 'localtesting',
10 'lockManager' => 'nullLockManager',
11 'containerPaths' => array( 'data' => $this->filePath )
12 ) );
13 $this->repo = new FSRepo( array(
14 'name' => 'temp',
15 'url' => 'http://localhost/thumbtest',
16 'backend' => $this->backend
17 ) );
18 $this->handler = new GIFHandler();
21 public function testInvalidFile() {
22 $res = $this->handler->getMetadata( null, $this->filePath . '/README' );
23 $this->assertEquals( GIFHandler::BROKEN_FILE, $res );
26 /**
27 * @param $filename String basename of the file to check
28 * @param $expected boolean Expected result.
29 * @dataProvider provideIsAnimated
31 public function testIsAnimanted( $filename, $expected ) {
32 $file = $this->dataFile( $filename, 'image/gif' );
33 $actual = $this->handler->isAnimatedImage( $file );
34 $this->assertEquals( $expected, $actual );
37 public static function provideIsAnimated() {
38 return array(
39 array( 'animated.gif', true ),
40 array( 'nonanimated.gif', false ),
44 /**
45 * @param $filename String
46 * @param $expected Integer Total image area
47 * @dataProvider provideGetImageArea
49 public function testGetImageArea( $filename, $expected ) {
50 $file = $this->dataFile( $filename, 'image/gif' );
51 $actual = $this->handler->getImageArea( $file, $file->getWidth(), $file->getHeight() );
52 $this->assertEquals( $expected, $actual );
55 public static function provideGetImageArea() {
56 return array(
57 array( 'animated.gif', 5400 ),
58 array( 'nonanimated.gif', 1350 ),
62 /**
63 * @param $metadata String Serialized metadata
64 * @param $expected Integer One of the class constants of GIFHandler
65 * @dataProvider provideIsMetadataValid
67 public function testIsMetadataValid( $metadata, $expected ) {
68 $actual = $this->handler->isMetadataValid( null, $metadata );
69 $this->assertEquals( $expected, $actual );
72 public static function provideIsMetadataValid() {
73 return array(
74 array( GIFHandler::BROKEN_FILE, GIFHandler::METADATA_GOOD ),
75 array( '', GIFHandler::METADATA_BAD ),
76 array( null, GIFHandler::METADATA_BAD ),
77 array( 'Something invalid!', GIFHandler::METADATA_BAD ),
78 array( 'a:4:{s:10:"frameCount";i:1;s:6:"looped";b:0;s:8:"duration";d:0.1000000000000000055511151231257827021181583404541015625;s:8:"metadata";a:2:{s:14:"GIFFileComment";a:1:{i:0;s:35:"GIF test file ⁕ Created with GIMP";}s:15:"_MW_GIF_VERSION";i:1;}}', GIFHandler::METADATA_GOOD ),
82 /**
83 * @param $filename String
84 * @param $expected String Serialized array
85 * @dataProvider provideGetMetadata
87 public function testGetMetadata( $filename, $expected ) {
88 $file = $this->dataFile( $filename, 'image/gif' );
89 $actual = $this->handler->getMetadata( $file, "$this->filePath/$filename" );
90 $this->assertEquals( unserialize( $expected ), unserialize( $actual ) );
93 public static function provideGetMetadata() {
94 return array(
95 array( 'nonanimated.gif', 'a:4:{s:10:"frameCount";i:1;s:6:"looped";b:0;s:8:"duration";d:0.1000000000000000055511151231257827021181583404541015625;s:8:"metadata";a:2:{s:14:"GIFFileComment";a:1:{i:0;s:35:"GIF test file ⁕ Created with GIMP";}s:15:"_MW_GIF_VERSION";i:1;}}' ),
96 array( 'animated-xmp.gif', 'a:4:{s:10:"frameCount";i:4;s:6:"looped";b:1;s:8:"duration";d:2.399999999999999911182158029987476766109466552734375;s:8:"metadata";a:5:{s:6:"Artist";s:7:"Bawolff";s:16:"ImageDescription";a:2:{s:9:"x-default";s:18:"A file to test GIF";s:5:"_type";s:4:"lang";}s:15:"SublocationDest";s:13:"The interwebs";s:14:"GIFFileComment";a:1:{i:0;s:16:"GIƒ·test·file";}s:15:"_MW_GIF_VERSION";i:1;}}' ),
100 private function dataFile( $name, $type ) {
101 return new UnregisteredLocalFile( false, $this->repo,
102 "mwstore://localtesting/data/$name", $type );