5 class DjVuTest
extends MediaWikiTestCase
{
8 * @var string the directory where test files are
13 * @var FSRepo the repository to use
22 protected function setUp() {
23 global $wgDjvuRenderer, $wgDjvuDump, $wgDjvuToXML;
27 $wgDjvuRenderer = $wgDjvuRenderer ?
$wgDjvuRenderer : '/usr/bin/ddjvu';
28 $wgDjvuDump = $wgDjvuDump ?
$wgDjvuDump : '/usr/bin/djvudump';
29 $wgDjvuToXML = $wgDjvuToXML ?
$wgDjvuToXML : '/usr/bin/djvutoxml';
31 !$this->checkIfToolExists( $wgDjvuRenderer ) ||
32 !$this->checkIfToolExists( $wgDjvuDump ) ||
33 !$this->checkIfToolExists( $wgDjvuToXML )
35 $this->markTestSkipped( 'This test needs the installation of the '
36 . 'ddjvu, djvutoxml and djvudump tools' );
40 $this->filePath
= __DIR__
. '/../../data/media/';
41 $backend = new FSFileBackend( array(
42 'name' => 'localtesting',
43 'wikiId' => wfWikiId(),
44 'lockManager' => new NullLockManager( array() ),
45 'containerPaths' => array( 'data' => $this->filePath
)
47 $this->repo
= new FSRepo( array(
49 'url' => 'http://localhost/thumbtest',
53 $this->handler
= new DjVuHandler();
57 * Check if a tool exist
59 * @param string $path path to the tool
62 protected function checkIfToolExists( $path ) {
64 $result = file_exists( $path );
69 protected function dataFile( $name, $type ) {
70 return new UnregisteredLocalFile(
73 'mwstore://localtesting/data/' . $name,
78 public function testGetImageSize() {
79 $this->assertArrayEquals(
80 array( 2480, 3508, 'DjVu', 'width="2480" height="3508"' ),
81 $this->handler
->getImageSize( null, $this->filePath
. '/LoremIpsum.djvu' ),
82 'Test file LoremIpsum.djvu should have a size of 2480 * 3508'
86 public function testInvalidFile() {
88 $this->handler
->getMetadata( null, $this->filePath
. '/README' ),
89 'Getting Metadata for an inexistent file should returns false'
93 public function testPageCount() {
94 $file = $this->dataFile( 'LoremIpsum.djvu', 'image/x.djvu' );
97 $this->handler
->pageCount( $file ),
98 'Test file LoremIpsum.djvu should be detected as containing 5 pages'
102 public function testGetPageDimensions() {
103 $file = $this->dataFile( 'LoremIpsum.djvu', 'image/x.djvu' );
104 $this->assertArrayEquals(
106 $this->handler
->getPageDimensions( $file, 1 ),
107 'Page 1 of test file LoremIpsum.djvu should have a size of 2480 * 3508'
111 public function testGetPageText() {
112 $file = $this->dataFile( 'LoremIpsum.djvu', 'image/x.djvu' );
114 "Lorem ipsum \n1 \n",
115 (string) $this->handler
->getPageText( $file, 1 ),
116 "Text layer of page 1 of file LoremIpsum.djvu should be 'Lorem ipsum \n1 \n'"