c952b23c94cac8848d4cd5d901e05f5864e2c96b
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 );
28 public function dataXMPParse() {
29 $xmpPath = dirname( __FILE__
) . '/../../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' ),
56 foreach( $xmpFiles as $file ) {
57 $xmp = file_get_contents( $xmpPath . $file[0] . '.xmp' );
58 // I'm not sure if this is the best way to handle getting the
59 // result array, but it seems kind of big to put directly in the test
62 include( $xmpPath . $file[0] . '.result.php' );
63 $data[] = array( $xmp, $result, '[' . $file[0] . '.xmp] ' . $file[1] );
68 /** Test ExtendedXMP block support. (Used when the XMP has to be split
69 * over multiple jpeg segments, due to 64k size limit on jpeg segments.
71 * @todo This is based on what the standard says. Need to find a real
72 * world example file to double check the support for this is right.
74 function testExtendedXMP() {
75 $xmpPath = dirname( __FILE__
) . '/../../data/xmp/';
76 $standardXMP = file_get_contents( $xmpPath . 'xmpExt.xmp' );
77 $extendedXMP = file_get_contents( $xmpPath . 'xmpExt2.xmp' );
79 $md5sum = '28C74E0AC2D796886759006FBE2E57B7'; // of xmpExt2.xmp
80 $length = pack( 'N', strlen( $extendedXMP ) );
81 $offset = pack( 'N', 0 );
82 $extendedPacket = $md5sum . $length . $offset . $extendedXMP;
84 $reader = new XMPReader();
85 $reader->parse( $standardXMP );
86 $reader->parseExtended( $extendedPacket );
87 $actual = $reader->getResults();
89 $expected = array( 'xmp-exif' =>
91 'DigitalZoomRatio' => '0/10',
97 $this->assertEquals( $expected, $actual );
101 * This test has an extended XMP block with a wrong guid (md5sum)
102 * and thus should only return the StandardXMP, not the ExtendedXMP.
104 function testExtendedXMPWithWrongGUID() {
105 $xmpPath = dirname( __FILE__
) . '/../../data/xmp/';
106 $standardXMP = file_get_contents( $xmpPath . 'xmpExt.xmp' );
107 $extendedXMP = file_get_contents( $xmpPath . 'xmpExt2.xmp' );
109 $md5sum = '28C74E0AC2D796886759006FBE2E57B9'; // Note last digit.
110 $length = pack( 'N', strlen( $extendedXMP ) );
111 $offset = pack( 'N', 0 );
112 $extendedPacket = $md5sum . $length . $offset . $extendedXMP;
114 $reader = new XMPReader();
115 $reader->parse( $standardXMP );
116 $reader->parseExtended( $extendedPacket );
117 $actual = $reader->getResults();
119 $expected = array( 'xmp-exif' =>
121 'DigitalZoomRatio' => '0/10',
126 $this->assertEquals( $expected, $actual );
129 * Have a high offset to simulate a missing packet,
130 * which should cause it to ignore the ExtendedXMP packet.
132 function testExtendedXMPMissingPacket() {
133 $xmpPath = dirname( __FILE__
) . '/../../data/xmp/';
134 $standardXMP = file_get_contents( $xmpPath . 'xmpExt.xmp' );
135 $extendedXMP = file_get_contents( $xmpPath . 'xmpExt2.xmp' );
137 $md5sum = '28C74E0AC2D796886759006FBE2E57B7'; // of xmpExt2.xmp
138 $length = pack( 'N', strlen( $extendedXMP ) );
139 $offset = pack( 'N', 2048 );
140 $extendedPacket = $md5sum . $length . $offset . $extendedXMP;
142 $reader = new XMPReader();
143 $reader->parse( $standardXMP );
144 $reader->parseExtended( $extendedPacket );
145 $actual = $reader->getResults();
147 $expected = array( 'xmp-exif' =>
149 'DigitalZoomRatio' => '0/10',
154 $this->assertEquals( $expected, $actual );