Tpt has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/98258


Change subject: Adds some beginning of tests for DjVu files
......................................................................

Adds some beginning of tests for DjVu files

Change-Id: I453b2b1a1c4999150a570e22170a9c630c2ef265
---
A tests/phpunit/data/media/LoremIpsum.djvu
A tests/phpunit/includes/media/DjVuTest.php
2 files changed, 102 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/58/98258/1

diff --git a/tests/phpunit/data/media/LoremIpsum.djvu 
b/tests/phpunit/data/media/LoremIpsum.djvu
new file mode 100644
index 0000000..42f47cd
--- /dev/null
+++ b/tests/phpunit/data/media/LoremIpsum.djvu
Binary files differ
diff --git a/tests/phpunit/includes/media/DjVuTest.php 
b/tests/phpunit/includes/media/DjVuTest.php
new file mode 100644
index 0000000..73b95b8
--- /dev/null
+++ b/tests/phpunit/includes/media/DjVuTest.php
@@ -0,0 +1,102 @@
+<?php
+/**
+ * @covers DjVuHandler
+ */
+class DjVuTest extends MediaWikiTestCase {
+
+       /**
+        * @var string the directory where test files are
+        */
+       protected $filePath;
+
+       /**
+        * @var FSRepo the repository to use
+        */
+       protected $repo;
+
+       /**
+        * @var DjVuHandler
+        */
+       protected $handler;
+
+       protected function setUp() {
+               global $wgDjvuRenderer, $wgDjvuDump, $wgDjvuToXML;
+               parent::setUp();
+
+               //cli tool setup
+               if (
+                       !$this->checkIfToolExists( 'ddjvu' ) ||
+                       !$this->checkIfToolExists( 'djvutoxml' ) ||
+                       !$this->checkIfToolExists( 'djvudump' )
+               ) {
+                       $this->markTestSkipped( 'This test needs the 
installation of the ddjvu, djvutoxml and djvudump tools' );
+               }
+               $wgDjvuToXML = 'djvutoxml';
+               $wgDjvuDump = 'djvudump';
+               $wgDjvuRenderer = 'ddjvu';
+
+               //file repo setup
+               $this->filePath = __DIR__ . '/../../data/media/';
+               $backend = new FSFileBackend( array(
+                       'name' => 'localtesting',
+                       'lockManager' => 'nullLockManager',
+                       'containerPaths' => array( 'data' => $this->filePath )
+               ) );
+               $this->repo = new FSRepo( array(
+                       'name' => 'temp',
+                       'url' => 'http://localhost/thumbtest',
+                       'backend' => $backend
+               ) );
+
+               $this->handler = new DjVuHandler();
+       }
+
+       /**
+        * Check if a tool exist
+        *
+        * @param string $tool
+        * @return bool
+        */
+       protected function checkIfToolExists( $tool ) {
+               $resultCode = -1;
+               wfShellExecWithStderr( $tool . ' --help', $resultCode );
+               return $resultCode !== 127;
+       }
+
+       protected function dataFile( $name, $type ) {
+               return new UnregisteredLocalFile(
+                       false,
+                       $this->repo,
+                       'mwstore://localtesting/data/' . $name,
+                       $type
+               );
+       }
+
+       public function testGetImageSize() {
+               $this->assertArrayEquals(
+                       array(  2480, 3508, 'width="2480" height="3508"', 
'DjVu' ),
+                       $this->handler->getImageSize( null, $this->filePath . 
'/LoremIpsum.djvu' )
+               );
+       }
+
+       public function testInvalidFile() {
+               $this->assertFalse(
+                       $this->handler->getMetadata( null, $this->filePath . 
'/README' )
+               );
+       }
+
+       public function testPageCount() {
+               $file = $this->dataFile( 'LoremIpsum.djvu', 'image/x.djvu' );
+               $this->assertEquals( 5, $this->handler->pageCount( $file ) );
+       }
+
+       public function testGetPageDimensions() {
+               $file = $this->dataFile( 'LoremIpsum.djvu', 'image/x.djvu' );
+               $this->assertArrayEquals( array( 2480, 3508 ), 
$this->handler->getPageDimensions( $file, 1 ) );
+       }
+
+       public function testGetPageText() {
+               $file = $this->dataFile( 'LoremIpsum.djvu', 'image/x.djvu' );
+               $this->assertEquals( 'Lorem ipsum \n1 \n', (string) 
$this->handler->getPageText( $file, 1 ) );
+       }
+}

-- 
To view, visit https://gerrit.wikimedia.org/r/98258
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I453b2b1a1c4999150a570e22170a9c630c2ef265
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Tpt <thoma...@hotmail.fr>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to