Merge "Fix Language::parseFormattedNumber for lzh and zh-classical"
[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 global $wgDjvuRenderer, $wgDjvuDump, $wgDjvuToXML;
24 parent::setUp();
25
26 //cli tool setup
27 $wgDjvuRenderer = $wgDjvuRenderer ? $wgDjvuRenderer : '/usr/bin/ddjvu';
28 $wgDjvuDump = $wgDjvuDump ? $wgDjvuDump : '/usr/bin/djvudump';
29 $wgDjvuToXML = $wgDjvuToXML ? $wgDjvuToXML : '/usr/bin/djvutoxml';
30 if (
31 !$this->checkIfToolExists( $wgDjvuRenderer ) ||
32 !$this->checkIfToolExists( $wgDjvuDump ) ||
33 !$this->checkIfToolExists( $wgDjvuToXML )
34 ) {
35 $this->markTestSkipped( 'This test needs the installation of the '
36 . 'ddjvu, djvutoxml and djvudump tools' );
37 }
38
39 //file repo setup
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 )
46 ) );
47 $this->repo = new FSRepo( array(
48 'name' => 'temp',
49 'url' => 'http://localhost/thumbtest',
50 'backend' => $backend
51 ) );
52
53 $this->handler = new DjVuHandler();
54 }
55
56 /**
57 * Check if a tool exist
58 *
59 * @param string $path path to the tool
60 * @return bool
61 */
62 protected function checkIfToolExists( $path ) {
63 wfSuppressWarnings();
64 $result = file_exists( $path );
65 wfRestoreWarnings();
66 return $result;
67 }
68
69 protected function dataFile( $name, $type ) {
70 return new UnregisteredLocalFile(
71 false,
72 $this->repo,
73 'mwstore://localtesting/data/' . $name,
74 $type
75 );
76 }
77
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'
83 );
84 }
85
86 public function testInvalidFile() {
87 $this->assertFalse(
88 $this->handler->getMetadata( null, $this->filePath . '/README' ),
89 'Getting Metadata for an inexistent file should returns false'
90 );
91 }
92
93 public function testPageCount() {
94 $file = $this->dataFile( 'LoremIpsum.djvu', 'image/x.djvu' );
95 $this->assertEquals(
96 5,
97 $this->handler->pageCount( $file ),
98 'Test file LoremIpsum.djvu should be detected as containing 5 pages'
99 );
100 }
101
102 public function testGetPageDimensions() {
103 $file = $this->dataFile( 'LoremIpsum.djvu', 'image/x.djvu' );
104 $this->assertArrayEquals(
105 array( 2480, 3508 ),
106 $this->handler->getPageDimensions( $file, 1 ),
107 'Page 1 of test file LoremIpsum.djvu should have a size of 2480 * 3508'
108 );
109 }
110
111 public function testGetPageText() {
112 $file = $this->dataFile( 'LoremIpsum.djvu', 'image/x.djvu' );
113 $this->assertEquals(
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'"
117 );
118 }
119 }