mirror of
https://github.com/10h30/Test-Laravel-File-Upload.git
synced 2026-07-11 18:56:13 +09:00
Task 2 - file size validation
This commit is contained in:
@@ -32,3 +32,11 @@ In `app/Http/Controllers/ProjectController.php` file, in the `store()` method, g
|
|||||||
Test method `test_original_filename_upload()`.
|
Test method `test_original_filename_upload()`.
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
## Task 2. File Size Validation.
|
||||||
|
|
||||||
|
In `app/Http/Controllers/ProjectController.php` file, in the `store()` method, put in the validation rule so "logo" file would be MAX 1 megabyte
|
||||||
|
|
||||||
|
Test method `test_file_size_validation()`.
|
||||||
|
|
||||||
|
---
|
||||||
|
|||||||
@@ -9,6 +9,10 @@ class ProjectController extends Controller
|
|||||||
{
|
{
|
||||||
public function store(Request $request)
|
public function store(Request $request)
|
||||||
{
|
{
|
||||||
|
$request->validate([
|
||||||
|
// TASK: Write the validation rule so "logo" file would be MAX 1 megabyte
|
||||||
|
]);
|
||||||
|
|
||||||
// TASK: change the below line so that $filename would contain only filename
|
// TASK: change the below line so that $filename would contain only filename
|
||||||
// The same filename as the original uploaded file
|
// The same filename as the original uploaded file
|
||||||
$filename = '???';
|
$filename = '???';
|
||||||
|
|||||||
@@ -28,4 +28,21 @@ class FileUploadTest extends TestCase
|
|||||||
'logo' => $filename
|
'logo' => $filename
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function test_file_size_validation()
|
||||||
|
{
|
||||||
|
Storage::fake('logos');
|
||||||
|
|
||||||
|
$response = $this->post('projects', [
|
||||||
|
'name' => 'Some name',
|
||||||
|
'logo' => UploadedFile::fake()->create('logo.jpg', 2000)
|
||||||
|
]);
|
||||||
|
$response->assertInvalid();
|
||||||
|
|
||||||
|
$response = $this->post('projects', [
|
||||||
|
'name' => 'Some name',
|
||||||
|
'logo' => UploadedFile::fake()->create('logo.jpg', 500)
|
||||||
|
]);
|
||||||
|
$response->assertValid();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user