MediaWiki  1.23.1
XMPTest.php
Go to the documentation of this file.
1 <?php
2 
6 class XMPTest extends MediaWikiTestCase {
7 
8  protected function setUp() {
9  parent::setUp();
10  $this->checkPHPExtension( 'exif' ); # Requires libxml to do XMP parsing
11  }
12 
25  public function testXMPParse( $xmp, $expected, $info ) {
26  if ( !is_string( $xmp ) || !is_array( $expected ) ) {
27  throw new Exception( "Invalid data provided to " . __METHOD__ );
28  }
29  $reader = new XMPReader;
30  $reader->parse( $xmp );
31  $this->assertEquals( $expected, $reader->getResults(), $info, 0.0000000001 );
32  }
33 
34  public static function provideXMPParse() {
35  $xmpPath = __DIR__ . '/../../data/xmp/';
36  $data = array();
37 
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.
42  $xmpFiles = array(
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' ),
62  );
63 
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
68  // file.
69  $result = null;
70  include $xmpPath . $file[0] . '.result.php';
71  $data[] = array( $xmp, $result, '[' . $file[0] . '.xmp] ' . $file[1] );
72  }
73 
74  return $data;
75  }
76 
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' );
89 
90  $md5sum = '28C74E0AC2D796886759006FBE2E57B7'; // of xmpExt2.xmp
91  $length = pack( 'N', strlen( $extendedXMP ) );
92  $offset = pack( 'N', 0 );
93  $extendedPacket = $md5sum . $length . $offset . $extendedXMP;
94 
95  $reader = new XMPReader();
96  $reader->parse( $standardXMP );
97  $reader->parseExtended( $extendedPacket );
98  $actual = $reader->getResults();
99 
100  $expected = array(
101  'xmp-exif' => array(
102  'DigitalZoomRatio' => '0/10',
103  'Flash' => 9,
104  'FNumber' => '2/10',
105  )
106  );
107 
108  $this->assertEquals( $expected, $actual );
109  }
110 
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' );
121 
122  $md5sum = '28C74E0AC2D796886759006FBE2E57B9'; // Note last digit.
123  $length = pack( 'N', strlen( $extendedXMP ) );
124  $offset = pack( 'N', 0 );
125  $extendedPacket = $md5sum . $length . $offset . $extendedXMP;
126 
127  $reader = new XMPReader();
128  $reader->parse( $standardXMP );
129  $reader->parseExtended( $extendedPacket );
130  $actual = $reader->getResults();
131 
132  $expected = array(
133  'xmp-exif' => array(
134  'DigitalZoomRatio' => '0/10',
135  'Flash' => 9,
136  )
137  );
138 
139  $this->assertEquals( $expected, $actual );
140  }
141 
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' );
152 
153  $md5sum = '28C74E0AC2D796886759006FBE2E57B7'; // of xmpExt2.xmp
154  $length = pack( 'N', strlen( $extendedXMP ) );
155  $offset = pack( 'N', 2048 );
156  $extendedPacket = $md5sum . $length . $offset . $extendedXMP;
157 
158  $reader = new XMPReader();
159  $reader->parse( $standardXMP );
160  $reader->parseExtended( $extendedPacket );
161  $actual = $reader->getResults();
162 
163  $expected = array(
164  'xmp-exif' => array(
165  'DigitalZoomRatio' => '0/10',
166  'Flash' => 9,
167  )
168  );
169 
170  $this->assertEquals( $expected, $actual );
171  }
172 }
XMPTest\provideXMPParse
static provideXMPParse()
Definition: XMPTest.php:34
$result
The index of the header message $result[1]=The index of the body text message $result[2 through n]=Parameters passed to body text message. Please note the header message cannot receive/use parameters. 'ImportHandleLogItemXMLTag':When parsing a XML tag in a log item. $reader:XMLReader object $logInfo:Array of information Return false to stop further processing of the tag 'ImportHandlePageXMLTag':When parsing a XML tag in a page. $reader:XMLReader object $pageInfo:Array of information Return false to stop further processing of the tag 'ImportHandleRevisionXMLTag':When parsing a XML tag in a page revision. $reader:XMLReader object $pageInfo:Array of page information $revisionInfo:Array of revision information Return false to stop further processing of the tag 'ImportHandleToplevelXMLTag':When parsing a top level XML tag. $reader:XMLReader object Return false to stop further processing of the tag 'ImportHandleUploadXMLTag':When parsing a XML tag in a file upload. $reader:XMLReader object $revisionInfo:Array of information Return false to stop further processing of the tag 'InfoAction':When building information to display on the action=info page. $context:IContextSource object & $pageInfo:Array of information 'InitializeArticleMaybeRedirect':MediaWiki check to see if title is a redirect. $title:Title object for the current page $request:WebRequest $ignoreRedirect:boolean to skip redirect check $target:Title/string of redirect target $article:Article object 'InterwikiLoadPrefix':When resolving if a given prefix is an interwiki or not. Return true without providing an interwiki to continue interwiki search. $prefix:interwiki prefix we are looking for. & $iwData:output array describing the interwiki with keys iw_url, iw_local, iw_trans and optionally iw_api and iw_wikiid. 'InternalParseBeforeSanitize':during Parser 's internalParse method just before the parser removes unwanted/dangerous HTML tags and after nowiki/noinclude/includeonly/onlyinclude and other processings. Ideal for syntax-extensions after template/parser function execution which respect nowiki and HTML-comments. & $parser:Parser object & $text:string containing partially parsed text & $stripState:Parser 's internal StripState object 'InternalParseBeforeLinks':during Parser 's internalParse method before links but after nowiki/noinclude/includeonly/onlyinclude and other processings. & $parser:Parser object & $text:string containing partially parsed text & $stripState:Parser 's internal StripState object 'InvalidateEmailComplete':Called after a user 's email has been invalidated successfully. $user:user(object) whose email is being invalidated 'IRCLineURL':When constructing the URL to use in an IRC notification. Callee may modify $url and $query, URL will be constructed as $url . $query & $url:URL to index.php & $query:Query string $rc:RecentChange object that triggered url generation 'IsFileCacheable':Override the result of Article::isFileCacheable()(if true) $article:article(object) being checked 'IsTrustedProxy':Override the result of wfIsTrustedProxy() $ip:IP being check $result:Change this value to override the result of wfIsTrustedProxy() 'IsUploadAllowedFromUrl':Override the result of UploadFromUrl::isAllowedUrl() $url:URL used to upload from & $allowed:Boolean indicating if uploading is allowed for given URL 'isValidEmailAddr':Override the result of User::isValidEmailAddr(), for instance to return false if the domain name doesn 't match your organization. $addr:The e-mail address entered by the user & $result:Set this and return false to override the internal checks 'isValidPassword':Override the result of User::isValidPassword() $password:The password entered by the user & $result:Set this and return false to override the internal checks $user:User the password is being validated for 'Language::getMessagesFileName':$code:The language code or the language we 're looking for a messages file for & $file:The messages file path, you can override this to change the location. 'LanguageGetNamespaces':Provide custom ordering for namespaces or remove namespaces. Do not use this hook to add namespaces. Use CanonicalNamespaces for that. & $namespaces:Array of namespaces indexed by their numbers 'LanguageGetMagic':DEPRECATED, use $magicWords in a file listed in $wgExtensionMessagesFiles instead. Use this to define synonyms of magic words depending of the language $magicExtensions:associative array of magic words synonyms $lang:language code(string) 'LanguageGetSpecialPageAliases':DEPRECATED, use $specialPageAliases in a file listed in $wgExtensionMessagesFiles instead. Use to define aliases of special pages names depending of the language $specialPageAliases:associative array of magic words synonyms $lang:language code(string) 'LanguageGetTranslatedLanguageNames':Provide translated language names. & $names:array of language code=> language name $code language of the preferred translations 'LanguageLinks':Manipulate a page 's language links. This is called in various places to allow extensions to define the effective language links for a page. $title:The page 's Title. & $links:Associative array mapping language codes to prefixed links of the form "language:title". & $linkFlags:Associative array mapping prefixed links to arrays of flags. Currently unused, but planned to provide support for marking individual language links in the UI, e.g. for featured articles. 'LinkBegin':Used when generating internal and interwiki links in Linker::link(), before processing starts. Return false to skip default processing and return $ret. See documentation for Linker::link() for details on the expected meanings of parameters. $skin:the Skin object $target:the Title that the link is pointing to & $html:the contents that the< a > tag should have(raw HTML) $result
Definition: hooks.txt:1528
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
XMPTest\testExtendedXMP
testExtendedXMP()
Test ExtendedXMP block support.
Definition: XMPTest.php:85
XMPTest\testXMPParse
testXMPParse( $xmp, $expected, $info)
Put XMP in, compare what comes out...
Definition: XMPTest.php:25
XMPTest\setUp
setUp()
Definition: XMPTest.php:8
MediaWikiTestCase
Definition: MediaWikiTestCase.php:6
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
XMPTest\testExtendedXMPWithWrongGUID
testExtendedXMPWithWrongGUID()
This test has an extended XMP block with a wrong guid (md5sum) and thus should only return the Standa...
Definition: XMPTest.php:117
XMPTest\testExtendedXMPMissingPacket
testExtendedXMPMissingPacket()
Have a high offset to simulate a missing packet, which should cause it to ignore the ExtendedXMP pack...
Definition: XMPTest.php:148
XMPTest
Definition: XMPTest.php:6
XMPReader
Class for reading xmp data containing properties relevant to images, and spitting out an array that F...
Definition: XMP.php:49
XMPReader\parse
parse( $content, $allOfIt=true, $reset=false)
Main function to call to parse XMP.
Definition: XMP.php:252
$file
if(PHP_SAPI !='cli') $file
Definition: UtfNormalTest2.php:30
as
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
MediaWikiTestCase\checkPHPExtension
checkPHPExtension( $extName)
Check if $extName is a loaded PHP extension, will skip the test whenever it is not loaded.
Definition: MediaWikiTestCase.php:1005