GIFMetadataExtractorTest.php 4.4 KB

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