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