Core MVC, HTTP client, Session, Cookie, Config, HTTPException — 111 PHPUnit tests. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
77 lines
2.3 KiB
PHP
77 lines
2.3 KiB
PHP
<?php
|
|
|
|
namespace Tests\Unit;
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
use System\Classes\Route;
|
|
|
|
class RouteTest extends TestCase
|
|
{
|
|
public function testEmptyUri(): void
|
|
{
|
|
$r = Route::resolve('');
|
|
$this->assertSame(['controller' => 'Index', 'action' => 'index', 'params' => []], $r);
|
|
}
|
|
|
|
public function testControllerOnly(): void
|
|
{
|
|
$r = Route::resolve('index');
|
|
$this->assertSame('Index', $r['controller']);
|
|
$this->assertSame('index', $r['action']);
|
|
$this->assertSame([], $r['params']);
|
|
}
|
|
|
|
public function testControllerAndAction(): void
|
|
{
|
|
$r = Route::resolve('index/about');
|
|
$this->assertSame('Index', $r['controller']);
|
|
$this->assertSame('about', $r['action']);
|
|
$this->assertSame([], $r['params']);
|
|
}
|
|
|
|
public function testControllerActionAndParams(): void
|
|
{
|
|
$r = Route::resolve('index/show/42/extra');
|
|
$this->assertSame('Index', $r['controller']);
|
|
$this->assertSame('show', $r['action']);
|
|
$this->assertSame(['42', 'extra'], $r['params']);
|
|
}
|
|
|
|
public function testSingleParam(): void
|
|
{
|
|
$r = Route::resolve('index/view/99');
|
|
$this->assertSame(['99'], $r['params']);
|
|
}
|
|
|
|
public function testCaseInsensitiveController(): void
|
|
{
|
|
$r = Route::resolve('INDEX/show');
|
|
// Файловая система находит IndexController.php → возвращает 'Index'
|
|
$this->assertSame('Index', $r['controller']);
|
|
$this->assertSame('show', $r['action']);
|
|
}
|
|
|
|
public function testUnknownControllerFallsBackToUcfirst(): void
|
|
{
|
|
$r = Route::resolve('nonexistent');
|
|
$this->assertSame('Nonexistent', $r['controller']);
|
|
$this->assertSame('index', $r['action']);
|
|
$this->assertSame([], $r['params']);
|
|
}
|
|
|
|
public function testUnknownControllerWithAction(): void
|
|
{
|
|
$r = Route::resolve('nonexistent/doSomething');
|
|
$this->assertSame('Nonexistent', $r['controller']);
|
|
$this->assertSame('doSomething', $r['action']);
|
|
}
|
|
|
|
public function testUnknownControllerWithParams(): void
|
|
{
|
|
$r = Route::resolve('nonexistent/action/1/2');
|
|
$this->assertSame('Nonexistent', $r['controller']);
|
|
$this->assertSame('action', $r['action']);
|
|
$this->assertSame(['1', '2'], $r['params']);
|
|
}
|
|
}
|