MediaWiki
REL1_20
|
00001 <?php 00002 class XMPTest extends MediaWikiTestCase { 00003 00004 function setUp() { 00005 if ( !wfDl( 'xml' ) ) { 00006 $this->markTestSkipped( 'Requires libxml to do XMP parsing' ); 00007 } 00008 } 00009 00019 public function testXMPParse( $xmp, $expected, $info ) { 00020 if ( !is_string( $xmp ) || !is_array( $expected ) ) { 00021 throw new Exception( "Invalid data provided to " . __METHOD__ ); 00022 } 00023 $reader = new XMPReader; 00024 $reader->parse( $xmp ); 00025 $this->assertEquals( $expected, $reader->getResults(), $info, 0.0000000001 ); 00026 } 00027 00028 public function dataXMPParse() { 00029 $xmpPath = __DIR__ . '/../../data/xmp/' ; 00030 $data = array(); 00031 00032 // $xmpFiles format: array of arrays with first arg file base name, 00033 // with the actual file having .xmp on the end for the xmp 00034 // and .result.php on the end for a php file containing the result 00035 // array. Second argument is some info on what's being tested. 00036 $xmpFiles = array( 00037 array( '1', 'parseType=Resource test' ), 00038 array( '2', 'Structure with mixed attribute and element props' ), 00039 array( '3', 'Extra qualifiers (that should be ignored)' ), 00040 array( '3-invalid', 'Test ignoring qualifiers that look like normal props' ), 00041 array( '4', 'Flash as qualifier' ), 00042 array( '5', 'Flash as qualifier 2' ), 00043 array( '6', 'Multiple rdf:Description' ), 00044 array( '7', 'Generic test of several property types' ), 00045 array( 'flash', 'Test of Flash property' ), 00046 array( 'invalid-child-not-struct', 'Test child props not in struct or ignored' ), 00047 array( 'no-recognized-props', 'Test namespace and no recognized props' ), 00048 array( 'no-namespace', 'Test non-namespaced attributes are ignored' ), 00049 array( 'bag-for-seq', "Allow bag's instead of seq's. (bug 27105)" ), 00050 array( 'utf16BE', 'UTF-16BE encoding' ), 00051 array( 'utf16LE', 'UTF-16LE encoding' ), 00052 array( 'utf32BE', 'UTF-32BE encoding' ), 00053 array( 'utf32LE', 'UTF-32LE encoding' ), 00054 array( 'xmpExt', 'Extended XMP missing second part' ), 00055 array( 'gps', 'Handling of exif GPS parameters in XMP' ), 00056 ); 00057 foreach( $xmpFiles as $file ) { 00058 $xmp = file_get_contents( $xmpPath . $file[0] . '.xmp' ); 00059 // I'm not sure if this is the best way to handle getting the 00060 // result array, but it seems kind of big to put directly in the test 00061 // file. 00062 $result = null; 00063 include( $xmpPath . $file[0] . '.result.php' ); 00064 $data[] = array( $xmp, $result, '[' . $file[0] . '.xmp] ' . $file[1] ); 00065 } 00066 return $data; 00067 } 00068 00075 function testExtendedXMP() { 00076 $xmpPath = __DIR__ . '/../../data/xmp/'; 00077 $standardXMP = file_get_contents( $xmpPath . 'xmpExt.xmp' ); 00078 $extendedXMP = file_get_contents( $xmpPath . 'xmpExt2.xmp' ); 00079 00080 $md5sum = '28C74E0AC2D796886759006FBE2E57B7'; // of xmpExt2.xmp 00081 $length = pack( 'N', strlen( $extendedXMP ) ); 00082 $offset = pack( 'N', 0 ); 00083 $extendedPacket = $md5sum . $length . $offset . $extendedXMP; 00084 00085 $reader = new XMPReader(); 00086 $reader->parse( $standardXMP ); 00087 $reader->parseExtended( $extendedPacket ); 00088 $actual = $reader->getResults(); 00089 00090 $expected = array( 'xmp-exif' => 00091 array( 00092 'DigitalZoomRatio' => '0/10', 00093 'Flash' => 9, 00094 'FNumber' => '2/10', 00095 ) 00096 ); 00097 00098 $this->assertEquals( $expected, $actual ); 00099 } 00100 00105 function testExtendedXMPWithWrongGUID() { 00106 $xmpPath = __DIR__ . '/../../data/xmp/'; 00107 $standardXMP = file_get_contents( $xmpPath . 'xmpExt.xmp' ); 00108 $extendedXMP = file_get_contents( $xmpPath . 'xmpExt2.xmp' ); 00109 00110 $md5sum = '28C74E0AC2D796886759006FBE2E57B9'; // Note last digit. 00111 $length = pack( 'N', strlen( $extendedXMP ) ); 00112 $offset = pack( 'N', 0 ); 00113 $extendedPacket = $md5sum . $length . $offset . $extendedXMP; 00114 00115 $reader = new XMPReader(); 00116 $reader->parse( $standardXMP ); 00117 $reader->parseExtended( $extendedPacket ); 00118 $actual = $reader->getResults(); 00119 00120 $expected = array( 'xmp-exif' => 00121 array( 00122 'DigitalZoomRatio' => '0/10', 00123 'Flash' => 9, 00124 ) 00125 ); 00126 00127 $this->assertEquals( $expected, $actual ); 00128 } 00133 function testExtendedXMPMissingPacket() { 00134 $xmpPath = __DIR__ . '/../../data/xmp/'; 00135 $standardXMP = file_get_contents( $xmpPath . 'xmpExt.xmp' ); 00136 $extendedXMP = file_get_contents( $xmpPath . 'xmpExt2.xmp' ); 00137 00138 $md5sum = '28C74E0AC2D796886759006FBE2E57B7'; // of xmpExt2.xmp 00139 $length = pack( 'N', strlen( $extendedXMP ) ); 00140 $offset = pack( 'N', 2048 ); 00141 $extendedPacket = $md5sum . $length . $offset . $extendedXMP; 00142 00143 $reader = new XMPReader(); 00144 $reader->parse( $standardXMP ); 00145 $reader->parseExtended( $extendedPacket ); 00146 $actual = $reader->getResults(); 00147 00148 $expected = array( 'xmp-exif' => 00149 array( 00150 'DigitalZoomRatio' => '0/10', 00151 'Flash' => 9, 00152 ) 00153 ); 00154 00155 $this->assertEquals( $expected, $actual ); 00156 } 00157 00158 }