49 lines
2.1 KiB
PHP
49 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace Tests\Unit\View;
|
|
|
|
use App\Listeners\Menu\ShowInAdmin;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
require_once dirname(__DIR__, 3) . '/app/Listeners/Menu/ShowInAdmin.php';
|
|
|
|
class PayablesGroupTest extends TestCase
|
|
{
|
|
public function test_group_preserves_sections_and_does_not_include_inventory(): void
|
|
{
|
|
$original = require dirname(__DIR__, 3) . '/config/business_navigation.php';
|
|
$grouped = ShowInAdmin::groupPayables($original);
|
|
$slugs = array_column($grouped, 'slug');
|
|
$index = array_search('payable-items', $slugs, true);
|
|
$this->assertSame('store-receivables', $slugs[$index - 1]);
|
|
$this->assertCount(6, $grouped[$index]['sections']);
|
|
$this->assertSame(['供应商应付', '快递应付'], array_column(array_slice($grouped[$index]['sections'], 0, 2), 'title'));
|
|
$this->assertSame(
|
|
[],
|
|
array_intersect(
|
|
['supplier-payables-final', 'courier-payables-final'],
|
|
array_column($grouped[$index]['sections'], 'slug')
|
|
)
|
|
);
|
|
$this->assertContains('inventory-management', $slugs);
|
|
foreach ($grouped[$index]['sections'] as $section) {
|
|
$this->assertNotContains($section['slug'], $slugs);
|
|
$this->assertSame($original[array_search($section['slug'], array_column($original, 'slug'), true)], $section);
|
|
}
|
|
}
|
|
|
|
public function test_only_authorized_sections_are_grouped(): void
|
|
{
|
|
$allowed = [['slug' => 'courier-payables', 'title' => '快递应付', 'pages' => [['slug' => 'freight-reconciliation']]]];
|
|
$result = ShowInAdmin::groupPayables($allowed);
|
|
$this->assertSame($allowed, $result[0]['sections']);
|
|
$this->assertSame([], ShowInAdmin::groupPayables([]));
|
|
|
|
$legacy = [
|
|
['slug' => 'supplier-payables-final', 'title' => '供应商应付(终版)', 'pages' => []],
|
|
['slug' => 'courier-payables-final', 'title' => '快递应付(终版)', 'pages' => []],
|
|
];
|
|
$this->assertSame([], ShowInAdmin::groupPayables($legacy));
|
|
}
|
|
}
|