MediaWiki  1.23.12
PNGTest.php
Go to the documentation of this file.
1 <?php
3 
5  protected $handler;
7  protected $repo;
9  protected $backend;
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 PNGHandler();
28  }
29 
33  public function testInvalidFile() {
34  $res = $this->handler->getMetadata( null, $this->filePath . '/README' );
35  $this->assertEquals( PNGHandler::BROKEN_FILE, $res );
36  }
37 
44  public function testIsAnimanted( $filename, $expected ) {
45  $file = $this->dataFile( $filename, 'image/png' );
46  $actual = $this->handler->isAnimatedImage( $file );
47  $this->assertEquals( $expected, $actual );
48  }
49 
50  public static function provideIsAnimated() {
51  return array(
52  array( 'Animated_PNG_example_bouncing_beach_ball.png', true ),
53  array( '1bit-png.png', false ),
54  );
55  }
56 
63  public function testGetImageArea( $filename, $expected ) {
64  $file = $this->dataFile( $filename, 'image/png' );
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( '1bit-png.png', 2500 ),
72  array( 'greyscale-png.png', 2500 ),
73  array( 'Png-native-test.png', 126000 ),
74  array( 'Animated_PNG_example_bouncing_beach_ball.png', 10000 ),
75  );
76  }
77 
84  public function testIsMetadataValid( $metadata, $expected ) {
85  $actual = $this->handler->isMetadataValid( null, $metadata );
86  $this->assertEquals( $expected, $actual );
87  }
88 
89  public static function provideIsMetadataValid() {
90  return array(
94  array( 'Something invalid!', PNGHandler::METADATA_BAD ),
95  array( 'a:6:{s:10:"frameCount";i:0;s:9:"loopCount";i:1;s:8:"duration";d:0;s:8:"bitDepth";i:8;s:9:"colorType";s:10:"truecolour";s:8:"metadata";a:1:{s:15:"_MW_PNG_VERSION";i:1;}}', PNGHandler::METADATA_GOOD ),
96  );
97  }
98 
105  public function testGetMetadata( $filename, $expected ) {
106  $file = $this->dataFile( $filename, 'image/png' );
107  $actual = $this->handler->getMetadata( $file, "$this->filePath/$filename" );
108 // $this->assertEquals( unserialize( $expected ), unserialize( $actual ) );
109  $this->assertEquals( ( $expected ), ( $actual ) );
110  }
111 
112  public static function provideGetMetadata() {
113  return array(
114  array( 'rgb-na-png.png', 'a:6:{s:10:"frameCount";i:0;s:9:"loopCount";i:1;s:8:"duration";d:0;s:8:"bitDepth";i:8;s:9:"colorType";s:10:"truecolour";s:8:"metadata";a:1:{s:15:"_MW_PNG_VERSION";i:1;}}' ),
115  array( 'xmp.png', 'a:6:{s:10:"frameCount";i:0;s:9:"loopCount";i:1;s:8:"duration";d:0;s:8:"bitDepth";i:1;s:9:"colorType";s:14:"index-coloured";s:8:"metadata";a:2:{s:12:"SerialNumber";s:9:"123456789";s:15:"_MW_PNG_VERSION";i:1;}}' ),
116  );
117  }
118 
125  public function testGetIndependentMetaArray( $filename, $expected ) {
126  $file = $this->dataFile( $filename, 'image/png' );
127  $actual = $this->handler->getCommonMetaArray( $file );
128  $this->assertEquals( $expected, $actual );
129  }
130 
131  public function provideGetIndependentMetaArray() {
132  return array(
133  array( 'rgb-na-png.png', array() ),
134  array( 'xmp.png',
135  array(
136  'SerialNumber' => '123456789',
137  )
138  ),
139  );
140  }
141 
142  private function dataFile( $name, $type ) {
143  return new UnregisteredLocalFile( false, $this->repo,
144  "mwstore://localtesting/data/$name", $type );
145  }
146 }
PNGHandlerTest
Definition: PNGTest.php:2
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
PNGHandlerTest\provideGetImageArea
static provideGetImageArea()
Definition: PNGTest.php:65
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
PNGHandler\BROKEN_FILE
const BROKEN_FILE
Definition: PNG.php:30
PNGHandlerTest\provideGetMetadata
static provideGetMetadata()
Definition: PNGTest.php:108
PNGHandlerTest\testIsMetadataValid
testIsMetadataValid( $metadata, $expected)
Definition: PNGTest.php:80
PNGHandlerTest\testIsAnimanted
testIsAnimanted( $filename, $expected)
Definition: PNGTest.php:40
PNGHandlerTest\testInvalidFile
testInvalidFile()
@covers PNGHandler::getMetadata
Definition: PNGTest.php:29
PNGHandlerTest\provideIsMetadataValid
static provideIsMetadataValid()
Definition: PNGTest.php:85
PNGHandlerTest\$filePath
string $filePath
Definition: PNGTest.php:7
PNGHandlerTest\provideGetIndependentMetaArray
provideGetIndependentMetaArray()
Definition: PNGTest.php:127
PNGHandlerTest\setUp
setUp()
Definition: PNGTest.php:9
MediaWikiTestCase
Definition: MediaWikiTestCase.php:6
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
PNGHandlerTest\provideIsAnimated
static provideIsAnimated()
Definition: PNGTest.php:46
PNGHandler
Handler for PNG images.
Definition: PNG.php:29
PNGHandlerTest\$repo
FSRepo $repo
Definition: PNGTest.php:5
$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
PNGHandlerTest\testGetImageArea
testGetImageArea( $filename, $expected)
Definition: PNGTest.php:59
FSFileBackend
Class for a file system (FS) based file backend.
Definition: FSFileBackend.php:41
PNGHandlerTest\dataFile
dataFile( $name, $type)
Definition: PNGTest.php:138
PNGHandlerTest\testGetIndependentMetaArray
testGetIndependentMetaArray( $filename, $expected)
Definition: PNGTest.php:121
PNGHandlerTest\$backend
FSFileBackend $backend
Definition: PNGTest.php:6
MediaHandler\METADATA_BAD
const METADATA_BAD
Definition: MediaHandler.php:32
$res
$res
Definition: database.txt:21
PNGHandlerTest\testGetMetadata
testGetMetadata( $filename, $expected)
Definition: PNGTest.php:101
PNGHandlerTest\$handler
PNGHandler $handler
Definition: PNGTest.php:4
MediaHandler\METADATA_GOOD
const METADATA_GOOD
Definition: MediaHandler.php:31
$type
$type
Definition: testCompression.php:46