follow-up r86169: unit tests for extraction of JPEG comment (COM) segments.
[lhc/web/wiklou.git] / tests / phpunit / includes / media / JpegMetadataExtractorTest.php
1 <?php
2 class JpegMetadataExtractorTest extends MediaWikiTestCase {
3
4 public function setUp() {
5 $this->filePath = dirname( __FILE__ ) . '/../../data/media/';
6 }
7
8 public function testUtf8Comment() {
9 $res = JpegMetadataExtractor::segmentSplitter( $this->filePath . 'jpeg-comment-utf.jpg' );
10 $this->assertEquals( array( 'UTF-8 JPEG Comment — ¼' ), $res['COM'] );
11 }
12 /** The file is iso-8859-1, but it should get auto converted */
13 public function testIso88591Comment() {
14 $res = JpegMetadataExtractor::segmentSplitter( $this->filePath . 'jpeg-comment-iso8859-1.jpg' );
15 $this->assertEquals( array( 'ISO-8859-1 JPEG Comment - ¼' ), $res['COM'] );
16 }
17 /** Comment values that are non-textual (random binary junk) should not be shown.
18 * The example test file has a comment with a 0x5 byte in it which is a control character
19 * and considered binary junk for our purposes.
20 */
21 public function testBinaryCommentStripped() {
22 $res = JpegMetadataExtractor::segmentSplitter( $this->filePath . 'jpeg-comment-binary.jpg' );
23 $this->assertEmpty( $res['COM'] );
24 }
25 /* Very rarely a file can have multiple comments.
26 * Order of comments is based on order inside the file.
27 */
28 public function testMultipleComment() {
29 $res = JpegMetadataExtractor::segmentSplitter( $this->filePath . 'jpeg-comment-multiple.jpg' );
30 $this->assertEquals( array( 'foo', 'bar' ), $res['COM'] );
31 }
32 }