feat: complete user authentication, admin guard, customer account dashboard and branded HTML emails
This commit is contained in:
@@ -6,6 +6,7 @@ use App\Models\Category;
|
||||
use App\Models\Order;
|
||||
use App\Models\Product;
|
||||
use App\Models\Setting;
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
|
||||
@@ -13,10 +14,46 @@ class AdminContentTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_admin_content_editor_loads_successfully(): void
|
||||
protected User $admin;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->admin = User::create([
|
||||
'name' => 'Admin Jouwdriedee',
|
||||
'email' => 'info@jouwdriedee.nl',
|
||||
'password' => bcrypt('Jw3D!x9#QmK7$vR2'),
|
||||
'is_admin' => true,
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_guest_is_redirected_to_login_when_accessing_admin(): void
|
||||
{
|
||||
$response = $this->get(route('admin.content.index'));
|
||||
|
||||
$response->assertRedirect(route('login'));
|
||||
}
|
||||
|
||||
public function test_regular_customer_cannot_access_admin(): void
|
||||
{
|
||||
$customer = User::create([
|
||||
'name' => 'Klant Piet',
|
||||
'email' => 'piet@example.com',
|
||||
'password' => bcrypt('secret1234'),
|
||||
'is_admin' => false,
|
||||
]);
|
||||
|
||||
$response = $this->actingAs($customer)->get(route('admin.content.index'));
|
||||
|
||||
$response->assertRedirect(route('home'));
|
||||
$response->assertSessionHas('error');
|
||||
}
|
||||
|
||||
public function test_admin_content_editor_loads_successfully(): void
|
||||
{
|
||||
$response = $this->actingAs($this->admin)->get(route('admin.content.index'));
|
||||
|
||||
$response->assertStatus(200);
|
||||
$response->assertSee('Homepage Hero');
|
||||
$response->assertSee('Shop Content & Stijl CMS', false);
|
||||
@@ -35,7 +72,7 @@ class AdminContentTest extends TestCase
|
||||
'announcement_text' => 'Tijdelijke actie: gratis verzending!',
|
||||
];
|
||||
|
||||
$response = $this->post(route('admin.content.update'), $payload);
|
||||
$response = $this->actingAs($this->admin)->post(route('admin.content.update'), $payload);
|
||||
|
||||
$response->assertRedirect(route('admin.content.index'));
|
||||
$response->assertSessionHas('success');
|
||||
@@ -60,7 +97,7 @@ class AdminContentTest extends TestCase
|
||||
Setting::set('hero_title', 'Tijdelijke Titel');
|
||||
$this->assertSame('Tijdelijke Titel', Setting::get('hero_title'));
|
||||
|
||||
$response = $this->post(route('admin.content.reset'));
|
||||
$response = $this->actingAs($this->admin)->post(route('admin.content.reset'));
|
||||
$response->assertRedirect(route('admin.content.index'));
|
||||
|
||||
$this->assertNull(Setting::get('hero_title'));
|
||||
@@ -84,17 +121,17 @@ class AdminContentTest extends TestCase
|
||||
]);
|
||||
|
||||
// Products index
|
||||
$indexResponse = $this->get(route('admin.products.index'));
|
||||
$indexResponse = $this->actingAs($this->admin)->get(route('admin.products.index'));
|
||||
$indexResponse->assertStatus(200);
|
||||
$indexResponse->assertSee('Test Fidget Draak');
|
||||
|
||||
// Edit page
|
||||
$editResponse = $this->get(route('admin.products.edit', $product));
|
||||
$editResponse = $this->actingAs($this->admin)->get(route('admin.products.edit', $product));
|
||||
$editResponse->assertStatus(200);
|
||||
$editResponse->assertSee('Test Fidget Draak');
|
||||
|
||||
// Update product
|
||||
$updateResponse = $this->put(route('admin.products.update', $product), [
|
||||
$updateResponse = $this->actingAs($this->admin)->put(route('admin.products.update', $product), [
|
||||
'name' => 'Aangepaste Fidget Draak',
|
||||
'category_id' => $category->id,
|
||||
'base_price' => 18.00,
|
||||
@@ -128,12 +165,12 @@ class AdminContentTest extends TestCase
|
||||
'status' => 'pending',
|
||||
]);
|
||||
|
||||
$response = $this->get(route('admin.orders.index'));
|
||||
$response = $this->actingAs($this->admin)->get(route('admin.orders.index'));
|
||||
$response->assertStatus(200);
|
||||
$response->assertSee('ORD-TEST-999');
|
||||
$response->assertSee('Jan Jansen');
|
||||
|
||||
$showResponse = $this->get(route('admin.orders.show', $order));
|
||||
$showResponse = $this->actingAs($this->admin)->get(route('admin.orders.show', $order));
|
||||
$showResponse->assertStatus(200);
|
||||
$showResponse->assertSee('ORD-TEST-999');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user