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 ddjvu, djvutoxml and djvudump tools' );
39 $this->filePath
= __DIR__
. '/../../data/media/';
40 $backend = new FSFileBackend( array(
41 'name' => 'localtesting',
42 'wikiId' => wfWikiId(),
43 'lockManager' => new NullLockManager( array() ),
44 'containerPaths' => array( 'data' => $this->filePath
)
46 $this->repo
= new FSRepo( array(
48 'url' => 'http://localhost/thumbtest',
52 $this->handler
= new DjVuHandler();
56 * Check if a tool exist
58 * @param string $path path to the tool
61 protected function checkIfToolExists( $path ) {
63 $result = file_exists( $path );
68 protected function dataFile( $name, $type ) {
69 return new UnregisteredLocalFile(
72 'mwstore://localtesting/data/' . $name,
77 public function testGetImageSize() {
78 $this->assertArrayEquals(
79 array( 2480, 3508, 'DjVu', 'width="2480" height="3508"' ),
80 $this->handler
->getImageSize( null, $this->filePath
. '/LoremIpsum.djvu' ),
81 'Test file LoremIpsum.djvu should have a size of 2480 * 3508'
85 public function testInvalidFile() {
87 $this->handler
->getMetadata( null, $this->filePath
. '/README' ),
88 'Getting Metadata for an inexistent file should returns false'
92 public function testPageCount() {
93 $file = $this->dataFile( 'LoremIpsum.djvu', 'image/x.djvu' );
96 $this->handler
->pageCount( $file ),
97 'Test file LoremIpsum.djvu should be detected as containing 5 pages'
101 public function testGetPageDimensions() {
102 $file = $this->dataFile( 'LoremIpsum.djvu', 'image/x.djvu' );
103 $this->assertArrayEquals(
105 $this->handler
->getPageDimensions( $file, 1 ),
106 'Page 1 of test file LoremIpsum.djvu should have a size of 2480 * 3508'
110 public function testGetPageText() {
111 $file = $this->dataFile( 'LoremIpsum.djvu', 'image/x.djvu' );
113 "Lorem ipsum \n1 \n",
114 (string) $this->handler
->getPageText( $file, 1 ),
115 "Text layer of page 1 of file LoremIpsum.djvu should be 'Lorem ipsum \n1 \n'"