TYPO3 CMS  TYPO3_8-7
LocalPreviewHelperTest.php
Go to the documentation of this file.
1 <?php
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
20 
24 class LocalPreviewHelperTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
25 {
30  {
31  $file = $this->createMock(File::class);
32  // Use size slightly larger than default size to ensure processing
33  $file->expects($this->any())->method('getProperty')->will($this->returnValueMap([
34  ['width', 65],
35  ['height', 65],
36  ]));
37 
38  $task = $this->createMock(TaskInterface::class);
39  $task->expects($this->once())->method('getSourceFile')->willReturn($file);
40  $task->expects($this->once())->method('getConfiguration')->willReturn([]);
41 
42  $localPreviewHelper = $this->getMockBuilder(LocalPreviewHelper::class)
43  ->disableOriginalConstructor()
44  ->setMethods(['getTemporaryFilePath', 'generatePreviewFromFile'])
45  ->getMock();
46  $localPreviewHelper->expects($this->once())->method('getTemporaryFilePath')->willReturn('test/file');
47  // Assert that by default 64x64 is used as preview size
48  $localPreviewHelper->expects($this->once())->method('generatePreviewFromFile')
49  ->with($file, ['width' => 64, 'height' => 64], 'test/file');
50 
51  $localPreviewHelper->process($task);
52  }
53 
57  public function processDoesNotScaleUpImages()
58  {
59  $file = $this->createMock(File::class);
60  $file->expects($this->any())->method('getProperty')->will($this->returnValueMap([
61  ['width', 20],
62  ['height', 20],
63  ]));
64 
65  $localPreviewHelper = $this->getMockBuilder(LocalPreviewHelper::class)
66  ->disableOriginalConstructor()
67  ->setMethods(['dummy'])
68  ->getMock();
69 
70  $task = $this->createMock(TaskInterface::class);
71  $task->expects($this->once())->method('getSourceFile')->willReturn($file);
72  $task->expects($this->once())->method('getConfiguration')->willReturn(['width' => 30, 'height' => 30]);
73 
74  $this->assertNull($localPreviewHelper->process($task));
75  }
76 
81  {
82  $file = $this->createMock(File::class);
83  $file->expects($this->any())->method('getProperty')->will($this->returnValueMap([
84  ['width', 0],
85  ['height', 0],
86  ]));
87 
88  $task = $this->createMock(TaskInterface::class);
89  $task->expects($this->once())->method('getSourceFile')->willReturn($file);
90  $task->expects($this->once())->method('getConfiguration')->willReturn([]);
91 
92  $localPreviewHelper = $this->getMockBuilder(LocalPreviewHelper::class)
93  ->disableOriginalConstructor()
94  ->setMethods(['getTemporaryFilePath', 'generatePreviewFromFile'])
95  ->getMock();
96  $expectedResult = ['width' => 20, 'height' => 20, 'filePath' => 'test/file'];
97  $localPreviewHelper->expects($this->once())->method('generatePreviewFromFile')->willReturn($expectedResult);
98 
99  $this->assertEquals($expectedResult, $localPreviewHelper->process($task));
100  }
101 }