mirror of
https://github.com/FriendsOfTYPO3/tea.git
synced 2025-04-28 13:00:51 +02:00
[FEATURE] Add proper 404 handling for tea detail action (#1643)
Properly trigger TYPO3 404 handling in case a none available tea was requested. That might happen when old links to no longer existing teas are called. Or if people play around with the URL. We also cover this new feature with a functional test. Related: #1565
This commit is contained in:
parent
e3aec8d3b2
commit
4b3bd8a120
3 changed files with 60 additions and 2 deletions
|
@ -7,7 +7,9 @@ namespace TTN\Tea\Controller;
|
|||
use Psr\Http\Message\ResponseInterface;
|
||||
use TTN\Tea\Domain\Model\Tea;
|
||||
use TTN\Tea\Domain\Repository\TeaRepository;
|
||||
use TYPO3\CMS\Core\Http\PropagateResponseException;
|
||||
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
|
||||
use TYPO3\CMS\Frontend\Controller\ErrorController;
|
||||
|
||||
/**
|
||||
* Controller for the main "Tea" FE plugin.
|
||||
|
@ -16,6 +18,7 @@ class TeaController extends ActionController
|
|||
{
|
||||
public function __construct(
|
||||
private readonly TeaRepository $teaRepository,
|
||||
private readonly ErrorController $errorController,
|
||||
) {}
|
||||
|
||||
public function indexAction(): ResponseInterface
|
||||
|
@ -24,9 +27,29 @@ class TeaController extends ActionController
|
|||
return $this->htmlResponse();
|
||||
}
|
||||
|
||||
public function showAction(Tea $tea): ResponseInterface
|
||||
/**
|
||||
* @throws PropagateResponseException
|
||||
*/
|
||||
public function showAction(?Tea $tea = null): ResponseInterface
|
||||
{
|
||||
if ($tea === null) {
|
||||
$this->trigger404('No tea given.');
|
||||
}
|
||||
|
||||
$this->view->assign('tea', $tea);
|
||||
return $this->htmlResponse();
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws PropagateResponseException
|
||||
*
|
||||
* @return never
|
||||
*/
|
||||
protected function trigger404(string $message): void
|
||||
{
|
||||
throw new PropagateResponseException(
|
||||
$this->errorController->pageNotFoundAction($this->request, $message),
|
||||
1744021673
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -101,4 +101,40 @@ final class TeaControllerTest extends FunctionalTestCase
|
|||
self::assertStringContainsString('Godesberger Burgtee', $html);
|
||||
self::assertStringNotContainsString('Oolong', $html);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function showActionTriggers404ForMissingTeaArgument(): void
|
||||
{
|
||||
$request = (new InternalRequest())->withPageId(3);
|
||||
|
||||
$response = $this->executeFrontendSubRequest($request);
|
||||
|
||||
self::assertSame(404, $response->getStatusCode());
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function showActionTriggers404ForUnavailableTea(): void
|
||||
{
|
||||
$request = (new InternalRequest())->withPageId(3)->withQueryParameters(['tx_tea_teashow[tea]' => 1]);
|
||||
|
||||
$response = $this->executeFrontendSubRequest($request);
|
||||
|
||||
self::assertSame(404, $response->getStatusCode());
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function showActionFor404RendersReasonFor404(): void
|
||||
{
|
||||
$request = (new InternalRequest())->withPageId(3);
|
||||
|
||||
$html = (string)$this->executeFrontendSubRequest($request)->getBody();
|
||||
|
||||
self::assertStringContainsString('Reason: No tea given.', $html);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,6 +7,5 @@ use ComposerUnused\ComposerUnused\Configuration\NamedFilter;
|
|||
|
||||
return static function (Configuration $config): Configuration {
|
||||
$config->addNamedFilter(NamedFilter::fromString('typo3/cms-fluid'));
|
||||
$config->addNamedFilter(NamedFilter::fromString('typo3/cms-frontend'));
|
||||
return $config;
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue