‪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 
25 use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
28 use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
29 
30 class ‪GifBuilderTest extends FunctionalTestCase
31 {
32  private function ‪setupFullTestEnvironment(): void
33  {
34  $this->importCSVDataSet(__DIR__ . '/../Fixtures/sys_file_storage.csv');
35  $this->importCSVDataSet(__DIR__ . '/../Fixtures/be_users.csv');
36  $this->setUpBackendUser(1);
37  ‪$GLOBALS['TYPO3_REQUEST'] = (new ‪ServerRequest('https://www.example.com/'))
38  ->withAttribute('applicationType', ‪SystemEnvironmentBuilder::REQUESTTYPE_BE);
39  ‪$GLOBALS['TSFE'] = $this->createMock(TypoScriptFrontendController::class);
41  }
42 
46  private function ‪simulateCliRequestInComposerMode(): void
47  {
50  true,
51  true,
53  ‪Environment::getPublicPath() . '/public',
57  ‪Environment::isWindows() ? 'WINDOWS' : 'UNIX'
58  );
59  }
60 
65  {
67 
68  $conf = [
69  'XY' => '10,10',
70  'format' => 'jpg',
71  ];
72 
73  $gifBuilder = new ‪GifBuilder();
74  $gifBuilder->start($conf, []);
75  $gifFileName = $gifBuilder->gifBuild();
76 
77  self::assertFileDoesNotExist(‪Environment::getProjectPath() . '/' . $gifFileName);
78  self::assertFileExists(‪Environment::getPublicPath() . '/' . $gifFileName);
79  }
80 
85  {
88 
89  copy(
90  __DIR__ . '/../Fixtures/Images/kasper-skarhoj1.jpg',
91  ‪Environment::getPublicPath() . '/fileadmin/kasper-skarhoj-gifbuilder.jpg'
92  );
93 
94  $contentObjectRenderer = GeneralUtility::makeInstance(ContentObjectRenderer::class);
95  $result = $contentObjectRenderer->cObjGetSingle(
96  'IMAGE',
97  [
98  'file' => 'GIFBUILDER',
99  'file.' => [
100  'XY' => '[10.w],[10.h]',
101  'format' => 'jpg',
102 
103  '10' => 'IMAGE',
104  '10.' => [
105  'file' => 'fileadmin/kasper-skarhoj-gifbuilder.jpg',
106  ],
107  ],
108  ]
109  );
110  self::assertStringStartsWith('<img src="typo3temp/assets/images/csm_kasper-skarhoj-gifbuilder_', $result);
111  }
112 
117  {
120 
121  copy(
122  __DIR__ . '/../Fixtures/Images/kasper-skarhoj1.jpg',
123  ‪Environment::getPublicPath() . '/fileadmin/kasper-skarhoj-gifbuilder-imageresource.jpg'
124  );
125 
126  $contentObjectRenderer = GeneralUtility::makeInstance(ContentObjectRenderer::class);
127  $result = $contentObjectRenderer->cObjGetSingle(
128  'IMG_RESOURCE',
129  [
130  'file' => 'GIFBUILDER',
131  'file.' => [
132  'XY' => '[10.w],[10.h]',
133  'format' => 'jpg',
134 
135  '10' => 'IMAGE',
136  '10.' => [
137  'file' => 'fileadmin/kasper-skarhoj-gifbuilder-imageresource.jpg',
138  ],
139  ],
140  ]
141  );
142  self::assertStringStartsWith('typo3temp/assets/images/csm_kasper-skarhoj-gifbuilder-imageresource_', $result);
143  }
144 
149  {
152 
153  copy(
154  __DIR__ . '/../Fixtures/Images/kasper-skarhoj1.jpg',
155  ‪Environment::getPublicPath() . '/fileadmin/kasper-skarhoj-gifbuilder.jpg'
156  );
157 
158  $contentObjectRenderer = GeneralUtility::makeInstance(ContentObjectRenderer::class);
159  $result = $contentObjectRenderer->cObjGetSingle(
160  'IMAGE',
161  [
162  'file' => 'GIFBUILDER',
163  'file.' => [
164  'XY' => '[10.w],[10.h]',
165  'format' => 'jpg',
166 
167  '10' => 'IMAGE',
168  '10.' => [
169  'file' => 'fileadmin/kasper-skarhoj-gifbuilder.jpg',
170  ],
171  '20' => 'IMAGE',
172  '20.' => [
173  'offset' => '0,500',
174  'XY' => '[mask.w],40',
175 
176  'file' => 'GIFBUILDER',
177  'file.' => [
178  'XY' => '400,60',
179  'backColor' => '#cccccc',
180  ],
181 
182  'mask' => 'GIFBUILDER',
183  'mask.' => [
184  'XY' => '[10.w]+55,60',
185  'backColor' => '#cccccc',
186 
187  '10' => 'TEXT',
188  '10.' => [
189  'text' => 'Kasper Skårhøj',
190  'fontColor' => '#111111',
191  'fontSize' => '20',
192  'offset' => '20,40',
193  ],
194  ],
195  ],
196  ],
197  ]
198  );
199  self::assertStringStartsWith('<img src="typo3temp/', $result);
200  }
201 
207  public function ‪overlayImagesHasStableHash(): void
208  {
210 
211  copy(
212  __DIR__ . '/../Fixtures/Images/kasper-skarhoj1.jpg',
213  ‪Environment::getPublicPath() . '/fileadmin/kasper-skarhoj1.jpg'
214  );
215 
216  $storageRepository = GeneralUtility::makeInstance(StorageRepository::class)->findByUid(1);
217  $file = $storageRepository->getFile('kasper-skarhoj1.jpg');
218 
219  self::assertFalse($file->isMissing());
220 
221  $conf = [
222  'XY' => '[10.w],[10.h]',
223  'format' => 'jpg',
224  'quality' => 88,
225  '10' => 'IMAGE',
226  '10.' => [
227  'file' => $file,
228  'file.' => [
229  'width' => 300,
230  ],
231  ],
232  '30' => 'IMAGE',
233  '30.' => [
234  'file' => $file,
235  'file.' => [
236  'align' => 'l,t',
237  'width' => 100,
238  ],
239  ],
240  ];
241 
242  $gifBuilder = new ‪GifBuilder();
243  $gifBuilder->start($conf, []);
244  $setup1 = $gifBuilder->setup;
245  $fileName1 = $gifBuilder->gifBuild();
246 
247  // Recreate a fresh GifBuilder instance, to catch inconsistencies in hashing for different instances
248  $gifBuilder = new ‪GifBuilder();
249  $gifBuilder->start($conf, []);
250  $setup2 = $gifBuilder->setup;
251  $fileName2 = $gifBuilder->gifBuild();
252 
253  self::assertSame($setup1, $setup2, 'The Setup resulting from two equal configurations must be equal');
254  self::assertSame($fileName1, $fileName2);
255  }
256 }
‪TYPO3\CMS\Frontend\Tests\Functional\Imaging\GifBuilderTest\setupFullTestEnvironment
‪setupFullTestEnvironment()
Definition: GifBuilderTest.php:32
‪TYPO3\CMS\Frontend\Tests\Functional\Imaging\GifBuilderTest\simulateCliRequestInComposerMode
‪simulateCliRequestInComposerMode()
Definition: GifBuilderTest.php:46
‪TYPO3\CMS\Core\Core\SystemEnvironmentBuilder
Definition: SystemEnvironmentBuilder.php:41
‪TYPO3\CMS\Frontend\Tests\Functional\Imaging\GifBuilderTest\buildImageInCommandLineInterfaceAndComposerMode
‪buildImageInCommandLineInterfaceAndComposerMode()
Definition: GifBuilderTest.php:84
‪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:116
‪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:1753
‪TYPO3\CMS\Core\Resource\StorageRepository
Definition: StorageRepository.php:38
‪TYPO3\CMS\Frontend\Tests\Functional\Imaging\GifBuilderTest\overlayImagesHasStableHash
‪overlayImagesHasStableHash()
Definition: GifBuilderTest.php:207
‪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:37
‪TYPO3\CMS\Frontend\Imaging\GifBuilder
Definition: GifBuilder.php:56
‪TYPO3\CMS\Frontend\Tests\Functional\Imaging\GifBuilderTest\buildImageWithMaskInCommandLineInterfaceAndComposerMode
‪buildImageWithMaskInCommandLineInterfaceAndComposerMode()
Definition: GifBuilderTest.php:148
‪TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController
Definition: TypoScriptFrontendController.php:105
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Frontend\Tests\Functional\Imaging\GifBuilderTest
Definition: GifBuilderTest.php:31
‪TYPO3\CMS\Core\Core\Environment
Definition: Environment.php:41
‪TYPO3\CMS\Frontend\Tests\Functional\Imaging\GifBuilderTest\buildSimpleGifBuilderImageInComposerMode
‪buildSimpleGifBuilderImageInComposerMode()
Definition: GifBuilderTest.php:64
‪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:287