keyBy('slug'); $financialOperations = $navigation->get('financial-operations'); $this->assertNotNull($financialOperations); $this->assertSame('ledger', collect($financialOperations['pages'])->last()['slug']); $this->assertFalse($navigation->has('financial-ledger')); } public function test_ledger_is_the_first_quick_link_under_operating_reports(): void { $this->loginAs(); $reports = collect(SidebarMenu::groups($this->user))->firstWhere('title', '经营报表'); $this->assertNotNull($reports); $this->assertSame([ 'section' => 'financial-operations', 'page' => 'ledger', 'title' => '财务台账', 'icon' => 'menu_book', ], $reports['items'][0]); } public function test_ledger_page_and_legacy_link_open_under_financial_operations(): void { $this->loginAs(); $target = route('business.pages.show', [ 'section' => 'financial-operations', 'page' => 'ledger', ]); $response = $this->get($target . '?tab=flows') ->assertOk() ->assertSeeText('财务经营报表') ->assertSeeText('财务台账') ->assertSee('data-ledger-page', false) ->assertSee('data-ledger-tab="flows"', false) ->assertSee($target . '?tab=accounts', false); $this->assertSame(1, substr_count($response->getContent(), 'href="' . e($target) . '"')); $legacy = route('business.pages.show', [ 'section' => 'financial-ledger', 'page' => 'ledger', ]); $this->get($legacy . '?tab=flows')->assertRedirect($target . '?tab=flows'); $this->get($legacy . '/flows')->assertRedirect($target . '?tab=flows'); $this->get(route('business.financial-ledger.accounts.template'))->assertOk(); } public function test_ledger_actions_use_financial_operations_permission(): void { foreach ([ 'business.financial-operations.ledger.mapping.update', 'business.financial-ledger.mapping.update', 'business.financial-ledger.accounts.status', 'business.financial-ledger.accounts.type', 'business.financial-ledger.accounts.template', 'business.financial-ledger.transactions.account.update', 'business.financial-ledger.mapping.shop.preview', 'business.financial-ledger.mapping.shop.apply', 'business.financial-ledger.mapping.payable.preview', 'business.financial-ledger.mapping.payable.apply', ] as $routeName) { $route = app('router')->getRoutes()->getByName($routeName); $this->assertNotNull($route, $routeName); $this->assertContains( 'business.page:financial-operations,ledger', $route->gatherMiddleware(), $routeName ); } } public function test_legacy_ledger_permissions_follow_the_page(): void { $regular = $this->regularAccount(); $subject = 'user_' . $regular->id; foreach (['financial-ledger', 'financial-ledger/ledger'] as $legacyKey) { setting()->set('system.sidebar_permissions', [ 'configured' => [$subject], 'subjects' => [$subject => [$legacyKey]], ]); $this->assertSame( ['financial-operations/ledger'], SidebarPermissions::allowedKeys($regular) ); $navigation = SidebarPermissions::navigationFor($regular); $this->assertSame(['financial-operations'], array_column($navigation, 'slug')); $this->assertSame(['ledger'], array_column($navigation[0]['pages'], 'slug')); } $this->loginAs($regular) ->get(route('business.pages.show', [ 'section' => 'financial-operations', 'page' => 'ledger', ])) ->assertOk() ->assertSee('data-ledger-page', false); } private function regularAccount(): User { $name = 'fixture-finance-ledger-' . User::count(); $user = User::create([ 'name' => $name, 'email' => $name . '@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; } }