8198d3b08b379d5c13ef1b147c049d1a1ee87fc6
2 class XMPTest
extends MediaWikiTestCase
{
5 if ( !wfDl( 'xml' ) ) {
6 $this->markTestSkipped( 'Requires libxml to do XMP parsing' );
11 * Put XMP in, compare what comes out...
13 * @param $xmp String the actual xml data.
14 * @param $expected Array expected result of parsing the xmp.
15 * @param $info String Short sentence on what's being tested.
17 * @dataProvider dataXMPParse
19 public function testXMPParse( $xmp, $expected, $info ) {
20 if ( !is_string( $xmp ) ||
!is_array( $expected ) ) {
21 throw new Exception( "Invalid data provided to " . __METHOD__
);
23 $reader = new XMPReader
;
24 $reader->parse( $xmp );
25 $this->assertEquals( $expected, $reader->getResults(), $info, 0.0000000001 );
28 public function dataXMPParse() {
29 $xmpPath = __DIR__
. '/../../data/xmp/' ;
32 // $xmpFiles format: array of arrays with first arg file base name,
33 // with the actual file having .xmp on the end for the xmp
34 // and .result.php on the end for a php file containing the result
35 // array. Second argument is some info on what's being tested.
37 array( '1', 'parseType=Resource test' ),
38 array( '2', 'Structure with mixed attribute and element props' ),
39 array( '3', 'Extra qualifiers (that should be ignored)' ),
40 array( '3-invalid', 'Test ignoring qualifiers that look like normal props' ),
41 array( '4', 'Flash as qualifier' ),
42 array( '5', 'Flash as qualifier 2' ),
43 array( '6', 'Multiple rdf:Description' ),
44 array( '7', 'Generic test of several property types' ),
45 array( 'flash', 'Test of Flash property' ),
46 array( 'invalid-child-not-struct', 'Test child props not in struct or ignored' ),
47 array( 'no-recognized-props', 'Test namespace and no recognized props' ),
48 array( 'no-namespace', 'Test non-namespaced attributes are ignored' ),
49 array( 'bag-for-seq', "Allow bag's instead of seq's. (bug 27105)" ),
50 array( 'utf16BE', 'UTF-16BE encoding' ),
51 array( 'utf16LE', 'UTF-16LE encoding' ),
52 array( 'utf32BE', 'UTF-32BE encoding' ),
53 array( 'utf32LE', 'UTF-32LE encoding' ),
54 array( 'xmpExt', 'Extended XMP missing second part' ),
55 array( 'gps', 'Handling of exif GPS parameters in XMP' ),
57 foreach( $xmpFiles as $file ) {
58 $xmp = file_get_contents( $xmpPath . $file[0] . '.xmp' );
59 // I'm not sure if this is the best way to handle getting the
60 // result array, but it seems kind of big to put directly in the test
63 include( $xmpPath . $file[0] . '.result.php' );
64 $data[] = array( $xmp, $result, '[' . $file[0] . '.xmp] ' . $file[1] );
69 /** Test ExtendedXMP block support. (Used when the XMP has to be split
70 * over multiple jpeg segments, due to 64k size limit on jpeg segments.
72 * @todo This is based on what the standard says. Need to find a real
73 * world example file to double check the support for this is right.
75 function testExtendedXMP() {
76 $xmpPath = __DIR__
. '/../../data/xmp/';
77 $standardXMP = file_get_contents( $xmpPath . 'xmpExt.xmp' );
78 $extendedXMP = file_get_contents( $xmpPath . 'xmpExt2.xmp' );
80 $md5sum = '28C74E0AC2D796886759006FBE2E57B7'; // of xmpExt2.xmp
81 $length = pack( 'N', strlen( $extendedXMP ) );
82 $offset = pack( 'N', 0 );
83 $extendedPacket = $md5sum . $length . $offset . $extendedXMP;
85 $reader = new XMPReader();
86 $reader->parse( $standardXMP );
87 $reader->parseExtended( $extendedPacket );
88 $actual = $reader->getResults();
90 $expected = array( 'xmp-exif' =>
92 'DigitalZoomRatio' => '0/10',
98 $this->assertEquals( $expected, $actual );
102 * This test has an extended XMP block with a wrong guid (md5sum)
103 * and thus should only return the StandardXMP, not the ExtendedXMP.
105 function testExtendedXMPWithWrongGUID() {
106 $xmpPath = __DIR__
. '/../../data/xmp/';
107 $standardXMP = file_get_contents( $xmpPath . 'xmpExt.xmp' );
108 $extendedXMP = file_get_contents( $xmpPath . 'xmpExt2.xmp' );
110 $md5sum = '28C74E0AC2D796886759006FBE2E57B9'; // Note last digit.
111 $length = pack( 'N', strlen( $extendedXMP ) );
112 $offset = pack( 'N', 0 );
113 $extendedPacket = $md5sum . $length . $offset . $extendedXMP;
115 $reader = new XMPReader();
116 $reader->parse( $standardXMP );
117 $reader->parseExtended( $extendedPacket );
118 $actual = $reader->getResults();
120 $expected = array( 'xmp-exif' =>
122 'DigitalZoomRatio' => '0/10',
127 $this->assertEquals( $expected, $actual );
130 * Have a high offset to simulate a missing packet,
131 * which should cause it to ignore the ExtendedXMP packet.
133 function testExtendedXMPMissingPacket() {
134 $xmpPath = __DIR__
. '/../../data/xmp/';
135 $standardXMP = file_get_contents( $xmpPath . 'xmpExt.xmp' );
136 $extendedXMP = file_get_contents( $xmpPath . 'xmpExt2.xmp' );
138 $md5sum = '28C74E0AC2D796886759006FBE2E57B7'; // of xmpExt2.xmp
139 $length = pack( 'N', strlen( $extendedXMP ) );
140 $offset = pack( 'N', 2048 );
141 $extendedPacket = $md5sum . $length . $offset . $extendedXMP;
143 $reader = new XMPReader();
144 $reader->parse( $standardXMP );
145 $reader->parseExtended( $extendedPacket );
146 $actual = $reader->getResults();
148 $expected = array( 'xmp-exif' =>
150 'DigitalZoomRatio' => '0/10',
155 $this->assertEquals( $expected, $actual );