Support offsets in prefix searching
[mediawiki.git] / tests / phpunit / includes / media / GIFTest.php
blob87ffd995e9c8c37332e86199d88df543df0c6f97
1 <?php
3 /**
4 * @group Media
5 */
6 class GIFHandlerTest extends MediaWikiMediaTestCase {
8 /** @var GIFHandler */
9 protected $handler;
11 protected function setUp() {
12 parent::setUp();
14 $this->handler = new GIFHandler();
17 /**
18 * @covers GIFHandler::getMetadata
20 public function testInvalidFile() {
21 $res = $this->handler->getMetadata( null, $this->filePath . '/README' );
22 $this->assertEquals( GIFHandler::BROKEN_FILE, $res );
25 /**
26 * @param string $filename Basename of the file to check
27 * @param bool $expected Expected result.
28 * @dataProvider provideIsAnimated
29 * @covers GIFHandler::isAnimatedImage
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 string $filename
46 * @param int $expected Total image area
47 * @dataProvider provideGetImageArea
48 * @covers GIFHandler::getImageArea
50 public function testGetImageArea( $filename, $expected ) {
51 $file = $this->dataFile( $filename, 'image/gif' );
52 $actual = $this->handler->getImageArea( $file, $file->getWidth(), $file->getHeight() );
53 $this->assertEquals( $expected, $actual );
56 public static function provideGetImageArea() {
57 return array(
58 array( 'animated.gif', 5400 ),
59 array( 'nonanimated.gif', 1350 ),
63 /**
64 * @param string $metadata Serialized metadata
65 * @param int $expected One of the class constants of GIFHandler
66 * @dataProvider provideIsMetadataValid
67 * @covers GIFHandler::isMetadataValid
69 public function testIsMetadataValid( $metadata, $expected ) {
70 $actual = $this->handler->isMetadataValid( null, $metadata );
71 $this->assertEquals( $expected, $actual );
74 public static function provideIsMetadataValid() {
75 return array(
76 array( GIFHandler::BROKEN_FILE, GIFHandler::METADATA_GOOD ),
77 array( '', GIFHandler::METADATA_BAD ),
78 array( null, GIFHandler::METADATA_BAD ),
79 array( 'Something invalid!', GIFHandler::METADATA_BAD ),
80 // @codingStandardsIgnoreStart Ignore Generic.Files.LineLength.TooLong
81 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 // @codingStandardsIgnoreEnd
86 /**
87 * @param string $filename
88 * @param string $expected Serialized array
89 * @dataProvider provideGetMetadata
90 * @covers GIFHandler::getMetadata
92 public function testGetMetadata( $filename, $expected ) {
93 $file = $this->dataFile( $filename, 'image/gif' );
94 $actual = $this->handler->getMetadata( $file, "$this->filePath/$filename" );
95 $this->assertEquals( unserialize( $expected ), unserialize( $actual ) );
98 public static function provideGetMetadata() {
99 return array(
100 // @codingStandardsIgnoreStart Ignore Generic.Files.LineLength.TooLong
101 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;}}' ),
102 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;}}' ),
103 // @codingStandardsIgnoreEnd
108 * @param string $filename
109 * @param string $expected Serialized array
110 * @dataProvider provideGetIndependentMetaArray
111 * @covers GIFHandler::getCommonMetaArray
113 public function testGetIndependentMetaArray( $filename, $expected ) {
114 $file = $this->dataFile( $filename, 'image/gif' );
115 $actual = $this->handler->getCommonMetaArray( $file );
116 $this->assertEquals( $expected, $actual );
119 public static function provideGetIndependentMetaArray() {
120 return array(
121 array( 'nonanimated.gif', array(
122 'GIFFileComment' => array(
123 'GIF test file ⁕ Created with GIMP',
125 ) ),
126 array( 'animated-xmp.gif',
127 array(
128 'Artist' => 'Bawolff',
129 'ImageDescription' => array(
130 'x-default' => 'A file to test GIF',
131 '_type' => 'lang',
133 'SublocationDest' => 'The interwebs',
134 'GIFFileComment' =>
135 array(
136 'GIƒ·test·file',