forked from mautic/mautic
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Do not redirect to the custom 404 page. Just show the content
- Loading branch information
Showing
2 changed files
with
51 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
app/bundles/PageBundle/Tests/Controller/NotFoundFunctionalTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Mautic\PageBundle\Tests\Controller; | ||
|
||
use Mautic\CoreBundle\Test\MauticMysqlTestCase; | ||
use Mautic\PageBundle\Entity\Page; | ||
use PHPUnit\Framework\Assert; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\HttpFoundation\Response; | ||
|
||
final class NotFoundFunctionalTest extends MauticMysqlTestCase | ||
{ | ||
protected $useCleanupRollback = false; | ||
|
||
public function testCustom404Page(): void | ||
{ | ||
// Create a custom 404 page: | ||
$notFoundPage = new Page(); | ||
$notFoundPage->setTitle('404 Not Found'); | ||
$notFoundPage->setAlias('404-not-found'); | ||
$notFoundPage->setCustomHtml('<html><body>Custom 404 Not Found Page</body></html>'); | ||
|
||
$this->em->persist($notFoundPage); | ||
$this->em->flush(); | ||
|
||
// Configure the 404 page: | ||
$this->configParams['404_page'] = $notFoundPage->getId(); | ||
parent::setUpSymfony($this->configParams); | ||
|
||
// Test the custom 404 page: | ||
$crawler = $this->client->request(Request::METHOD_GET, '/s/page-that-does-not-exist'); | ||
Assert::assertSame(Response::HTTP_NOT_FOUND, $this->client->getResponse()->getStatusCode()); | ||
Assert::assertStringContainsString('Custom 404 Not Found Page', $crawler->text()); | ||
Assert::assertFalse($this->client->getResponse()->isRedirection(), 'The response should not be a redirect.'); | ||
Assert::assertSame('/s/page-that-does-not-exist', $this->client->getRequest()->getRequestUri(), 'The request URI should be the same as the original URI.'); | ||
} | ||
} |