forked from fa/breadcrumb-the-shire
Completes the generic module platform that enables modules to contribute
UI elements, runtime JS components, and search resources without any
core hardcoding.
New generic UI slot types:
- topbar.right_item: module-contributed topbar buttons
- layout.body_end_template: module-contributed dialog/overlay templates
- layout.head_style: module-contributed global CSS
- runtime.component: declarative JS component registration with phase ordering
New infrastructure:
- ModuleAutoloader: PSR-4 autoloading for module-local PHP classes
- ModuleRuntimePageBuilder: symlinks module pages into runtime directory
- ModuleRuntimeAssetPublisher: publishes module CSS/JS to web/modules/
- ModulePermissionSynchronizer: syncs module permissions to DB
- CLI scripts: module-runtime-sync, module-build, module-migrate,
module-permissions-sync, module-assets-sync
- {{userId}} placeholder in SearchDataService for user-scoped search queries
- Component runtime with phased initialization (early/default/late)
- AppContainer.protectExistingBindings() to prevent module→core overwrites
- Architecture tests: ModuleStructureContractTest, CoreTemplateIsolationTest,
FrontendComponentRuntimeContractTest, AppContainerIsolationContractTest
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
84 lines
2.9 KiB
PHP
84 lines
2.9 KiB
PHP
<?php
|
|
|
|
namespace MintyPHP\Tests\Unit\Module;
|
|
|
|
use MintyPHP\App\AppContainer;
|
|
use MintyPHP\Module\AddressBook\Providers\AddressBookLayoutProvider;
|
|
use MintyPHP\Tests\Support\AppContainerIsolationTrait;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
/**
|
|
* Verifies that the AddressBookLayoutProvider correctly contributes
|
|
* the 'addressbook.nav' key to the layout context.
|
|
*/
|
|
final class LayoutContextProviderTest extends TestCase
|
|
{
|
|
use AppContainerIsolationTrait;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
// Guard against other tests overwriting the global container
|
|
if (!($GLOBALS['minty_app_container'] ?? null) instanceof AppContainer
|
|
|| !($GLOBALS['minty_app_container'])->has(\MintyPHP\App\Module\ModuleRegistry::class)
|
|
|| !($GLOBALS['minty_app_container'])->has(\MintyPHP\Service\Access\UiAccessService::class)) {
|
|
$container = require dirname(__DIR__, 3) . '/lib/App/registerContainer.php';
|
|
$this->pushAppContainer($container);
|
|
setAppContainer($container);
|
|
}
|
|
}
|
|
|
|
protected function tearDown(): void
|
|
{
|
|
$this->restoreAppContainer();
|
|
}
|
|
|
|
public function testProviderReturnsAddressBookKey(): void
|
|
{
|
|
$provider = new AddressBookLayoutProvider();
|
|
$container = new AppContainer();
|
|
|
|
$session = [
|
|
'available_departments_by_tenant' => [
|
|
[
|
|
'tenant' => ['uuid' => 'abc', 'description' => 'Tenant A'],
|
|
'departments' => [['id' => 1, 'description' => 'Dept 1']],
|
|
],
|
|
],
|
|
];
|
|
|
|
$result = $provider->provide($session, $container);
|
|
|
|
self::assertArrayHasKey('addressbook.nav', $result);
|
|
$ab = $result['addressbook.nav'];
|
|
self::assertArrayHasKey('url', $ab);
|
|
self::assertArrayHasKey('activeSearch', $ab);
|
|
self::assertArrayHasKey('activeTenants', $ab);
|
|
self::assertArrayHasKey('activeDepartments', $ab);
|
|
self::assertArrayHasKey('activeRoles', $ab);
|
|
self::assertArrayHasKey('activeCustomFilters', $ab);
|
|
self::assertArrayHasKey('peopleGroups', $ab);
|
|
self::assertCount(1, $ab['peopleGroups']);
|
|
}
|
|
|
|
public function testProviderReturnsEmptyPeopleGroupsWhenSessionEmpty(): void
|
|
{
|
|
$provider = new AddressBookLayoutProvider();
|
|
$container = new AppContainer();
|
|
|
|
$result = $provider->provide([], $container);
|
|
|
|
self::assertArrayHasKey('addressbook.nav', $result);
|
|
self::assertSame([], $result['addressbook.nav']['peopleGroups']);
|
|
}
|
|
|
|
public function testProviderIsIncludedInLayoutNavWhenModuleActive(): void
|
|
{
|
|
// When the module is active, appBuildLayoutNavContext() should include
|
|
// addressbook.nav via the provider loop
|
|
$layoutNav = appBuildLayoutNavContext([], [], []);
|
|
|
|
self::assertArrayHasKey('addressbook.nav', $layoutNav,
|
|
'addressbook.nav key must be present in layoutNav when module is active');
|
|
}
|
|
}
|