jenkins-bot has submitted this change and it was merged.
Change subject: Parsertests: Fix the video parsertests to run using phpunit
......................................................................
Parsertests: Fix the video parsertests to run using phpunit
Bug: T126723
Change-Id: Ib3777413e1f86ddca9e460b41a8e3ef0eb8fb7cc
---
M tests/TestsAutoLoader.php
M tests/phpunit/includes/parser/NewParserTest.php
A tests/phpunit/mocks/media/MockOggHandler.php
3 files changed, 100 insertions(+), 3 deletions(-)
Approvals:
Hashar: Looks good to me, approved
jenkins-bot: Verified
diff --git a/tests/TestsAutoLoader.php b/tests/TestsAutoLoader.php
index 63f6a19..76a6335 100644
--- a/tests/TestsAutoLoader.php
+++ b/tests/TestsAutoLoader.php
@@ -126,6 +126,7 @@
'MockImageHandler' =>
"$testDir/phpunit/mocks/media/MockImageHandler.php",
'MockSvgHandler' => "$testDir/phpunit/mocks/media/MockSvgHandler.php",
'MockDjVuHandler' => "$testDir/phpunit/mocks/media/MockDjVuHandler.php",
+ 'MockOggHandler' => "$testDir/phpunit/mocks/media/MockOggHandler.php",
'MockWebRequest' => "$testDir/phpunit/mocks/MockWebRequest.php",
'MediaWiki\\Session\\DummySessionBackend'
=> "$testDir/phpunit/mocks/session/DummySessionBackend.php",
diff --git a/tests/phpunit/includes/parser/NewParserTest.php
b/tests/phpunit/includes/parser/NewParserTest.php
index 895398f..fa86eed 100644
--- a/tests/phpunit/includes/parser/NewParserTest.php
+++ b/tests/phpunit/includes/parser/NewParserTest.php
@@ -142,6 +142,9 @@
// DjVu images have to be handled slightly differently
$tmpGlobals['wgMediaHandlers']['image/vnd.djvu'] =
'MockDjVuHandler';
+ // Ogg video/audio increasingly more differently
+ $tmpGlobals['wgMediaHandlers']['application/ogg'] =
'MockOggHandler';
+
$tmpHooks = $wgHooks;
$tmpHooks['ParserTestParser'][] = 'ParserTestParserHook::setup';
$tmpHooks['ParserGetVariableValueTs'][] =
'ParserTest::getFakeTimestamp';
@@ -308,13 +311,13 @@
if ( !$this->db->selectField( 'image', '1', [ 'img_name' =>
$image->getName() ] ) ) {
$image->recordUpload2( '', 'A pretty movie', 'Will it
play', [
'size' => 12345,
- 'width' => 240,
- 'height' => 180,
+ 'width' => 320,
+ 'height' => 240,
'bits' => 0,
'media_type' => MEDIATYPE_VIDEO,
'mime' => 'application/ogg',
'metadata' => serialize( [] ),
- 'sha1' =>
Wikimedia\base_convert( '', 16, 36, 31 ),
+ 'sha1' =>
Wikimedia\base_convert( '', 16, 36, 32 ),
'fileExists' => true
], $this->db->timestamp( '20010115123500' ), $user );
}
diff --git a/tests/phpunit/mocks/media/MockOggHandler.php
b/tests/phpunit/mocks/media/MockOggHandler.php
new file mode 100644
index 0000000..b110e21
--- /dev/null
+++ b/tests/phpunit/mocks/media/MockOggHandler.php
@@ -0,0 +1,93 @@
+<?php
+/**
+ * Fake handler for Ogg videos.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
+ * @ingroup Media
+ */
+
+class MockOggHandler extends OggHandlerTMH {
+ function doTransform( $file, $dstPath, $dstUrl, $params, $flags = 0 ) {
+ # Important or height handling is wrong.
+ if ( !$this->normaliseParams( $file, $params ) ) {
+ return new TransformParameterError( $params );
+ }
+
+ $srcWidth = $file->getWidth();
+ $srcHeight = $file->getHeight();
+
+ // Audio should not be transformed by size, give it a default
width and height
+ if ( $this->isAudio( $file ) ) {
+ $srcWidth = 220;
+ $srcHeight = 23;
+ }
+
+ $params['width'] = isset( $params['width'] ) ? $params['width']
: $srcWidth;
+
+ // if height overtakes width use height as max:
+ $targetWidth = $params['width'];
+ $targetHeight = $srcWidth == 0 ? $srcHeight : round(
$params['width'] * $srcHeight / $srcWidth );
+ if ( isset( $params['height'] ) && $targetHeight >
$params['height'] ) {
+ $targetHeight = $params['height'];
+ $targetWidth = round( $params['height'] * $srcWidth /
$srcHeight );
+ }
+ $options = [
+ 'file' => $file,
+ 'length' => $this->getLength( $file ),
+ 'offset' => $this->getOffset( $file ),
+ 'width' => $targetWidth,
+ 'height' => $targetHeight,
+ 'isVideo' => !$this->isAudio( $file ),
+ 'thumbtime' => isset(
+ $params['thumbtime']
+ ) ? $params['thumbtime'] : intval( $file->getLength() /
2 ),
+ 'start' => isset( $params['start'] ) ? $params['start']
: false,
+ 'end' => isset( $params['end'] ) ? $params['end'] :
false,
+ 'fillwindow' => isset( $params['fillwindow'] ) ?
$params['fillwindow'] : false,
+ 'disablecontrols' => isset ( $params['disablecontrols']
) ? $params['disablecontrols'] : false
+ ];
+
+ // No thumbs for audio
+ if ( !$options['isVideo'] ) {
+ return new TimedMediaTransformOutput( $options );
+ }
+
+ // Setup pointer to thumb arguments
+ $options[ 'thumbUrl' ] = $dstUrl;
+ $options[ 'dstPath' ] = $dstPath;
+ $options[ 'path' ] = $dstPath;
+
+ return new TimedMediaTransformOutput( $options );
+ }
+
+ function getLength( $file ) {
+ return 4.3666666666667;
+ }
+
+ function getBitRate( $file ) {
+ return 590013;
+ }
+
+ function getWebType( $file ) {
+ return "video/ogg; codecs=\"theora\"";
+ }
+
+ function getFramerate( $file ) {
+ return 30;
+ }
+}
--
To view, visit https://gerrit.wikimedia.org/r/270303
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ib3777413e1f86ddca9e460b41a8e3ef0eb8fb7cc
Gerrit-PatchSet: 4
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: TheDJ <[email protected]>
Gerrit-Reviewer: Brion VIBBER <[email protected]>
Gerrit-Reviewer: Cscott <[email protected]>
Gerrit-Reviewer: Hashar <[email protected]>
Gerrit-Reviewer: Jackmcbarn <[email protected]>
Gerrit-Reviewer: Subramanya Sastry <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits