Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F4106490
IPTCTest.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
IPTCTest.php
View Options
<?php
/**
* @group Media
*/
class
IPTCTest
extends
\MediaWikiUnitTestCase
{
/**
* @covers \IPTC::getCharset
*/
public
function
testRecognizeUtf8
()
{
// utf-8 is the only one used in practise.
$res
=
IPTC
::
getCharset
(
"
\x
1b%G"
);
$this
->
assertEquals
(
'UTF-8'
,
$res
);
}
public
static
function
provideParse
()
{
// $rawData, $expectedKeywords
// basically IPTC for keyword with value of 0xBC which is 1/4 in iso-8859-1
// This data doesn't specify a charset. We're supposed to guess
// (which basically means utf-8 if valid, windows 1252 (iso 8859-1) if not)
yield
'No charset 88591'
=>
[
"Photoshop 3.0
\0
8BIM
\4\4\0\0\0\0\0\x
06
\x
1c
\x
02
\x
19
\x
00
\x
01
\x
BC"
,
[
'¼'
]
];
/* This one contains a sequence that's valid iso 8859-1 but not valid utf8 */
/* \xC3 = Ã, \xB8 = ¸ */
yield
'No charset 88591b'
=>
[
"Photoshop 3.0
\0
8BIM
\4\4\0\0\0\0\0\x
09
\x
1c
\x
02
\x
19
\x
00
\x
04
\x
C3
\x
C3
\x
C3
\x
B8"
,
[
'ÃÃø'
]
];
// Same as above, but forcing the charset to utf-8. What should happen is the
// first "\xC3\xC3" should be dropped as invalid, leaving \xC3\xB8, which is ø
yield
'Forced UTF but invalid'
=>
[
"Photoshop 3.0
\0
8BIM
\4\4\0\0\0\0\0\x
11
\x
1c
\x
02
\x
19
\x
00
\x
04
\x
C3
\x
C3
\x
C3
\x
B8"
.
"
\x
1c
\x
01
\x
5A
\x
00
\x
03
\x
1B
\x
25
\x
47"
,
[
'ø'
]
];
yield
'No charset UTF8'
=>
[
"Photoshop 3.0
\0
8BIM
\4\4\0\0\0\0\0\x
07
\x
1c
\x
02
\x
19
\x
00
\x
02¼"
,
[
'¼'
]
];
// Testing something that has 2 values for keyword
yield
'Multiple keywords (2)'
=>
[
"Photoshop 3.0
\0
8BIM
\4\4
"
.
/* identifier */
"
\0\0\0\0\0\x
0D"
.
/* length */
"
\x
1c
\x
02
\x
19
\x
00
\x
01
\x
BC"
.
"
\x
1c
\x
02
\x
19
\x
00
\x
02
\x
BC
\x
BD"
,
[
'¼'
,
'¼½'
]
];
// This has the magic "\x1c\x01\x5A\x00\x03\x1B\x25\x47" which marks content as UTF8.
yield
'UTF8'
=>
[
"Photoshop 3.0
\0
8BIM
\4\4\0\0\0\0\0\x
0F
\x
1c
\x
02
\x
19
\x
00
\x
02¼
\x
1c
\x
01
\x
5A
\x
00
\x
03
\x
1B
\x
25
\x
47"
,
[
'¼'
]
];
}
/**
* @covers \IPTC::parse
* @dataProvider provideParse
*/
public
function
testIPTCParseUTF8
(
$rawData
,
$expectedKeywords
)
{
$res
=
IPTC
::
parse
(
$rawData
);
$this
->
assertEquals
(
$expectedKeywords
,
$res
[
'Keywords'
]
);
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Tue, Aug 18, 19:34 (2 w, 4 d ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
c3/d9/c50636b3624f215a36eb75c9f865
Default Alt Text
IPTCTest.php (2 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment