Merge "Update list item newline handling to follow Parsoid's model"
[lhc/web/wiklou.git] / tests / phpunit / includes / media / FormatMetadataTest.php
1 <?php
2
3 class FormatMetadataTest extends MediaWikiMediaTestCase {
4
5 protected function setUp() {
6 parent::setUp();
7
8 $this->checkPHPExtension( 'exif' );
9 $this->setMwGlobals( 'wgShowEXIF', true );
10 }
11
12 /**
13 * @covers File::formatMetadata
14 */
15 public function testInvalidDate() {
16 $file = $this->dataFile( 'broken_exif_date.jpg', 'image/jpeg' );
17
18 // Throws an error if bug hit
19 $meta = $file->formatMetadata();
20 $this->assertNotEquals( false, $meta, 'Valid metadata extracted' );
21
22 // Find date exif entry
23 $this->assertArrayHasKey( 'visible', $meta );
24 $dateIndex = null;
25 foreach ( $meta['visible'] as $i => $data ) {
26 if ( $data['id'] == 'exif-datetimeoriginal' ) {
27 $dateIndex = $i;
28 }
29 }
30 $this->assertNotNull( $dateIndex, 'Date entry exists in metadata' );
31 $this->assertEquals( '0000:01:00 00:02:27',
32 $meta['visible'][$dateIndex]['value'],
33 'File with invalid date metadata (bug 29471)' );
34 }
35
36 /**
37 * @param string $filename
38 * @param int $expected Total image area
39 * @dataProvider provideFlattenArray
40 * @covers FormatMetadata::flattenArray
41 */
42 public function testFlattenArray( $vals, $type, $noHtml, $ctx, $expected ) {
43 $actual = FormatMetadata::flattenArray( $vals, $type, $noHtml, $ctx );
44 $this->assertEquals( $expected, $actual );
45 }
46
47 public static function provideFlattenArray() {
48 return array(
49 array(
50 array( 1, 2, 3 ), 'ul', false, false,
51 "<ul><li>1</li>\n<li>2</li>\n<li>3</li></ul>",
52 ),
53 array(
54 array( 1, 2, 3 ), 'ol', false, false,
55 "<ol><li>1</li>\n<li>2</li>\n<li>3</li></ol>",
56 ),
57 array(
58 array( 1, 2, 3 ), 'ul', true, false,
59 "\n*1\n*2\n*3",
60 ),
61 array(
62 array( 1, 2, 3 ), 'ol', true, false,
63 "\n#1\n#2\n#3",
64 ),
65 // TODO: more test cases
66 );
67 }
68 }