Make cache object mandatory for MessageCache
[mediawiki.git] / tests / phpunit / mocks / media / MockOggHandler.php
blob99992fe3d8f251b29e5054f962faed3f590a305c
1 <?php
2 /**
3 * Fake handler for Ogg videos.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
20 * @file
21 * @ingroup Media
24 class MockOggHandler extends OggHandlerTMH {
25 function doTransform( $file, $dstPath, $dstUrl, $params, $flags = 0 ) {
26 # Important or height handling is wrong.
27 if ( !$this->normaliseParams( $file, $params ) ) {
28 return new TransformParameterError( $params );
31 $srcWidth = $file->getWidth();
32 $srcHeight = $file->getHeight();
34 // Audio should not be transformed by size, give it a default width and height
35 if ( $this->isAudio( $file ) ) {
36 $srcWidth = 220;
37 $srcHeight = 23;
40 $params['width'] = isset( $params['width'] ) ? $params['width'] : $srcWidth;
42 // if height overtakes width use height as max:
43 $targetWidth = $params['width'];
44 $targetHeight = $srcWidth == 0 ? $srcHeight : round( $params['width'] * $srcHeight / $srcWidth );
45 if ( isset( $params['height'] ) && $targetHeight > $params['height'] ) {
46 $targetHeight = $params['height'];
47 $targetWidth = round( $params['height'] * $srcWidth / $srcHeight );
49 $options = [
50 'file' => $file,
51 'length' => $this->getLength( $file ),
52 'offset' => $this->getOffset( $file ),
53 'width' => $targetWidth,
54 'height' => $targetHeight,
55 'isVideo' => !$this->isAudio( $file ),
56 'thumbtime' => isset(
57 $params['thumbtime']
58 ) ? $params['thumbtime'] : intval( $file->getLength() / 2 ),
59 'start' => isset( $params['start'] ) ? $params['start'] : false,
60 'end' => isset( $params['end'] ) ? $params['end'] : false,
61 'fillwindow' => isset( $params['fillwindow'] ) ? $params['fillwindow'] : false,
62 'disablecontrols' => isset ( $params['disablecontrols'] ) ? $params['disablecontrols'] : false
65 // No thumbs for audio
66 if ( !$options['isVideo'] ) {
67 return new TimedMediaTransformOutput( $options );
70 // Setup pointer to thumb arguments
71 $options[ 'thumbUrl' ] = $dstUrl;
72 $options[ 'dstPath' ] = $dstPath;
73 $options[ 'path' ] = $dstPath;
75 return new TimedMediaTransformOutput( $options );
78 function getLength( $file ) {
79 if ( $this->isAudio( $file ) ) {
80 return 0.99875;
82 return 4.3666666666667;
85 function getBitRate( $file ) {
86 if ( $this->isAudio( $file ) ) {
87 return 41107;
89 return 590013;
92 function getWebType( $file ) {
93 if ( $this->isAudio( $file ) ) {
94 return "audio/ogg; codecs=\"vorbis\"";
96 return "video/ogg; codecs=\"theora\"";
99 function getFramerate( $file ) {
100 if ( $this->isAudio( $file ) ) {
101 return 0;
103 return 30;