64 lines
2.1 KiB
PHP
64 lines
2.1 KiB
PHP
|
<?php
|
||
|
|
||
|
declare(strict_types=1);
|
||
|
|
||
|
namespace DigiComp\FlowTranslationEndpoint\Tests\Functional;
|
||
|
|
||
|
use Neos\Flow\Tests\FunctionalTestCase;
|
||
|
use Psr\Http\Message\ServerRequestFactoryInterface;
|
||
|
|
||
|
class TranslationMiddlewareTest extends FunctionalTestCase
|
||
|
{
|
||
|
/**
|
||
|
* @var ServerRequestFactoryInterface
|
||
|
*/
|
||
|
protected $serverRequestFactory;
|
||
|
|
||
|
protected function setUp(): void
|
||
|
{
|
||
|
parent::setUp();
|
||
|
$this->serverRequestFactory = $this->objectManager->get(ServerRequestFactoryInterface::class);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @test
|
||
|
*/
|
||
|
public function itRespondsToRequestsWithTheConfiguredHeader(): void
|
||
|
{
|
||
|
$request = $this->serverRequestFactory->createServerRequest('GET', 'dummyUrl');
|
||
|
$request = $request
|
||
|
->withHeader('X-Translation-Request', 'DigiComp.FlowTranslationEndpoint:Test|.*')
|
||
|
->withHeader('Accept-Language', 'en');
|
||
|
$response = $this->browser->sendRequest($request);
|
||
|
static::assertEquals(
|
||
|
'{"DigiComp.FlowTranslationEndpoint:Test":{"key1":"en_key1"}}',
|
||
|
(string)$response->getBody()
|
||
|
);
|
||
|
$request = $this->serverRequestFactory->createServerRequest('GET', 'dummyUrl');
|
||
|
$request = $request
|
||
|
->withHeader('X-Translation-Request', 'DigiComp.FlowTranslationEndpoint:Test|.*')
|
||
|
->withHeader('Accept-Language', 'de');
|
||
|
$response = $this->browser->sendRequest($request);
|
||
|
static::assertEquals(
|
||
|
'{"DigiComp.FlowTranslationEndpoint:Test":{"key1":"de_key1"}}',
|
||
|
(string)$response->getBody()
|
||
|
);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @test
|
||
|
*/
|
||
|
public function itRespondsToConfiguredRoute(): void
|
||
|
{
|
||
|
$request = $this->serverRequestFactory->createServerRequest('GET', 'testing/translate');
|
||
|
$request = $request
|
||
|
->withQueryParams(['idPatterns' => 'DigiComp.FlowTranslationEndpoint:Test|.*'])
|
||
|
->withHeader('Accept-Language', 'en');
|
||
|
$response = $this->browser->sendRequest($request);
|
||
|
static::assertEquals(
|
||
|
'{"DigiComp.FlowTranslationEndpoint:Test":{"key1":"en_key1"}}',
|
||
|
(string)$response->getBody()
|
||
|
);
|
||
|
}
|
||
|
}
|