79 lines
2.6 KiB
PHP
79 lines
2.6 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature\Business;
|
|
|
|
use App\Models\Auth\Role;
|
|
use App\Utilities\BusinessNavigation;
|
|
use App\Utilities\SidebarMenu;
|
|
use App\Utilities\SidebarPermissions;
|
|
use Tests\Feature\FeatureTestCase;
|
|
|
|
class ProcessDetailsNavigationTest extends FeatureTestCase
|
|
{
|
|
public function test_oa_process_is_in_dedicated_process_data_section(): void
|
|
{
|
|
$navigation = BusinessNavigation::all();
|
|
$slugs = array_column($navigation, 'slug');
|
|
|
|
$inventoryIndex = array_search('inventory-management', $slugs, true);
|
|
$processDataIndex = array_search('process-data', $slugs, true);
|
|
$financeIndex = array_search('financial-operations', $slugs, true);
|
|
|
|
$this->assertIsInt($inventoryIndex);
|
|
$this->assertIsInt($processDataIndex);
|
|
$this->assertIsInt($financeIndex);
|
|
$this->assertSame($inventoryIndex + 1, $processDataIndex);
|
|
$this->assertSame($processDataIndex + 1, $financeIndex);
|
|
|
|
$section = $navigation[$processDataIndex];
|
|
$this->assertSame('流程数据', $section['title']);
|
|
$this->assertSame(
|
|
[
|
|
['slug' => 'oa-process', 'title' => 'OA流程'],
|
|
['slug' => 'invoice-data', 'title' => '发票数据'],
|
|
],
|
|
array_map(
|
|
static fn (array $page): array => [
|
|
'slug' => $page['slug'],
|
|
'title' => $page['title'],
|
|
],
|
|
$section['pages'],
|
|
),
|
|
);
|
|
|
|
$finance = $navigation[$financeIndex];
|
|
$this->assertNotContains(
|
|
'process-details',
|
|
array_column($finance['pages'] ?? [], 'slug'),
|
|
);
|
|
}
|
|
|
|
public function test_invoice_data_inherits_oa_process_permission_in_navigation(): void
|
|
{
|
|
$this->user->roles()->sync([Role::where('name', 'user')->firstOrFail()->id]);
|
|
$subject = 'user_' . $this->user->id;
|
|
setting()->set('system.sidebar_permissions', [
|
|
'configured' => [$subject],
|
|
'subjects' => [$subject => ['process-data/oa-process']],
|
|
]);
|
|
setting()->save();
|
|
|
|
$this->assertSame(
|
|
['process-data/oa-process'],
|
|
SidebarPermissions::allowedKeys($this->user),
|
|
);
|
|
$this->assertContains(
|
|
'process-data/invoice-data',
|
|
SidebarPermissions::effectiveAllowedKeys($this->user),
|
|
);
|
|
|
|
$processSection = collect(SidebarMenu::sections($this->user))
|
|
->firstWhere('slug', 'process-data');
|
|
|
|
$this->assertSame(
|
|
['oa-process', 'invoice-data'],
|
|
array_column($processSection['pages'] ?? [], 'slug'),
|
|
);
|
|
}
|
|
}
|