feat: complete admin CMS for customizable layout, texts, products, categories and orders
This commit is contained in:
@@ -0,0 +1,140 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\Category;
|
||||
use App\Models\Order;
|
||||
use App\Models\Product;
|
||||
use App\Models\Setting;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
|
||||
class AdminContentTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_admin_content_editor_loads_successfully(): void
|
||||
{
|
||||
$response = $this->get(route('admin.content.index'));
|
||||
|
||||
$response->assertStatus(200);
|
||||
$response->assertSee('Homepage Hero');
|
||||
$response->assertSee('Shop Content & Stijl CMS', false);
|
||||
}
|
||||
|
||||
public function test_admin_can_update_layout_and_texts(): void
|
||||
{
|
||||
$payload = [
|
||||
'site_name' => 'Mega 3D Shop',
|
||||
'hero_title' => 'Custom 3D Speelgoed & Figuren',
|
||||
'hero_subtitle' => 'Nieuwe custom introductietekst voor de winkel.',
|
||||
'hero_primary_btn_text' => 'Direct Winkelen',
|
||||
'usp_title' => 'Waarom kiezen voor onze prints?',
|
||||
'footer_email' => 'hallo@mega3d.nl',
|
||||
'announcement_enabled' => '1',
|
||||
'announcement_text' => 'Tijdelijke actie: gratis verzending!',
|
||||
];
|
||||
|
||||
$response = $this->post(route('admin.content.update'), $payload);
|
||||
|
||||
$response->assertRedirect(route('admin.content.index'));
|
||||
$response->assertSessionHas('success');
|
||||
|
||||
$this->assertSame('Mega 3D Shop', Setting::get('site_name'));
|
||||
$this->assertSame('Custom 3D Speelgoed & Figuren', Setting::get('hero_title'));
|
||||
$this->assertSame('hallo@mega3d.nl', Setting::get('footer_email'));
|
||||
|
||||
// Homepage should now display the updated content!
|
||||
$homeResponse = $this->get(route('home'));
|
||||
$homeResponse->assertStatus(200);
|
||||
$homeResponse->assertSee('Custom 3D Speelgoed & Figuren');
|
||||
$homeResponse->assertSee('Nieuwe custom introductietekst voor de winkel.');
|
||||
$homeResponse->assertSee('Direct Winkelen');
|
||||
$homeResponse->assertSee('Waarom kiezen voor onze prints?');
|
||||
$homeResponse->assertSee('hallo@mega3d.nl');
|
||||
$homeResponse->assertSee('Tijdelijke actie: gratis verzending!');
|
||||
}
|
||||
|
||||
public function test_admin_can_reset_content_to_defaults(): void
|
||||
{
|
||||
Setting::set('hero_title', 'Tijdelijke Titel');
|
||||
$this->assertSame('Tijdelijke Titel', Setting::get('hero_title'));
|
||||
|
||||
$response = $this->post(route('admin.content.reset'));
|
||||
$response->assertRedirect(route('admin.content.index'));
|
||||
|
||||
$this->assertNull(Setting::get('hero_title'));
|
||||
}
|
||||
|
||||
public function test_admin_can_view_and_edit_products(): void
|
||||
{
|
||||
$category = Category::create([
|
||||
'name' => 'Fidgets',
|
||||
'slug' => 'fidgets',
|
||||
]);
|
||||
|
||||
$product = Product::create([
|
||||
'name' => 'Test Fidget Draak',
|
||||
'slug' => 'test-fidget-draak',
|
||||
'category_id' => $category->id,
|
||||
'base_price' => 12.50,
|
||||
'short_description' => 'Korte test',
|
||||
'description' => 'Uitgebreide test beschrijving',
|
||||
'is_active' => true,
|
||||
]);
|
||||
|
||||
// Products index
|
||||
$indexResponse = $this->get(route('admin.products.index'));
|
||||
$indexResponse->assertStatus(200);
|
||||
$indexResponse->assertSee('Test Fidget Draak');
|
||||
|
||||
// Edit page
|
||||
$editResponse = $this->get(route('admin.products.edit', $product));
|
||||
$editResponse->assertStatus(200);
|
||||
$editResponse->assertSee('Test Fidget Draak');
|
||||
|
||||
// Update product
|
||||
$updateResponse = $this->put(route('admin.products.update', $product), [
|
||||
'name' => 'Aangepaste Fidget Draak',
|
||||
'category_id' => $category->id,
|
||||
'base_price' => 18.00,
|
||||
'short_description' => 'Geüpdatete korte test',
|
||||
'description' => 'Nieuwe lange beschrijving',
|
||||
'is_active' => 1,
|
||||
'is_featured' => 1,
|
||||
]);
|
||||
|
||||
$updateResponse->assertRedirect(route('admin.products.index'));
|
||||
$this->assertDatabaseHas('products', [
|
||||
'id' => $product->id,
|
||||
'name' => 'Aangepaste Fidget Draak',
|
||||
'base_price' => 18.00,
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_admin_can_view_orders(): void
|
||||
{
|
||||
$order = Order::create([
|
||||
'order_number' => 'ORD-TEST-999',
|
||||
'customer_name' => 'Jan Jansen',
|
||||
'customer_email' => 'jan@example.com',
|
||||
'shipping_street' => 'Dorpstraat',
|
||||
'shipping_number' => '1',
|
||||
'shipping_postal_code' => '1234AB',
|
||||
'shipping_city' => 'Amsterdam',
|
||||
'subtotal' => 25.00,
|
||||
'shipping_cost' => 0.00,
|
||||
'total' => 25.00,
|
||||
'status' => 'pending',
|
||||
]);
|
||||
|
||||
$response = $this->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->assertStatus(200);
|
||||
$showResponse->assertSee('ORD-TEST-999');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user