MediaWiki  REL1_23
DjVuTest.php
Go to the documentation of this file.
00001 <?php
00005 class DjVuTest extends MediaWikiTestCase {
00006 
00010     protected $filePath;
00011 
00015     protected $repo;
00016 
00020     protected $handler;
00021 
00022     protected function setUp() {
00023         global $wgDjvuRenderer, $wgDjvuDump, $wgDjvuToXML;
00024         parent::setUp();
00025 
00026         //cli tool setup
00027         $wgDjvuRenderer = $wgDjvuRenderer ? $wgDjvuRenderer : '/usr/bin/ddjvu';
00028         $wgDjvuDump = $wgDjvuDump ? $wgDjvuDump : '/usr/bin/djvudump';
00029         $wgDjvuToXML = $wgDjvuToXML ? $wgDjvuToXML : '/usr/bin/djvutoxml';
00030         if (
00031             !$this->checkIfToolExists( $wgDjvuRenderer ) ||
00032             !$this->checkIfToolExists( $wgDjvuDump ) ||
00033             !$this->checkIfToolExists( $wgDjvuToXML )
00034         ) {
00035             $this->markTestSkipped( 'This test needs the installation of the ddjvu, djvutoxml and djvudump tools' );
00036         }
00037 
00038         //file repo setup
00039         $this->filePath = __DIR__ . '/../../data/media/';
00040         $backend = new FSFileBackend( array(
00041             'name' => 'localtesting',
00042             'wikiId' => wfWikiId(),
00043             'lockManager' => new NullLockManager( array() ),
00044             'containerPaths' => array( 'data' => $this->filePath )
00045         ) );
00046         $this->repo = new FSRepo( array(
00047             'name' => 'temp',
00048             'url' => 'http://localhost/thumbtest',
00049             'backend' => $backend
00050         ) );
00051 
00052         $this->handler = new DjVuHandler();
00053     }
00054 
00061     protected function checkIfToolExists( $path ) {
00062         wfSuppressWarnings();
00063         $result = file_exists( $path );
00064         wfRestoreWarnings();
00065         return $result;
00066     }
00067 
00068     protected function dataFile( $name, $type ) {
00069         return new UnregisteredLocalFile(
00070             false,
00071             $this->repo,
00072             'mwstore://localtesting/data/' . $name,
00073             $type
00074         );
00075     }
00076 
00077     public function testGetImageSize() {
00078         $this->assertArrayEquals(
00079             array( 2480, 3508, 'DjVu', 'width="2480" height="3508"' ),
00080             $this->handler->getImageSize( null, $this->filePath . '/LoremIpsum.djvu' ),
00081             'Test file LoremIpsum.djvu should have a size of 2480 * 3508'
00082         );
00083     }
00084 
00085     public function testInvalidFile() {
00086         $this->assertFalse(
00087             $this->handler->getMetadata( null, $this->filePath . '/README' ),
00088             'Getting Metadata for an inexistent file should returns false'
00089         );
00090     }
00091 
00092     public function testPageCount() {
00093         $file = $this->dataFile( 'LoremIpsum.djvu', 'image/x.djvu' );
00094         $this->assertEquals(
00095             5,
00096             $this->handler->pageCount( $file ),
00097             'Test file LoremIpsum.djvu should be detected as containing 5 pages'
00098         );
00099     }
00100 
00101     public function testGetPageDimensions() {
00102         $file = $this->dataFile( 'LoremIpsum.djvu', 'image/x.djvu' );
00103         $this->assertArrayEquals(
00104             array( 2480, 3508 ),
00105             $this->handler->getPageDimensions( $file, 1 ),
00106             'Page 1 of test file LoremIpsum.djvu should have a size of 2480 * 3508'
00107         );
00108     }
00109 
00110     public function testGetPageText() {
00111         $file = $this->dataFile( 'LoremIpsum.djvu', 'image/x.djvu' );
00112         $this->assertEquals(
00113             "Lorem ipsum \n1 \n",
00114             (string) $this->handler->getPageText( $file, 1 ),
00115             "Text layer of page 1 of file LoremIpsum.djvu should be 'Lorem ipsum \n1 \n'"
00116         );
00117     }
00118 }