MediaWiki  1.23.1
GIFTest.php
Go to the documentation of this file.
1 <?php
3 
5  protected $backend;
7  protected $handler;
9  protected $repo;
11  protected $filePath;
12 
13  protected function setUp() {
14  parent::setUp();
15 
16  $this->filePath = __DIR__ . '/../../data/media';
17  $this->backend = new FSFileBackend( array(
18  'name' => 'localtesting',
19  'wikiId' => wfWikiId(),
20  'containerPaths' => array( 'data' => $this->filePath )
21  ) );
22  $this->repo = new FSRepo( array(
23  'name' => 'temp',
24  'url' => 'http://localhost/thumbtest',
25  'backend' => $this->backend
26  ) );
27  $this->handler = new GIFHandler();
28  }
29 
33  public function testInvalidFile() {
34  $res = $this->handler->getMetadata( null, $this->filePath . '/README' );
35  $this->assertEquals( GIFHandler::BROKEN_FILE, $res );
36  }
37 
44  public function testIsAnimanted( $filename, $expected ) {
45  $file = $this->dataFile( $filename, 'image/gif' );
46  $actual = $this->handler->isAnimatedImage( $file );
47  $this->assertEquals( $expected, $actual );
48  }
49 
50  public static function provideIsAnimated() {
51  return array(
52  array( 'animated.gif', true ),
53  array( 'nonanimated.gif', false ),
54  );
55  }
56 
63  public function testGetImageArea( $filename, $expected ) {
64  $file = $this->dataFile( $filename, 'image/gif' );
65  $actual = $this->handler->getImageArea( $file, $file->getWidth(), $file->getHeight() );
66  $this->assertEquals( $expected, $actual );
67  }
68 
69  public static function provideGetImageArea() {
70  return array(
71  array( 'animated.gif', 5400 ),
72  array( 'nonanimated.gif', 1350 ),
73  );
74  }
75 
82  public function testIsMetadataValid( $metadata, $expected ) {
83  $actual = $this->handler->isMetadataValid( null, $metadata );
84  $this->assertEquals( $expected, $actual );
85  }
86 
87  public static function provideIsMetadataValid() {
88  return array(
92  array( 'Something invalid!', GIFHandler::METADATA_BAD ),
93  array( 'a:4:{s:10:"frameCount";i:1;s:6:"looped";b:0;s:8:"duration";d:0.1000000000000000055511151231257827021181583404541015625;s:8:"metadata";a:2:{s:14:"GIFFileComment";a:1:{i:0;s:35:"GIF test file ⁕ Created with GIMP";}s:15:"_MW_GIF_VERSION";i:1;}}', GIFHandler::METADATA_GOOD ),
94  );
95  }
96 
103  public function testGetMetadata( $filename, $expected ) {
104  $file = $this->dataFile( $filename, 'image/gif' );
105  $actual = $this->handler->getMetadata( $file, "$this->filePath/$filename" );
106  $this->assertEquals( unserialize( $expected ), unserialize( $actual ) );
107  }
108 
109  public static function provideGetMetadata() {
110  return array(
111  array( 'nonanimated.gif', 'a:4:{s:10:"frameCount";i:1;s:6:"looped";b:0;s:8:"duration";d:0.1000000000000000055511151231257827021181583404541015625;s:8:"metadata";a:2:{s:14:"GIFFileComment";a:1:{i:0;s:35:"GIF test file ⁕ Created with GIMP";}s:15:"_MW_GIF_VERSION";i:1;}}' ),
112  array( 'animated-xmp.gif', 'a:4:{s:10:"frameCount";i:4;s:6:"looped";b:1;s:8:"duration";d:2.399999999999999911182158029987476766109466552734375;s:8:"metadata";a:5:{s:6:"Artist";s:7:"Bawolff";s:16:"ImageDescription";a:2:{s:9:"x-default";s:18:"A file to test GIF";s:5:"_type";s:4:"lang";}s:15:"SublocationDest";s:13:"The interwebs";s:14:"GIFFileComment";a:1:{i:0;s:16:"GIƒ·test·file";}s:15:"_MW_GIF_VERSION";i:1;}}' ),
113  );
114  }
115 
122  public function testGetIndependentMetaArray( $filename, $expected ) {
123  $file = $this->dataFile( $filename, 'image/gif' );
124  $actual = $this->handler->getCommonMetaArray( $file );
125  $this->assertEquals( $expected, $actual );
126  }
127 
128  public function provideGetIndependentMetaArray() {
129  return array(
130  array( 'nonanimated.gif', array(
131  'GIFFileComment' => array(
132  'GIF test file ⁕ Created with GIMP',
133  ),
134  ) ),
135  array( 'animated-xmp.gif',
136  array(
137  'Artist' => 'Bawolff',
138  'ImageDescription' => array(
139  'x-default' => 'A file to test GIF',
140  '_type' => 'lang',
141  ),
142  'SublocationDest' => 'The interwebs',
143  'GIFFileComment' =>
144  array(
145  'GIƒ·test·file',
146  ),
147  )
148  ),
149  );
150  }
151 
152  private function dataFile( $name, $type ) {
153  return new UnregisteredLocalFile( false, $this->repo,
154  "mwstore://localtesting/data/$name", $type );
155  }
156 }
GIFHandlerTest\testGetImageArea
testGetImageArea( $filename, $expected)
Definition: GIFTest.php:59
GIFHandlerTest\testIsMetadataValid
testIsMetadataValid( $metadata, $expected)
Definition: GIFTest.php:78
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
GIFHandlerTest\testGetMetadata
testGetMetadata( $filename, $expected)
Definition: GIFTest.php:99
GIFHandlerTest\$repo
FSRepo $repo
Definition: GIFTest.php:6
FSRepo
A repository for files accessible via the local filesystem.
Definition: FSRepo.php:33
GIFHandlerTest\$filePath
string $filePath
Definition: GIFTest.php:7
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
GIFHandler
Handler for GIF images.
Definition: GIF.php:29
GIFHandlerTest\setUp
setUp()
Definition: GIFTest.php:9
GIFHandlerTest\dataFile
dataFile( $name, $type)
Definition: GIFTest.php:148
GIFHandlerTest\provideGetImageArea
static provideGetImageArea()
Definition: GIFTest.php:65
MediaWikiTestCase
Definition: MediaWikiTestCase.php:6
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
GIFHandlerTest\provideGetIndependentMetaArray
provideGetIndependentMetaArray()
Definition: GIFTest.php:124
$name
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:336
GIFHandlerTest\provideGetMetadata
static provideGetMetadata()
Definition: GIFTest.php:105
GIFHandlerTest\testInvalidFile
testInvalidFile()
@covers GIFHandler::getMetadata
Definition: GIFTest.php:29
GIFHandlerTest\testIsAnimanted
testIsAnimanted( $filename, $expected)
Definition: GIFTest.php:40
GIFHandler\BROKEN_FILE
const BROKEN_FILE
Definition: GIF.php:30
$file
if(PHP_SAPI !='cli') $file
Definition: UtfNormalTest2.php:30
GIFHandlerTest\testGetIndependentMetaArray
testGetIndependentMetaArray( $filename, $expected)
Definition: GIFTest.php:118
FSFileBackend
Class for a file system (FS) based file backend.
Definition: FSFileBackend.php:41
MediaHandler\METADATA_BAD
const METADATA_BAD
Definition: MediaHandler.php:32
GIFHandlerTest\provideIsAnimated
static provideIsAnimated()
Definition: GIFTest.php:46
$res
$res
Definition: database.txt:21
GIFHandlerTest\$backend
FSFileBackend $backend
Definition: GIFTest.php:4
GIFHandlerTest\$handler
GIFHandler $handler
Definition: GIFTest.php:5
GIFHandlerTest\provideIsMetadataValid
static provideIsMetadataValid()
Definition: GIFTest.php:83
MediaHandler\METADATA_GOOD
const METADATA_GOOD
Definition: MediaHandler.php:31
$type
$type
Definition: testCompression.php:46
GIFHandlerTest
Definition: GIFTest.php:2