2013-11-30 09:41:26 +00:00
|
|
|
<?php
|
|
|
|
|
/**
|
2014-07-15 17:31:07 +00:00
|
|
|
* @group Media
|
2013-11-30 09:41:26 +00:00
|
|
|
* @covers DjVuHandler
|
|
|
|
|
*/
|
2014-05-26 20:16:07 +00:00
|
|
|
class DjVuTest extends MediaWikiMediaTestCase {
|
2013-11-30 09:41:26 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @var DjVuHandler
|
|
|
|
|
*/
|
|
|
|
|
protected $handler;
|
|
|
|
|
|
|
|
|
|
protected function setUp() {
|
|
|
|
|
parent::setUp();
|
|
|
|
|
|
2015-09-11 13:44:59 +00:00
|
|
|
// cli tool setup
|
2013-12-18 17:56:15 +00:00
|
|
|
$djvuSupport = new DjVuSupport();
|
|
|
|
|
|
|
|
|
|
if ( !$djvuSupport->isEnabled() ) {
|
2014-05-26 20:16:07 +00:00
|
|
|
$this->markTestSkipped(
|
|
|
|
|
'This test needs the installation of the ddjvu, djvutoxml and djvudump tools' );
|
2013-11-30 09:41:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->handler = new DjVuHandler();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testGetImageSize() {
|
|
|
|
|
$this->assertArrayEquals(
|
2016-02-17 09:09:32 +00:00
|
|
|
[ 2480, 3508, 'DjVu', 'width="2480" height="3508"' ],
|
2013-11-30 09:41:26 +00:00
|
|
|
$this->handler->getImageSize( null, $this->filePath . '/LoremIpsum.djvu' ),
|
|
|
|
|
'Test file LoremIpsum.djvu should have a size of 2480 * 3508'
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testInvalidFile() {
|
2014-05-23 00:00:21 +00:00
|
|
|
$this->assertEquals(
|
|
|
|
|
'a:1:{s:5:"error";s:25:"Error extracting metadata";}',
|
2014-07-15 17:31:07 +00:00
|
|
|
$this->handler->getMetadata( null, $this->filePath . '/some-nonexistent-file' ),
|
|
|
|
|
'Getting metadata for an inexistent file should return false'
|
2013-11-30 09:41:26 +00:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testPageCount() {
|
|
|
|
|
$file = $this->dataFile( 'LoremIpsum.djvu', 'image/x.djvu' );
|
|
|
|
|
$this->assertEquals(
|
|
|
|
|
5,
|
|
|
|
|
$this->handler->pageCount( $file ),
|
|
|
|
|
'Test file LoremIpsum.djvu should be detected as containing 5 pages'
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testGetPageDimensions() {
|
|
|
|
|
$file = $this->dataFile( 'LoremIpsum.djvu', 'image/x.djvu' );
|
|
|
|
|
$this->assertArrayEquals(
|
2016-02-17 09:09:32 +00:00
|
|
|
[ 2480, 3508 ],
|
2013-11-30 09:41:26 +00:00
|
|
|
$this->handler->getPageDimensions( $file, 1 ),
|
|
|
|
|
'Page 1 of test file LoremIpsum.djvu should have a size of 2480 * 3508'
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testGetPageText() {
|
|
|
|
|
$file = $this->dataFile( 'LoremIpsum.djvu', 'image/x.djvu' );
|
|
|
|
|
$this->assertEquals(
|
|
|
|
|
"Lorem ipsum \n1 \n",
|
2014-07-21 12:47:42 +00:00
|
|
|
(string)$this->handler->getPageText( $file, 1 ),
|
2013-11-30 09:41:26 +00:00
|
|
|
"Text layer of page 1 of file LoremIpsum.djvu should be 'Lorem ipsum \n1 \n'"
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|