2011-06-19 21:38:58 +00:00
|
|
|
<?php
|
2013-10-23 22:12:39 +00:00
|
|
|
|
2011-06-19 21:38:58 +00:00
|
|
|
class FormatMetadataTest extends MediaWikiTestCase {
|
2012-10-08 10:56:20 +00:00
|
|
|
|
2013-10-23 22:12:39 +00:00
|
|
|
/** @var FSFileBackend */
|
|
|
|
|
protected $backend;
|
|
|
|
|
/** @var FSRepo */
|
|
|
|
|
protected $repo;
|
|
|
|
|
|
2012-10-08 10:56:20 +00:00
|
|
|
protected function setUp() {
|
|
|
|
|
parent::setUp();
|
|
|
|
|
|
2013-10-09 16:46:57 +00:00
|
|
|
if ( !extension_loaded( 'exif' ) ) {
|
2011-09-18 01:53:09 +00:00
|
|
|
$this->markTestSkipped( "This test needs the exif extension." );
|
2011-06-29 20:24:53 +00:00
|
|
|
}
|
2013-02-15 10:17:52 +00:00
|
|
|
$filePath = __DIR__ . '/../../data/media';
|
2011-12-20 03:52:06 +00:00
|
|
|
$this->backend = new FSFileBackend( array(
|
2013-02-15 10:17:52 +00:00
|
|
|
'name' => 'localtesting',
|
|
|
|
|
'lockManager' => 'nullLockManager',
|
2011-12-20 03:52:06 +00:00
|
|
|
'containerPaths' => array( 'data' => $filePath )
|
|
|
|
|
) );
|
|
|
|
|
$this->repo = new FSRepo( array(
|
2013-02-15 10:17:52 +00:00
|
|
|
'name' => 'temp',
|
|
|
|
|
'url' => 'http://localhost/thumbtest',
|
2011-12-20 03:52:06 +00:00
|
|
|
'backend' => $this->backend
|
|
|
|
|
) );
|
2012-10-08 10:56:20 +00:00
|
|
|
|
|
|
|
|
$this->setMwGlobals( 'wgShowEXIF', true );
|
2011-09-18 01:53:09 +00:00
|
|
|
}
|
|
|
|
|
|
2013-10-24 18:04:38 +00:00
|
|
|
/**
|
|
|
|
|
* @covers File::formatMetadata
|
|
|
|
|
*/
|
2011-09-18 01:53:09 +00:00
|
|
|
public function testInvalidDate() {
|
2011-12-20 03:52:06 +00:00
|
|
|
$file = $this->dataFile( 'broken_exif_date.jpg', 'image/jpeg' );
|
2013-02-15 10:17:52 +00:00
|
|
|
|
2011-06-19 21:38:58 +00:00
|
|
|
// Throws an error if bug hit
|
|
|
|
|
$meta = $file->formatMetadata();
|
2011-06-29 20:24:53 +00:00
|
|
|
$this->assertNotEquals( false, $meta, 'Valid metadata extracted' );
|
2013-02-15 10:17:52 +00:00
|
|
|
|
2011-06-19 21:38:58 +00:00
|
|
|
// Find date exif entry
|
|
|
|
|
$this->assertArrayHasKey( 'visible', $meta );
|
|
|
|
|
$dateIndex = null;
|
|
|
|
|
foreach ( $meta['visible'] as $i => $data ) {
|
|
|
|
|
if ( $data['id'] == 'exif-datetimeoriginal' ) {
|
|
|
|
|
$dateIndex = $i;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$this->assertNotNull( $dateIndex, 'Date entry exists in metadata' );
|
2013-02-15 10:17:52 +00:00
|
|
|
$this->assertEquals( '0000:01:00 00:02:27',
|
2011-06-19 21:38:58 +00:00
|
|
|
$meta['visible'][$dateIndex]['value'],
|
|
|
|
|
'File with invalid date metadata (bug 29471)' );
|
|
|
|
|
}
|
2011-12-20 03:52:06 +00:00
|
|
|
|
2013-08-07 23:03:34 +00:00
|
|
|
/**
|
|
|
|
|
* @param $filename String
|
|
|
|
|
* @param $expected Integer Total image area
|
|
|
|
|
* @dataProvider provideFlattenArray
|
|
|
|
|
* @covers FormatMetadata::flattenArray
|
|
|
|
|
*/
|
|
|
|
|
public function testFlattenArray( $vals, $type, $noHtml, $ctx, $expected ) {
|
|
|
|
|
$actual = FormatMetadata::flattenArray( $vals, $type, $noHtml, $ctx );
|
|
|
|
|
$this->assertEquals( $expected, $actual );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static function provideFlattenArray() {
|
|
|
|
|
return array(
|
|
|
|
|
array (
|
|
|
|
|
array(1 ,2 ,3), 'ul', false, false,
|
|
|
|
|
"<ul><li>1</li>\n<li>2</li>\n<li>3</li></ul>",
|
|
|
|
|
),
|
|
|
|
|
array (
|
|
|
|
|
array(1 ,2 ,3), 'ol', false, false,
|
|
|
|
|
"<ol><li>1</li>\n<li>2</li>\n<li>3</li></ol>",
|
|
|
|
|
),
|
|
|
|
|
array (
|
|
|
|
|
array(1 ,2 ,3), 'ul', true, false,
|
|
|
|
|
"\n*1\n*2\n*3",
|
|
|
|
|
),
|
|
|
|
|
array (
|
|
|
|
|
array(1 ,2 ,3), 'ol', true, false,
|
|
|
|
|
"\n#1\n#2\n#3",
|
|
|
|
|
),
|
|
|
|
|
// TODO: more test cases
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2011-12-20 03:52:06 +00:00
|
|
|
private function dataFile( $name, $type ) {
|
|
|
|
|
return new UnregisteredLocalFile( false, $this->repo,
|
|
|
|
|
"mwstore://localtesting/data/$name", $type );
|
|
|
|
|
}
|
2011-07-20 15:35:48 +00:00
|
|
|
}
|