| 1 |
<?php |
| 2 |
|
| 3 |
use MediaWiki\MainConfigNames; |
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
class DjVuTest extends MediaWikiMediaTestCase { |
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
protected $handler; |
| 15 |
|
| 16 |
protected function setUp(): void { |
| 17 |
parent::setUp(); |
| 18 |
|
| 19 |
|
| 20 |
$djvuSupport = new DjVuSupport(); |
| 21 |
|
| 22 |
if ( !$djvuSupport->isEnabled() ) { |
| 23 |
$this->markTestSkipped( |
| 24 |
'This test needs the installation of the ddjvu, djvutoxml and djvudump tools' ); |
| 25 |
} |
| 26 |
|
| 27 |
$this->overrideConfigValue( MainConfigNames::DjvuUseBoxedCommand, true ); |
| 28 |
|
| 29 |
$this->handler = new DjVuHandler(); |
| 30 |
} |
| 31 |
|
| 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'] ); |
| 38 |
} |
| 39 |
|
| 40 |
public function testInvalidFile() { |
| 41 |
$this->assertEquals( |
| 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' |
| 46 |
); |
| 47 |
} |
| 48 |
|
| 49 |
public function testPageCount() { |
| 50 |
$file = $this->dataFile( 'LoremIpsum.djvu', 'image/x.djvu' ); |
| 51 |
$this->assertEquals( |
| 52 |
5, |
| 53 |
$this->handler->pageCount( $file ), |
| 54 |
'Test file LoremIpsum.djvu should be detected as containing 5 pages' |
| 55 |
); |
| 56 |
} |
| 57 |
|
| 58 |
public function testGetPageDimensions() { |
| 59 |
$file = $this->dataFile( 'LoremIpsum.djvu', 'image/x.djvu' ); |
| 60 |
$this->assertSame( |
| 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' |
| 64 |
); |
| 65 |
} |
| 66 |
|
| 67 |
public function testGetPageText() { |
| 68 |
$file = $this->dataFile( 'LoremIpsum.djvu', 'image/x.djvu' ); |
| 69 |
$this->assertSame( |
| 70 |
|
| 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'" |
| 74 |
); |
| 75 |
} |
| 76 |
} |