diff --git a/README.md b/README.md index 2a2cf93..3391007 100644 --- a/README.md +++ b/README.md @@ -32,3 +32,11 @@ In `app/Http/Controllers/ProjectController.php` file, in the `store()` method, g 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()`. + +--- diff --git a/app/Http/Controllers/ProjectController.php b/app/Http/Controllers/ProjectController.php index 11ce43c..95aed4f 100644 --- a/app/Http/Controllers/ProjectController.php +++ b/app/Http/Controllers/ProjectController.php @@ -9,6 +9,10 @@ class ProjectController extends Controller { 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 // The same filename as the original uploaded file $filename = '???'; diff --git a/tests/Feature/FileUploadTest.php b/tests/Feature/FileUploadTest.php index b0b8cec..e5fa34f 100644 --- a/tests/Feature/FileUploadTest.php +++ b/tests/Feature/FileUploadTest.php @@ -28,4 +28,21 @@ class FileUploadTest extends TestCase '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(); + } }