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