7class XMPTest extends PHPUnit\Framework\TestCase {
9 use MediaWikiCoversValidator;
13 # Requires libxml to do XMP parsing
14 if ( !extension_loaded(
'exif' ) ) {
15 $this->markTestSkipped(
"PHP extension 'exif' is not loaded, skipping." );
32 if ( !is_string( $xmp ) || !is_array( $expected ) ) {
33 throw new Exception(
"Invalid data provided to " . __METHOD__ );
36 $reader->
parse( $xmp );
37 $this->assertEquals( $expected, $reader->getResults(), $info, 0.0000000001 );
41 $xmpPath = __DIR__ .
'/../../../data/xmp/';
49 [
'1',
'parseType=Resource test' ],
50 [
'2',
'Structure with mixed attribute and element props' ],
51 [
'3',
'Extra qualifiers (that should be ignored)' ],
52 [
'3-invalid',
'Test ignoring qualifiers that look like normal props' ],
53 [
'4',
'Flash as qualifier' ],
54 [
'5',
'Flash as qualifier 2' ],
55 [
'6',
'Multiple rdf:Description' ],
56 [
'7',
'Generic test of several property types' ],
57 [
'flash',
'Test of Flash property' ],
58 [
'invalid-child-not-struct',
'Test child props not in struct or ignored' ],
59 [
'no-recognized-props',
'Test namespace and no recognized props' ],
60 [
'no-namespace',
'Test non-namespaced attributes are ignored' ],
61 [
'bag-for-seq',
"Allow bag's instead of seq's. (T29105)" ],
62 [
'utf16BE',
'UTF-16BE encoding' ],
63 [
'utf16LE',
'UTF-16LE encoding' ],
64 [
'utf32BE',
'UTF-32BE encoding' ],
65 [
'utf32LE',
'UTF-32LE encoding' ],
66 [
'xmpExt',
'Extended XMP missing second part' ],
67 [
'gps',
'Handling of exif GPS parameters in XMP' ],
70 $xmpFiles[] = [
'doctype-included',
'XMP includes doctype' ];
72 foreach ( $xmpFiles as $file ) {
73 $xmp = file_get_contents( $xmpPath . $file[0] .
'.xmp' );
78 include $xmpPath . $file[0] .
'.result.php';
79 $data[] = [ $xmp,
$result,
'[' . $file[0] .
'.xmp] ' . $file[1] ];
94 $xmpPath = __DIR__ .
'/../../../data/xmp/';
95 $standardXMP = file_get_contents( $xmpPath .
'xmpExt.xmp' );
96 $extendedXMP = file_get_contents( $xmpPath .
'xmpExt2.xmp' );
98 $md5sum =
'28C74E0AC2D796886759006FBE2E57B7';
99 $length = pack(
'N', strlen( $extendedXMP ) );
100 $offset = pack(
'N', 0 );
101 $extendedPacket = $md5sum . $length . $offset . $extendedXMP;
104 $reader->parse( $standardXMP );
105 $reader->parseExtended( $extendedPacket );
106 $actual = $reader->getResults();
110 'DigitalZoomRatio' =>
'0/10',
116 $this->assertEquals( $expected, $actual );
126 $xmpPath = __DIR__ .
'/../../../data/xmp/';
127 $standardXMP = file_get_contents( $xmpPath .
'xmpExt.xmp' );
128 $extendedXMP = file_get_contents( $xmpPath .
'xmpExt2.xmp' );
130 $md5sum =
'28C74E0AC2D796886759006FBE2E57B9';
131 $length = pack(
'N', strlen( $extendedXMP ) );
132 $offset = pack(
'N', 0 );
133 $extendedPacket = $md5sum . $length . $offset . $extendedXMP;
136 $reader->parse( $standardXMP );
137 $reader->parseExtended( $extendedPacket );
138 $actual = $reader->getResults();
142 'DigitalZoomRatio' =>
'0/10',
147 $this->assertEquals( $expected, $actual );
157 $xmpPath = __DIR__ .
'/../../../data/xmp/';
158 $standardXMP = file_get_contents( $xmpPath .
'xmpExt.xmp' );
159 $extendedXMP = file_get_contents( $xmpPath .
'xmpExt2.xmp' );
161 $md5sum =
'28C74E0AC2D796886759006FBE2E57B7';
162 $length = pack(
'N', strlen( $extendedXMP ) );
163 $offset = pack(
'N', 2048 );
164 $extendedPacket = $md5sum . $length . $offset . $extendedXMP;
167 $reader->parse( $standardXMP );
168 $reader->parseExtended( $extendedPacket );
169 $actual = $reader->getResults();
173 'DigitalZoomRatio' =>
'0/10',
178 $this->assertEquals( $expected, $actual );
187 $xmpPath = __DIR__ .
'/../../../data/xmp/';
188 $file = fopen( $xmpPath .
'doctype-included.xmp',
'rb' );
192 $chunk = fread( $file, 10 );
193 $valid = $reader->parse( $chunk, feof( $file ) );
194 }
while ( !feof( $file ) );
195 $this->assertFalse( $valid,
'Check that doctype is detected in fragmented XML' );
198 $reader->getResults(),
199 'Check that doctype is detected in fragmented XML'
205 $file = fopen( $xmpPath .
'doctype-not-included.xmp',
'rb' );
209 $chunk = fread( $file, 10 );
210 $valid = $reader->parse( $chunk, feof( $file ) );
211 }
while ( !feof( $file ) );
214 'Check for false-positive detecting doctype in fragmented XML'
219 'DigitalZoomRatio' =>
'0/10',
223 $reader->getResults(),
224 '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