52 lines
1.8 KiB
PHP
52 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature;
|
|
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Tests\TestCase;
|
|
|
|
class MerchantProtectedPagesTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
protected function loginAsMerchantAdmin(): void
|
|
{
|
|
$this->seed();
|
|
|
|
$this->post('/merchant-admin/login', [
|
|
'email' => 'merchant.admin@demo.local',
|
|
'password' => 'Merchant@123456',
|
|
])->assertRedirect('/merchant-admin');
|
|
}
|
|
|
|
public function test_guest_is_redirected_to_merchant_admin_login_for_protected_pages(): void
|
|
{
|
|
foreach (['/merchant-admin', '/merchant-admin/products', '/merchant-admin/orders', '/merchant-admin/product-categories', '/merchant-admin/users'] as $path) {
|
|
$this->get($path)->assertRedirect('/merchant-admin/login');
|
|
}
|
|
}
|
|
|
|
public function test_merchant_admin_can_access_key_merchant_pages(): void
|
|
{
|
|
$this->loginAsMerchantAdmin();
|
|
|
|
$this->get('/merchant-admin')->assertOk()->assertSee('商家后台仪表盘');
|
|
$this->get('/merchant-admin/products')->assertOk()->assertSee('商家商品管理');
|
|
$this->get('/merchant-admin/orders')->assertOk()->assertSee('商家订单管理');
|
|
$this->get('/merchant-admin/product-categories')->assertOk()->assertSee('商家商品分类');
|
|
$this->get('/merchant-admin/users')->assertOk()->assertSee('商家用户管理');
|
|
}
|
|
|
|
public function test_platform_admin_is_forbidden_from_merchant_admin_pages(): void
|
|
{
|
|
$this->seed();
|
|
|
|
$this->post('/admin/login', [
|
|
'email' => 'platform.admin@demo.local',
|
|
'password' => 'Platform@123456',
|
|
])->assertRedirect('/admin');
|
|
|
|
$this->get('/merchant-admin')->assertForbidden()->assertSee('当前账号未绑定商家后台访问权限');
|
|
}
|
|
}
|