45 lines
2.0 KiB
PHP
45 lines
2.0 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(8, $grouped[$index]['sections']);
|
|
$this->assertSame(
|
|
['供应商应付(终版)', '快递应付(终版)', '供应商应付', '快递应付'],
|
|
array_column(array_slice($grouped[$index]['sections'], 0, 4), 'title')
|
|
);
|
|
$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([]));
|
|
|
|
$finalEntries = [
|
|
['slug' => 'supplier-payables-final', 'title' => '供应商应付(终版)', 'pages' => []],
|
|
['slug' => 'courier-payables-final', 'title' => '快递应付(终版)', 'pages' => []],
|
|
];
|
|
$this->assertSame($finalEntries, ShowInAdmin::groupPayables($finalEntries)[0]['sections']);
|
|
}
|
|
}
|