Files
saasshop/tests/Feature/AdminProtectedPagesTest.php

52 lines
1.6 KiB
PHP

<?php
namespace Tests\Feature;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class AdminProtectedPagesTest extends TestCase
{
use RefreshDatabase;
protected function loginAsPlatformAdmin(): void
{
$this->seed();
$this->post('/admin/login', [
'email' => 'platform.admin@demo.local',
'password' => 'Platform@123456',
])->assertRedirect('/admin');
}
public function test_guest_is_redirected_to_admin_login_for_protected_pages(): void
{
foreach (['/admin', '/admin/merchants', '/admin/orders', '/admin/products', '/admin/product-categories'] as $path) {
$this->get($path)->assertRedirect('/admin/login');
}
}
public function test_platform_admin_can_access_key_admin_pages(): void
{
$this->loginAsPlatformAdmin();
$this->get('/admin')->assertOk()->assertSee('总台仪表盘');
$this->get('/admin/merchants')->assertOk()->assertSee('站点管理');
$this->get('/admin/orders')->assertOk()->assertSee('订单监控');
$this->get('/admin/products')->assertOk()->assertSee('商品巡检');
$this->get('/admin/product-categories')->assertOk()->assertSee('商品分类');
}
public function test_merchant_admin_is_forbidden_from_admin_pages(): void
{
$this->seed();
$this->post('/merchant-admin/login', [
'email' => 'merchant.admin@demo.local',
'password' => 'Merchant@123456',
])->assertRedirect('/merchant-admin');
$this->get('/admin')->assertForbidden()->assertSee('当前账号没有总台管理访问权限');
}
}