‪TYPO3CMS  9.5
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 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
21 
25 class ‪LocalPreviewHelperTest extends UnitTestCase
26 {
31  {
32  $file = $this->createMock(File::class);
33  // Use size slightly larger than default size to ensure processing
34  $file->expects($this->any())->method('getProperty')->will($this->returnValueMap([
35  ['width', 65],
36  ['height', 65],
37  ]));
38 
39  $task = $this->createMock(TaskInterface::class);
40  $task->expects($this->once())->method('getSourceFile')->willReturn($file);
41  $task->expects($this->once())->method('getConfiguration')->willReturn([]);
42 
43  $localPreviewHelper = $this->getMockBuilder(LocalPreviewHelper::class)
44  ->disableOriginalConstructor()
45  ->setMethods(['getTemporaryFilePath', 'generatePreviewFromFile'])
46  ->getMock();
47  $localPreviewHelper->expects($this->once())->method('getTemporaryFilePath')->willReturn('test/file');
48  // Assert that by default 64x64 is used as preview size
49  $localPreviewHelper->expects($this->once())->method('generatePreviewFromFile')
50  ->with($file, ['width' => 64, 'height' => 64], 'test/file');
51 
52  $localPreviewHelper->process($task);
53  }
54 
59  {
60  $file = $this->createMock(File::class);
61  $file->expects($this->any())->method('getProperty')->will($this->returnValueMap([
62  ['width', 20],
63  ['height', 20],
64  ]));
65 
66  $localPreviewHelper = $this->getMockBuilder(LocalPreviewHelper::class)
67  ->disableOriginalConstructor()
68  ->setMethods(['dummy'])
69  ->getMock();
70 
71  $task = $this->createMock(TaskInterface::class);
72  $task->expects($this->once())->method('getSourceFile')->willReturn($file);
73  $task->expects($this->once())->method('getConfiguration')->willReturn(['width' => 30, 'height' => 30]);
74 
75  $this->assertNull($localPreviewHelper->process($task));
76  }
77 
82  {
83  $file = $this->createMock(File::class);
84  $file->expects($this->any())->method('getProperty')->will($this->returnValueMap([
85  ['width', 0],
86  ['height', 0],
87  ]));
88 
89  $task = $this->createMock(TaskInterface::class);
90  $task->expects($this->once())->method('getSourceFile')->willReturn($file);
91  $task->expects($this->once())->method('getConfiguration')->willReturn([]);
92 
93  $localPreviewHelper = $this->getMockBuilder(LocalPreviewHelper::class)
94  ->disableOriginalConstructor()
95  ->setMethods(['getTemporaryFilePath', 'generatePreviewFromFile'])
96  ->getMock();
97  $expectedResult = ['width' => 20, 'height' => 20, 'filePath' => 'test/file'];
98  $localPreviewHelper->expects($this->once())->method('generatePreviewFromFile')->willReturn($expectedResult);
99 
100  $this->assertEquals($expectedResult, $localPreviewHelper->process($task));
101  }
102 }
‪TYPO3\CMS\Core\Resource\Processing\LocalPreviewHelper
Definition: LocalPreviewHelper.php:29
‪TYPO3\CMS\Core\Tests\Unit\Resource\Processing\LocalPreviewHelperTest
Definition: LocalPreviewHelperTest.php:26
‪TYPO3\CMS\Core\Resource\Processing\TaskInterface
Definition: TaskInterface.php:31
‪TYPO3\CMS\Core\Tests\Unit\Resource\Processing\LocalPreviewHelperTest\processGeneratesPreviewEvenIfSourceFileHasNoSize
‪processGeneratesPreviewEvenIfSourceFileHasNoSize()
Definition: LocalPreviewHelperTest.php:81
‪TYPO3\CMS\Core\Tests\Unit\Resource\Processing\LocalPreviewHelperTest\processDoesNotScaleUpImages
‪processDoesNotScaleUpImages()
Definition: LocalPreviewHelperTest.php:58
‪TYPO3\CMS\Core\Tests\Unit\Resource\Processing
Definition: LocalPreviewHelperTest.php:2
‪TYPO3\CMS\Core\Resource\File
Definition: File.php:23
‪TYPO3\CMS\Core\Tests\Unit\Resource\Processing\LocalPreviewHelperTest\processProvidesDefaultSizeIfNotConfigured
‪processProvidesDefaultSizeIfNotConfigured()
Definition: LocalPreviewHelperTest.php:30