MediaWiki REL1_31
DjVuTest.php
Go to the documentation of this file.
1<?php
7
11 protected $handler;
12
13 protected function setUp() {
14 parent::setUp();
15
16 // cli tool setup
17 $djvuSupport = new DjVuSupport();
18
19 if ( !$djvuSupport->isEnabled() ) {
20 $this->markTestSkipped(
21 'This test needs the installation of the ddjvu, djvutoxml and djvudump tools' );
22 }
23
24 $this->handler = new DjVuHandler();
25 }
26
27 public function testGetImageSize() {
28 $this->assertArrayEquals(
29 [ 2480, 3508, 'DjVu', 'width="2480" height="3508"' ],
30 $this->handler->getImageSize( null, $this->filePath . '/LoremIpsum.djvu' ),
31 'Test file LoremIpsum.djvu should have a size of 2480 * 3508'
32 );
33 }
34
35 public function testInvalidFile() {
36 $this->assertEquals(
37 'a:1:{s:5:"error";s:25:"Error extracting metadata";}',
38 $this->handler->getMetadata( null, $this->filePath . '/some-nonexistent-file' ),
39 'Getting metadata for an inexistent file should return false'
40 );
41 }
42
43 public function testPageCount() {
44 $file = $this->dataFile( 'LoremIpsum.djvu', 'image/x.djvu' );
45 $this->assertEquals(
46 5,
47 $this->handler->pageCount( $file ),
48 'Test file LoremIpsum.djvu should be detected as containing 5 pages'
49 );
50 }
51
52 public function testGetPageDimensions() {
53 $file = $this->dataFile( 'LoremIpsum.djvu', 'image/x.djvu' );
54 $this->assertArrayEquals(
55 [ 2480, 3508 ],
56 $this->handler->getPageDimensions( $file, 1 ),
57 'Page 1 of test file LoremIpsum.djvu should have a size of 2480 * 3508'
58 );
59 }
60
61 public function testGetPageText() {
62 $file = $this->dataFile( 'LoremIpsum.djvu', 'image/x.djvu' );
63 $this->assertEquals(
64 "Lorem ipsum \n1 \n",
65 (string)$this->handler->getPageText( $file, 1 ),
66 "Text layer of page 1 of file LoremIpsum.djvu should be 'Lorem ipsum \n1 \n'"
67 );
68 }
69}
Handler for DjVu images.
Definition DjVu.php:29
Initialize and detect the DjVu files support.
Media DjVuHandler.
Definition DjVuTest.php:6
DjVuHandler $handler
Definition DjVuTest.php:11
testGetPageText()
Definition DjVuTest.php:61
testPageCount()
Definition DjVuTest.php:43
testGetImageSize()
Definition DjVuTest.php:27
testInvalidFile()
Definition DjVuTest.php:35
testGetPageDimensions()
Definition DjVuTest.php:52
Specificly for testing Media handlers.
dataFile( $name, $type=null)
Utility function: Get a new file object for a file on disk but not actually in db.
assertArrayEquals(array $expected, array $actual, $ordered=false, $named=false)
Assert that two arrays are equal.
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that probably a stub it is not rendered in wiki pages or galleries in category pages allow injecting custom HTML after the section Any uses of the hook need to handle escaping see BaseTemplate::getToolbox and BaseTemplate::makeListItem for details on the format of individual items inside of this array or by returning and letting standard HTTP rendering take place modifiable or by returning false and taking over the output modifiable modifiable after all normalizations have been except for the $wgMaxImageArea check set to true or false to override the $wgMaxImageArea check result gives extension the possibility to transform it themselves set to a MediaTransformOutput the error message to be returned in an array you should do so by altering $wgNamespaceProtection and $wgNamespaceContentModels outside the handler
Definition hooks.txt:930