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