整合基础数据与商品价格管理导航 #165
@ -20,7 +20,34 @@ class ShowInAdmin
|
||||
*/
|
||||
public function handle(Event $event): void
|
||||
{
|
||||
$this->renderSections($event->menu, self::groupPayables(SidebarPermissions::navigationFor(user())));
|
||||
$this->renderSections($event->menu, self::groupBasicData(self::groupPayables(SidebarPermissions::navigationFor(user()))));
|
||||
}
|
||||
|
||||
public static function groupBasicData(array $navigation): array
|
||||
{
|
||||
$keys = ['order-data', 'refunds'];
|
||||
$children = array_values(array_filter($navigation, static fn (array $section): bool => in_array($section['slug'], $keys, true)));
|
||||
if ($children === []) {
|
||||
return $navigation;
|
||||
}
|
||||
|
||||
$group = ['slug' => 'basic-data', 'title' => '基础数据', 'icon' => 'folder', 'sections' => $children];
|
||||
$hasDirectory = in_array('basic-data', array_column($navigation, 'slug'), true);
|
||||
$result = [];
|
||||
foreach ($navigation as $section) {
|
||||
if ($section['slug'] === 'basic-data') {
|
||||
$result[] = array_replace($section, ['sections' => $children]);
|
||||
} elseif (in_array($section['slug'], $keys, true)) {
|
||||
if (! $hasDirectory) {
|
||||
$result[] = $group;
|
||||
$hasDirectory = true;
|
||||
}
|
||||
} else {
|
||||
$result[] = $section;
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public static function groupPayables(array $navigation): array
|
||||
|
||||
@ -289,9 +289,15 @@ $navigation = [
|
||||
],
|
||||
],
|
||||
],
|
||||
[
|
||||
'slug' => 'basic-data',
|
||||
'title' => '基础数据',
|
||||
'icon' => 'folder',
|
||||
'pages' => [],
|
||||
],
|
||||
[
|
||||
'slug' => 'product-inventory',
|
||||
'title' => '商品及库存管理',
|
||||
'title' => '商品价格管理',
|
||||
'icon' => 'inventory_2',
|
||||
'pages' => [
|
||||
['slug' => 'normal-products', 'title' => '普通商品资料'],
|
||||
@ -653,6 +659,7 @@ $navigation = [
|
||||
|
||||
// Keep the requested finance-data sections together while preserving every other section's order.
|
||||
$requestedSectionOrder = [
|
||||
'basic-data',
|
||||
'invoice-management',
|
||||
'fund-management',
|
||||
'order-data',
|
||||
|
||||
@ -9,6 +9,40 @@ use Tests\Feature\FeatureTestCase;
|
||||
|
||||
class NavigationTest extends FeatureTestCase
|
||||
{
|
||||
public function testGroupedNavigationRendersExistingPageLinks(): void
|
||||
{
|
||||
$this->loginAs()
|
||||
->get(route('business.pages.show', ['section' => 'basic-data']))
|
||||
->assertOk()
|
||||
->assertSeeText('基础数据')
|
||||
->assertSeeText('商品价格管理')
|
||||
->assertSee('/workspace/order-data/raw-data', false)
|
||||
->assertSee('/workspace/refunds/non-jingxi-refund-data', false)
|
||||
->assertSee('/workspace/product-inventory/normal-products', false);
|
||||
}
|
||||
|
||||
public function testGroupedNavigationKeepsRestrictedPagePermissions(): void
|
||||
{
|
||||
$this->user->roles()->sync([Role::where('name', 'manager')->firstOrFail()->id]);
|
||||
$subject = 'user_' . $this->user->id;
|
||||
setting()->set('system.sidebar_permissions', [
|
||||
'configured' => [$subject],
|
||||
'subjects' => [$subject => ['basic-data', 'refunds/non-jingxi-refund-data']],
|
||||
]);
|
||||
setting()->save();
|
||||
|
||||
$this->loginAs()
|
||||
->get(route('business.pages.show', ['section' => 'basic-data']))
|
||||
->assertOk()
|
||||
->assertSee('/workspace/refunds/non-jingxi-refund-data', false)
|
||||
->assertDontSee('/workspace/order-data/raw-data', false)
|
||||
->assertDontSee('/workspace/product-inventory/normal-products', false);
|
||||
|
||||
$this->withExceptionHandling()
|
||||
->get(route('business.pages.show', ['section' => 'order-data']))
|
||||
->assertForbidden();
|
||||
}
|
||||
|
||||
public function testAdminCanUpdateSidebarLabels()
|
||||
{
|
||||
$this->user->roles()->sync([
|
||||
@ -87,7 +121,7 @@ class NavigationTest extends FeatureTestCase
|
||||
'退款数据',
|
||||
'账单流水数据',
|
||||
'账单余额数据',
|
||||
'商品及库存管理',
|
||||
'商品价格管理',
|
||||
],
|
||||
array_column(array_slice($navigation, $invoiceIndex, 7), 'title')
|
||||
);
|
||||
|
||||
46
tests/Unit/View/BasicDataNavigationTest.php
Normal file
46
tests/Unit/View/BasicDataNavigationTest.php
Normal file
@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\View;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use App\Listeners\Menu\ShowInAdmin;
|
||||
|
||||
require_once dirname(__DIR__, 3) . '/app/Listeners/Menu/ShowInAdmin.php';
|
||||
|
||||
class BasicDataNavigationTest extends TestCase
|
||||
{
|
||||
public function test_group_moves_only_order_data_and_refunds_without_changing_pages(): void
|
||||
{
|
||||
$navigation = require dirname(__DIR__, 3) . '/config/business_navigation.php';
|
||||
$grouped = ShowInAdmin::groupBasicData($navigation);
|
||||
$slugs = array_column($grouped, 'slug');
|
||||
$group = $grouped[array_search('basic-data', $slugs, true)];
|
||||
$this->assertSame(['order-data', 'refunds'], array_column($group['sections'], 'slug'));
|
||||
$this->assertNotContains('order-data', $slugs);
|
||||
$this->assertNotContains('refunds', $slugs);
|
||||
foreach ($group['sections'] as $section) {
|
||||
$this->assertSame($navigation[array_search($section['slug'], array_column($navigation, 'slug'), true)], $section);
|
||||
}
|
||||
}
|
||||
|
||||
public function test_group_contains_only_authorized_sections_even_without_directory_permission(): void
|
||||
{
|
||||
$allowed = [['slug' => 'refunds', 'title' => '退款', 'pages' => [['slug' => 'non-jingxi-refund-data']]]];
|
||||
$grouped = ShowInAdmin::groupBasicData($allowed);
|
||||
$this->assertSame($allowed, $grouped[0]['sections']);
|
||||
$this->assertSame([], ShowInAdmin::groupBasicData([]));
|
||||
}
|
||||
|
||||
public function test_basic_data_is_an_empty_top_level_directory_before_invoice_management(): void
|
||||
{
|
||||
$navigation = require dirname(__DIR__, 3) . '/config/business_navigation.php';
|
||||
$slugs = array_column($navigation, 'slug');
|
||||
$index = array_search('basic-data', $slugs, true);
|
||||
|
||||
$this->assertNotFalse($index);
|
||||
$this->assertSame('基础数据', $navigation[$index]['title']);
|
||||
$this->assertSame([], $navigation[$index]['pages']);
|
||||
$this->assertSame('invoice-management', $slugs[$index + 1]);
|
||||
$this->assertCount(1, array_keys($slugs, 'basic-data', true));
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user