38 $this->
setMwGlobals(
'wgThumbnailBuckets', $data[
'buckets'] );
39 $this->
setMwGlobals(
'wgThumbnailMinimumBucketDistance', $data[
'minimumBucketDistance'] );
41 $fileMock = $this->getMockBuilder( File::class )
42 ->setConstructorArgs( [
'fileMock',
false ] )
43 ->setMethods( [
'getWidth' ] )
44 ->getMockForAbstractClass();
46 $fileMock->expects( $this->
any() )
47 ->method(
'getWidth' )
48 ->will( $this->returnValue( $data[
'width'] ) );
51 $data[
'expectedBucket'],
52 $fileMock->getThumbnailBucket( $data[
'requestedWidth'] ),
140 $backendMock = $this->getMockBuilder( FSFileBackend::class )
141 ->setConstructorArgs( [ [
'name' =>
'backendMock',
'wikiId' =>
wfWikiID() ] ] )
144 $repoMock = $this->getMockBuilder( FileRepo::class )
145 ->setConstructorArgs( [ [
'name' =>
'repoMock',
'backend' => $backendMock ] ] )
146 ->setMethods( [
'fileExists',
'getLocalReference' ] )
149 $fsFile =
new FSFile(
'fsFilePath' );
151 $repoMock->expects( $this->
any() )
152 ->method(
'fileExists' )
153 ->will( $this->returnValue(
true ) );
155 $repoMock->expects( $this->
any() )
156 ->method(
'getLocalReference' )
157 ->will( $this->returnValue( $fsFile ) );
159 $handlerMock = $this->getMockBuilder( BitmapHandler::class )
160 ->setMethods( [
'supportsBucketing' ] )->getMock();
161 $handlerMock->expects( $this->
any() )
162 ->method(
'supportsBucketing' )
163 ->will( $this->returnValue( $data[
'supportsBucketing'] ) );
165 $fileMock = $this->getMockBuilder( File::class )
166 ->setConstructorArgs( [
'fileMock', $repoMock ] )
167 ->setMethods( [
'getThumbnailBucket',
'getLocalRefPath',
'getHandler' ] )
168 ->getMockForAbstractClass();
170 $fileMock->expects( $this->
any() )
171 ->method(
'getThumbnailBucket' )
172 ->will( $this->returnValue( $data[
'thumbnailBucket'] ) );
174 $fileMock->expects( $this->
any() )
175 ->method(
'getLocalRefPath' )
176 ->will( $this->returnValue(
'localRefPath' ) );
178 $fileMock->expects( $this->
any() )
179 ->method(
'getHandler' )
180 ->will( $this->returnValue( $handlerMock ) );
182 $reflection =
new ReflectionClass( $fileMock );
183 $reflection_property = $reflection->getProperty(
'handler' );
184 $reflection_property->setAccessible(
true );
185 $reflection_property->setValue( $fileMock, $handlerMock );
187 if ( !is_null( $data[
'tmpBucketedThumbCache'] ) ) {
188 $reflection_property = $reflection->getProperty(
'tmpBucketedThumbCache' );
189 $reflection_property->setAccessible(
true );
190 $reflection_property->setValue( $fileMock, $data[
'tmpBucketedThumbCache'] );
193 $result = $fileMock->getThumbnailSource(
194 [
'physicalWidth' => $data[
'physicalWidth'] ] );
196 $this->assertEquals( $data[
'expectedPath'], $result[
'path'], $data[
'message'] );
249 $this->
setMwGlobals(
'wgThumbnailBuckets', $data[
'buckets'] );
251 $backendMock = $this->getMockBuilder( FSFileBackend::class )
252 ->setConstructorArgs( [ [
'name' =>
'backendMock',
'wikiId' =>
wfWikiID() ] ] )
255 $repoMock = $this->getMockBuilder( FileRepo::class )
256 ->setConstructorArgs( [ [
'name' =>
'repoMock',
'backend' => $backendMock ] ] )
257 ->setMethods( [
'fileExists',
'getLocalReference' ] )
260 $fileMock = $this->getMockBuilder( File::class )
261 ->setConstructorArgs( [
'fileMock', $repoMock ] )
262 ->setMethods( [
'getWidth',
'getBucketThumbPath',
'makeTransformTmpFile',
263 'generateAndSaveThumb',
'getHandler' ] )
264 ->getMockForAbstractClass();
266 $handlerMock = $this->getMockBuilder( JpegHandler::class )
267 ->setMethods( [
'supportsBucketing' ] )->getMock();
268 $handlerMock->expects( $this->
any() )
269 ->method(
'supportsBucketing' )
270 ->will( $this->returnValue(
true ) );
272 $fileMock->expects( $this->
any() )
273 ->method(
'getHandler' )
274 ->will( $this->returnValue( $handlerMock ) );
276 $reflectionMethod =
new ReflectionMethod( File::class,
'generateBucketsIfNeeded' );
277 $reflectionMethod->setAccessible(
true );
279 $fileMock->expects( $this->
any() )
280 ->method(
'getWidth' )
281 ->will( $this->returnValue( $data[
'width'] ) );
283 $fileMock->expects( $data[
'expectedGetBucketThumbPathCalls'] )
284 ->method(
'getBucketThumbPath' );
286 $repoMock->expects( $data[
'expectedFileExistsCalls'] )
287 ->method(
'fileExists' )
288 ->will( $this->returnValue( $data[
'fileExistsReturn'] ) );
290 $fileMock->expects( $data[
'expectedMakeTransformTmpFile'] )
291 ->method(
'makeTransformTmpFile' )
292 ->will( $this->returnValue( $data[
'makeTransformTmpFileReturn'] ) );
294 $fileMock->expects( $data[
'expectedGenerateAndSaveThumb'] )
295 ->method(
'generateAndSaveThumb' )
296 ->will( $this->returnValue( $data[
'generateAndSaveThumbReturn'] ) );
298 $this->assertEquals( $data[
'expectedResult'],
299 $reflectionMethod->invoke(
302 'physicalWidth' => $data[
'physicalWidth'],
303 'physicalHeight' => $data[
'physicalHeight'] ]