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