From ecc70f4d9f445c77c4dced6123a320b1dd441e2e Mon Sep 17 00:00:00 2001 From: thinkverse Date: Wed, 1 Dec 2021 15:07:43 +0100 Subject: [PATCH 1/2] Fix Task 7 - update forbidden field --- app/Models/User.php | 1 + tests/Feature/ValidationTest.php | 6 ++++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/app/Models/User.php b/app/Models/User.php index 6a41429..4f83a9c 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -41,5 +41,6 @@ class User extends Authenticatable */ protected $casts = [ 'email_verified_at' => 'datetime', + 'is_admin' => 'boolean', ]; } diff --git a/tests/Feature/ValidationTest.php b/tests/Feature/ValidationTest.php index afc187e..eac1799 100644 --- a/tests/Feature/ValidationTest.php +++ b/tests/Feature/ValidationTest.php @@ -94,7 +94,7 @@ class ValidationTest extends TestCase $user = User::where('name', $updatedUser['name'])->first(); $this->assertNotNull($user); - $this->assertEquals(false, $user->is_admin); + $this->assertFalse($user->is_admin); } public function test_custom_error_message() @@ -107,6 +107,8 @@ class ValidationTest extends TestCase public function test_custom_validation_rule() { $response = $this->post('articles', ['title' => 'lowercase']); - $response->assertSessionHasErrors('title')->assertStatus(302); + $response->assertSessionHasErrors([ + 'title' => 'The title does not start with an uppercased letter.', + ])->assertStatus(302); } } From 721762f0bab6b56fc70e888103471204c1de0804 Mon Sep 17 00:00:00 2001 From: thinkverse Date: Wed, 1 Dec 2021 15:14:00 +0100 Subject: [PATCH 2/2] Fix Task 9 - your own validation rule --- README.md | 2 +- tests/Feature/ValidationTest.php | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index aaa3d5d..4b92d3c 100644 --- a/README.md +++ b/README.md @@ -98,7 +98,7 @@ Test method `test_custom_error_message()`. ## Task 9. Your Own Validation Rule. -In `app/Http/Controllers/ArticleController.php` file, in `store` method, the code uses `Uppercase` validation rule that you need to create with Artisan command, and fill in with the rule of "title" having first letter as uppercase. +In `app/Http/Controllers/ArticleController.php` file, in `store` method, the code uses `Uppercase` validation rule that you need to create with Artisan command, and fill in with the rule of "title" having first letter as uppercase with the error message "The title does not start with an uppercased letter". Test method `test_custom_validation_rule()`. diff --git a/tests/Feature/ValidationTest.php b/tests/Feature/ValidationTest.php index eac1799..f5dba8b 100644 --- a/tests/Feature/ValidationTest.php +++ b/tests/Feature/ValidationTest.php @@ -108,7 +108,10 @@ class ValidationTest extends TestCase { $response = $this->post('articles', ['title' => 'lowercase']); $response->assertSessionHasErrors([ - 'title' => 'The title does not start with an uppercased letter.', + 'title' => 'The title does not start with an uppercased letter', ])->assertStatus(302); + + $response = $this->post('articles', ['title' => 'Uppercase']); + $response->assertStatus(200); } }