TYPO3 CMS  TYPO3_8-7
ImageScriptServiceTest.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 
22 
26 class ImageScriptServiceTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
27 {
31  protected $subject;
32 
37 
41  protected function setUp()
42  {
43  $this->subject = new ImageService();
44  $this->environmentService = $this->createMock(EnvironmentService::class);
45  $this->inject($this->subject, 'environmentService', $this->environmentService);
46  $_SERVER['HTTP_HOST'] = 'foo.bar';
47  }
48 
53  {
54  $reference = $this->getAccessibleMock(FileReference::class, [], [], '', false);
55  $file = $this->createMock(File::class);
56  $file->expects($this->once())->method('process')->willReturn($this->createMock(ProcessedFile::class));
57  $reference->expects($this->once())->method('getOriginalFile')->willReturn($file);
58  $reference->_set('file', $file);
59 
60  $this->subject->applyProcessingInstructions($reference, []);
61  }
62 
67  {
68  return [
69  'with scheme' => ['http://foo.bar/img.jpg', 'http://foo.bar/img.jpg'],
70  'scheme relative' => ['//foo.bar/img.jpg', '//foo.bar/img.jpg'],
71  'without scheme' => ['foo.bar/img.jpg', '/prefix/foo.bar/img.jpg'],
72  ];
73  }
74 
79  public function prefixIsCorrectlyAppliedToGetImageUri($imageUri, $expected)
80  {
81  $this->environmentService->expects($this->any())->method('isEnvironmentInFrontendMode')->willReturn(true);
82  $GLOBALS['TSFE'] = new \stdClass();
83  $GLOBALS['TSFE']->absRefPrefix = '/prefix/';
84 
85  $file = $this->createMock(File::class);
86  $file->expects($this->once())->method('getPublicUrl')->willReturn($imageUri);
87 
88  $this->assertSame($expected, $this->subject->getImageUri($file));
89  }
90 
95  {
96  return [
97  'with scheme' => ['http://foo.bar/img.jpg', 'http://foo.bar/img.jpg'],
98  'scheme relative' => ['//foo.bar/img.jpg', 'http://foo.bar/img.jpg'],
99  'without scheme' => ['foo.bar/img.jpg', 'http://foo.bar/prefix/foo.bar/img.jpg'],
100  ];
101  }
102 
108  {
109  $this->environmentService->expects($this->any())->method('isEnvironmentInFrontendMode')->willReturn(true);
110  $GLOBALS['TSFE'] = new \stdClass();
111  $GLOBALS['TSFE']->absRefPrefix = '/prefix/';
112 
113  $file = $this->createMock(File::class);
114  $file->expects($this->once())->method('getPublicUrl')->willReturn($imageUri);
115 
116  $this->assertSame($expected, $this->subject->getImageUri($file, true));
117  }
118 }
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']