Merge "mw.Upload.BookletLayout: Don't explode when the API call fails with 'exception'"
[lhc/web/wiklou.git] / tests / phpunit / includes / parser / NewParserTest.php
index df7da98..256ad69 100644 (file)
@@ -27,7 +27,7 @@ class NewParserTest extends MediaWikiTestCase {
        public $functionHooks = array();
        public $transparentHooks = array();
 
-       //Fuzz test
+       // Fuzz test
        public $maxFuzzTestLength = 300;
        public $fuzzSeed = 0;
        public $memoryLimit = 50;
@@ -54,7 +54,7 @@ class NewParserTest extends MediaWikiTestCase {
 
                parent::setUp();
 
-               //Setup CLI arguments
+               // Setup CLI arguments
                if ( $this->getCliArg( 'regex' ) ) {
                        $this->regex = $this->getCliArg( 'regex' );
                } else {
@@ -210,7 +210,7 @@ class NewParserTest extends MediaWikiTestCase {
        function addDBData() {
                $this->tablesUsed[] = 'site_stats';
                # disabled for performance
-               #$this->tablesUsed[] = 'image';
+               # $this->tablesUsed[] = 'image';
 
                # Update certain things in site_stats
                $this->db->insert( 'site_stats',
@@ -243,7 +243,7 @@ class NewParserTest extends MediaWikiTestCase {
                                        'media_type' => MEDIATYPE_BITMAP,
                                        'mime' => 'image/jpeg',
                                        'metadata' => serialize( array() ),
-                                       'sha1' => wfBaseConvert( '1', 16, 36, 31 ),
+                                       'sha1' => Wikimedia\base_convert( '1', 16, 36, 31 ),
                                        'fileExists' => true ),
                                $this->db->timestamp( '20010115123500' ), $user
                        );
@@ -263,7 +263,7 @@ class NewParserTest extends MediaWikiTestCase {
                                        'media_type' => MEDIATYPE_BITMAP,
                                        'mime' => 'image/png',
                                        'metadata' => serialize( array() ),
-                                       'sha1' => wfBaseConvert( '2', 16, 36, 31 ),
+                                       'sha1' => Wikimedia\base_convert( '2', 16, 36, 31 ),
                                        'fileExists' => true ),
                                $this->db->timestamp( '20130225203040' ), $user
                        );
@@ -284,7 +284,7 @@ class NewParserTest extends MediaWikiTestCase {
                                        'media_type' => MEDIATYPE_BITMAP,
                                        'mime' => 'image/jpeg',
                                        'metadata' => serialize( array() ),
-                                       'sha1' => wfBaseConvert( '3', 16, 36, 31 ),
+                                       'sha1' => Wikimedia\base_convert( '3', 16, 36, 31 ),
                                        'fileExists' => true ),
                                $this->db->timestamp( '20010115123500' ), $user
                        );
@@ -299,11 +299,27 @@ class NewParserTest extends MediaWikiTestCase {
                                        'media_type'  => MEDIATYPE_DRAWING,
                                        'mime'        => 'image/svg+xml',
                                        'metadata'    => serialize( array() ),
-                                       'sha1'        => wfBaseConvert( '', 16, 36, 31 ),
+                                       'sha1'        => Wikimedia\base_convert( '', 16, 36, 31 ),
                                        'fileExists'  => true
                        ), $this->db->timestamp( '20010115123500' ), $user );
                }
 
+               $image = wfLocalFile( Title::makeTitle( NS_FILE, 'Video.ogv' ) );
+               if ( !$this->db->selectField( 'image', '1', array( 'img_name' => $image->getName() ) ) ) {
+                       $image->recordUpload2( '', 'A pretty movie', 'Will it play', array(
+                                       'size'        => 12345,
+                                       'width'       => 240,
+                                       'height'      => 180,
+                                       'bits'        => 0,
+                                       'media_type'  => MEDIATYPE_VIDEO,
+                                       'mime'        => 'application/ogg',
+                                       'metadata'    => serialize( array() ),
+                                       'sha1'        => Wikimedia\base_convert( '', 16, 36, 31 ),
+                                       'fileExists'  => true
+                       ), $this->db->timestamp( '20010115123500' ), $user );
+               }
+
+               # A DjVu file
                # A DjVu file
                $image = wfLocalFile( Title::makeTitle( NS_FILE, 'LoremIpsum.djvu' ) );
                if ( !$this->db->selectField( 'image', '1', array( 'img_name' => $image->getName() ) ) ) {
@@ -340,13 +356,13 @@ class NewParserTest extends MediaWikiTestCase {
 </OBJECT>
 </BODY>
 </DjVuXML>',
-                               'sha1' => wfBaseConvert( '', 16, 36, 31 ),
+                               'sha1' => Wikimedia\base_convert( '', 16, 36, 31 ),
                                'fileExists' => true
                        ), $this->db->timestamp( '20140115123600' ), $user );
                }
        }
 
-       //ParserTest setup/teardown functions
+       // ParserTest setup/teardown functions
 
        /**
         * Set up the global variables for a consistent environment for each test.
@@ -426,7 +442,7 @@ class NewParserTest extends MediaWikiTestCase {
                        foreach ( $configLines as $line ) {
                                list( $var, $value ) = explode( '=', $line, 2 );
 
-                               $settings[$var] = eval( "return $value;" ); //???
+                               $settings[$var] = eval( "return $value;" ); // ???
                        }
                }
 
@@ -640,11 +656,12 @@ class NewParserTest extends MediaWikiTestCase {
                        $backend->delete( array( 'src' => $file ), array( 'force' => 1 ) );
                }
                foreach ( $files as $file ) {
-                       $tmp = $file;
-                       while ( $tmp = FileBackend::parentStoragePath( $tmp ) ) {
+                       $tmp = FileBackend::parentStoragePath( $file );
+                       while ( $tmp ) {
                                if ( !$backend->clean( array( 'dir' => $tmp ) )->isOK() ) {
                                        break;
                                }
+                               $tmp = FileBackend::parentStoragePath( $tmp );
                        }
                }
        }
@@ -672,6 +689,7 @@ class NewParserTest extends MediaWikiTestCase {
 
        /**
         * @group medium
+        * @group ParserTests
         * @dataProvider parserTestProvider
         * @param string $desc
         * @param string $input
@@ -682,7 +700,7 @@ class NewParserTest extends MediaWikiTestCase {
        public function testParserTest( $desc, $input, $result, $opts, $config ) {
                if ( $this->regex != '' && !preg_match( '/' . $this->regex . '/', $desc ) ) {
                        $this->assertTrue( true ); // XXX: don't flood output with "test made no assertions"
-                       //$this->markTestSkipped( 'Filtered out by the user' );
+                       // $this->markTestSkipped( 'Filtered out by the user' );
                        return;
                }
 
@@ -865,7 +883,7 @@ class NewParserTest extends MediaWikiTestCase {
 
                        if ( $id % 100 == 0 ) {
                                $usage = intval( memory_get_usage( true ) / $this->memoryLimit / 1048576 * 100 );
-                               //echo "{$this->fuzzSeed}: $numSuccess/$numTotal (mem: $usage%)\n";
+                               // echo "{$this->fuzzSeed}: $numSuccess/$numTotal (mem: $usage%)\n";
                                if ( $usage > 90 ) {
                                        $ret = "Out of memory:\n";
                                        $memStats = $this->getMemoryBreakdown();
@@ -882,7 +900,7 @@ class NewParserTest extends MediaWikiTestCase {
                }
        }
 
-       //Various getter functions
+       // Various getter functions
 
        /**
         * Get an input dictionary from a set of parser test files
@@ -956,7 +974,7 @@ class NewParserTest extends MediaWikiTestCase {
                return $parser;
        }
 
-       //Various action functions
+       // Various action functions
 
        public function addArticle( $name, $text, $line ) {
                self::$articles[$name] = array( $text, $line );
@@ -999,7 +1017,7 @@ class NewParserTest extends MediaWikiTestCase {
                return isset( $wgParser->mTransparentTagHooks[$name] );
        }
 
-       //Various "cleanup" functions
+       // Various "cleanup" functions
 
        /**
         * Remove last character if it is a newline
@@ -1014,7 +1032,7 @@ class NewParserTest extends MediaWikiTestCase {
                }
        }
 
-       //Test options parser functions
+       // Test options parser functions
 
        protected function parseOptions( $instring ) {
                $opts = array();