MediaWiki  1.23.15
FormatMetadataTest.php
Go to the documentation of this file.
1 <?php
2 
4 
6  protected $backend;
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 
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 
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 }
FormatMetadataTest\$repo
FSRepo $repo
Definition: FormatMetadataTest.php:6
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
FSRepo
A repository for files accessible via the local filesystem.
Definition: FSRepo.php:33
FormatMetadataTest\$backend
FSFileBackend $backend
Definition: FormatMetadataTest.php:5
UnregisteredLocalFile
A file object referring to either a standalone local file, or a file in a local repository with no da...
Definition: UnregisteredLocalFile.php:36
FormatMetadataTest
Definition: FormatMetadataTest.php:3
FormatMetadataTest\dataFile
dataFile( $name, $type)
Definition: FormatMetadataTest.php:84
FormatMetadataTest\testInvalidDate
testInvalidDate()
@covers File::formatMetadata
Definition: FormatMetadataTest.php:30
MediaWikiTestCase\setMwGlobals
setMwGlobals( $pairs, $value=null)
Definition: MediaWikiTestCase.php:302
MediaWikiTestCase
Definition: MediaWikiTestCase.php:6
FormatMetadataTest\provideFlattenArray
static provideFlattenArray()
Definition: FormatMetadataTest.php:62
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
$name
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:336
$file
if(PHP_SAPI !='cli') $file
Definition: UtfNormalTest2.php:30
FSFileBackend
Class for a file system (FS) based file backend.
Definition: FSFileBackend.php:41
as
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
MediaWikiTestCase\checkPHPExtension
checkPHPExtension( $extName)
Check if $extName is a loaded PHP extension, will skip the test whenever it is not loaded.
Definition: MediaWikiTestCase.php:1005
FormatMetadataTest\testFlattenArray
testFlattenArray( $vals, $type, $noHtml, $ctx, $expected)
Definition: FormatMetadataTest.php:57
FormatMetadata\flattenArray
static flattenArray( $vals, $type='ul', $noHtml=false, $context=false)
Flatten an array, using the user language for any messages.
Definition: FormatMetadata.php:1018
FormatMetadataTest\setUp
setUp()
Definition: FormatMetadataTest.php:8
$type
$type
Definition: testCompression.php:46