Pass phpcs-strict on some test files (9/11)
[mediawiki.git] / tests / phpunit / includes / media / DjVuTest.php
blobc61ed22ad56fc6849b479375f1acfc5a1a80f5d8
1 <?php
2 /**
3 * @covers DjVuHandler
4 */
5 class DjVuTest extends MediaWikiTestCase {
7 /**
8 * @var string the directory where test files are
9 */
10 protected $filePath;
12 /**
13 * @var FSRepo the repository to use
15 protected $repo;
17 /**
18 * @var DjVuHandler
20 protected $handler;
22 protected function setUp() {
23 global $wgDjvuRenderer, $wgDjvuDump, $wgDjvuToXML;
24 parent::setUp();
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' );
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 ) );
53 $this->handler = new DjVuHandler();
56 /**
57 * Check if a tool exist
59 * @param string $path path to the tool
60 * @return bool
62 protected function checkIfToolExists( $path ) {
63 wfSuppressWarnings();
64 $result = file_exists( $path );
65 wfRestoreWarnings();
66 return $result;
69 protected function dataFile( $name, $type ) {
70 return new UnregisteredLocalFile(
71 false,
72 $this->repo,
73 'mwstore://localtesting/data/' . $name,
74 $type
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() {
87 $this->assertFalse(
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' );
95 $this->assertEquals(
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(
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'
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'"