3 use MediaWiki\MainConfigNames
;
9 class DjVuTest
extends MediaWikiMediaTestCase
{
16 protected function setUp(): void
{
20 $djvuSupport = new DjVuSupport();
22 if ( !$djvuSupport->isEnabled() ) {
23 $this->markTestSkipped(
24 'This test needs the installation of the ddjvu, djvutoxml and djvudump tools' );
27 $this->overrideConfigValue( MainConfigNames
::DjvuUseBoxedCommand
, true );
29 $this->handler
= new DjVuHandler();
32 public function testGetSizeAndMetadata() {
33 $info = $this->handler
->getSizeAndMetadata(
34 new TrivialMediaHandlerState
, $this->filePath
. '/LoremIpsum.djvu' );
35 $this->assertSame( 2480, $info['width'] );
36 $this->assertSame( 3508, $info['height'] );
37 $this->assertIsArray( $info['metadata']['data'] );
40 public function testInvalidFile() {
42 [ 'metadata' => [ 'error' => 'Error extracting metadata' ] ],
43 $this->handler
->getSizeAndMetadata(
44 new TrivialMediaHandlerState
, $this->filePath
. '/some-nonexistent-file' ),
45 'Getting metadata for a nonexistent file should return false'
49 public function testPageCount() {
50 $file = $this->dataFile( 'LoremIpsum.djvu', 'image/x.djvu' );
53 $this->handler
->pageCount( $file ),
54 'Test file LoremIpsum.djvu should be detected as containing 5 pages'
58 public function testGetPageDimensions() {
59 $file = $this->dataFile( 'LoremIpsum.djvu', 'image/x.djvu' );
61 [ 'width' => 2480, 'height' => 3508 ],
62 $this->handler
->getPageDimensions( $file, 1 ),
63 'Page 1 of test file LoremIpsum.djvu should have a size of 2480 * 3508'
67 public function testGetPageText() {
68 $file = $this->dataFile( 'LoremIpsum.djvu', 'image/x.djvu' );
70 // note: this also tests that the column/paragraph is detected and converted
71 "Lorem ipsum \n\n1 \n",
72 $this->handler
->getPageText( $file, 1 ),
73 "Text layer of page 1 of file LoremIpsum.djvu should be 'Lorem ipsum \n\n1 \n'"