7class XMPTest extends PHPUnit_Framework_TestCase {
9 protected function setUp() {
11 # Requires libxml to do XMP parsing
12 if ( !extension_loaded(
'exif' ) ) {
13 $this->markTestSkipped(
"PHP extension 'exif' is not loaded, skipping." );
30 if ( !is_string( $xmp ) || !is_array( $expected ) ) {
31 throw new Exception(
"Invalid data provided to " . __METHOD__ );
34 $reader->
parse( $xmp );
35 $this->assertEquals( $expected, $reader->getResults(), $info, 0.0000000001 );
39 $xmpPath = __DIR__ .
'/../../../data/xmp/';
47 [
'1',
'parseType=Resource test' ],
48 [
'2',
'Structure with mixed attribute and element props' ],
49 [
'3',
'Extra qualifiers (that should be ignored)' ],
50 [
'3-invalid',
'Test ignoring qualifiers that look like normal props' ],
51 [
'4',
'Flash as qualifier' ],
52 [
'5',
'Flash as qualifier 2' ],
53 [
'6',
'Multiple rdf:Description' ],
54 [
'7',
'Generic test of several property types' ],
55 [
'flash',
'Test of Flash property' ],
56 [
'invalid-child-not-struct',
'Test child props not in struct or ignored' ],
57 [
'no-recognized-props',
'Test namespace and no recognized props' ],
58 [
'no-namespace',
'Test non-namespaced attributes are ignored' ],
59 [
'bag-for-seq',
"Allow bag's instead of seq's. (T29105)" ],
60 [
'utf16BE',
'UTF-16BE encoding' ],
61 [
'utf16LE',
'UTF-16LE encoding' ],
62 [
'utf32BE',
'UTF-32BE encoding' ],
63 [
'utf32LE',
'UTF-32LE encoding' ],
64 [
'xmpExt',
'Extended XMP missing second part' ],
65 [
'gps',
'Handling of exif GPS parameters in XMP' ],
68 $xmpFiles[] = [
'doctype-included',
'XMP includes doctype' ];
70 foreach ( $xmpFiles as $file ) {
71 $xmp = file_get_contents( $xmpPath . $file[0] .
'.xmp' );
76 include $xmpPath . $file[0] .
'.result.php';
77 $data[] = [ $xmp,
$result,
'[' . $file[0] .
'.xmp] ' . $file[1] ];
92 $xmpPath = __DIR__ .
'/../../../data/xmp/';
93 $standardXMP = file_get_contents( $xmpPath .
'xmpExt.xmp' );
94 $extendedXMP = file_get_contents( $xmpPath .
'xmpExt2.xmp' );
96 $md5sum =
'28C74E0AC2D796886759006FBE2E57B7';
97 $length = pack(
'N', strlen( $extendedXMP ) );
98 $offset = pack(
'N', 0 );
99 $extendedPacket = $md5sum . $length . $offset . $extendedXMP;
102 $reader->parse( $standardXMP );
103 $reader->parseExtended( $extendedPacket );
104 $actual = $reader->getResults();
108 'DigitalZoomRatio' =>
'0/10',
114 $this->assertEquals( $expected, $actual );
124 $xmpPath = __DIR__ .
'/../../../data/xmp/';
125 $standardXMP = file_get_contents( $xmpPath .
'xmpExt.xmp' );
126 $extendedXMP = file_get_contents( $xmpPath .
'xmpExt2.xmp' );
128 $md5sum =
'28C74E0AC2D796886759006FBE2E57B9';
129 $length = pack(
'N', strlen( $extendedXMP ) );
130 $offset = pack(
'N', 0 );
131 $extendedPacket = $md5sum . $length . $offset . $extendedXMP;
134 $reader->parse( $standardXMP );
135 $reader->parseExtended( $extendedPacket );
136 $actual = $reader->getResults();
140 'DigitalZoomRatio' =>
'0/10',
145 $this->assertEquals( $expected, $actual );
155 $xmpPath = __DIR__ .
'/../../../data/xmp/';
156 $standardXMP = file_get_contents( $xmpPath .
'xmpExt.xmp' );
157 $extendedXMP = file_get_contents( $xmpPath .
'xmpExt2.xmp' );
159 $md5sum =
'28C74E0AC2D796886759006FBE2E57B7';
160 $length = pack(
'N', strlen( $extendedXMP ) );
161 $offset = pack(
'N', 2048 );
162 $extendedPacket = $md5sum . $length . $offset . $extendedXMP;
165 $reader->parse( $standardXMP );
166 $reader->parseExtended( $extendedPacket );
167 $actual = $reader->getResults();
171 'DigitalZoomRatio' =>
'0/10',
176 $this->assertEquals( $expected, $actual );
185 $xmpPath = __DIR__ .
'/../../../data/xmp/';
186 $file = fopen( $xmpPath .
'doctype-included.xmp',
'rb' );
190 $chunk = fread( $file, 10 );
191 $valid = $reader->parse( $chunk, feof( $file ) );
192 }
while ( !feof( $file ) );
193 $this->assertFalse( $valid,
'Check that doctype is detected in fragmented XML' );
196 $reader->getResults(),
197 'Check that doctype is detected in fragmented XML'
203 $file = fopen( $xmpPath .
'doctype-not-included.xmp',
'rb' );
207 $chunk = fread( $file, 10 );
208 $valid = $reader->parse( $chunk, feof( $file ) );
209 }
while ( !feof( $file ) );
212 'Check for false-positive detecting doctype in fragmented XML'
217 'DigitalZoomRatio' =>
'0/10',
221 $reader->getResults(),
222 'Check that doctype is detected in fragmented XML'
Class for reading xmp data containing properties relevant to images, and spitting out an array that F...
parse( $content, $allOfIt=true)
Main function to call to parse XMP.
testExtendedXMPWithWrongGUID()
This test has an extended XMP block with a wrong guid (md5sum) and thus should only return the Standa...
testExtendedXMPMissingPacket()
Have a high offset to simulate a missing packet, which should cause it to ignore the ExtendedXMP pack...
testExtendedXMP()
Test ExtendedXMP block support.
testCheckParseSafety()
Test for multi-section, hostile XML XMPReader::checkParseSafety.
testXMPParse( $xmp, $expected, $info)
Put XMP in, compare what comes out...
namespace being checked & $result