mirror of
https://github.com/RSS-Bridge/rss-bridge.git
synced 2024-11-27 12:01:09 +03:00
23f8c81646
* fix: php notice * refactor/feat: merge HtmlFormat.css into style.css Also improve ux of error rendering. * fix: center-align footer text
50 lines
1.4 KiB
PHP
50 lines
1.4 KiB
PHP
<?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, '[...]'));
|
|
}
|
|
|
|
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));
|
|
}
|
|
|
|
public function testFileCache()
|
|
{
|
|
$sut = new \FileCache();
|
|
$sut->setScope('scope');
|
|
$sut->purgeCache(-1);
|
|
$sut->setKey(['key']);
|
|
|
|
$this->assertNull($sut->loadData());
|
|
|
|
$sut->saveData('data');
|
|
$this->assertSame('data', $sut->loadData());
|
|
$this->assertIsNumeric($sut->getTime());
|
|
$sut->purgeCache(-1);
|
|
}
|
|
|
|
public function testTrimFilePath()
|
|
{
|
|
$this->assertSame('', trim_path_prefix(dirname(__DIR__)));
|
|
$this->assertSame('tests', trim_path_prefix(__DIR__));
|
|
$this->assertSame('tests/UtilsTest.php', trim_path_prefix(__DIR__ . '/UtilsTest.php'));
|
|
}
|
|
}
|