2 declare(strict_types = 1);
18 use Psr\Log\LoggerInterface;
25 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
50 protected function setUp()
54 $this->frontendControllerMock = $this->getAccessibleMock(
55 TypoScriptFrontendController::class,
72 $logManagerMock = $this->getMockBuilder(LogManager::class)->getMock();
73 $loggerMock = $this->getMockBuilder(LoggerInterface::class)->getMock();
74 $logManagerMock->expects($this->any())
76 ->willReturn($loggerMock);
77 GeneralUtility::setSingletonInstance(LogManager::class, $logManagerMock);
86 'Missing forceAbsoluteUrl leaves URL untouched' => [
91 'Absolute URL stays unchanged' => [
92 'http://example.org/',
93 'http://example.org/',
95 'forceAbsoluteUrl' =>
'1'
98 'Absolute URL stays unchanged 2' => [
99 'http://example.org/resource.html',
100 'http://example.org/resource.html',
102 'forceAbsoluteUrl' =>
'1'
105 'Scheme and host w/o ending slash stays unchanged' => [
106 'http://example.org',
107 'http://example.org',
109 'forceAbsoluteUrl' =>
'1'
112 'Scheme can be forced' => [
113 'typo3://example.org',
114 'http://example.org',
116 'forceAbsoluteUrl' =>
'1',
117 'forceAbsoluteUrl.' => [
122 'Relative path old-style' => [
123 'http://localhost/fileadmin/dummy.txt',
124 '/fileadmin/dummy.txt',
126 'forceAbsoluteUrl' =>
'1',
130 'http://localhost/fileadmin/dummy.txt',
131 'fileadmin/dummy.txt',
133 'forceAbsoluteUrl' =>
'1',
136 'Scheme can be forced with pseudo-relative path' => [
137 'typo3://localhost/fileadmin/dummy.txt',
138 '/fileadmin/dummy.txt',
140 'forceAbsoluteUrl' =>
'1',
141 'forceAbsoluteUrl.' => [
146 'Hostname only is not treated as valid absolute URL' => [
147 'http://localhost/example.org',
150 'forceAbsoluteUrl' =>
'1'
153 'Scheme and host is added to local file path' => [
154 'typo3://localhost/fileadmin/my.pdf',
157 'forceAbsoluteUrl' =>
'1',
158 'forceAbsoluteUrl.' => [
186 $this->frontendControllerMock->absRefPrefix =
'';
187 $contentObjectRendererProphecy = $this->prophesize(ContentObjectRenderer::class);
188 $subject = $this->getAccessibleMock(
189 AbstractTypolinkBuilder::class,
191 [$contentObjectRendererProphecy->reveal(), $this->frontendControllerMock]
194 $_SERVER[
'HTTP_HOST'] =
'localhost';
195 $_SERVER[
'SCRIPT_NAME'] =
'/typo3/index.php';
196 $this->assertEquals($expected, $subject->_call(
'forceAbsoluteUrl', $url, $configuration));
215 $contentObjectRendererProphecy = $this->prophesize(ContentObjectRenderer::class);
216 $subject = $this->getAccessibleMock(
217 AbstractTypolinkBuilder::class,
219 [$contentObjectRendererProphecy->reveal(), $this->frontendControllerMock]
222 $_SERVER[
'HTTP_HOST'] =
'localhost';
223 $_SERVER[
'SCRIPT_NAME'] =
'/subfolder/typo3/index.php';
225 $expected =
'http://localhost/subfolder/fileadmin/my.pdf';
226 $url =
'fileadmin/my.pdf';
228 'forceAbsoluteUrl' =>
'1'
231 $this->assertEquals($expected, $subject->_call(
'forceAbsoluteUrl', $url, $configuration));
241 $targetName = $this->getUniqueId(
'name_');
242 $target = $this->getUniqueId(
'target_');
243 $fallback = $this->getUniqueId(
'fallback_');
245 'Take target from $conf, if $conf[$targetName] is set.' =>
248 [$targetName => $target],
254 'Else from fallback, if not $respectFrameSetOption ...' =>
257 [
'directImageLink' =>
false],
263 ' ... or no doctype ... ' =>
266 [
'directImageLink' =>
false],
272 ' ... or doctype xhtml_trans... ' =>
275 [
'directImageLink' =>
false],
281 ' ... or doctype xhtml_basic... ' =>
284 [
'directImageLink' =>
false],
290 ' ... or doctype html5... ' =>
293 [
'directImageLink' =>
false],
299 ' If all hopes fail, an empty string is returned. ' =>
308 'It finally applies stdWrap' =>
311 [$targetName .
'.' =>
312 [
'ifEmpty' =>
'wrap_target' ]
336 bool $respectFrameSetOption,
337 string $fallbackTarget,
340 $this->frontendControllerMock->config =
341 [
'config' => [
'doctype' => $doctype]];
342 $renderer = GeneralUtility::makeInstance(ContentObjectRenderer::class);
343 $subject = $this->getMockBuilder(AbstractTypolinkBuilder::class)
344 ->setConstructorArgs([$renderer, $this->frontendControllerMock])
345 ->setMethods([
'build'])
347 $actual = $this->callInaccessibleMethod(
349 'resolveTargetAttribute',
352 $respectFrameSetOption,
355 $this->assertEquals($expected, $actual);