DigiComp.FlowTranslationEnd.../Tests/Functional/TranslationMiddlewareTest.php
2023-08-08 17:02:13 +02:00

48 lines
1.6 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 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()
);
$request = $this->serverRequestFactory->createServerRequest('GET', 'testing/translate');
$request = $request
->withQueryParams(['idPatterns' => 'DigiComp.FlowTranslationEndpoint:Test|.*'])
->withHeader('Accept-Language', 'de');
$response = $this->browser->sendRequest($request);
static::assertEquals(
'{"DigiComp.FlowTranslationEndpoint:Test":{"key1":"de_key1"}}',
(string)$response->getBody()
);
}
}