feat: add webshop offline maintenance mode with admin toggle and red maintenance screen
This commit is contained in:
@@ -257,4 +257,50 @@ class AdminContentTest extends TestCase
|
||||
$storagePath = str_replace('/storage/', '', $url);
|
||||
Storage::disk('public')->assertExists($storagePath);
|
||||
}
|
||||
|
||||
public function test_admin_can_toggle_webshop_offline_mode(): void
|
||||
{
|
||||
$this->assertEquals('0', Setting::get('shop_offline', '0'));
|
||||
|
||||
// Toggle offline via admin button
|
||||
$response = $this->actingAs($this->admin)->post(route('admin.toggle-offline'));
|
||||
$response->assertRedirect();
|
||||
Setting::flushCache();
|
||||
$this->assertEquals('1', Setting::get('shop_offline'));
|
||||
|
||||
// Logout admin so subsequent requests are unauthenticated guest requests
|
||||
auth()->logout();
|
||||
$this->flushSession();
|
||||
|
||||
// Guest visitor receives 503 with big red offline banner
|
||||
$guestResponse = $this->get(route('home'));
|
||||
$guestResponse->assertStatus(503);
|
||||
$guestResponse->assertSee('Aan deze webshop wordt hard gewerkt', false);
|
||||
$guestResponse->assertSee('Webshop Tijdelijk Offline');
|
||||
|
||||
// Other customer routes are blocked
|
||||
$catalogResponse = $this->get(route('catalog'));
|
||||
$catalogResponse->assertStatus(503);
|
||||
|
||||
// Login page remains accessible
|
||||
$loginResponse = $this->get(route('login'));
|
||||
$loginResponse->assertStatus(200);
|
||||
|
||||
// Admin can still view storefront normally with preview banner
|
||||
$adminShopResponse = $this->actingAs($this->admin)->get(route('home'));
|
||||
$adminShopResponse->assertStatus(200);
|
||||
$adminShopResponse->assertSee('OFFLINE BEHEERDERS-PREVIEW');
|
||||
|
||||
// Toggle back online
|
||||
$this->actingAs($this->admin)->post(route('admin.toggle-offline'));
|
||||
Setting::flushCache();
|
||||
$this->assertEquals('0', Setting::get('shop_offline'));
|
||||
|
||||
// Logout admin and verify guest can visit normally again
|
||||
auth()->logout();
|
||||
$this->flushSession();
|
||||
|
||||
$guestOnlineResponse = $this->get(route('home'));
|
||||
$guestOnlineResponse->assertStatus(200);
|
||||
}
|
||||
}
|
||||
|
||||
+6
-1
@@ -2,9 +2,14 @@
|
||||
|
||||
namespace Tests;
|
||||
|
||||
use App\Models\Setting;
|
||||
use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
|
||||
|
||||
abstract class TestCase extends BaseTestCase
|
||||
{
|
||||
//
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
Setting::flushCache();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user