forked from fa/breadcrumb-the-shire
baseline
This commit is contained in:
54
tests/Http/RequestTest.php
Normal file
54
tests/Http/RequestTest.php
Normal file
@@ -0,0 +1,54 @@
|
||||
<?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());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user