jonnybarnes.uk/tests/Feature/Admin/ClientsTest.php
Jonny Barnes 1dfa17abca
Some checks failed
PHP Unit / PHPUnit test suite (pull_request) Has been cancelled
Laravel Pint / Laravel Pint (pull_request) Has been cancelled
Update Laravel to v12
2025-04-01 21:10:30 +01:00

100 lines
2.7 KiB
PHP

<?php
declare(strict_types=1);
namespace Tests\Feature\Admin;
use App\Models\MicropubClient;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use PHPUnit\Framework\Attributes\Test;
use Tests\TestCase;
class ClientsTest extends TestCase
{
use RefreshDatabase;
#[Test]
public function clientsPageLoads(): void
{
$user = User::factory()->make();
$response = $this->actingAs($user)
->get('/admin/clients');
$response->assertSeeText('Clients');
}
#[Test]
public function adminCanLoadFormToCreateClient(): void
{
$user = User::factory()->make();
$response = $this->actingAs($user)
->get('/admin/clients/create');
$response->assertSeeText('New Client');
}
#[Test]
public function adminCanCreateNewClient(): void
{
$user = User::factory()->make();
$this->actingAs($user)
->post('/admin/clients', [
'client_name' => 'Micropublish',
'client_url' => 'https://micropublish.net',
]);
$this->assertDatabaseHas('clients', [
'client_name' => 'Micropublish',
'client_url' => 'https://micropublish.net',
]);
}
#[Test]
public function adminCanLoadEditFormForClient(): void
{
$user = User::factory()->make();
$client = MicropubClient::factory()->create([
'client_url' => 'https://jbl5.dev/notes/new',
]);
$response = $this->actingAs($user)
->get('/admin/clients/' . $client->id . '/edit');
$response->assertSee('https://jbl5.dev/notes/new');
}
#[Test]
public function adminCanEditClient(): void
{
$user = User::factory()->make();
$client = MicropubClient::factory()->create();
$this->actingAs($user)
->post('/admin/clients/' . $client->id, [
'_method' => 'PUT',
'client_url' => 'https://jbl5.dev/notes/new',
'client_name' => 'JBL5dev',
]);
$this->assertDatabaseHas('clients', [
'client_url' => 'https://jbl5.dev/notes/new',
'client_name' => 'JBL5dev',
]);
}
#[Test]
public function adminCanDeleteClient(): void
{
$user = User::factory()->make();
$client = MicropubClient::factory()->create([
'client_url' => 'https://jbl5.dev/notes/new',
]);
$this->actingAs($user)
->post('/admin/clients/' . $client->id, [
'_method' => 'DELETE',
]);
$this->assertDatabaseMissing('clients', [
'client_url' => 'https://jbl5.dev/notes/new',
]);
}
}