TYPO3 CMS  TYPO3_7-6
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 
23 
28 {
32  protected $subject;
33 
38 
42  protected function setUp()
43  {
44  $this->subject = new ImageService();
45  $this->environmentService = $this->getMock(EnvironmentService::class);
46  $this->inject($this->subject, 'environmentService', $this->environmentService);
48  $_SERVER['HTTP_HOST'] = 'foo.bar';
49  }
50 
55  {
56  $reference = $this->getAccessibleMock(FileReference::class, [], [], '', false);
57  $file = $this->getMock(File::class, [], [], '', false);
58  $file->expects($this->once())->method('process')->willReturn($this->getMock(ProcessedFile::class, [], [], '', false));
59  $reference->expects($this->once())->method('getOriginalFile')->willReturn($file);
60  $reference->_set('file', $file);
61 
62  $this->subject->applyProcessingInstructions($reference, []);
63  }
64 
69  {
70  return [
71  'with scheme' => ['http://foo.bar/img.jpg', 'http://foo.bar/img.jpg'],
72  'scheme relative' => ['//foo.bar/img.jpg', '//foo.bar/img.jpg'],
73  'without scheme' => ['foo.bar/img.jpg', '/prefix/foo.bar/img.jpg'],
74  ];
75  }
76 
81  public function prefixIsCorrectlyAppliedToGetImageUri($imageUri, $expected)
82  {
83  $this->environmentService->expects($this->any())->method('isEnvironmentInFrontendMode')->willReturn(true);
84  $GLOBALS['TSFE'] = new \stdClass();
85  $GLOBALS['TSFE']->absRefPrefix = '/prefix/';
86 
87  $file = $this->getMock(File::class, [], [], '', false);
88  $file->expects($this->once())->method('getPublicUrl')->willReturn($imageUri);
89 
90  $this->assertSame($expected, $this->subject->getImageUri($file));
91  }
92 
97  {
98  return [
99  'with scheme' => ['http://foo.bar/img.jpg', 'http://foo.bar/img.jpg'],
100  'scheme relative' => ['//foo.bar/img.jpg', 'http://foo.bar/img.jpg'],
101  'without scheme' => ['foo.bar/img.jpg', 'http://foo.bar/prefix/foo.bar/img.jpg'],
102  ];
103  }
104 
110  {
111  $this->environmentService->expects($this->any())->method('isEnvironmentInFrontendMode')->willReturn(true);
112  $GLOBALS['TSFE'] = new \stdClass();
113  $GLOBALS['TSFE']->absRefPrefix = '/prefix/';
114 
115  $file = $this->getMock(File::class, [], [], '', false);
116  $file->expects($this->once())->method('getPublicUrl')->willReturn($imageUri);
117 
118  $this->assertSame($expected, $this->subject->getImageUri($file, true));
119  }
120 }
inject($target, $name, $dependency)
getAccessibleMock( $originalClassName, $methods=[], array $arguments=[], $mockClassName='', $callOriginalConstructor=true, $callOriginalClone=true, $callAutoload=true)
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']