Skip to content

Commit

Permalink
[BUGFIX] Make the redirectToUri tests compatible with 11LTS/12LTS (#…
Browse files Browse the repository at this point in the history
…3669)

Part of #1482
  • Loading branch information
oliverklee authored Sep 23, 2024
1 parent fc5088e commit b44597c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ This project adheres to [Semantic Versioning](https://semver.org/).

- Avoid the deprecated `ActionController::forward()` method (#3637)
- Drop tests for duplicated place associations (#3631)
- Always return a response from controller actions (#3619, #3638, #3668)
- Always return a response from controller actions (#3619, #3638, #3668, #3669)
- Stop setting `TemplateHelper::cObj` (#3613)
- Avoid using the deprecated `GeneralUtility::_GPmerged()` (#3595)
- Drop unused dependency on `MarkerBasedTemplateService` (#3594)
Expand Down
6 changes: 1 addition & 5 deletions Tests/Unit/Controller/EventRegistrationControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Http\ForwardResponse;
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
use TYPO3\CMS\Extbase\Mvc\Exception\StopActionException;
use TYPO3\CMS\Extbase\Mvc\Web\Routing\UriBuilder;
use TYPO3\CMS\Fluid\View\TemplateView;
use TYPO3\TestingFramework\Core\AccessibleObjectInterface;
Expand Down Expand Up @@ -316,10 +315,7 @@ public function checkPrerequisitesActionForNoUserInSessionRedirectsLoginPageWith
$this->uriBuilderMock->expects(self::exactly(2))->method('buildFrontendUri')
->willReturnOnConsecutiveCalls($redirectUrl, $loginPageUrl);

$this->subject->expects(self::once())->method('redirectToUri')
->with($loginPageUrl)
->willThrowException(new StopActionException('redirectToUri', 1476045828));
$this->expectException(StopActionException::class);
$this->mockRedirectToUri($loginPageUrl);

$this->subject->checkPrerequisitesAction($event);
}
Expand Down
17 changes: 17 additions & 0 deletions Tests/Unit/Controller/RedirectMockTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,21 @@ private function stubRedirect(): void
$this->subject->method('redirect')->willReturn($redirectResponse);
}
}

/**
* @param non-empty-string $uri
*/
private function mockRedirectToUri(string $uri): void
{
if ((new Typo3Version())->getMajorVersion() < 12) {
$this->subject->expects(self::once())->method('redirectToUri')
->with($uri)
->willThrowException(new StopActionException('redirectToUri', 1476045828));
$this->expectException(StopActionException::class);
} else {
$redirectResponse = $this->createStub(RedirectResponse::class);
$this->subject->expects(self::once())->method('redirectToUri')->with($uri)
->willReturn($redirectResponse);
}
}
}

0 comments on commit b44597c

Please sign in to comment.