MediaWiki  master
FormatMetadataTest.php
Go to the documentation of this file.
1 <?php
2 
7 
8  protected function setUp() {
9  parent::setUp();
10 
11  $this->checkPHPExtension( 'exif' );
12  $this->setMwGlobals( 'wgShowEXIF', true );
13  }
14 
18  public function testInvalidDate() {
19  $file = $this->dataFile( 'broken_exif_date.jpg', 'image/jpeg' );
20 
21  // Throws an error if bug hit
22  $meta = $file->formatMetadata();
23  $this->assertNotEquals( false, $meta, 'Valid metadata extracted' );
24 
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;
31  }
32  }
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 (T31471)' );
37  }
38 
46  $formatMetadata = new FormatMetadata();
47  $class = new ReflectionClass( FormatMetadata::class );
48  $method = $class->getMethod( 'resolveMultivalueValue' );
49  $method->setAccessible( true );
50  $actualInput = $method->invoke( $formatMetadata, $input );
51  $this->assertEquals( $output, $actualInput );
52  }
53 
54  public function provideResolveMultivalueValue() {
55  return [
56  'nonArray' => [
57  'foo',
58  'foo'
59  ],
60  'multiValue' => [
61  [ 'first', 'second', 'third', '_type' => 'ol' ],
62  'first'
63  ],
64  'noType' => [
65  [ 'first', 'second', 'third' ],
66  'first'
67  ],
68  'typeFirst' => [
69  [ '_type' => 'ol', 'first', 'second', 'third' ],
70  'first'
71  ],
72  'multilang' => [
73  [
74  'en' => 'first',
75  'de' => 'Erste',
76  '_type' => 'lang'
77  ],
78  [
79  'en' => 'first',
80  'de' => 'Erste',
81  '_type' => 'lang'
82  ],
83  ],
84  'multilang-multivalue' => [
85  [
86  'en' => [ 'first', 'second' ],
87  'de' => [ 'Erste', 'Zweite' ],
88  '_type' => 'lang'
89  ],
90  [
91  'en' => 'first',
92  'de' => 'Erste',
93  '_type' => 'lang'
94  ],
95  ],
96  ];
97  }
98 
105  public function testGetFormattedData( $input, $output ) {
106  $this->assertEquals( $output, FormatMetadata::getFormattedData( $input ) );
107  }
108 
109  public function provideGetFormattedData() {
110  return [
111  [
112  [ 'Software' => 'Adobe Photoshop CS6 (Macintosh)' ],
113  [ 'Software' => 'Adobe Photoshop CS6 (Macintosh)' ],
114  ],
115  [
116  [ 'Software' => [ 'FotoWare FotoStation' ] ],
117  [ 'Software' => 'FotoWare FotoStation' ],
118  ],
119  [
120  [ 'Software' => [ [ 'Capture One PRO', '3.7.7' ] ] ],
121  [ 'Software' => 'Capture One PRO (Version 3.7.7)' ],
122  ],
123  [
124  [ 'Software' => [ [ 'FotoWare ColorFactory', '' ] ] ],
125  [ 'Software' => 'FotoWare ColorFactory (Version )' ],
126  ],
127  [
128  [ 'Software' => [ 'x-default' => 'paint.net 4.0.12', '_type' => 'lang' ] ],
129  [ 'Software' => '<ul class="metadata-langlist">' .
130  '<li class="mw-metadata-lang-default">' .
131  '<span class="mw-metadata-lang-value">paint.net 4.0.12</span>' .
132  "</li>\n" .
133  '</ul>'
134  ],
135  ],
136  [
137  // https://phabricator.wikimedia.org/T178130
138  // WebMHandler.php turns both 'muxingapp' & 'writingapp' to 'Software'
139  [ 'Software' => [ [ 'Lavf57.25.100' ], [ 'Lavf57.25.100' ] ] ],
140  [ 'Software' => "<ul><li>Lavf57.25.100</li>\n<li>Lavf57.25.100</li></ul>" ],
141  ],
142  ];
143  }
144 }
static getFormattedData( $tags, $context=false)
Numbers given by Exif user agents are often magical, that is they should be replaced by a detailed ex...
if(is_array( $mode)) switch( $mode) $input
if(PHP_SAPI !='cli-server') if(!isset( $_SERVER['SCRIPT_FILENAME'])) $file
Definition: router.php:42
Format Image metadata values into a human readable form.
static configuration should be added through ResourceLoaderGetConfigVars instead can be used to get the real title e g db for database replication lag or jobqueue for job queue size converted to pseudo seconds It is possible to add more fields and they will be returned to the user in the API response after the basic globals have been set but before ordinary actions take place $output
Definition: hooks.txt:2204
dataFile( $name, $type=false)
Utility function: Get a new file object for a file on disk but not actually in db.
testInvalidDate()
File::formatMetadata.
testGetFormattedData( $input, $output)
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that When $user is not null
Definition: hooks.txt:767
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
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
testResolveMultivalueValue( $input, $output)
you have access to all of the normal MediaWiki so you can get a DB use the etc For full docs on the Maintenance class
Definition: maintenance.txt:52
Specificly for testing Media handlers.