2022-07-31 04:52:27 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace RssBridge\Tests;
|
|
|
|
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
|
|
|
|
final class UtilsTest extends TestCase
|
|
|
|
{
|
|
|
|
public function testTruncate()
|
|
|
|
{
|
|
|
|
$this->assertSame('f...', truncate('foo', 1));
|
|
|
|
$this->assertSame('fo...', truncate('foo', 2));
|
|
|
|
$this->assertSame('foo', truncate('foo', 3));
|
|
|
|
$this->assertSame('foo', truncate('foo', 4));
|
|
|
|
$this->assertSame('fo[...]', truncate('foo', 2, '[...]'));
|
|
|
|
}
|
2022-08-06 23:46:28 +03:00
|
|
|
|
2022-09-04 05:35:21 +03:00
|
|
|
public function testFormatBytes()
|
|
|
|
{
|
|
|
|
$this->assertSame('1 B', format_bytes(1));
|
|
|
|
$this->assertSame('1 KB', format_bytes(1024));
|
|
|
|
$this->assertSame('1 MB', format_bytes(1024 ** 2));
|
|
|
|
$this->assertSame('1 GB', format_bytes(1024 ** 3));
|
|
|
|
$this->assertSame('1 TB', format_bytes(1024 ** 4));
|
|
|
|
}
|
|
|
|
|
2023-03-06 23:47:25 +03:00
|
|
|
public function testSanitizePathName()
|
2022-10-29 11:46:37 +03:00
|
|
|
{
|
2023-03-06 23:47:25 +03:00
|
|
|
$this->assertSame('index.php', _sanitize_path_name('/home/satoshi/rss-bridge/index.php', '/home/satoshi/rss-bridge'));
|
|
|
|
$this->assertSame('tests/UtilsTest.php', _sanitize_path_name('/home/satoshi/rss-bridge/tests/UtilsTest.php', '/home/satoshi/rss-bridge'));
|
|
|
|
$this->assertSame('bug in lib/kek.php', _sanitize_path_name('bug in /home/satoshi/rss-bridge/lib/kek.php', '/home/satoshi/rss-bridge'));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testSanitizePathNameInErrorMessage()
|
|
|
|
{
|
|
|
|
$raw = 'Error: Argument 1 passed to foo() must be an instance of kk, string given, called in /home/satoshi/rss-bridge/bridges/RumbleBridge.php';
|
|
|
|
$sanitized = 'Error: Argument 1 passed to foo() must be an instance of kk, string given, called in bridges/RumbleBridge.php';
|
|
|
|
$this->assertSame($sanitized, _sanitize_path_name($raw, '/home/satoshi/rss-bridge'));
|
2022-10-29 11:46:37 +03:00
|
|
|
}
|
2023-03-20 21:10:01 +03:00
|
|
|
|
|
|
|
public function testCreateRandomString()
|
|
|
|
{
|
|
|
|
$this->assertSame(2, strlen(create_random_string(1)));
|
|
|
|
$this->assertSame(4, strlen(create_random_string(2)));
|
|
|
|
$this->assertSame(6, strlen(create_random_string(3)));
|
|
|
|
}
|
2022-07-31 04:52:27 +03:00
|
|
|
}
|