Add an audio file parser test
authorDerk-Jan Hartman <hartman.wiki@gmail.com>
Wed, 18 May 2016 15:48:04 +0000 (17:48 +0200)
committerDerk-Jan Hartman <hartman.wiki@gmail.com>
Wed, 18 May 2016 15:48:30 +0000 (17:48 +0200)
Change-Id: I478b1ea23700a66520d51ec40dcf5c392318d8b6

tests/parser/parserTest.inc
tests/parser/parserTests.txt
tests/phpunit/includes/parser/NewParserTest.php
tests/phpunit/mocks/media/MockOggHandler.php

index 1be2d62..efadc3f 100644 (file)
@@ -1136,6 +1136,19 @@ class ParserTest {
                        'fileExists' => true
                ], $this->db->timestamp( '20010115123500' ), $user );
 
+               $image = wfLocalFile( Title::makeTitle( NS_FILE, 'Audio.oga' ) );
+               $image->recordUpload2( '', 'An awesome hitsong', 'Will it play', [
+                       'size' => 12345,
+                       'width' => 0,
+                       'height' => 0,
+                       'bits' => 0,
+                       'media_type' => MEDIATYPE_AUDIO,
+                       'mime' => 'application/ogg',
+                       'metadata' => serialize( [] ),
+                       'sha1' => Wikimedia\base_convert( '', 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', [
@@ -1251,6 +1264,8 @@ class ParserTest {
                copy( "$IP/tests/phpunit/data/parser/LoremIpsum.djvu", "$dir/5/5f/LoremIpsum.djvu" );
                wfMkdirParents( $dir . '/0/00', null, __METHOD__ );
                copy( "$IP/tests/phpunit/data/parser/320x240.ogv", "$dir/0/00/Video.ogv" );
+               wfMkdirParents( $dir . '/4/41', null, __METHOD__ );
+               copy( "$IP/tests/phpunit/data/media/say-test.ogg", "$dir/4/41/Audio.oga" );
 
                return;
        }
@@ -1300,6 +1315,7 @@ class ParserTest {
                                "$dir/thumb/0/00/Video.ogv/270px--Video.ogv.jpg",
                                "$dir/thumb/0/00/Video.ogv/320px-seek=2-Video.ogv.jpg",
                                "$dir/thumb/0/00/Video.ogv/320px-seek=3.3666666666667-Video.ogv.jpg",
+                               "$dir/4/41/Audio.oga",
                        ]
                );
 
@@ -1329,6 +1345,8 @@ class ParserTest {
                                "$dir/thumb/5/5f",
                                "$dir/thumb/5",
                                "$dir/thumb",
+                               "$dir/4/41",
+                               "$dir/4",
                                "$dir/math/f/a/5",
                                "$dir/math/f/a",
                                "$dir/math/f",
index 7051b4f..ce11ced 100644 (file)
@@ -9777,7 +9777,7 @@ Magic Word: {{NUMBEROFFILES}}
 !! wikitext
 {{NUMBEROFFILES}}
 !! html
-<p>6
+<p>7
 </p>
 !! end
 
index c024555..ce8c823 100644 (file)
@@ -324,7 +324,21 @@ class NewParserTest extends MediaWikiTestCase {
                        ], $this->db->timestamp( '20010115123500' ), $user );
                }
 
-               # A DjVu file
+               $image = wfLocalFile( Title::makeTitle( NS_FILE, 'Audio.oga' ) );
+               if ( !$this->db->selectField( 'image', '1', [ 'img_name' => $image->getName() ] ) ) {
+                       $image->recordUpload2( '', 'An awesome hitsong ', 'Will it play', [
+                                       'size'        => 12345,
+                                       'width'       => 0,
+                                       'height'      => 0,
+                                       'bits'        => 0,
+                                       'media_type'  => MEDIATYPE_AUDIO,
+                                       'mime'        => 'application/ogg',
+                                       'metadata'    => serialize( [] ),
+                                       'sha1'        => Wikimedia\base_convert( '', 16, 36, 32 ),
+                                       'fileExists'  => true
+                       ], $this->db->timestamp( '20010115123500' ), $user );
+               }
+
                # A DjVu file
                $image = wfLocalFile( Title::makeTitle( NS_FILE, 'LoremIpsum.djvu' ) );
                if ( !$this->db->selectField( 'image', '1', [ 'img_name' => $image->getName() ] ) ) {
index b110e21..99992fe 100644 (file)
@@ -76,18 +76,30 @@ class MockOggHandler extends OggHandlerTMH {
        }
 
        function getLength( $file ) {
+               if ( $this->isAudio( $file ) ) {
+                       return 0.99875;
+               }
                return 4.3666666666667;
        }
 
        function getBitRate( $file ) {
+               if ( $this->isAudio( $file ) ) {
+                       return 41107;
+               }
                return 590013;
        }
 
        function getWebType( $file ) {
+               if ( $this->isAudio( $file ) ) {
+                       return "audio/ogg; codecs=\"vorbis\"";
+               }
                return "video/ogg; codecs=\"theora\"";
        }
 
        function getFramerate( $file ) {
+               if ( $this->isAudio( $file ) ) {
+                       return 0;
+               }
                return 30;
        }
 }