-
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.
- Loading branch information
Showing
4 changed files
with
98 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
/composer.lock | ||
/vendor/ | ||
|
||
phpunit.xml | ||
.phpunit.result.cache |
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
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,26 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/8.5/phpunit.xsd" | ||
bootstrap="vendor/autoload.php" | ||
executionOrder="depends,defects" | ||
forceCoversAnnotation="true" | ||
beStrictAboutCoversAnnotation="true" | ||
beStrictAboutOutputDuringTests="true" | ||
beStrictAboutTodoAnnotatedTests="true" | ||
convertDeprecationsToExceptions="true" | ||
verbose="true"> | ||
<php> | ||
<const name="REQUEST_TOKEN" value="3745f4756fg" /> | ||
</php> | ||
<testsuites> | ||
<testsuite name="default"> | ||
<directory>tests</directory> | ||
</testsuite> | ||
</testsuites> | ||
|
||
<filter> | ||
<whitelist processUncoveredFilesFromWhitelist="true"> | ||
<directory suffix=".php">src</directory> | ||
</whitelist> | ||
</filter> | ||
</phpunit> |
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,62 @@ | ||
<?php | ||
/** | ||
* @author Andrey Vinichenko <[email protected]> | ||
*/ | ||
|
||
namespace Ameotoko\BackendRedirect\Test\Controller; | ||
|
||
use Ameotoko\BackendRedirect\Controller\RedirectController; | ||
use Contao\System; | ||
use Contao\TestCase\ContaoTestCase; | ||
use Symfony\Component\HttpFoundation\RedirectResponse; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\HttpFoundation\RequestStack; | ||
use Symfony\Component\Routing\Router; | ||
|
||
class RedirectControllerTest extends ContaoTestCase | ||
{ | ||
public function testBackendRedirectResponse(): void | ||
{ | ||
$request = Request::create('https://localhost/contao/redirect?do=members&act=edit&id=42'); | ||
$request->attributes->set('_contao_referer_id', '_OY4TOxP'); | ||
|
||
\define('TL_SCRIPT', substr($request->getBaseUrl().$request->getPathInfo(), \strlen($request->getBasePath().'/'))); | ||
|
||
$requestStack = $this->createMock(RequestStack::class); | ||
$requestStack->method('getCurrentRequest')->willReturn($request); | ||
|
||
$container = $this->getContainerWithContaoConfiguration(); | ||
$container->set('request_stack', $requestStack); | ||
|
||
$framework = $this->mockContaoFramework(); | ||
$framework->expects($this->atLeastOnce())->method('initialize'); | ||
|
||
System::setContainer($container); | ||
|
||
$router = $this->createMock(Router::class); | ||
$router->method('generate')->with('contao_backend')->willReturn('/contao'); | ||
|
||
$controller = new RedirectController(); | ||
|
||
/** @var RedirectResponse $response */ | ||
$response = $controller($request, $framework, $router); | ||
|
||
$this->assertInstanceOf(RedirectResponse::class, $response); | ||
|
||
$parsedUrl = parse_url($response->getTargetUrl()); | ||
|
||
// Path must become /contao instead of /contao/redirect | ||
$this->assertSame('/contao', $parsedUrl['path']); | ||
|
||
parse_str($parsedUrl['query'], $query); | ||
|
||
// Original query params must be preserved | ||
$this->assertSame('members', $query['do']); | ||
$this->assertSame('edit', $query['act']); | ||
$this->assertSame('42', $query['id']); | ||
|
||
// ref and request token must be added to the response url | ||
$this->assertSame('_OY4TOxP', $query['ref']); | ||
$this->assertArrayHasKey('rt', $query); | ||
} | ||
} |