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] );
71 /** Test ExtendedXMP block support. (Used when the XMP has to be split
72 * over multiple jpeg segments, due to 64k size limit on jpeg segments.
74 * @todo This is based on what the standard says. Need to find a real
75 * world example file to double check the support for this is right.
77 function testExtendedXMP() {
78 $xmpPath = __DIR__
. '/../../data/xmp/';
79 $standardXMP = file_get_contents( $xmpPath . 'xmpExt.xmp' );
80 $extendedXMP = file_get_contents( $xmpPath . 'xmpExt2.xmp' );
82 $md5sum = '28C74E0AC2D796886759006FBE2E57B7'; // of xmpExt2.xmp
83 $length = pack( 'N', strlen( $extendedXMP ) );
84 $offset = pack( 'N', 0 );
85 $extendedPacket = $md5sum . $length . $offset . $extendedXMP;
87 $reader = new XMPReader();
88 $reader->parse( $standardXMP );
89 $reader->parseExtended( $extendedPacket );
90 $actual = $reader->getResults();
94 'DigitalZoomRatio' => '0/10',
100 $this->assertEquals( $expected, $actual );
104 * This test has an extended XMP block with a wrong guid (md5sum)
105 * and thus should only return the StandardXMP, not the ExtendedXMP.
107 function testExtendedXMPWithWrongGUID() {
108 $xmpPath = __DIR__
. '/../../data/xmp/';
109 $standardXMP = file_get_contents( $xmpPath . 'xmpExt.xmp' );
110 $extendedXMP = file_get_contents( $xmpPath . 'xmpExt2.xmp' );
112 $md5sum = '28C74E0AC2D796886759006FBE2E57B9'; // Note last digit.
113 $length = pack( 'N', strlen( $extendedXMP ) );
114 $offset = pack( 'N', 0 );
115 $extendedPacket = $md5sum . $length . $offset . $extendedXMP;
117 $reader = new XMPReader();
118 $reader->parse( $standardXMP );
119 $reader->parseExtended( $extendedPacket );
120 $actual = $reader->getResults();
124 'DigitalZoomRatio' => '0/10',
129 $this->assertEquals( $expected, $actual );
133 * Have a high offset to simulate a missing packet,
134 * which should cause it to ignore the ExtendedXMP packet.
136 function testExtendedXMPMissingPacket() {
137 $xmpPath = __DIR__
. '/../../data/xmp/';
138 $standardXMP = file_get_contents( $xmpPath . 'xmpExt.xmp' );
139 $extendedXMP = file_get_contents( $xmpPath . 'xmpExt2.xmp' );
141 $md5sum = '28C74E0AC2D796886759006FBE2E57B7'; // of xmpExt2.xmp
142 $length = pack( 'N', strlen( $extendedXMP ) );
143 $offset = pack( 'N', 2048 );
144 $extendedPacket = $md5sum . $length . $offset . $extendedXMP;
146 $reader = new XMPReader();
147 $reader->parse( $standardXMP );
148 $reader->parseExtended( $extendedPacket );
149 $actual = $reader->getResults();
153 'DigitalZoomRatio' => '0/10',
158 $this->assertEquals( $expected, $actual );