This commit is contained in:
2026-02-04 23:31:53 +01:00
commit cd59ccd99b
2401 changed files with 56808 additions and 0 deletions

BIN
tests/.DS_Store vendored Normal file

Binary file not shown.

View 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());
}
}

View File

@@ -0,0 +1,49 @@
<?php
namespace MintyPHP\Service;
if (!function_exists(__NAMESPACE__ . '\\t')) {
function t($string, ...$arguments)
{
$string = (string) $string;
return $arguments ? sprintf($string, ...$arguments) : $string;
}
}
namespace MintyPHP\Tests\Service;
use MintyPHP\Service\UserService;
use PHPUnit\Framework\TestCase;
use ReflectionMethod;
class UserServicePasswordTest extends TestCase
{
private function validate(string $password, string $password2, bool $required, ?string $email = null): array
{
$method = new ReflectionMethod(UserService::class, 'validatePasswordStrength');
return $method->invoke(null, $password, $password2, $required, $email);
}
public function testRequiresPasswordWhenRequired(): void
{
$errors = $this->validate('', '', true, 'test@example.com');
$this->assertNotEmpty($errors);
}
public function testRejectsMismatch(): void
{
$errors = $this->validate('Abcd1234$efg', 'Abcd1234$xxx', true, 'test@example.com');
$this->assertNotEmpty($errors);
}
public function testAcceptsStrongPassword(): void
{
$errors = $this->validate('StrongPass1!', 'StrongPass1!', true, 'test@example.com');
$this->assertSame([], $errors);
}
public function testRejectsPasswordContainingEmail(): void
{
$errors = $this->validate('test@example.comA1!', 'test@example.comA1!', true, 'test@example.com');
$this->assertNotEmpty($errors);
}
}