account('普通财务'); $denied = $this->account('未授权账号'); $subject = 'user_' . $viewer->id; $deniedSubject = 'user_' . $denied->id; setting()->set('system.sidebar_permissions', [ 'configured' => [$subject, $deniedSubject], 'subjects' => [ $subject => ['other/log-statistics'], $deniedSubject => [], ], ]); $this->assertTrue(SidebarPermissions::canViewPage($viewer, 'other', 'log-statistics')); $otherSection = collect(SidebarPermissions::navigationFor($viewer)) ->firstWhere('slug', 'other'); $this->assertTrue(collect($otherSection['pages'] ?? [])->contains('slug', 'log-statistics')); $this->loginAs($viewer) ->get(route('business.pages.show', [ 'section' => 'other', 'page' => 'log-statistics', ])) ->assertOk(); $this->withExceptionHandling()->loginAs($denied) ->get(route('business.pages.show', [ 'section' => 'other', 'page' => 'log-statistics', ])) ->assertForbidden(); } private function account(string $name): User { $suffix = User::count(); $user = User::create([ 'name' => $name, 'email' => 'log-statistics-access-' . $suffix . '@example.test', 'password' => 'fixture-unused-password', 'enabled' => true, 'locale' => 'zh-CN', 'landing_page' => 'dashboard', ]); $user->roles()->attach(Role::where('name', 'user')->firstOrFail()->id); $user->permissions()->attach(Permission::where('name', 'read-admin-panel')->firstOrFail()->id); $user->companies()->attach($this->company->id); return $user; } }