Files
SGS/www/tests/Unit/FileSizeTest.php
Fabián Gonzalo Artur de la Villarmois 0993bfa666 ### Changes
Fixes #3: Error on DBI when files or folders contains special characters.

### Additional changes
* Added unit and feature tests
* Fix file size display
* Run tests on CI/CD
* Publish docker image on release
2026-03-29 17:35:32 +13:00

33 lines
941 B
PHP

<?php
use App\Helpers\FileSize;
test('formats zero bytes as "0"', function () {
expect(FileSize::format(0))->toBe('0');
});
test('formats byte values without decimal places', function () {
expect(FileSize::format(1))->toBe('1');
expect(FileSize::format(512))->toBe('512');
expect(FileSize::format(1001))->toBe('1001');
expect(FileSize::format(1023))->toBe('1023');
});
test('formats kilobytes', function () {
expect(FileSize::format(1024))->toBe('1.00K');
expect(FileSize::format(1536))->toBe('1.50K');
});
test('formats megabytes', function () {
expect(FileSize::format(1024 * 1024))->toBe('1.00M');
expect(FileSize::format((int) (1.5 * 1024 * 1024)))->toBe('1.50M');
});
test('formats gigabytes', function () {
expect(FileSize::format(1024 * 1024 * 1024))->toBe('1.00G');
});
test('formats terabytes', function () {
expect(FileSize::format(1024 * 1024 * 1024 * 1024))->toBe('1.00T');
});