49 lines
1.6 KiB
PHP
49 lines
1.6 KiB
PHP
|
|
<?php
|
||
|
|
declare(strict_types=1);
|
||
|
|
|
||
|
|
namespace Phred\Tests;
|
||
|
|
|
||
|
|
use Nyholm\Psr7\ServerRequest;
|
||
|
|
use PHPUnit\Framework\TestCase;
|
||
|
|
|
||
|
|
final class UrlExtensionNegotiationTest extends TestCase
|
||
|
|
{
|
||
|
|
public function testJsonExtensionForcesJsonNegotiation(): void
|
||
|
|
{
|
||
|
|
putenv('URL_EXTENSION_NEGOTIATION=true');
|
||
|
|
putenv('URL_EXTENSION_WHITELIST=json|php|none');
|
||
|
|
|
||
|
|
$root = dirname(__DIR__);
|
||
|
|
/** @var object $app */
|
||
|
|
$app = require $root . '/bootstrap/app.php';
|
||
|
|
|
||
|
|
$request = new ServerRequest('GET', '/_phred/format.json');
|
||
|
|
$response = $app->handle($request);
|
||
|
|
|
||
|
|
$this->assertSame(200, $response->getStatusCode());
|
||
|
|
$this->assertSame('application/json', $response->getHeaderLine('Content-Type'));
|
||
|
|
$payload = json_decode((string) $response->getBody(), true);
|
||
|
|
$this->assertIsArray($payload);
|
||
|
|
$this->assertSame('rest', $payload['format'] ?? null);
|
||
|
|
}
|
||
|
|
|
||
|
|
public function testNoExtensionHonorsWhitelistAndDoesNotBreakRouting(): void
|
||
|
|
{
|
||
|
|
putenv('URL_EXTENSION_NEGOTIATION=true');
|
||
|
|
putenv('URL_EXTENSION_WHITELIST=json|php|none');
|
||
|
|
|
||
|
|
$root = dirname(__DIR__);
|
||
|
|
/** @var object $app */
|
||
|
|
$app = require $root . '/bootstrap/app.php';
|
||
|
|
|
||
|
|
$request = new ServerRequest('GET', '/_phred/format');
|
||
|
|
$response = $app->handle($request);
|
||
|
|
|
||
|
|
$this->assertSame(200, $response->getStatusCode());
|
||
|
|
$this->assertSame('application/json', $response->getHeaderLine('Content-Type'));
|
||
|
|
$payload = json_decode((string) $response->getBody(), true);
|
||
|
|
$this->assertIsArray($payload);
|
||
|
|
$this->assertSame('rest', $payload['format'] ?? null);
|
||
|
|
}
|
||
|
|
}
|