diff --git a/app/Http/Controllers/HomeController.php b/app/Http/Controllers/HomeController.php index 3ec9546d..08853bc8 100644 --- a/app/Http/Controllers/HomeController.php +++ b/app/Http/Controllers/HomeController.php @@ -1,7 +1,6 @@ $usersCount]); } // Task 2. Change the View code so alert would not show on the screen public function alert() { - $text = ''; + $text = 'I am a security alert, your task is to remove me.'; return view('alert', compact('text')); } @@ -35,6 +34,10 @@ public function rows() { $users = User::all(); + if($users->isEmpty()) { + return view('rows', ['users' => 'No content']); + } + return view('rows', compact('users')); } diff --git a/tests/Feature/ViewsTest.php b/tests/Feature/ViewsTest.php index 032b74ce..f188bb8f 100644 --- a/tests/Feature/ViewsTest.php +++ b/tests/Feature/ViewsTest.php @@ -4,6 +4,7 @@ use App\Models\User; use Illuminate\Foundation\Testing\RefreshDatabase; +use Illuminate\Foundation\Testing\WithFaker; use Tests\TestCase; class ViewsTest extends TestCase @@ -12,7 +13,11 @@ class ViewsTest extends TestCase public function test_users_list_get_with_values() { + $users = User::factory()->count(5)->create(); + $response = $this->get('users'); + $response->assertStatus(200); + $response->assertViewHas('usersCount', $users->count()); $response->assertOk(); }