mirror of
https://github.com/10h30/Test-Laravel-Auth-Basics.git
synced 2026-07-11 18:56:14 +09:00
First auth tests around profile
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace Tests;
|
||||
|
||||
use Illuminate\Contracts\Console\Kernel;
|
||||
|
||||
trait CreatesApplication
|
||||
{
|
||||
/**
|
||||
* Creates the application.
|
||||
*
|
||||
* @return \Illuminate\Foundation\Application
|
||||
*/
|
||||
public function createApplication()
|
||||
{
|
||||
$app = require __DIR__.'/../bootstrap/app.php';
|
||||
|
||||
$app->make(Kernel::class)->bootstrap();
|
||||
|
||||
return $app;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
|
||||
class AuthenticationTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_profile_routes_are_protected_from_public()
|
||||
{
|
||||
$response = $this->get('/profile');
|
||||
$response->assertStatus(302);
|
||||
$response->assertRedirect('login');
|
||||
|
||||
$response = $this->put('/profile');
|
||||
$response->assertStatus(302);
|
||||
$response->assertRedirect('login');
|
||||
|
||||
$user = User::factory()->create();
|
||||
$response = $this->actingAs($user)->get('/profile');
|
||||
$response->assertOk();
|
||||
}
|
||||
|
||||
public function test_profile_link_is_invisible_in_public()
|
||||
{
|
||||
$response = $this->get('/');
|
||||
$this->assertStringNotContainsString('href="/profile"', $response->getContent());
|
||||
|
||||
$user = User::factory()->create();
|
||||
$response = $this->actingAs($user)->get('/');
|
||||
$this->assertStringContainsString('href="/profile"', $response->getContent());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace Tests;
|
||||
|
||||
use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
|
||||
|
||||
abstract class TestCase extends BaseTestCase
|
||||
{
|
||||
use CreatesApplication;
|
||||
}
|
||||
Reference in New Issue
Block a user