First auth tests around profile

This commit is contained in:
PovilasKorop
2021-10-31 18:48:55 +02:00
commit 583796d502
129 changed files with 239714 additions and 0 deletions
+22
View File
@@ -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;
}
}
+37
View File
@@ -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());
}
}
+10
View File
@@ -0,0 +1,10 @@
<?php
namespace Tests;
use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
abstract class TestCase extends BaseTestCase
{
use CreatesApplication;
}