3665835804bd2ad56b0db7d4757722056382fdb0
2 class GIFHandlerTest
extends MediaWikiTestCase
{
4 public function setUp() {
5 $this->filePath
= dirname( __FILE__
) . '/../../data/media';
6 $this->backend
= new FSFileBackend( array(
7 'name' => 'localtesting',
8 'lockManager' => 'nullLockManager',
9 'containerPaths' => array( 'data' => $this->filePath
)
11 $this->repo
= new FSRepo( array(
13 'url' => 'http://localhost/thumbtest',
14 'backend' => $this->backend
16 $this->handler
= new GIFHandler();
19 public function testInvalidFile() {
20 $res = $this->handler
->getMetadata( null, $this->filePath
. '/README' );
21 $this->assertEquals( GIFHandler
::BROKEN_FILE
, $res );
24 * @param $filename String basename of the file to check
25 * @param $expected boolean Expected result.
26 * @dataProvider dataIsAnimated
28 public function testIsAnimanted( $filename, $expected ) {
29 $file = $this->dataFile( $filename, 'image/gif' );
30 $actual = $this->handler
->isAnimatedImage( $file );
31 $this->assertEquals( $expected, $actual );
33 public function dataIsAnimated() {
35 array( 'animated.gif', true ),
36 array( 'nonanimated.gif', false ),
41 * @param $filename String
42 * @param $expected Integer Total image area
43 * @dataProvider dataGetImageArea
45 public function testGetImageArea( $filename, $expected ) {
46 $file = $this->dataFile( $filename, 'image/gif' );
47 $actual = $this->handler
->getImageArea( $file, $file->getWidth(), $file->getHeight() );
48 $this->assertEquals( $expected, $actual );
50 public function dataGetImageArea() {
52 array( 'animated.gif', 5400 ),
53 array( 'nonanimated.gif', 1350 ),
58 * @param $metadata String Serialized metadata
59 * @param $expected Integer One of the class constants of GIFHandler
60 * @dataProvider dataIsMetadataValid
62 public function testIsMetadataValid( $metadata, $expected ) {
63 $actual = $this->handler
->isMetadataValid( null, $metadata );
64 $this->assertEquals( $expected, $actual );
66 public function dataIsMetadataValid() {
68 array( GIFHandler
::BROKEN_FILE
, GIFHandler
::METADATA_GOOD
),
69 array( '', GIFHandler
::METADATA_BAD
),
70 array( null, GIFHandler
::METADATA_BAD
),
71 array( 'Something invalid!', GIFHandler
::METADATA_BAD
),
72 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
),
77 * @param $filename String
78 * @param $expected String Serialized array
79 * @dataProvider dataGetMetadata
81 public function testGetMetadata( $filename, $expected ) {
82 $file = $this->dataFile( $filename, 'image/gif' );
83 $actual = $this->handler
->getMetadata( $file, "$this->filePath/$filename" );
84 $this->assertEquals( unserialize( $expected ), unserialize( $actual ) );
87 public function dataGetMetadata() {
89 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;}}' ),
90 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;}}' ),
94 private function dataFile( $name, $type ) {
95 return new UnregisteredLocalFile( false, $this->repo
,
96 "mwstore://localtesting/data/$name", $type );