1<?php 2 3/** 4 * @group Media 5 */ 6class GIFMetadataExtractorTest extends \MediaWikiUnitTestCase { 7 8 protected function setUp() : void { 9 parent::setUp(); 10 11 $this->mediaPath = __DIR__ . '/../../../data/media/'; 12 } 13 14 /** 15 * Put in a file, and see if the metadata coming out is as expected. 16 * @param string $filename 17 * @param array $expected The extracted metadata. 18 * @dataProvider provideGetMetadata 19 * @covers GIFMetadataExtractor::getMetadata 20 */ 21 public function testGetMetadata( $filename, $expected ) { 22 $actual = GIFMetadataExtractor::getMetadata( $this->mediaPath . $filename ); 23 $this->assertEquals( $expected, $actual ); 24 } 25 26 public static function provideGetMetadata() { 27 $xmpNugget = <<<EOF 28<?xpacket begin='' id='W5M0MpCehiHzreSzNTczkc9d'?> 29<x:xmpmeta xmlns:x='adobe:ns:meta/' x:xmptk='Image::ExifTool 7.30'> 30<rdf:RDF xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#'> 31 32 <rdf:Description rdf:about='' 33 xmlns:Iptc4xmpCore='http://iptc.org/std/Iptc4xmpCore/1.0/xmlns/'> 34 <Iptc4xmpCore:Location>The interwebs</Iptc4xmpCore:Location> 35 </rdf:Description> 36 37 <rdf:Description rdf:about='' 38 xmlns:tiff='http://ns.adobe.com/tiff/1.0/'> 39 <tiff:Artist>Bawolff</tiff:Artist> 40 <tiff:ImageDescription> 41 <rdf:Alt> 42 <rdf:li xml:lang='x-default'>A file to test GIF</rdf:li> 43 </rdf:Alt> 44 </tiff:ImageDescription> 45 </rdf:Description> 46</rdf:RDF> 47</x:xmpmeta> 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72<?xpacket end='w'?> 73EOF; 74 $xmpNugget = str_replace( "\r", '', $xmpNugget ); // Windows compat 75 76 return [ 77 [ 78 'nonanimated.gif', 79 [ 80 'comment' => [ 'GIF test file ⁕ Created with GIMP' ], 81 'duration' => 0.1, 82 'frameCount' => 1, 83 'looped' => false, 84 'xmp' => '', 85 ] 86 ], 87 [ 88 'animated.gif', 89 [ 90 'comment' => [ 'GIF test file . Created with GIMP' ], 91 'duration' => 2.4, 92 'frameCount' => 4, 93 'looped' => true, 94 'xmp' => '', 95 ] 96 ], 97 98 [ 99 'animated-xmp.gif', 100 [ 101 'xmp' => $xmpNugget, 102 'duration' => 2.4, 103 'frameCount' => 4, 104 'looped' => true, 105 'comment' => [ 'GIƒ·test·file' ], 106 ] 107 ], 108 ]; 109 } 110} 111