Change 'editfont' default preference to 'monospace'
[lhc/web/wiklou.git] / tests / phpunit / mocks / media / MockOggHandler.php
1 <?php
2 /**
3 * Fake handler for Ogg videos.
4 *
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.
9 *
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.
14 *
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
19 *
20 * @file
21 * @ingroup Media
22 */
23
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 );
29 }
30
31 $srcWidth = $file->getWidth();
32 $srcHeight = $file->getHeight();
33
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;
38 }
39
40 $params['width'] = isset( $params['width'] ) ? $params['width'] : $srcWidth;
41
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 );
48 }
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
63 ];
64
65 // No thumbs for audio
66 if ( !$options['isVideo'] ) {
67 return new TimedMediaTransformOutput( $options );
68 }
69
70 // Setup pointer to thumb arguments
71 $options[ 'thumbUrl' ] = $dstUrl;
72 $options[ 'dstPath' ] = $dstPath;
73 $options[ 'path' ] = $dstPath;
74
75 return new TimedMediaTransformOutput( $options );
76 }
77
78 function getLength( $file ) {
79 if ( $this->isAudio( $file ) ) {
80 return 0.99875;
81 }
82 return 4.3666666666667;
83 }
84
85 function getBitRate( $file ) {
86 if ( $this->isAudio( $file ) ) {
87 return 41107;
88 }
89 return 590013;
90 }
91
92 function getWebType( $file ) {
93 if ( $this->isAudio( $file ) ) {
94 return "audio/ogg; codecs=\"vorbis\"";
95 }
96 return "video/ogg; codecs=\"theora\"";
97 }
98
99 function getFramerate( $file ) {
100 if ( $this->isAudio( $file ) ) {
101 return 0;
102 }
103 return 30;
104 }
105 }