‪TYPO3CMS  11.5
RedirectFinisherTest.php
Go to the documentation of this file.
1 <?php
2 
3 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 
19 
20 use Prophecy\Argument;
30 use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
32 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
33 
37 class ‪RedirectFinisherTest extends UnitTestCase
38 {
39  use \Prophecy\PhpUnit\ProphecyTrait;
40  protected ‪$resetSingletonInstances = true;
41 
49  public function ‪pageUidOptionForFinisherAcceptsVariousPageRepresentations($pageUid, int $expectedPage): void
50  {
51  $uriPrefix = 'https://site.test/?id=';
52 
53  $contentObjectRendererProphecy = $this->prophesize(ContentObjectRenderer::class);
54  $contentObjectRendererProphecy->typoLink_URL(Argument::type('array'))->will(static function ($arguments) use ($uriPrefix) {
55  return $uriPrefix . $arguments[0]['parameter'];
56  });
57  $frontendControllerProphecy = $this->prophesize(TypoScriptFrontendController::class);
58  $frontendController = $frontendControllerProphecy->reveal();
59  $frontendController->cObj = $contentObjectRendererProphecy->reveal();
60  ‪$GLOBALS['TSFE'] = $frontendController;
61 
62  $redirectFinisherMock = $this->getAccessibleMock(RedirectFinisher::class, null, [], '', false);
63  $redirectFinisherMock->_set('options', [
64  'pageUid' => $pageUid,
65  ]);
66 
67  $formRuntimeProphecy = $this->prophesize(FormRuntime::class);
68  $formRuntimeProphecy->getRequest()->willReturn(new ‪Request());
69  $formRuntimeProphecy->getResponse()->willReturn(new ‪Response());
70 
71  $finisherContextProphecy = $this->prophesize(FinisherContext::class);
72  $finisherContextProphecy->getFormRuntime()->willReturn($formRuntimeProphecy->reveal());
73  $finisherContextProphecy->cancel()->shouldBeCalledOnce();
74 
75  $translationServiceProphecy = $this->prophesize(TranslationService::class);
76  GeneralUtility::setSingletonInstance(TranslationService::class, $translationServiceProphecy->reveal());
77  $translationServiceProphecy->translateFinisherOption(Argument::cetera())->willReturnArgument(3);
78 
79  try {
80  $redirectFinisherMock->execute($finisherContextProphecy->reveal());
81  self::fail('RedirectFinisher did not throw expected exception.');
82  } catch (‪PropagateResponseException $e) {
83  $response = $e->‪getResponse();
84  self::assertSame($uriPrefix . $expectedPage, $response->getHeader('Location')[0]);
85  }
86  }
87 
89  {
90  return [
91  'null' => [
92  null,
93  1,
94  ],
95  'no page' => [
96  '',
97  1,
98  ],
99  'page as integer' => [
100  3,
101  3,
102  ],
103  'page as string' => [
104  '3',
105  3,
106  ],
107  'page with table prefix' => [
108  'pages_3',
109  3,
110  ],
111  ];
112  }
113 }
‪TYPO3\CMS\Form\Service\TranslationService
Definition: TranslationService.php:45
‪TYPO3\CMS\Form\Tests\Unit\Domain\Finishers\RedirectFinisherTest\pageUidOptionForFinisherAcceptsVariousPageRepresentations
‪pageUidOptionForFinisherAcceptsVariousPageRepresentations($pageUid, int $expectedPage)
Definition: RedirectFinisherTest.php:48
‪TYPO3\CMS\Core\Http\Response
Definition: Response.php:30
‪TYPO3\CMS\Core\Http\ImmediateResponseException\getResponse
‪Response getResponse()
Definition: ImmediateResponseException.php:53
‪TYPO3\CMS\Extbase\Object\Exception
Definition: CannotBuildObjectException.php:18
‪TYPO3\CMS\Core\Http\PropagateResponseException
Definition: PropagateResponseException.php:47
‪TYPO3\CMS\Form\Domain\Finishers\FinisherContext
Definition: FinisherContext.php:38
‪TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController
Definition: TypoScriptFrontendController.php:104
‪TYPO3\CMS\Form\Domain\Runtime\FormRuntime
Definition: FormSession.php:18
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Form\Tests\Unit\Domain\Finishers\RedirectFinisherTest\pageUidOptionForFinisherAcceptsVariousPageRepresentationsDataProvider
‪pageUidOptionForFinisherAcceptsVariousPageRepresentationsDataProvider()
Definition: RedirectFinisherTest.php:87
‪TYPO3\CMS\Form\Tests\Unit\Domain\Finishers\RedirectFinisherTest
Definition: RedirectFinisherTest.php:38
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:50
‪TYPO3\CMS\Form\Tests\Unit\Domain\Finishers\RedirectFinisherTest\$resetSingletonInstances
‪$resetSingletonInstances
Definition: RedirectFinisherTest.php:39
‪TYPO3\CMS\Extbase\Mvc\Request
Definition: Request.php:39
‪TYPO3\CMS\Form\Domain\Finishers\RedirectFinisher
Definition: RedirectFinisher.php:31
‪TYPO3\CMS\Form\Tests\Unit\Domain\Finishers
Definition: AbstractFinisherTest.php:18