Task 2 - file size validation

This commit is contained in:
PovilasKorop
2021-12-05 13:44:24 +02:00
parent 52d876c88f
commit 669b1de915
3 changed files with 29 additions and 0 deletions
+8
View File
@@ -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()`.
---
@@ -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 = '???';
+17
View File
@@ -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();
}
}