Matthias Mullie has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/364751 )

Change subject: Add MockOggHandler and reenable parser tests
......................................................................

Add MockOggHandler and reenable parser tests

Bug: T169258
Depends-On: I1c2e903fb235395a8de8e0f7bf65ce07739d2930
Change-Id: I6e6f45f39987ef08b68271f70015720bb3ee2669
---
M TimedMediaHandler.hooks.php
M TimedMediaHandler.php
A tests/phpunit/mocks/MockOggHandler.php
3 files changed, 120 insertions(+), 2 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/TimedMediaHandler 
refs/changes/51/364751/1

diff --git a/TimedMediaHandler.hooks.php b/TimedMediaHandler.hooks.php
index 8ce088e..4b43d42 100644
--- a/TimedMediaHandler.hooks.php
+++ b/TimedMediaHandler.hooks.php
@@ -1,12 +1,13 @@
 <?php
 
+use MediaWiki\MediaWikiServices;
+
 /**
  * Hooks for TimedMediaHandler extension
  *
  * @file
  * @ingroup Extensions
  */
-
 class TimedMediaHandlerHooks {
 
        /**
@@ -877,4 +878,14 @@
                global $wgTmhWebPlayer;
                return $wgTmhWebPlayer;
        }
+
+       /**
+        * Parser tests don't need to generate actual thumbnails
+        * @param array $overrides
+        * @return bool
+        */
+       public static function mockMediaHandlerFactoryOverrides( array 
&$overrides ) {
+               $overrides['application/ogg'] = MockOggHandler::class;
+               return true;
+       }
 }
diff --git a/TimedMediaHandler.php b/TimedMediaHandler.php
index 490708b..1cc96eb 100644
--- a/TimedMediaHandler.php
+++ b/TimedMediaHandler.php
@@ -268,7 +268,9 @@
 // Testing:
 $wgAutoloadClasses['ApiTestCaseVideoUpload'] =
        "$timedMediaDir/tests/phpunit/ApiTestCaseVideoUpload.php";
-//$wgParserTestFiles[] = "$timedMediaDir/tests/parserTests.txt";
+$wgAutoloadClasses['MockOggHandler'] = 
"$timedMediaDir/tests/phpunit/mocks/MockOggHandler.php";
+$wgParserTestFiles[] = "$timedMediaDir/tests/parserTests.txt";
+$wgHooks['MockMediaHandlerFactoryOverrides'][] = 
'TimedMediaHandlerHooks::mockMediaHandlerFactoryOverrides';
 
 // Ogg Handler
 $wgAutoloadClasses['OggHandlerTMH'] = 
"$timedMediaDir/handlers/OggHandler/OggHandler.php";
diff --git a/tests/phpunit/mocks/MockOggHandler.php 
b/tests/phpunit/mocks/MockOggHandler.php
new file mode 100644
index 0000000..99992fe
--- /dev/null
+++ b/tests/phpunit/mocks/MockOggHandler.php
@@ -0,0 +1,105 @@
+<?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 ) {
+               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;
+       }
+}

-- 
To view, visit https://gerrit.wikimedia.org/r/364751
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I6e6f45f39987ef08b68271f70015720bb3ee2669
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/TimedMediaHandler
Gerrit-Branch: master
Gerrit-Owner: Matthias Mullie <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to