2022-09-20 19:59:52 +00:00
|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
uses(\Tests\TestCase::class);
|
|
|
|
|
|
2024-02-23 10:54:12 +00:00
|
|
|
|
use Illuminate\Support\Str;
|
2023-02-23 18:05:17 +00:00
|
|
|
|
|
2022-09-20 19:59:52 +00:00
|
|
|
|
it('can parse filenames', function () {
|
|
|
|
|
$fileName = 'Notion_app_logo_85e16d7b-58ed-43bc-8dce-7d3ff7d69f41.png';
|
|
|
|
|
$parsedFilename = \App\Service\Storage\StorageFileNameParser::parse($fileName);
|
|
|
|
|
expect($parsedFilename->fileName)->toBe('Notion_app_logo');
|
|
|
|
|
expect($parsedFilename->uuid)->toBe('85e16d7b-58ed-43bc-8dce-7d3ff7d69f41');
|
|
|
|
|
expect($parsedFilename->extension)->toBe('png');
|
|
|
|
|
expect($parsedFilename->getMovedFileName())->toBe($fileName);
|
|
|
|
|
|
|
|
|
|
$uuid = Str::uuid()->toString();
|
|
|
|
|
$parsedFilename = \App\Service\Storage\StorageFileNameParser::parse($uuid);
|
|
|
|
|
expect($parsedFilename->uuid)->toBe($uuid);
|
|
|
|
|
expect($parsedFilename->fileName)->toBeNull();
|
|
|
|
|
expect($parsedFilename->extension)->toBeNull();
|
|
|
|
|
expect($parsedFilename->getMovedFileName())->toBe($uuid);
|
|
|
|
|
|
|
|
|
|
$randomString = Str::random(20);
|
|
|
|
|
$parsedFilename = \App\Service\Storage\StorageFileNameParser::parse($randomString);
|
|
|
|
|
expect($parsedFilename->fileName)->toBeNull();
|
|
|
|
|
expect($parsedFilename->uuid)->toBeNull();
|
|
|
|
|
expect($parsedFilename->extension)->toBeNull();
|
|
|
|
|
expect($parsedFilename->getMovedFileName())->toBeNull();
|
|
|
|
|
|
|
|
|
|
});
|
2022-11-15 10:07:07 +00:00
|
|
|
|
|
|
|
|
|
it('can handles non-utf characters', function () {
|
|
|
|
|
$fileName = 'Образец_для_заполнения_85e16d7b-58ed-43bc-8dce-7d3ff7d69f41.png';
|
|
|
|
|
$parsedFilename = \App\Service\Storage\StorageFileNameParser::parse($fileName);
|
|
|
|
|
expect($parsedFilename->fileName)->toBe('Образец_для_заполнения');
|
|
|
|
|
expect($parsedFilename->uuid)->toBe('85e16d7b-58ed-43bc-8dce-7d3ff7d69f41');
|
|
|
|
|
expect($parsedFilename->extension)->toBe('png');
|
|
|
|
|
expect($parsedFilename->getMovedFileName())->toBe($fileName);
|
|
|
|
|
});
|