1<?php 2/** 3 * @group Media 4 * @covers DjVuHandler 5 */ 6class DjVuTest extends MediaWikiMediaTestCase { 7 8 /** 9 * @var DjVuHandler 10 */ 11 protected $handler; 12 13 protected function setUp(): void { 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 testGetSizeAndMetadata() { 28 $info = $this->handler->getSizeAndMetadata( 29 new TrivialMediaHandlerState, $this->filePath . '/LoremIpsum.djvu' ); 30 $this->assertSame( 2480, $info['width'] ); 31 $this->assertSame( 3508, $info['height'] ); 32 $this->assertIsString( $info['metadata']['xml'] ); 33 } 34 35 public function testInvalidFile() { 36 $this->assertEquals( 37 [ 'metadata' => [ 'error' => 'Error extracting metadata' ] ], 38 $this->handler->getSizeAndMetadata( 39 new TrivialMediaHandlerState, $this->filePath . '/some-nonexistent-file' ), 40 'Getting metadata for a nonexistent file should return false' 41 ); 42 } 43 44 public function testPageCount() { 45 $file = $this->dataFile( 'LoremIpsum.djvu', 'image/x.djvu' ); 46 $this->assertEquals( 47 5, 48 $this->handler->pageCount( $file ), 49 'Test file LoremIpsum.djvu should be detected as containing 5 pages' 50 ); 51 } 52 53 public function testGetPageDimensions() { 54 $file = $this->dataFile( 'LoremIpsum.djvu', 'image/x.djvu' ); 55 $this->assertSame( 56 [ 'width' => 2480, 'height' => 3508 ], 57 $this->handler->getPageDimensions( $file, 1 ), 58 'Page 1 of test file LoremIpsum.djvu should have a size of 2480 * 3508' 59 ); 60 } 61 62 public function testGetPageText() { 63 $file = $this->dataFile( 'LoremIpsum.djvu', 'image/x.djvu' ); 64 $this->assertSame( 65 // note: this also tests that the column/paragraph is detected and converted 66 "Lorem ipsum \n\n1 \n", 67 $this->handler->getPageText( $file, 1 ), 68 "Text layer of page 1 of file LoremIpsum.djvu should be 'Lorem ipsum \n\n1 \n'" 69 ); 70 } 71} 72