2023-08-05 15:49:46 +02:00
|
|
|
<?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
|
|
|
|
*/
|
2023-08-08 17:02:13 +02:00
|
|
|
public function itRespondsToConfiguredRoute(): void
|
2023-08-05 15:49:46 +02:00
|
|
|
{
|
2023-08-08 17:02:13 +02:00
|
|
|
$request = $this->serverRequestFactory->createServerRequest('GET', 'testing/translate');
|
2023-08-05 15:49:46 +02:00
|
|
|
$request = $request
|
2023-08-08 17:02:13 +02:00
|
|
|
->withQueryParams(['idPatterns' => 'DigiComp.FlowTranslationEndpoint:Test|.*'])
|
2023-08-05 15:49:46 +02:00
|
|
|
->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|.*'])
|
2023-08-08 17:02:13 +02:00
|
|
|
->withHeader('Accept-Language', 'de');
|
2023-08-05 15:49:46 +02:00
|
|
|
$response = $this->browser->sendRequest($request);
|
|
|
|
static::assertEquals(
|
2023-08-08 17:02:13 +02:00
|
|
|
'{"DigiComp.FlowTranslationEndpoint:Test":{"key1":"de_key1"}}',
|
2023-08-05 15:49:46 +02:00
|
|
|
(string)$response->getBody()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|