mediawiki.api: Adopt async-await and assert.rejects() in various tests
[mediawiki.git] / tests / phpunit / includes / media / DjVuTest.php
bloba5c40d32073c9971dcf0ac205307af83c8c8de19
1 <?php
3 use MediaWiki\MainConfigNames;
5 /**
6 * @group Media
7 * @covers \DjVuHandler
8 */
9 class DjVuTest extends MediaWikiMediaTestCase {
11 /**
12 * @var DjVuHandler
14 protected $handler;
16 protected function setUp(): void {
17 parent::setUp();
19 // cli tool setup
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() {
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'
49 public function testPageCount() {
50 $file = $this->dataFile( 'LoremIpsum.djvu', 'image/x.djvu' );
51 $this->assertEquals(
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' );
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'
67 public function testGetPageText() {
68 $file = $this->dataFile( 'LoremIpsum.djvu', 'image/x.djvu' );
69 $this->assertSame(
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'"