Addition of a parser test for page= parameter of image inclusion
[lhc/web/wiklou.git] / tests / phpunit / includes / media / DjVuTest.php
1 <?php
2 /**
3 * @covers DjVuHandler
4 */
5 class DjVuTest extends MediaWikiTestCase {
6
7 /**
8 * @var string the directory where test files are
9 */
10 protected $filePath;
11
12 /**
13 * @var FSRepo the repository to use
14 */
15 protected $repo;
16
17 /**
18 * @var DjVuHandler
19 */
20 protected $handler;
21
22 protected function setUp() {
23 parent::setUp();
24
25 //cli tool setup
26 $djvuSupport = new DjVuSupport();
27
28 if ( !$djvuSupport->isEnabled() ) {
29 $this->markTestSkipped( 'This test needs the installation of the ddjvu, djvutoxml and djvudump tools' );
30 }
31
32 //file repo setup
33 $this->filePath = __DIR__ . '/../../data/media/';
34 $backend = new FSFileBackend( array(
35 'name' => 'localtesting',
36 'wikiId' => wfWikiId(),
37 'lockManager' => new NullLockManager( array() ),
38 'containerPaths' => array( 'data' => $this->filePath )
39 ) );
40 $this->repo = new FSRepo( array(
41 'name' => 'temp',
42 'url' => 'http://localhost/thumbtest',
43 'backend' => $backend
44 ) );
45
46 $this->handler = new DjVuHandler();
47 }
48
49 protected function dataFile( $name, $type ) {
50 return new UnregisteredLocalFile(
51 false,
52 $this->repo,
53 'mwstore://localtesting/data/' . $name,
54 $type
55 );
56 }
57
58 public function testGetImageSize() {
59 $this->assertArrayEquals(
60 array( 2480, 3508, 'DjVu', 'width="2480" height="3508"' ),
61 $this->handler->getImageSize( null, $this->filePath . '/LoremIpsum.djvu' ),
62 'Test file LoremIpsum.djvu should have a size of 2480 * 3508'
63 );
64 }
65
66 public function testInvalidFile() {
67 $this->assertFalse(
68 $this->handler->getMetadata( null, $this->filePath . '/README' ),
69 'Getting Metadata for an inexistent file should returns false'
70 );
71 }
72
73 public function testPageCount() {
74 $file = $this->dataFile( 'LoremIpsum.djvu', 'image/x.djvu' );
75 $this->assertEquals(
76 5,
77 $this->handler->pageCount( $file ),
78 'Test file LoremIpsum.djvu should be detected as containing 5 pages'
79 );
80 }
81
82 public function testGetPageDimensions() {
83 $file = $this->dataFile( 'LoremIpsum.djvu', 'image/x.djvu' );
84 $this->assertArrayEquals(
85 array( 2480, 3508 ),
86 $this->handler->getPageDimensions( $file, 1 ),
87 'Page 1 of test file LoremIpsum.djvu should have a size of 2480 * 3508'
88 );
89 }
90
91 public function testGetPageText() {
92 $file = $this->dataFile( 'LoremIpsum.djvu', 'image/x.djvu' );
93 $this->assertEquals(
94 "Lorem ipsum \n1 \n",
95 (string) $this->handler->getPageText( $file, 1 ),
96 "Text layer of page 1 of file LoremIpsum.djvu should be 'Lorem ipsum \n1 \n'"
97 );
98 }
99 }