DigiComp.FlowTranslationEnd.../Tests/Functional/TranslationMiddlewareTest.php

49 lines
1.6 KiB
PHP
Raw Normal View History

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