-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12940 from recca0120/fix/test-fake-uploaded-file
UploadedFile should be converted to TemporaryUploadedFile
- Loading branch information
Showing
2 changed files
with
57 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
use Filament\Forms\Components\FileUpload; | ||
use Filament\Forms\Form; | ||
use Filament\Tests\Forms\Fixtures\Livewire; | ||
use Filament\Tests\TestCase; | ||
use Illuminate\Contracts\View\View; | ||
use Illuminate\Http\UploadedFile; | ||
use Livewire\Features\SupportFileUploads\TemporaryUploadedFile; | ||
|
||
use function Filament\Tests\livewire; | ||
|
||
uses(TestCase::class); | ||
|
||
it('UploadedFile should be converted to TemporaryUploadedFile', function () { | ||
livewire(TestComponentWithFileUpload::class) | ||
->fillForm([ | ||
'single-file' => UploadedFile::fake()->image('single-file.jpg'), | ||
'multiple-files' => [ | ||
UploadedFile::fake()->image('multiple-file1.jpg'), | ||
UploadedFile::fake()->image('multiple-file2.jpg'), | ||
], | ||
]) | ||
->assertFormSet(function (array $data) { | ||
expect($data['single-file'][0])->toBeInstanceOf(TemporaryUploadedFile::class) | ||
->and($data['multiple-files'][0])->toBeInstanceOf(TemporaryUploadedFile::class) | ||
->and($data['multiple-files'][1])->toBeInstanceOf(TemporaryUploadedFile::class); | ||
}); | ||
}); | ||
|
||
class TestComponentWithFileUpload extends Livewire | ||
{ | ||
public function form(Form $form): Form | ||
{ | ||
return $form | ||
->schema([ | ||
FileUpload::make('single-file'), | ||
FileUpload::make('multiple-files')->multiple(), | ||
]) | ||
->statePath('data'); | ||
} | ||
|
||
public function render(): View | ||
{ | ||
return view('forms.fixtures.form'); | ||
} | ||
} |