‪TYPO3CMS  ‪main
GifBuilderTest.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
29 use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
30 
31 final class ‪GifBuilderTest extends FunctionalTestCase
32 {
33  private function ‪setupFullTestEnvironment(): void
34  {
35  $this->importCSVDataSet(__DIR__ . '/../Fixtures/sys_file_storage.csv');
36  $this->importCSVDataSet(__DIR__ . '/../Fixtures/be_users.csv');
37  $this->setUpBackendUser(1);
38  ‪$GLOBALS['TYPO3_REQUEST'] = (new ‪ServerRequest('https://www.example.com/'))
39  ->withAttribute('applicationType', ‪SystemEnvironmentBuilder::REQUESTTYPE_BE);
40  ‪$GLOBALS['TSFE'] = $this->createMock(TypoScriptFrontendController::class);
42  }
43 
47  private function ‪simulateCliRequestInComposerMode(): void
48  {
51  true,
52  true,
54  ‪Environment::getPublicPath() . '/public',
58  ‪Environment::isWindows() ? 'WINDOWS' : 'UNIX'
59  );
60  }
61 
66  {
68 
69  $conf = [
70  'XY' => '10,10',
71  'format' => 'jpg',
72  ];
73 
74  $gifBuilder = new ‪GifBuilder();
75  $gifBuilder->start($conf, []);
76  $gifFileName = $gifBuilder->gifBuild();
77 
78  self::assertFileDoesNotExist(‪Environment::getProjectPath() . '/' . $gifFileName);
79  self::assertFileExists(‪Environment::getPublicPath() . '/' . $gifFileName);
80  }
81 
86  {
89 
90  copy(
91  __DIR__ . '/../Fixtures/Images/kasper-skarhoj1.jpg',
92  ‪Environment::getPublicPath() . '/fileadmin/kasper-skarhoj-gifbuilder.jpg'
93  );
94 
95  $contentObjectRenderer = GeneralUtility::makeInstance(ContentObjectRenderer::class);
96  $result = $contentObjectRenderer->cObjGetSingle(
97  'IMAGE',
98  [
99  'file' => 'GIFBUILDER',
100  'file.' => [
101  'XY' => '[10.w],[10.h]',
102  'format' => 'jpg',
103 
104  '10' => 'IMAGE',
105  '10.' => [
106  'file' => 'fileadmin/kasper-skarhoj-gifbuilder.jpg',
107  ],
108  ],
109  ]
110  );
111  self::assertStringStartsWith('<img src="typo3temp/assets/images/csm_kasper-skarhoj-gifbuilder_', $result);
112  }
113 
118  {
121 
122  copy(
123  __DIR__ . '/../Fixtures/Images/kasper-skarhoj1.jpg',
124  ‪Environment::getPublicPath() . '/fileadmin/kasper-skarhoj-gifbuilder-imageresource.jpg'
125  );
126 
127  $contentObjectRenderer = GeneralUtility::makeInstance(ContentObjectRenderer::class);
128  $result = $contentObjectRenderer->cObjGetSingle(
129  'IMG_RESOURCE',
130  [
131  'file' => 'GIFBUILDER',
132  'file.' => [
133  'XY' => '[10.w],[10.h]',
134  'format' => 'jpg',
135 
136  '10' => 'IMAGE',
137  '10.' => [
138  'file' => 'fileadmin/kasper-skarhoj-gifbuilder-imageresource.jpg',
139  ],
140  ],
141  ]
142  );
143  self::assertStringStartsWith('typo3temp/assets/images/csm_kasper-skarhoj-gifbuilder-imageresource_', $result);
144  }
145 
150  {
153 
154  copy(
155  __DIR__ . '/../Fixtures/Images/kasper-skarhoj1.jpg',
156  ‪Environment::getPublicPath() . '/fileadmin/kasper-skarhoj-gifbuilder.jpg'
157  );
158 
159  $contentObjectRenderer = GeneralUtility::makeInstance(ContentObjectRenderer::class);
160  $result = $contentObjectRenderer->cObjGetSingle(
161  'IMAGE',
162  [
163  'file' => 'GIFBUILDER',
164  'file.' => [
165  'XY' => '[10.w],[10.h]',
166  'format' => 'jpg',
167 
168  '10' => 'IMAGE',
169  '10.' => [
170  'file' => 'fileadmin/kasper-skarhoj-gifbuilder.jpg',
171  ],
172  '20' => 'IMAGE',
173  '20.' => [
174  'offset' => '0,500',
175  'XY' => '[mask.w],40',
176 
177  'file' => 'GIFBUILDER',
178  'file.' => [
179  'XY' => '400,60',
180  'backColor' => '#cccccc',
181  ],
182 
183  'mask' => 'GIFBUILDER',
184  'mask.' => [
185  'XY' => '[10.w]+55,60',
186  'backColor' => '#cccccc',
187 
188  '10' => 'TEXT',
189  '10.' => [
190  'text' => 'Kasper Skårhøj',
191  'fontColor' => '#111111',
192  'fontSize' => '20',
193  'offset' => '20,40',
194  ],
195  ],
196  ],
197  ],
198  ]
199  );
200  self::assertStringStartsWith('<img src="typo3temp/', $result);
201  }
202 
208  public function ‪overlayImagesHasStableHash(): void
209  {
211 
212  copy(
213  __DIR__ . '/../Fixtures/Images/kasper-skarhoj1.jpg',
214  ‪Environment::getPublicPath() . '/fileadmin/kasper-skarhoj1.jpg'
215  );
216 
217  $storageRepository = GeneralUtility::makeInstance(StorageRepository::class)->findByUid(1);
218  $file = $storageRepository->getFile('kasper-skarhoj1.jpg');
219 
220  self::assertInstanceOf(File::class, $file);
221  self::assertFalse($file->isMissing());
222 
223  $conf = [
224  'XY' => '[10.w],[10.h]',
225  'format' => 'jpg',
226  'quality' => 88,
227  '10' => 'IMAGE',
228  '10.' => [
229  'file' => $file,
230  'file.' => [
231  'width' => 300,
232  ],
233  ],
234  '30' => 'IMAGE',
235  '30.' => [
236  'file' => $file,
237  'file.' => [
238  'align' => 'l,t',
239  'width' => 100,
240  ],
241  ],
242  ];
243 
244  $gifBuilder = new ‪GifBuilder();
245  $gifBuilder->start($conf, []);
246  $setup1 = $gifBuilder->setup;
247  $fileName1 = $gifBuilder->gifBuild();
248 
249  // Recreate a fresh GifBuilder instance, to catch inconsistencies in hashing for different instances
250  $gifBuilder = new ‪GifBuilder();
251  $gifBuilder->start($conf, []);
252  $setup2 = $gifBuilder->setup;
253  $fileName2 = $gifBuilder->gifBuild();
254 
255  self::assertSame($setup1, $setup2, 'The Setup resulting from two equal configurations must be equal');
256  self::assertSame($fileName1, $fileName2);
257  }
258 }
‪TYPO3\CMS\Frontend\Tests\Functional\Imaging\GifBuilderTest\setupFullTestEnvironment
‪setupFullTestEnvironment()
Definition: GifBuilderTest.php:33
‪TYPO3\CMS\Frontend\Tests\Functional\Imaging\GifBuilderTest\simulateCliRequestInComposerMode
‪simulateCliRequestInComposerMode()
Definition: GifBuilderTest.php:47
‪TYPO3\CMS\Core\Core\SystemEnvironmentBuilder
Definition: SystemEnvironmentBuilder.php:41
‪TYPO3\CMS\Frontend\Tests\Functional\Imaging\GifBuilderTest\buildImageInCommandLineInterfaceAndComposerMode
‪buildImageInCommandLineInterfaceAndComposerMode()
Definition: GifBuilderTest.php:85
‪TYPO3\CMS\Core\Core\Environment\getPublicPath
‪static getPublicPath()
Definition: Environment.php:187
‪TYPO3\CMS\Core\Core\SystemEnvironmentBuilder\REQUESTTYPE_BE
‪const REQUESTTYPE_BE
Definition: SystemEnvironmentBuilder.php:45
‪TYPO3\CMS\Frontend\Tests\Functional\Imaging\GifBuilderTest\getImageResourceInCommandLineInterfaceAndComposerMode
‪getImageResourceInCommandLineInterfaceAndComposerMode()
Definition: GifBuilderTest.php:117
‪TYPO3\CMS\Core\Core\Environment\getCurrentScript
‪static getCurrentScript()
Definition: Environment.php:220
‪TYPO3\CMS\Frontend\Tests\Functional\Imaging
Definition: GifBuilderTest.php:18
‪TYPO3\CMS\Core\Core\Environment\getVarPath
‪static getVarPath()
Definition: Environment.php:197
‪TYPO3\CMS\Core\Core\Environment\getConfigPath
‪static getConfigPath()
Definition: Environment.php:212
‪TYPO3\CMS\Core\Core\Environment\getProjectPath
‪static string getProjectPath()
Definition: Environment.php:160
‪TYPO3\CMS\Core\Utility\GeneralUtility\mkdir_deep
‪static mkdir_deep($directory)
Definition: GeneralUtility.php:1638
‪TYPO3\CMS\Core\Resource\StorageRepository
Definition: StorageRepository.php:38
‪TYPO3\CMS\Core\Resource\File
Definition: File.php:26
‪TYPO3\CMS\Frontend\Tests\Functional\Imaging\GifBuilderTest\overlayImagesHasStableHash
‪overlayImagesHasStableHash()
Definition: GifBuilderTest.php:208
‪TYPO3\CMS\Core\Core\Environment\initialize
‪static initialize(ApplicationContext $context, bool $cli, bool $composerMode, string $projectPath, string $publicPath, string $varPath, string $configPath, string $currentScript, string $os)
Definition: Environment.php:100
‪TYPO3\CMS\Core\Http\ServerRequest
Definition: ServerRequest.php:39
‪TYPO3\CMS\Frontend\Imaging\GifBuilder
Definition: GifBuilder.php:59
‪TYPO3\CMS\Frontend\Tests\Functional\Imaging\GifBuilderTest\buildImageWithMaskInCommandLineInterfaceAndComposerMode
‪buildImageWithMaskInCommandLineInterfaceAndComposerMode()
Definition: GifBuilderTest.php:149
‪TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController
Definition: TypoScriptFrontendController.php:102
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Frontend\Tests\Functional\Imaging\GifBuilderTest
Definition: GifBuilderTest.php:32
‪TYPO3\CMS\Core\Core\Environment
Definition: Environment.php:41
‪TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer
Definition: ContentObjectRenderer.php:90
‪TYPO3\CMS\Frontend\Tests\Functional\Imaging\GifBuilderTest\buildSimpleGifBuilderImageInComposerMode
‪buildSimpleGifBuilderImageInComposerMode()
Definition: GifBuilderTest.php:65
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:51
‪TYPO3\CMS\Core\Core\Environment\getContext
‪static getContext()
Definition: Environment.php:128
‪TYPO3\CMS\Core\Core\Environment\isWindows
‪static isWindows()
Definition: Environment.php:276