Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

3 tasks complete #650

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions app/Http/Controllers/HomeController.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<?php

namespace App\Http\Controllers;

use App\Models\User;

class HomeController extends Controller
Expand All @@ -11,13 +10,13 @@ public function users()
{
$usersCount = User::count();

return view('users');
return view('users', ['usersCount' => $usersCount]);
}

// Task 2. Change the View code so alert would not show on the screen
public function alert()
{
$text = '<script>alert("I am a security alert, your task is to remove me.");</script>';
$text = 'I am a security alert, your task is to remove me.';

return view('alert', compact('text'));
}
Expand All @@ -35,6 +34,10 @@ public function rows()
{
$users = User::all();

if($users->isEmpty()) {
return view('rows', ['users' => 'No content']);
}

return view('rows', compact('users'));
}

Expand Down
5 changes: 5 additions & 0 deletions tests/Feature/ViewsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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();
}

Expand Down
Loading