mediawiki.searchSuggest: Show full article title as a tooltip for each suggestion
[lhc/web/wiklou.git] / tests / phpunit / includes / media / FormatMetadataTest.php
1 <?php
2
3 class FormatMetadataTest extends MediaWikiTestCase {
4
5 /** @var FSFileBackend */
6 protected $backend;
7 /** @var FSRepo */
8 protected $repo;
9
10 protected function setUp() {
11 parent::setUp();
12
13 $this->checkPHPExtension( 'exif' );
14 $filePath = __DIR__ . '/../../data/media';
15 $this->backend = new FSFileBackend( array(
16 'name' => 'localtesting',
17 'wikiId' => wfWikiId(),
18 'containerPaths' => array( 'data' => $filePath )
19 ) );
20 $this->repo = new FSRepo( array(
21 'name' => 'temp',
22 'url' => 'http://localhost/thumbtest',
23 'backend' => $this->backend
24 ) );
25
26 $this->setMwGlobals( 'wgShowEXIF', true );
27 }
28
29 /**
30 * @covers File::formatMetadata
31 */
32 public function testInvalidDate() {
33 $file = $this->dataFile( 'broken_exif_date.jpg', 'image/jpeg' );
34
35 // Throws an error if bug hit
36 $meta = $file->formatMetadata();
37 $this->assertNotEquals( false, $meta, 'Valid metadata extracted' );
38
39 // Find date exif entry
40 $this->assertArrayHasKey( 'visible', $meta );
41 $dateIndex = null;
42 foreach ( $meta['visible'] as $i => $data ) {
43 if ( $data['id'] == 'exif-datetimeoriginal' ) {
44 $dateIndex = $i;
45 }
46 }
47 $this->assertNotNull( $dateIndex, 'Date entry exists in metadata' );
48 $this->assertEquals( '0000:01:00 00:02:27',
49 $meta['visible'][$dateIndex]['value'],
50 'File with invalid date metadata (bug 29471)' );
51 }
52
53 /**
54 * @param string $filename
55 * @param int $expected Total image area
56 * @dataProvider provideFlattenArray
57 * @covers FormatMetadata::flattenArray
58 */
59 public function testFlattenArray( $vals, $type, $noHtml, $ctx, $expected ) {
60 $actual = FormatMetadata::flattenArray( $vals, $type, $noHtml, $ctx );
61 $this->assertEquals( $expected, $actual );
62 }
63
64 public static function provideFlattenArray() {
65 return array(
66 array(
67 array( 1, 2, 3 ), 'ul', false, false,
68 "<ul><li>1</li>\n<li>2</li>\n<li>3</li></ul>",
69 ),
70 array(
71 array( 1, 2, 3 ), 'ol', false, false,
72 "<ol><li>1</li>\n<li>2</li>\n<li>3</li></ol>",
73 ),
74 array(
75 array( 1, 2, 3 ), 'ul', true, false,
76 "\n*1\n*2\n*3",
77 ),
78 array(
79 array( 1, 2, 3 ), 'ol', true, false,
80 "\n#1\n#2\n#3",
81 ),
82 // TODO: more test cases
83 );
84 }
85
86 private function dataFile( $name, $type ) {
87 return new UnregisteredLocalFile( false, $this->repo,
88 "mwstore://localtesting/data/$name", $type );
89 }
90 }