Core MVC, HTTP client, Session, Cookie, Config, HTTPException — 111 PHPUnit tests. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
54 lines
1.4 KiB
PHP
54 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace Tests\Unit;
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
use System\Classes\Cookie;
|
|
|
|
class CookieTest extends TestCase
|
|
{
|
|
protected function setUp(): void
|
|
{
|
|
Cookie::$expiration = 0;
|
|
Cookie::$path = '/';
|
|
Cookie::$domain = null;
|
|
Cookie::$secure = false;
|
|
Cookie::$httponly = true;
|
|
Cookie::$samesite = 'Lax';
|
|
}
|
|
|
|
public function testGetReturnsNullWhenNotSet(): void
|
|
{
|
|
unset($_COOKIE['test_key']);
|
|
$this->assertNull(Cookie::get('test_key'));
|
|
}
|
|
|
|
public function testGetReturnsDefault(): void
|
|
{
|
|
unset($_COOKIE['test_key']);
|
|
$this->assertSame('default', Cookie::get('test_key', 'default'));
|
|
}
|
|
|
|
public function testGetReturnsValue(): void
|
|
{
|
|
$_COOKIE['test_key'] = 'hello';
|
|
$this->assertSame('hello', Cookie::get('test_key'));
|
|
unset($_COOKIE['test_key']);
|
|
}
|
|
|
|
public function testDeleteUnsetsFromGlobal(): void
|
|
{
|
|
$_COOKIE['to_delete'] = 'value';
|
|
Cookie::delete('to_delete');
|
|
$this->assertArrayNotHasKey('to_delete', $_COOKIE);
|
|
}
|
|
|
|
public function testDefaultsAreCorrect(): void
|
|
{
|
|
$this->assertSame('/', Cookie::$path);
|
|
$this->assertTrue(Cookie::$httponly);
|
|
$this->assertFalse(Cookie::$secure);
|
|
$this->assertSame('Lax', Cookie::$samesite);
|
|
}
|
|
}
|