‪TYPO3CMS  9.5
ImageScriptServiceTest.php
Go to the documentation of this file.
1 <?php
2 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 
24 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
25 
29 class ‪ImageScriptServiceTest extends UnitTestCase
30 {
34  protected ‪$resetSingletonInstances = true;
35 
39  protected ‪$subject;
40 
44  protected ‪$environmentService;
45 
49  protected function ‪setUp(): void
50  {
51  $this->environmentService = $this->createMock(EnvironmentService::class);
52  $resourceFactory = $this->createMock(ResourceFactory::class);
53  $this->subject = new ‪ImageService($this->environmentService, $resourceFactory);
54  $_SERVER['HTTP_HOST'] = 'foo.bar';
55  }
56 
60  public function ‪fileIsUnwrappedFromReferenceForProcessing(): void
61  {
62  $reference = $this->getAccessibleMock(FileReference::class, [], [], '', false);
63  $file = $this->createMock(File::class);
64  $file->expects($this->once())->method('process')->willReturn($this->createMock(ProcessedFile::class));
65  $reference->expects($this->once())->method('getOriginalFile')->willReturn($file);
66  $reference->_set('file', $file);
67 
68  $this->subject->applyProcessingInstructions($reference, []);
69  }
70 
75  {
76  return [
77  'with scheme' => ['http://foo.bar/img.jpg', 'http://foo.bar/img.jpg'],
78  'scheme relative' => ['//foo.bar/img.jpg', '//foo.bar/img.jpg'],
79  'without scheme' => ['foo.bar/img.jpg', '/prefix/foo.bar/img.jpg'],
80  ];
81  }
82 
87  public function ‪prefixIsCorrectlyAppliedToGetImageUri($imageUri, $expected): void
88  {
89  $this->environmentService->expects($this->any())->method('isEnvironmentInFrontendMode')->willReturn(true);
90  ‪$GLOBALS['TSFE'] = new \stdClass();
91  ‪$GLOBALS['TSFE']->absRefPrefix = '/prefix/';
92 
93  $file = $this->createMock(File::class);
94  $file->expects($this->once())->method('getPublicUrl')->willReturn($imageUri);
95 
96  $this->assertSame($expected, $this->subject->getImageUri($file));
97  }
98 
103  {
104  return [
105  'with scheme' => ['http://foo.bar/img.jpg', 'http://foo.bar/img.jpg'],
106  'scheme relative' => ['//foo.bar/img.jpg', 'http://foo.bar/img.jpg'],
107  'without scheme' => ['foo.bar/img.jpg', 'http://foo.bar/prefix/foo.bar/img.jpg'],
108  ];
109  }
110 
115  public function ‪prefixIsCorrectlyAppliedToGetImageUriWithForcedAbsoluteUrl($imageUri, $expected): void
116  {
117  $this->environmentService->expects($this->any())->method('isEnvironmentInFrontendMode')->willReturn(true);
118  ‪$GLOBALS['TSFE'] = new \stdClass();
119  ‪$GLOBALS['TSFE']->absRefPrefix = '/prefix/';
120 
121  $file = $this->createMock(File::class);
122  $file->expects($this->once())->method('getPublicUrl')->willReturn($imageUri);
123 
124  $this->assertSame($expected, $this->subject->getImageUri($file, true));
125  }
126 }
‪TYPO3\CMS\Extbase\Tests\Unit\Service
Definition: CacheServiceTest.php:2
‪TYPO3\CMS\Extbase\Tests\Unit\Service\ImageScriptServiceTest\prefixIsCorrectlyAppliedToGetImageUriDataProvider
‪array prefixIsCorrectlyAppliedToGetImageUriDataProvider()
Definition: ImageScriptServiceTest.php:71
‪TYPO3\CMS\Extbase\Tests\Unit\Service\ImageScriptServiceTest
Definition: ImageScriptServiceTest.php:30
‪TYPO3\CMS\Core\Resource\FileReference
Definition: FileReference.php:31
‪TYPO3\CMS\Extbase\Service\ImageService
Definition: ImageService.php:30
‪TYPO3\CMS\Core\Resource\ResourceFactory
Definition: ResourceFactory.php:33
‪TYPO3\CMS\Core\Resource\File
Definition: File.php:23
‪TYPO3\CMS\Extbase\Tests\Unit\Service\ImageScriptServiceTest\$resetSingletonInstances
‪bool $resetSingletonInstances
Definition: ImageScriptServiceTest.php:33
‪TYPO3\CMS\Extbase\Tests\Unit\Service\ImageScriptServiceTest\prefixIsCorrectlyAppliedToGetImageUri
‪prefixIsCorrectlyAppliedToGetImageUri($imageUri, $expected)
Definition: ImageScriptServiceTest.php:84
‪TYPO3\CMS\Extbase\Tests\Unit\Service\ImageScriptServiceTest\setUp
‪setUp()
Definition: ImageScriptServiceTest.php:46
‪TYPO3\CMS\Extbase\Service\EnvironmentService
Definition: EnvironmentService.php:24
‪TYPO3\CMS\Core\Resource\ProcessedFile
Definition: ProcessedFile.php:42
‪TYPO3\CMS\Extbase\Tests\Unit\Service\ImageScriptServiceTest\fileIsUnwrappedFromReferenceForProcessing
‪fileIsUnwrappedFromReferenceForProcessing()
Definition: ImageScriptServiceTest.php:57
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Extbase\Tests\Unit\Service\ImageScriptServiceTest\prefixIsCorrectlyAppliedToGetImageUriWithAbsolutePathDataProvider
‪array prefixIsCorrectlyAppliedToGetImageUriWithAbsolutePathDataProvider()
Definition: ImageScriptServiceTest.php:99
‪TYPO3\CMS\Extbase\Tests\Unit\Service\ImageScriptServiceTest\$environmentService
‪EnvironmentService PHPUnit_Framework_MockObject_MockObject $environmentService
Definition: ImageScriptServiceTest.php:41
‪TYPO3\CMS\Extbase\Tests\Unit\Service\ImageScriptServiceTest\prefixIsCorrectlyAppliedToGetImageUriWithForcedAbsoluteUrl
‪prefixIsCorrectlyAppliedToGetImageUriWithForcedAbsoluteUrl($imageUri, $expected)
Definition: ImageScriptServiceTest.php:112
‪TYPO3\CMS\Extbase\Tests\Unit\Service\ImageScriptServiceTest\$subject
‪ImageService $subject
Definition: ImageScriptServiceTest.php:37