TYPO3 CMS  TYPO3_7-6
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 
21 
26 {
31  {
32  $file = $this->getMockBuilder(File::class)
33  ->disableOriginalConstructor()
34  ->getMock();
35  // Use size slightly larger than default size to ensure processing
36  $file->expects($this->any())->method('getProperty')->will($this->returnValueMap([
37  ['width', 65],
38  ['height', 65],
39  ]));
40 
41  $task = $this->getMock(TaskInterface::class);
42  $task->expects($this->once())->method('getSourceFile')->willReturn($file);
43  $task->expects($this->once())->method('getConfiguration')->willReturn([]);
44 
45  $localPreviewHelper = $this->getMockBuilder(LocalPreviewHelper::class)
46  ->disableOriginalConstructor()
47  ->setMethods(['getTemporaryFilePath', 'generatePreviewFromFile'])
48  ->getMock();
49  $localPreviewHelper->expects($this->once())->method('getTemporaryFilePath')->willReturn('test/file');
50  // Assert that by default 64x64 is used as preview size
51  $localPreviewHelper->expects($this->once())->method('generatePreviewFromFile')
52  ->with($file, ['width' => 64, 'height' => 64], 'test/file');
53 
54  $localPreviewHelper->process($task);
55  }
56 
60  public function processDoesNotScaleUpImages()
61  {
62  $file = $this->getMockBuilder(File::class)
63  ->disableOriginalConstructor()
64  ->getMock();
65  $file->expects($this->any())->method('getProperty')->will($this->returnValueMap([
66  ['width', 20],
67  ['height', 20],
68  ]));
69 
70  $localPreviewHelper = $this->getMockBuilder(LocalPreviewHelper::class)
71  ->disableOriginalConstructor()
72  ->setMethods(['dummy'])
73  ->getMock();
74 
75  $task = $this->getMock(TaskInterface::class);
76  $task->expects($this->once())->method('getSourceFile')->willReturn($file);
77  $task->expects($this->once())->method('getConfiguration')->willReturn(['width' => 30, 'height' => 30]);
78 
79  $this->assertNull($localPreviewHelper->process($task));
80  }
81 
86  {
87  $file = $this->getMockBuilder(File::class)
88  ->disableOriginalConstructor()
89  ->getMock();
90  $file->expects($this->any())->method('getProperty')->will($this->returnValueMap([
91  ['width', 0],
92  ['height', 0],
93  ]));
94 
95  $task = $this->getMock(TaskInterface::class);
96  $task->expects($this->once())->method('getSourceFile')->willReturn($file);
97  $task->expects($this->once())->method('getConfiguration')->willReturn([]);
98 
99  $localPreviewHelper = $this->getMockBuilder(LocalPreviewHelper::class)
100  ->disableOriginalConstructor()
101  ->setMethods(['getTemporaryFilePath', 'generatePreviewFromFile'])
102  ->getMock();
103  $expectedResult = ['width' => 20, 'height' => 20, 'filePath' => 'test/file'];
104  $localPreviewHelper->expects($this->once())->method('generatePreviewFromFile')->willReturn($expectedResult);
105 
106  $this->assertEquals($expectedResult, $localPreviewHelper->process($task));
107  }
108 }