1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
|
<?php
class TestTimedMediaTransformOutput extends MediaWikiMediaTestCase {
private $sortMethod;
private $thumbObj;
function getFilePath() {
return __DIR__ . '/media';
}
protected function setUp() {
parent::setUp();
// Disable video thumbnail generation. Not needed for this test.
$reflection = new ReflectionClass( $this->repo );
$reflectionProperty = $reflection->getProperty( 'transformVia404' );
$reflectionProperty->setAccessible( true );
$reflectionProperty->setValue( $this->repo, true );
$this->setMWGlobals( 'wgMinimumVideoPlayerSize', '400' );
}
/**
* @param $width int The requested width of the thumbnail
* @param $minVideoSize int The min width a non-pop up video is acceptable
* @param $expectPopup boolean Do we expect a pop up video
*
* @dataProvider providerIsPopUp
*/
function testIsPopUp( $width, $minVideoSize, $expectPopup ) {
$this->setMwGlobals( 'wgMinimumVideoPlayerSize', $minVideoSize );
// Note this file has a width of 400px and a height of 300px
$file = $this->dataFile( 'test5seconds.electricsheep.300x400.ogv', 'application/ogg' );
$thumbnail = $file->transform( array( 'width' => $width ) );
$this->assertTrue( $thumbnail && !$thumbnail->isError() );
$reflection = new ReflectionClass( $thumbnail );
$reflMethod = $reflection->getMethod( 'useImagePopUp' );
$reflMethod->setAccessible( true );
$actual = $reflMethod->invoke( $thumbnail );
$this->assertEquals( $actual, $expectPopup );
}
function providerIsPopUp() {
return array(
array( 400, 800, false ),
array( 300, 800, true ),
array( 300, 200, false ),
array( 300, 300, false )
);
}
/**
* @param $thumbWidth int Requested width
* @param $sources array
* @param $sortedSources array
* @dataProvider providerSortMediaByBandwidth
*/
function testSortMediaByBandwidth( $thumbWidth, $sources, $sortedSources ) {
$params = array(
'width' => $thumbWidth,
'height' => $thumbWidth * 9 / 16,
'isVideo' => true,
'fillwindow' => false,
'file' => new FakeDimensionFile( array( 1820, 1024 ) )
);
$this->thumbObj = new TimedMediaTransformOutput( $params );
$reflection = new ReflectionClass( $this->thumbObj );
$this->sortMethod = $reflection->getMethod( 'sortMediaByBandwidth' );
$this->sortMethod->setAccessible( true );
usort( $sources, array( $this, 'callSortMethodHelper' ) );
$this->assertEquals( $sortedSources, $sources );
}
public function callSortMethodHelper( $a, $b ) {
return $this->sortMethod->invoke( $this->thumbObj, $a, $b );
}
function providerSortMediaByBandwidth() {
return array(
array(
600,
array(
array( 'width' => 1000, 'bandwidth' => 2000 ),
array( 'width' => 1000, 'bandwidth' => 7000 ),
array( 'width' => 1000, 'bandwidth' => 1000 ),
),
array(
array( 'width' => 1000, 'bandwidth' => 1000 ),
array( 'width' => 1000, 'bandwidth' => 2000 ),
array( 'width' => 1000, 'bandwidth' => 7000 ),
),
),
array(
600,
array(
array( 'width' => 200, 'bandwidth' => 2000 ),
array( 'width' => 1000, 'bandwidth' => 7000 ),
array( 'width' => 200, 'bandwidth' => 1000 ),
),
array(
array( 'width' => 1000, 'bandwidth' => 7000 ),
array( 'width' => 200, 'bandwidth' => 1000 ),
array( 'width' => 200, 'bandwidth' => 2000 ),
),
),
array(
/* Pop up viewer in this case */
100,
array(
array( 'width' => 700, 'bandwidth' => 2000 ),
array( 'width' => 1000, 'bandwidth' => 7000 ),
array( 'width' => 700, 'bandwidth' => 1000 ),
),
array(
array( 'width' => 1000, 'bandwidth' => 7000 ),
array( 'width' => 700, 'bandwidth' => 1000 ),
array( 'width' => 700, 'bandwidth' => 2000 ),
),
),
array(
600,
array(
array( 'width' => 700, 'bandwidth' => 2000 ),
array( 'width' => 800, 'bandwidth' => 7000 ),
array( 'width' => 1000, 'bandwidth' => 1000 ),
),
array(
array( 'width' => 1000, 'bandwidth' => 1000 ),
array( 'width' => 700, 'bandwidth' => 2000 ),
array( 'width' => 800, 'bandwidth' => 7000 ),
),
),
);
}
}
|