MediaWiki  REL1_23
FormatMetadataTest.php
Go to the documentation of this file.
00001 <?php
00002 
00003 class FormatMetadataTest extends MediaWikiTestCase {
00004 
00006     protected $backend;
00008     protected $repo;
00009 
00010     protected function setUp() {
00011         parent::setUp();
00012 
00013         $this->checkPHPExtension( 'exif' );
00014         $filePath = __DIR__ . '/../../data/media';
00015         $this->backend = new FSFileBackend( array(
00016             'name' => 'localtesting',
00017             'wikiId' => wfWikiId(),
00018             'containerPaths' => array( 'data' => $filePath )
00019         ) );
00020         $this->repo = new FSRepo( array(
00021             'name' => 'temp',
00022             'url' => 'http://localhost/thumbtest',
00023             'backend' => $this->backend
00024         ) );
00025 
00026         $this->setMwGlobals( 'wgShowEXIF', true );
00027     }
00028 
00032     public function testInvalidDate() {
00033         $file = $this->dataFile( 'broken_exif_date.jpg', 'image/jpeg' );
00034 
00035         // Throws an error if bug hit
00036         $meta = $file->formatMetadata();
00037         $this->assertNotEquals( false, $meta, 'Valid metadata extracted' );
00038 
00039         // Find date exif entry
00040         $this->assertArrayHasKey( 'visible', $meta );
00041         $dateIndex = null;
00042         foreach ( $meta['visible'] as $i => $data ) {
00043             if ( $data['id'] == 'exif-datetimeoriginal' ) {
00044                 $dateIndex = $i;
00045             }
00046         }
00047         $this->assertNotNull( $dateIndex, 'Date entry exists in metadata' );
00048         $this->assertEquals( '0000:01:00 00:02:27',
00049             $meta['visible'][$dateIndex]['value'],
00050             'File with invalid date metadata (bug 29471)' );
00051     }
00052 
00059     public function testFlattenArray( $vals, $type, $noHtml, $ctx, $expected ) {
00060         $actual = FormatMetadata::flattenArray( $vals, $type, $noHtml, $ctx );
00061         $this->assertEquals( $expected, $actual );
00062     }
00063 
00064     public static function provideFlattenArray() {
00065         return array(
00066             array(
00067                 array( 1, 2, 3 ), 'ul', false, false,
00068                 "<ul><li>1</li>\n<li>2</li>\n<li>3</li></ul>",
00069             ),
00070             array(
00071                 array( 1, 2, 3 ), 'ol', false, false,
00072                 "<ol><li>1</li>\n<li>2</li>\n<li>3</li></ol>",
00073             ),
00074             array(
00075                 array( 1, 2, 3 ), 'ul', true, false,
00076                 "\n*1\n*2\n*3",
00077             ),
00078             array(
00079                 array( 1, 2, 3 ), 'ol', true, false,
00080                 "\n#1\n#2\n#3",
00081             ),
00082             // TODO: more test cases
00083         );
00084     }
00085 
00086     private function dataFile( $name, $type ) {
00087         return new UnregisteredLocalFile( false, $this->repo,
00088             "mwstore://localtesting/data/$name", $type );
00089     }
00090 }