Debian Codegraph @

tests/phpunit/unit/includes/media/IPTCTest.php

raw symbols SCIP
1 <?php
2
3 /**
4 * @group Media
5 */
6 class IPTCTest extends \MediaWikiUnitTestCase {
7
8 /**
9 * @covers \IPTC::getCharset
10 */
11 public function testRecognizeUtf8() {
12 // utf-8 is the only one used in practise.
13 $res = IPTC::getCharset( "\x1b%G" );
14 $this->assertEquals( 'UTF-8', $res );
15 }
16
17 public static function provideParse() {
18 // $rawData, $expectedKeywords
19
20 // basically IPTC for keyword with value of 0xBC which is 1/4 in iso-8859-1
21 // This data doesn't specify a charset. We're supposed to guess
22 // (which basically means utf-8 if valid, windows 1252 (iso 8859-1) if not)
23 yield 'No charset 88591' => [
24 "Photoshop 3.0\08BIM\4\4\0\0\0\0\0\x06\x1c\x02\x19\x00\x01\xBC",
25 [ '¼' ]
26 ];
27
28 /* This one contains a sequence that's valid iso 8859-1 but not valid utf8 */
29 /* \xC3 = Ã, \xB8 = ¸ */
30 yield 'No charset 88591b' => [
31 "Photoshop 3.0\08BIM\4\4\0\0\0\0\0\x09\x1c\x02\x19\x00\x04\xC3\xC3\xC3\xB8",
32 [ 'ÃÃø' ]
33 ];
34
35 // Same as above, but forcing the charset to utf-8. What should happen is the
36 // first "\xC3\xC3" should be dropped as invalid, leaving \xC3\xB8, which is ø
37 yield 'Forced UTF but invalid' => [
38 "Photoshop 3.0\08BIM\4\4\0\0\0\0\0\x11\x1c\x02\x19\x00\x04\xC3\xC3\xC3\xB8"
39 . "\x1c\x01\x5A\x00\x03\x1B\x25\x47",
40 [ 'ø' ]
41 ];
42
43 yield 'No charset UTF8' => [
44 "Photoshop 3.0\08BIM\4\4\0\0\0\0\0\x07\x1c\x02\x19\x00\x02¼",
45 [ '¼' ]
46 ];
47
48 // Testing something that has 2 values for keyword
49 yield 'Multiple keywords (2)' => [
50 "Photoshop 3.0\08BIM\4\4" . /* identifier */
51 "\0\0\0\0\0\x0D" . /* length */
52 "\x1c\x02\x19\x00\x01\xBC" .
53 "\x1c\x02\x19\x00\x02\xBC\xBD",
54 [ '¼', '¼½' ]
55 ];
56
57 // This has the magic "\x1c\x01\x5A\x00\x03\x1B\x25\x47" which marks content as UTF8.
58 yield 'UTF8' => [
59 "Photoshop 3.0\08BIM\4\4\0\0\0\0\0\x0F\x1c\x02\x19\x00\x02¼\x1c\x01\x5A\x00\x03\x1B\x25\x47",
60 [ '¼' ]
61 ];
62 }
63
64 /**
65 * @covers \IPTC::parse
66 * @dataProvider provideParse
67 */
68 public function testIPTCParseUTF8( $rawData, $expectedKeywords ) {
69 $res = IPTC::parse( $rawData );
70 $this->assertEquals( $expectedKeywords, $res['Keywords'] );
71 }
72 }