DjVuTest.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. /**
  3. * @group Media
  4. * @covers DjVuHandler
  5. */
  6. class DjVuTest extends MediaWikiMediaTestCase {
  7. /**
  8. * @var DjVuHandler
  9. */
  10. protected $handler;
  11. protected function setUp() {
  12. parent::setUp();
  13. // cli tool setup
  14. $djvuSupport = new DjVuSupport();
  15. if ( !$djvuSupport->isEnabled() ) {
  16. $this->markTestSkipped(
  17. 'This test needs the installation of the ddjvu, djvutoxml and djvudump tools' );
  18. }
  19. $this->handler = new DjVuHandler();
  20. }
  21. public function testGetImageSize() {
  22. $this->assertArrayEquals(
  23. [ 2480, 3508, 'DjVu', 'width="2480" height="3508"' ],
  24. $this->handler->getImageSize( null, $this->filePath . '/LoremIpsum.djvu' ),
  25. 'Test file LoremIpsum.djvu should have a size of 2480 * 3508'
  26. );
  27. }
  28. public function testInvalidFile() {
  29. $this->assertEquals(
  30. 'a:1:{s:5:"error";s:25:"Error extracting metadata";}',
  31. $this->handler->getMetadata( null, $this->filePath . '/some-nonexistent-file' ),
  32. 'Getting metadata for an inexistent file should return false'
  33. );
  34. }
  35. public function testPageCount() {
  36. $file = $this->dataFile( 'LoremIpsum.djvu', 'image/x.djvu' );
  37. $this->assertEquals(
  38. 5,
  39. $this->handler->pageCount( $file ),
  40. 'Test file LoremIpsum.djvu should be detected as containing 5 pages'
  41. );
  42. }
  43. public function testGetPageDimensions() {
  44. $file = $this->dataFile( 'LoremIpsum.djvu', 'image/x.djvu' );
  45. $this->assertArrayEquals(
  46. [ 2480, 3508 ],
  47. $this->handler->getPageDimensions( $file, 1 ),
  48. 'Page 1 of test file LoremIpsum.djvu should have a size of 2480 * 3508'
  49. );
  50. }
  51. public function testGetPageText() {
  52. $file = $this->dataFile( 'LoremIpsum.djvu', 'image/x.djvu' );
  53. $this->assertEquals(
  54. "Lorem ipsum \n1 \n",
  55. (string)$this->handler->getPageText( $file, 1 ),
  56. "Text layer of page 1 of file LoremIpsum.djvu should be 'Lorem ipsum \n1 \n'"
  57. );
  58. }
  59. }