/
RedirectFinisherTest.php
118 lines (104 loc) · 4.42 KB
/
RedirectFinisherTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
<?php
declare(strict_types=1);
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
namespace TYPO3\CMS\Form\Tests\Unit\Domain\Finishers;
use Prophecy\Argument;
use TYPO3\CMS\Core\Http\PropagateResponseException;
use TYPO3\CMS\Core\Http\Response;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Mvc\Request;
use TYPO3\CMS\Extbase\Mvc\Web\Routing\UriBuilder;
use TYPO3\CMS\Extbase\Object\Exception;
use TYPO3\CMS\Extbase\Object\ObjectManager;
use TYPO3\CMS\Form\Domain\Finishers\FinisherContext;
use TYPO3\CMS\Form\Domain\Finishers\RedirectFinisher;
use TYPO3\CMS\Form\Domain\Runtime\FormRuntime;
use TYPO3\CMS\Form\Service\TranslationService;
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
/**
* Test case
*/
class RedirectFinisherTest extends UnitTestCase
{
protected $resetSingletonInstances = true;
/**
* @test
* @dataProvider pageUidOptionForFinisherAcceptsVariousPageRepresentationsDataProvider
* @param string|int|null $pageUid
* @param int $expectedPage
* @throws Exception
*/
public function pageUidOptionForFinisherAcceptsVariousPageRepresentations($pageUid, int $expectedPage): void
{
$uriPrefix = 'https://site.test/?id=';
$contentObjectRendererProphecy = $this->prophesize(ContentObjectRenderer::class);
$contentObjectRendererProphecy->typoLink_URL(Argument::type('array'))->will(function ($arguments) use ($uriPrefix) {
return $uriPrefix . $arguments[0]['parameter'];
});
$tsfeProphecy = $this->prophesize(TypoScriptFrontendController::class);
$tsfeProphecy->cObj = $contentObjectRendererProphecy->reveal();
$GLOBALS['TSFE'] = $tsfeProphecy->reveal();
$redirectFinisherMock = $this->getAccessibleMock(RedirectFinisher::class, null, [], '', false);
$redirectFinisherMock->_set('options', [
'pageUid' => $pageUid,
]);
$formRuntimeProphecy = $this->prophesize(FormRuntime::class);
$formRuntimeProphecy->getRequest()->willReturn(new Request());
$formRuntimeProphecy->getResponse()->willReturn(new Response());
$finisherContextProphecy = $this->prophesize(FinisherContext::class);
$finisherContextProphecy->getFormRuntime()->willReturn($formRuntimeProphecy->reveal());
$finisherContextProphecy->cancel()->shouldBeCalledOnce();
$translationServiceProphecy = $this->prophesize(TranslationService::class);
GeneralUtility::setSingletonInstance(TranslationService::class, $translationServiceProphecy->reveal());
$translationServiceProphecy->translateFinisherOption(Argument::cetera())->willReturnArgument(3);
$objectManagerProphecy = $this->prophesize(ObjectManager::class);
$objectManagerProphecy->get(UriBuilder::class)->willReturn(new UriBuilder());
GeneralUtility::setSingletonInstance(ObjectManager::class, $objectManagerProphecy->reveal());
$redirectFinisherMock->injectObjectManager($objectManagerProphecy->reveal());
try {
$redirectFinisherMock->execute($finisherContextProphecy->reveal());
self::fail('RedirectFinisher did not throw expected exception.');
} /** @noinspection PhpRedundantCatchClauseInspection */ catch (PropagateResponseException $e) {
$response = $e->getResponse();
self::assertSame($uriPrefix . $expectedPage, $response->getHeader('Location')[0]);
}
}
public function pageUidOptionForFinisherAcceptsVariousPageRepresentationsDataProvider(): array
{
return [
'null' => [
null,
1,
],
'no page' => [
'',
1,
],
'page as integer' => [
3,
3,
],
'page as string' => [
'3',
3,
],
'page with table prefix' => [
'pages_3',
3,
],
];
}
}