Merge "DatabaseMssql: Don't duplicate body of makeList()"
[mediawiki.git] / tests / phpunit / includes / media / FormatMetadataTest.php
blob54758f9486261312da4b449fdf126485d8ffcec5
1 <?php
3 /**
4 * @group Media
5 */
6 class FormatMetadataTest extends MediaWikiMediaTestCase {
8 protected function setUp() {
9 parent::setUp();
11 $this->checkPHPExtension( 'exif' );
12 $this->setMwGlobals( 'wgShowEXIF', true );
15 /**
16 * @covers File::formatMetadata
18 public function testInvalidDate() {
19 $file = $this->dataFile( 'broken_exif_date.jpg', 'image/jpeg' );
21 // Throws an error if bug hit
22 $meta = $file->formatMetadata();
23 $this->assertNotEquals( false, $meta, 'Valid metadata extracted' );
25 // Find date exif entry
26 $this->assertArrayHasKey( 'visible', $meta );
27 $dateIndex = null;
28 foreach ( $meta['visible'] as $i => $data ) {
29 if ( $data['id'] == 'exif-datetimeoriginal' ) {
30 $dateIndex = $i;
33 $this->assertNotNull( $dateIndex, 'Date entry exists in metadata' );
34 $this->assertEquals( '0000:01:00 00:02:27',
35 $meta['visible'][$dateIndex]['value'],
36 'File with invalid date metadata (bug 29471)' );
39 /**
40 * @param string $filename
41 * @param int $expected Total image area
42 * @dataProvider provideFlattenArray
43 * @covers FormatMetadata::flattenArray
45 public function testFlattenArray( $vals, $type, $noHtml, $ctx, $expected ) {
46 $actual = FormatMetadata::flattenArray( $vals, $type, $noHtml, $ctx );
47 $this->assertEquals( $expected, $actual );
50 public static function provideFlattenArray() {
51 return array(
52 array(
53 array( 1, 2, 3 ), 'ul', false, false,
54 "<ul><li>1</li>\n<li>2</li>\n<li>3</li></ul>",
56 array(
57 array( 1, 2, 3 ), 'ol', false, false,
58 "<ol><li>1</li>\n<li>2</li>\n<li>3</li></ol>",
60 array(
61 array( 1, 2, 3 ), 'ul', true, false,
62 "\n*1\n*2\n*3",
64 array(
65 array( 1, 2, 3 ), 'ol', true, false,
66 "\n#1\n#2\n#3",
68 // TODO: more test cases
72 /**
73 * @param mixed $input
74 * @param mixed $output
75 * @dataProvider provideResolveMultivalueValue
76 * @covers FormatMetadata::resolveMultivalueValue
78 public function testResolveMultivalueValue( $input, $output ) {
79 $formatMetadata = new FormatMetadata();
80 $class = new ReflectionClass( 'FormatMetadata' );
81 $method = $class->getMethod( 'resolveMultivalueValue' );
82 $method->setAccessible( true );
83 $actualInput = $method->invoke( $formatMetadata, $input );
84 $this->assertEquals( $output, $actualInput );
87 public function provideResolveMultivalueValue() {
88 return array(
89 'nonArray' => array( 'foo', 'foo' ),
90 'multiValue' => array( array( 'first', 'second', 'third', '_type' => 'ol' ), 'first' ),
91 'noType' => array( array( 'first', 'second', 'third' ), 'first' ),
92 'typeFirst' => array( array( '_type' => 'ol', 'first', 'second', 'third' ), 'first' ),
93 'multilang' => array(
94 array( 'en' => 'first', 'de' => 'Erste', '_type' => 'lang' ),
95 array( 'en' => 'first', 'de' => 'Erste', '_type' => 'lang' ),
97 'multilang-multivalue' => array(
98 array( 'en' => array( 'first', 'second' ), 'de' => array( 'Erste', 'Zweite' ), '_type' => 'lang' ),
99 array( 'en' => 'first', 'de' => 'Erste', '_type' => 'lang' ),