summaryrefslogtreecommitdiff
path: root/tests/phpunit/includes/media/GIFMetadataExtractorTest.php
blob: 47fc368b27c4bcb65e1578f0000e857a40aadd3e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<?php
class GIFMetadataExtractorTest extends MediaWikiTestCase {

	public function setUp() {
		$this->mediaPath = dirname( __FILE__ ) . '/../../data/media/';
	}
	/**
	 * Put in a file, and see if the metadata coming out is as expected.
	 * @param $filename String
	 * @param $expected Array The extracted metadata.
	 * @dataProvider dataGetMetadata
	 */
	public function testGetMetadata( $filename, $expected ) {
		$actual = GIFMetadataExtractor::getMetadata( $this->mediaPath . $filename );
		$this->assertEquals( $expected, $actual );
	}
	public function dataGetMetadata() {

		$xmpNugget = <<<EOF
<?xpacket begin='' id='W5M0MpCehiHzreSzNTczkc9d'?>
<x:xmpmeta xmlns:x='adobe:ns:meta/' x:xmptk='Image::ExifTool 7.30'>
<rdf:RDF xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#'>

 <rdf:Description rdf:about=''
  xmlns:Iptc4xmpCore='http://iptc.org/std/Iptc4xmpCore/1.0/xmlns/'>
  <Iptc4xmpCore:Location>The interwebs</Iptc4xmpCore:Location>
 </rdf:Description>

 <rdf:Description rdf:about=''
  xmlns:tiff='http://ns.adobe.com/tiff/1.0/'>
  <tiff:Artist>Bawolff</tiff:Artist>
  <tiff:ImageDescription>
   <rdf:Alt>
    <rdf:li xml:lang='x-default'>A file to test GIF</rdf:li>
   </rdf:Alt>
  </tiff:ImageDescription>
 </rdf:Description>
</rdf:RDF>
</x:xmpmeta>
                                                                                                    
                                                                                                    
                                                                                                    
                                                                                                    
                                                                                                    
                                                                                                    
                                                                                                    
                                                                                                    
                                                                                                    
                                                                                                    
                                                                                                    
                                                                                                    
                                                                                                    
                                                                                                    
                                                                                                    
                                                                                                    
                                                                                                    
                                                                                                    
                                                                                                    
                                                                                                    
                                                                                                    
                                                                                                    
                                                                                                    
                                                                                                    
<?xpacket end='w'?>
EOF;
		$xmpNugget = str_replace( "\r", '', $xmpNugget ); // Windows compat

		return array(
			array( 'nonanimated.gif', array(
				'comment' => array( 'GIF test file ⁕ Created with GIMP' ),
				'duration' => 0.1,
				'frameCount' => 1,
				'looped' => false,
				'xmp' => '',
				)
			),
			array( 'animated.gif', array(
				'comment' => array( 'GIF test file . Created with GIMP' ),
				'duration' => 2.4,
				'frameCount' => 4,
				'looped' => true,
				'xmp' => '',
				)
			),

			array( 'animated-xmp.gif', array(
				'xmp' => $xmpNugget,
				'duration' => 2.4,
				'frameCount' => 4,
				'looped' => true,
				'comment' => array( 'GIƒ·test·file' ),
				)
			),
		);
	}
}