ParserTests: fix `bits` column in uploaded images for test cases.
[lhc/web/wiklou.git] / tests / parser / parserTest.inc
index 0899d46..7e7c42f 100644 (file)
@@ -64,6 +64,11 @@ class ParserTest {
         */
        private $dbClone;
 
+       /**
+        * @var DjVuSupport
+        */
+       private $djVuSupport;
+
        /**
         * @var string $oldTablePrefix Original table prefix
         */
@@ -136,6 +141,8 @@ class ParserTest {
                $this->runDisabled = isset( $options['run-disabled'] );
                $this->runParsoid = isset( $options['run-parsoid'] );
 
+               $this->djVuSupport = new DjVuSupport();
+
                $this->hooks = array();
                $this->functionHooks = array();
                self::setUp();
@@ -549,6 +556,12 @@ class ParserTest {
                $user = $context->getUser();
                $options = ParserOptions::newFromContext( $context );
 
+               if ( isset( $opts['djvu'] ) ) {
+                       if ( !$this->djVuSupport->isEnabled() ) {
+                               return $this->showSkipped();
+                       }
+               }
+
                if ( isset( $opts['title'] ) ) {
                        $titleText = $opts['title'];
                } else {
@@ -750,6 +763,7 @@ class ParserTest {
 
                $settings = array(
                        'wgServer' => 'http://example.org',
+                       'wgServerName' => 'example.org',
                        'wgScript' => '/index.php',
                        'wgScriptPath' => '/',
                        'wgArticlePath' => '/wiki/$1',
@@ -993,7 +1007,7 @@ class ParserTest {
                                'size'        => 12345,
                                'width'       => 240,
                                'height'      => 180,
-                               'bits'        => 24,
+                               'bits'        => 0,
                                'media_type'  => MEDIATYPE_DRAWING,
                                'mime'        => 'image/svg+xml',
                                'metadata'    => serialize( array() ),
@@ -1014,6 +1028,45 @@ class ParserTest {
                        'sha1' => wfBaseConvert( '3', 16, 36, 31 ),
                        'fileExists' => true
                ), $this->db->timestamp( '20010115123500' ), $user );
+
+               # A DjVu file
+               $image = wfLocalFile( Title::makeTitle( NS_FILE, 'LoremIpsum.djvu' ) );
+               $image->recordUpload2( '', 'Upload a DjVu', 'A DjVu', array(
+                       'size' => 3249,
+                       'width' => 2480,
+                       'height' => 3508,
+                       'bits' => 0,
+                       'media_type' => MEDIATYPE_BITMAP,
+                       'mime' => 'image/vnd.djvu',
+                       'metadata' => '<?xml version="1.0" ?>
+<!DOCTYPE DjVuXML PUBLIC "-//W3C//DTD DjVuXML 1.1//EN" "pubtext/DjVuXML-s.dtd">
+<DjVuXML>
+<HEAD></HEAD>
+<BODY><OBJECT height="3508" width="2480">
+<PARAM name="DPI" value="300" />
+<PARAM name="GAMMA" value="2.2" />
+</OBJECT>
+<OBJECT height="3508" width="2480">
+<PARAM name="DPI" value="300" />
+<PARAM name="GAMMA" value="2.2" />
+</OBJECT>
+<OBJECT height="3508" width="2480">
+<PARAM name="DPI" value="300" />
+<PARAM name="GAMMA" value="2.2" />
+</OBJECT>
+<OBJECT height="3508" width="2480">
+<PARAM name="DPI" value="300" />
+<PARAM name="GAMMA" value="2.2" />
+</OBJECT>
+<OBJECT height="3508" width="2480">
+<PARAM name="DPI" value="300" />
+<PARAM name="GAMMA" value="2.2" />
+</OBJECT>
+</BODY>
+</DjVuXML>',
+                       'sha1' => wfBaseConvert( '', 16, 36, 31 ),
+                       'fileExists' => true
+               ), $this->db->timestamp( '20010115123600' ), $user );
        }
 
        public function teardownDatabase() {
@@ -1082,16 +1135,19 @@ class ParserTest {
                }
 
                wfMkdirParents( $dir . '/3/3a', null, __METHOD__ );
-               copy( "$IP/skins/monobook/headbg.jpg", "$dir/3/3a/Foobar.jpg" );
+               copy( "$IP/tests/phpunit/data/parser/headbg.jpg", "$dir/3/3a/Foobar.jpg" );
                wfMkdirParents( $dir . '/e/ea', null, __METHOD__ );
-               copy( "$IP/skins/monobook/wiki.png", "$dir/e/ea/Thumb.png" );
+               copy( "$IP/tests/phpunit/data/parser/wiki.png", "$dir/e/ea/Thumb.png" );
                wfMkdirParents( $dir . '/0/09', null, __METHOD__ );
-               copy( "$IP/skins/monobook/headbg.jpg", "$dir/0/09/Bad.jpg" );
+               copy( "$IP/tests/phpunit/data/parser/headbg.jpg", "$dir/0/09/Bad.jpg" );
                wfMkdirParents( $dir . '/f/ff', null, __METHOD__ );
                file_put_contents( "$dir/f/ff/Foobar.svg",
                        '<?xml version="1.0" encoding="utf-8"?>' .
                        '<svg xmlns="http://www.w3.org/2000/svg"' .
                        ' version="1.1" width="240" height="180"/>' );
+               wfMkdirParents( $dir . '/5/5f', null, __METHOD__ );
+               copy( "$IP/tests/phpunit/data/parser/LoremIpsum.djvu", "$dir/5/5f/LoremIpsum.djvu" );
+
                return $dir;
        }
 
@@ -1159,6 +1215,11 @@ class ParserTest {
 
                                "$dir/0/09/Bad.jpg",
 
+                               "$dir/5/5f/LoremIpsum.djvu",
+                               "$dir/thumb/5/5f/LoremIpsum.djvu/page2-2480px-LoremIpsum.djvu.jpg",
+                               "$dir/thumb/5/5f/LoremIpsum.djvu/page2-3720px-LoremIpsum.djvu.jpg",
+                               "$dir/thumb/5/5f/LoremIpsum.djvu/page2-4960px-LoremIpsum.djvu.jpg",
+
                                "$dir/f/ff/Foobar.svg",
                                "$dir/thumb/f/ff/Foobar.svg/180px-Foobar.svg.png",
                                "$dir/thumb/f/ff/Foobar.svg/2000px-Foobar.svg.png",
@@ -1190,6 +1251,11 @@ class ParserTest {
                                "$dir/thumb/f/",
                                "$dir/0/09/",
                                "$dir/0/",
+                               "$dir/5/5f",
+                               "$dir/5",
+                               "$dir/thumb/5/5f/LoremIpsum.djvu",
+                               "$dir/thumb/5/5f",
+                               "$dir/thumb/5",
                                "$dir/thumb",
                                "$dir/math/f/a/5",
                                "$dir/math/f/a",
@@ -1283,6 +1349,19 @@ class ParserTest {
                return false;
        }
 
+       /**
+        * Print a skipped message.
+        *
+        * @return boolean
+        */
+       protected function showSkipped() {
+               if ( $this->showProgress ) {
+                       print $this->term->color( '1;33' ) . 'SKIPPED' . $this->term->reset() . "\n";
+               }
+
+               return true;
+       }
+
        /**
         * Run given strings through a diff and return the (colorized) output.
         * Requires writable /tmp directory and a 'diff' command in the PATH.