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