32 lines
895 B
PHP
32 lines
895 B
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Tests\Unit;
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
final class TextSanitizeTest extends TestCase
|
|
{
|
|
public function testStripsSqlLikePatterns(): void
|
|
{
|
|
require_once dirname(__DIR__, 2) . '/lib/text_sanitize.php';
|
|
$out = sanitize_free_text("hello'; DROP TABLE users;--");
|
|
$this->assertStringNotContainsString('DROP TABLE', $out);
|
|
$this->assertStringNotContainsString('--', $out);
|
|
}
|
|
|
|
public function testPreservesNewlines(): void
|
|
{
|
|
require_once dirname(__DIR__, 2) . '/lib/text_sanitize.php';
|
|
$out = sanitize_free_text("line1\nline2");
|
|
$this->assertStringContainsString("\n", $out);
|
|
}
|
|
|
|
public function testNonStringReturnsEmpty(): void
|
|
{
|
|
require_once dirname(__DIR__, 2) . '/lib/text_sanitize.php';
|
|
$this->assertSame('', sanitize_free_text(null));
|
|
}
|
|
}
|