54 lines
2.9 KiB
PHP
54 lines
2.9 KiB
PHP
<?php
|
|
|
|
use Tempo\Purchasing\Delivery\BootOverlay;
|
|
|
|
require_once __DIR__.'/../../integrations/sgf/operational/BootOverlay.php';
|
|
|
|
beforeEach(function () {
|
|
$this->host = __DIR__.'/../../storage/framework/testing/boot-overlay-'.bin2hex(random_bytes(6));
|
|
mkdir($this->host.'/app/Providers', 0700, true);
|
|
mkdir($this->host.'/app/Shared/Context', 0700, true);
|
|
file_put_contents($this->host.'/app/Providers/AppServiceProvider.php', '<?php class Provider { public function register() { $this->app->scoped(CompanyContext::class); }'."\npublic function boot(): void\n {\n }\n}");
|
|
});
|
|
|
|
afterEach(function () {
|
|
foreach (['app/Providers/AppServiceProvider.php', 'app/Shared/Context/ModuleNavigation.php'] as $file) {
|
|
unlink($this->host.'/'.$file);
|
|
}
|
|
foreach (['app/Providers', 'app/Shared/Context', 'app/Shared', 'app', ''] as $directory) {
|
|
rmdir($this->host.($directory === '' ? '' : '/'.$directory));
|
|
}
|
|
});
|
|
|
|
test('prepares legacy host without changing source files or grants', function () {
|
|
$file = $this->host.'/app/Shared/Context/ModuleNavigation.php';
|
|
$before = "<?php class Nav { const RIGHTS=['purchasing'=>['purchasing_budget.', 'supplier_payables.']]; }";
|
|
file_put_contents($file, $before);
|
|
$result = BootOverlay::prepare($this->host);
|
|
expect($result['app/Shared/Context/ModuleNavigation.php']['contents'])->toContain("'purchasing_requisitions.'")
|
|
->and(file_get_contents($file))->toBe($before);
|
|
});
|
|
|
|
test('preserves expanded host navigation and is repeatable', function () {
|
|
$before = "<?php class Nav { const RIGHTS=['purchasing' => ['purchasing_budget.', 'purchasing_requisitions.', 'purchasing_orders.', 'purchasing_invoices.', 'supplier_payables.']]; }";
|
|
file_put_contents($this->host.'/app/Shared/Context/ModuleNavigation.php', $before);
|
|
$result = BootOverlay::prepare($this->host);
|
|
expect($result['app/Shared/Context/ModuleNavigation.php']['contents'])->toBe($before);
|
|
foreach ($result as $file => $entry) {
|
|
file_put_contents($this->host.'/'.$file, $entry['contents']);
|
|
}
|
|
$again = BootOverlay::prepare($this->host);
|
|
foreach ($result as $file => $entry) {
|
|
expect($again[$file]['contents'])->toBe($entry['contents']);
|
|
}
|
|
});
|
|
|
|
test('refuses ambiguous or executable host prefix lists', function (string $navigation) {
|
|
file_put_contents($this->host.'/app/Shared/Context/ModuleNavigation.php', $navigation);
|
|
expect(fn () => BootOverlay::prepare($this->host))->toThrow(RuntimeException::class);
|
|
})->with([
|
|
'unknown expression' => "<?php class Nav { const RIGHTS=['purchasing'=>['purchasing_budget.', dynamicPrefix(), 'supplier_payables.']]; }",
|
|
'missing anchor' => "<?php class Nav { const RIGHTS=['purchasing'=>['supplier_payables.']]; }",
|
|
'duplicate' => "<?php class Nav { const RIGHTS=['purchasing'=>['purchasing_budget.', 'supplier_payables.'], 'purchasing'=>['purchasing_budget.', 'supplier_payables.']]; }",
|
|
]);
|