File: DjVuTest.php

package info (click to toggle)
mediawiki 1%3A1.43.3%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 417,464 kB
  • sloc: php: 1,062,949; javascript: 664,290; sql: 9,714; python: 5,458; xml: 3,489; sh: 1,131; makefile: 64
file content (76 lines) | stat: -rw-r--r-- 2,122 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<?php

use MediaWiki\MainConfigNames;

/**
 * @group Media
 * @covers \DjVuHandler
 */
class DjVuTest extends MediaWikiMediaTestCase {

	/**
	 * @var DjVuHandler
	 */
	protected $handler;

	protected function setUp(): void {
		parent::setUp();

		// cli tool setup
		$djvuSupport = new DjVuSupport();

		if ( !$djvuSupport->isEnabled() ) {
			$this->markTestSkipped(
			'This test needs the installation of the ddjvu, djvutoxml and djvudump tools' );
		}

		$this->overrideConfigValue( MainConfigNames::DjvuUseBoxedCommand, true );

		$this->handler = new DjVuHandler();
	}

	public function testGetSizeAndMetadata() {
		$info = $this->handler->getSizeAndMetadata(
			new TrivialMediaHandlerState, $this->filePath . '/LoremIpsum.djvu' );
		$this->assertSame( 2480, $info['width'] );
		$this->assertSame( 3508, $info['height'] );
		$this->assertIsArray( $info['metadata']['data'] );
	}

	public function testInvalidFile() {
		$this->assertEquals(
			[ 'metadata' => [ 'error' => 'Error extracting metadata' ] ],
			$this->handler->getSizeAndMetadata(
				new TrivialMediaHandlerState, $this->filePath . '/some-nonexistent-file' ),
			'Getting metadata for a nonexistent file should return false'
		);
	}

	public function testPageCount() {
		$file = $this->dataFile( 'LoremIpsum.djvu', 'image/x.djvu' );
		$this->assertEquals(
			5,
			$this->handler->pageCount( $file ),
			'Test file LoremIpsum.djvu should be detected as containing 5 pages'
		);
	}

	public function testGetPageDimensions() {
		$file = $this->dataFile( 'LoremIpsum.djvu', 'image/x.djvu' );
		$this->assertSame(
			[ 'width' => 2480, 'height' => 3508 ],
			$this->handler->getPageDimensions( $file, 1 ),
			'Page 1 of test file LoremIpsum.djvu should have a size of 2480 * 3508'
		);
	}

	public function testGetPageText() {
		$file = $this->dataFile( 'LoremIpsum.djvu', 'image/x.djvu' );
		$this->assertSame(
			// note: this also tests that the column/paragraph is detected and converted
			"Lorem ipsum \n\n1 \n",
			$this->handler->getPageText( $file, 1 ),
			"Text layer of page 1 of file LoremIpsum.djvu should be 'Lorem ipsum \n\n1 \n'"
		);
	}
}