‪TYPO3CMS  ‪main
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 PHPUnit\Framework\Attributes\DataProvider;
21 use PHPUnit\Framework\Attributes\Test;
34 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
35 
36 final class ‪RedirectFinisherTest extends UnitTestCase
37 {
38  protected bool ‪$resetSingletonInstances = true;
39 
43  #[DataProvider('pageUidOptionForFinisherAcceptsVariousPageRepresentationsDataProvider')]
44  #[Test]
45  public function ‪pageUidOptionForFinisherAcceptsVariousPageRepresentations($pageUid, int $expectedPage): void
46  {
47  $uriPrefix = 'https://site.test/?id=';
48  $contentObjectRendererMock = $this->createMock(ContentObjectRenderer::class);
49  $contentObjectRendererMock->method('createUrl')->willReturnCallback(static function (array $conf) use ($uriPrefix): string {
50  return $uriPrefix . $conf['parameter'];
51  });
52  $frontendControllerMock = $this->createMock(TypoScriptFrontendController::class);
53  $frontendController = $frontendControllerMock;
54  $frontendController->cObj = $contentObjectRendererMock;
55  ‪$GLOBALS['TSFE'] = $frontendController;
56 
57  $redirectFinisherMock = $this->getAccessibleMock(RedirectFinisher::class, null, [], '', false);
58  $redirectFinisherMock->_set('options', [
59  'pageUid' => $pageUid,
60  ]);
61 
62  $formRuntimeMock = $this->createMock(FormRuntime::class);
63  $serverRequest = (new ‪ServerRequest())->withAttribute('extbase', new ‪ExtbaseRequestParameters());
64  $request = new ‪Request($serverRequest);
65  $formRuntimeMock->method('getRequest')->willReturn($request);
66  $formRuntimeMock->method('getResponse')->willReturn(new ‪Response());
67 
68  $finisherContextMock = $this->createMock(FinisherContext::class);
69  $finisherContextMock->method('getFormRuntime')->willReturn($formRuntimeMock);
70  $finisherContextMock->expects(self::once())->method('cancel');
71 
72  $translationServiceMock = $this->createMock(TranslationService::class);
73  $translationServiceMock->method('translateFinisherOption')->with(self::anything())->willReturnArgument(3);
74  GeneralUtility::setSingletonInstance(TranslationService::class, $translationServiceMock);
75 
76  try {
77  $redirectFinisherMock->execute($finisherContextMock);
78  self::fail('RedirectFinisher did not throw expected exception.');
79  } catch (‪PropagateResponseException $e) {
80  $response = $e->‪getResponse();
81  self::assertSame($uriPrefix . $expectedPage, $response->getHeader('Location')[0]);
82  }
83  }
84 
86  {
87  return [
88  'null' => [
89  null,
90  1,
91  ],
92  'no page' => [
93  '',
94  1,
95  ],
96  'page as integer' => [
97  3,
98  3,
99  ],
100  'page as string' => [
101  '3',
102  3,
103  ],
104  'page with table prefix' => [
105  'pages_3',
106  3,
107  ],
108  ];
109  }
110 }
‪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:45
‪TYPO3\CMS\Core\Http\Response
Definition: Response.php:32
‪TYPO3\CMS\Core\Http\ImmediateResponseException\getResponse
‪Response getResponse()
Definition: ImmediateResponseException.php:49
‪TYPO3\CMS\Core\Http\ServerRequest
Definition: ServerRequest.php:39
‪TYPO3\CMS\Core\Http\PropagateResponseException
Definition: PropagateResponseException.php:47
‪TYPO3\CMS\Form\Tests\Unit\Domain\Finishers\RedirectFinisherTest\pageUidOptionForFinisherAcceptsVariousPageRepresentationsDataProvider
‪static pageUidOptionForFinisherAcceptsVariousPageRepresentationsDataProvider()
Definition: RedirectFinisherTest.php:85
‪TYPO3\CMS\Form\Domain\Finishers\FinisherContext
Definition: FinisherContext.php:37
‪TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController
Definition: TypoScriptFrontendController.php:58
‪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\Frontend\ContentObject\ContentObjectRenderer
Definition: ContentObjectRenderer.php:102
‪TYPO3\CMS\Form\Tests\Unit\Domain\Finishers\RedirectFinisherTest\$resetSingletonInstances
‪bool $resetSingletonInstances
Definition: RedirectFinisherTest.php:38
‪TYPO3\CMS\Extbase\Mvc\ExtbaseRequestParameters
Definition: ExtbaseRequestParameters.php:35
‪TYPO3\CMS\Form\Tests\Unit\Domain\Finishers\RedirectFinisherTest
Definition: RedirectFinisherTest.php:37
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52
‪TYPO3\CMS\Extbase\Mvc\Request
Definition: Request.php:35
‪TYPO3\CMS\Form\Domain\Finishers\RedirectFinisher
Definition: RedirectFinisher.php:30
‪TYPO3\CMS\Form\Tests\Unit\Domain\Finishers
Definition: AbstractFinisherTest.php:18