From 1d41e80818cf24801cf719d2492e983f99d1861c Mon Sep 17 00:00:00 2001 From: Derk-Jan Hartman Date: Wed, 18 May 2016 17:48:04 +0200 Subject: [PATCH] Add an audio file parser test Change-Id: I478b1ea23700a66520d51ec40dcf5c392318d8b6 --- tests/parser/parserTest.inc | 18 ++++++++++++++++++ tests/parser/parserTests.txt | 2 +- .../phpunit/includes/parser/NewParserTest.php | 16 +++++++++++++++- tests/phpunit/mocks/media/MockOggHandler.php | 12 ++++++++++++ 4 files changed, 46 insertions(+), 2 deletions(-) diff --git a/tests/parser/parserTest.inc b/tests/parser/parserTest.inc index 1be2d62b23..efadc3fc2c 100644 --- a/tests/parser/parserTest.inc +++ b/tests/parser/parserTest.inc @@ -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", diff --git a/tests/parser/parserTests.txt b/tests/parser/parserTests.txt index 7051b4f5b0..ce11ceda8f 100644 --- a/tests/parser/parserTests.txt +++ b/tests/parser/parserTests.txt @@ -9777,7 +9777,7 @@ Magic Word: {{NUMBEROFFILES}} !! wikitext {{NUMBEROFFILES}} !! html -

6 +

7

!! end diff --git a/tests/phpunit/includes/parser/NewParserTest.php b/tests/phpunit/includes/parser/NewParserTest.php index c024555a2c..ce8c8235a1 100644 --- a/tests/phpunit/includes/parser/NewParserTest.php +++ b/tests/phpunit/includes/parser/NewParserTest.php @@ -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() ] ) ) { diff --git a/tests/phpunit/mocks/media/MockOggHandler.php b/tests/phpunit/mocks/media/MockOggHandler.php index b110e2137f..99992fe3d8 100644 --- a/tests/phpunit/mocks/media/MockOggHandler.php +++ b/tests/phpunit/mocks/media/MockOggHandler.php @@ -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; } } -- 2.20.1