1
0
mirror of git://f0xx.org/android_cast synced 2026-07-29 06:18:42 +03:00
This commit is contained in:
Anton Afanasyeu
2026-06-11 22:45:47 +02:00
parent f878700a0c
commit fef93d7cdc
23 changed files with 831 additions and 97 deletions

View File

@@ -0,0 +1,35 @@
<?php
declare(strict_types=1);
require_once dirname(__DIR__) . '/src/UrlNormalizer.php';
require_once dirname(__DIR__) . '/src/SlugGenerator.php';
function assert_true(bool $cond, string $msg): void {
if (!$cond) {
fwrite(STDERR, "FAIL: $msg\n");
exit(1);
}
}
$n = UrlNormalizer::normalize('HTTPS://Example.COM/path?q=1#frag');
assert_true($n === 'https://example.com/path?q=1#frag', 'normalize host case');
$h = UrlNormalizer::originHash($n);
assert_true(strlen($h) === 64, 'origin hash length');
try {
UrlNormalizer::normalize('http://127.0.0.1/');
fwrite(STDERR, "FAIL: should block localhost\n");
exit(1);
} catch (InvalidArgumentException $e) {
// ok
}
$slug = SlugGenerator::baseSlug(42, 'https://example.com/a');
assert_true(strlen($slug) === 12, 'slug length 12');
assert_true(ctype_xdigit($slug), 'slug hex');
$candidates = SlugGenerator::candidates(1, 'https://a.test/');
assert_true(count($candidates) >= 2, 'collision candidates');
echo "OK url-shortener php tests\n";