MediaWiki  1.30.0
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 }
MediaWikiTestCase\assertArrayEquals
assertArrayEquals(array $expected, array $actual, $ordered=false, $named=false)
Assert that two arrays are equal.
Definition: MediaWikiTestCase.php:1552
DjVuTest\testGetPageText
testGetPageText()
Definition: DjVuTest.php:61
DjVuTest\testGetImageSize
testGetImageSize()
Definition: DjVuTest.php:27
DjVuTest\testInvalidFile
testInvalidFile()
Definition: DjVuTest.php:35
DjVuTest
Media DjVuHandler.
Definition: DjVuTest.php:6
php
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
MediaWikiMediaTestCase
Specificly for testing Media handlers.
Definition: MediaWikiMediaTestCase.php:5
handler
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:781
DjVuTest\$handler
DjVuHandler $handler
Definition: DjVuTest.php:11
DjVuTest\testGetPageDimensions
testGetPageDimensions()
Definition: DjVuTest.php:52
MediaWikiMediaTestCase\dataFile
dataFile( $name, $type=null)
Utility function: Get a new file object for a file on disk but not actually in db.
Definition: MediaWikiMediaTestCase.php:76
DjVuSupport
Initialize and detect the DjVu files support.
Definition: DjVuSupport.php:26
DjVuHandler
Handler for DjVu images.
Definition: DjVu.php:29
DjVuTest\setUp
setUp()
Definition: DjVuTest.php:13
DjVuTest\testPageCount
testPageCount()
Definition: DjVuTest.php:43