86 lines
2.3 KiB
PHP
86 lines
2.3 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
use Illuminate\Support\Facades\Storage;
|
|
use Tests\Integration\WithApp\Helpers\ToolboxHelperCoreHarness;
|
|
|
|
it('returns false when replace is array but search is string', function (): void {
|
|
// GIVEN
|
|
$count = 0;
|
|
|
|
// WHEN
|
|
$result = ToolboxHelperCoreHarness::mbReplace('a', ['b'], 'aaa', $count);
|
|
|
|
// THEN
|
|
expect($result)->toBeFalse();
|
|
});
|
|
|
|
it('replaces recursively in nested array subject', function (): void {
|
|
// GIVEN
|
|
$count = 0;
|
|
$subject = ['a.b', ['a.b', 'z']];
|
|
|
|
// WHEN
|
|
$result = ToolboxHelperCoreHarness::mbReplace('.', '-', $subject, $count);
|
|
|
|
// THEN
|
|
expect($result)->toBe(['a-b', ['a-b', 'z']])
|
|
->and($count)->toBe(0);
|
|
});
|
|
|
|
it('replaces with search array and scalar replacement', function (): void {
|
|
// GIVEN
|
|
$count = 0;
|
|
|
|
// WHEN
|
|
$result = ToolboxHelperCoreHarness::mbReplace(['ab', 'cd'], '_', 'ab-cd', $count);
|
|
|
|
// THEN
|
|
expect($result)->toBe('_-_');
|
|
});
|
|
|
|
it('replaces with paired search and replace arrays', function (): void {
|
|
// GIVEN
|
|
$count = 0;
|
|
|
|
// WHEN
|
|
$result = ToolboxHelperCoreHarness::mbReplace(['ab', 'cd'], ['X', 'Y'], 'ab-cd', $count);
|
|
|
|
// THEN
|
|
expect($result)->toBe('X-Y');
|
|
});
|
|
|
|
it('resolves full path and mime type without storage disk', function (): void {
|
|
// GIVEN
|
|
$tmpFile = tempnam(sys_get_temp_dir(), 'tbx-');
|
|
expect($tmpFile)->toBeString();
|
|
file_put_contents((string) $tmpFile, 'hello');
|
|
|
|
// WHEN
|
|
$fullPath = ToolboxHelperCoreHarness::exposeGetUploadedFileFullPath((string) $tmpFile, false);
|
|
$mimeType = ToolboxHelperCoreHarness::exposeGetUploadedFileMimeType((string) $tmpFile, false);
|
|
|
|
// THEN
|
|
expect($fullPath)->toBe(realpath((string) $tmpFile) ?: (string) $tmpFile)
|
|
->and($mimeType)->toBeString();
|
|
|
|
unlink((string) $tmpFile);
|
|
});
|
|
|
|
it('resolves full path and mime type through storage disk', function (): void {
|
|
// GIVEN
|
|
$path = 'tests/toolbox-core/demo.txt';
|
|
Storage::disk()->put($path, 'hello world');
|
|
|
|
// WHEN
|
|
$fullPath = ToolboxHelperCoreHarness::exposeGetUploadedFileFullPath($path, true);
|
|
$mimeType = ToolboxHelperCoreHarness::exposeGetUploadedFileMimeType($path, true);
|
|
|
|
// THEN
|
|
expect($fullPath)->toBeString()
|
|
->and($fullPath)->toContain('demo.txt')
|
|
->and($mimeType)->toBeString();
|
|
|
|
Storage::disk()->delete($path);
|
|
});
|