Skip to main content

Black Friday 2025! Only until December 1st: coupon FRIDAY25 for 40% off Yearly/Lifetime membership!

Read more here

JustinByrne/Mealing

99 stars
1 code files
View JustinByrne/Mealing on GitHub

tests/Feature/PageTest.php

Open in GitHub
use Tests\TestCase;
use App\Models\User;
use Illuminate\Foundation\Testing\WithFaker;
use Illuminate\Foundation\Testing\RefreshDatabase;
 
class PageTest extends TestCase
{
use RefreshDatabase, WithFaker;
 
public $user;
 
protected function setUp(): void
{
parent::setUp();
 
$this->seed();
$this->user = User::factory()->create();
}
 
public function testAllowHomepage()
{
$this->withoutExceptionHandling();
 
$response = $this->actingAs($this->user)->get('/');
 
$response->assertOk();
$response->assertViewIs('homepage');
}
 
public function testDenyHomepageWhenNotLoggedIn()
{
$response = $this->get('/');
 
$response->assertRedirect(route('login'));
}
 
public function testAllowAdminDashboard()
{
$this->withoutExceptionHandling();
$this->user->givePermissionTo('admin_access');
 
$response = $this->actingAs($this->user)->get(route('admin.dashboard'));
 
$response->assertOk();
$response->assertViewIs('admin.dashboard');
}
 
public function testDenyAdminDashboardWhenNotLoggedIn()
{
$response = $this->get(route('admin.dashboard'));
 
$response->assertRedirect(route('login'));
}
 
public function testDeniedAdminDashboardWithoutPermission()
{
$response = $this->actingAs($this->user)->get(route('admin.dashboard'));
 
$response->assertForbidden();
}

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.