55 lines
1.2 KiB
PHP
55 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace MintyPHP\Tests\Http;
|
|
|
|
use MintyPHP\Http\Request;
|
|
use MintyPHP\Router;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
class RequestTest extends TestCase
|
|
{
|
|
private array $serverBackup = [];
|
|
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
$this->serverBackup = $_SERVER;
|
|
Router::$baseUrl = '/';
|
|
}
|
|
|
|
protected function tearDown(): void
|
|
{
|
|
$_SERVER = $this->serverBackup;
|
|
parent::tearDown();
|
|
}
|
|
|
|
public function testPathWithQuery(): void
|
|
{
|
|
$_SERVER['REQUEST_URI'] = '/admin/users?active=1';
|
|
|
|
$this->assertSame('admin/users?active=1', Request::pathWithQuery());
|
|
}
|
|
|
|
public function testSafeReturnTargetPrefersRelativeParam(): void
|
|
{
|
|
$this->assertSame(
|
|
'admin/users?active=1',
|
|
Request::safeReturnTarget('admin/users?active=1')
|
|
);
|
|
}
|
|
|
|
public function testWantsJsonFromAcceptHeader(): void
|
|
{
|
|
$_SERVER['HTTP_ACCEPT'] = 'application/json';
|
|
|
|
$this->assertTrue(Request::wantsJson());
|
|
}
|
|
|
|
public function testWantsJsonFalseForHtml(): void
|
|
{
|
|
$_SERVER['HTTP_ACCEPT'] = 'text/html';
|
|
|
|
$this->assertFalse(Request::wantsJson());
|
|
}
|
|
}
|