Add a module kernel (ModuleManifest, ModuleRegistry) that allows modules to contribute routes, UI slots, search providers, layout context, session lifecycle, and permissions. Modules are activated via config/modules.php or APP_ENABLED_MODULES env variable. Conflicts (duplicate routes, permissions, slot keys) cause a fail-fast with a clear error message. Extract the address book from hardcoded Core integration points into the first module (modules/addressbook/). The module provides: - Aside icon-bar tab + People panel via UI slot system - Global search resource via AddressBookSearchProvider - Layout context data via AddressBookLayoutProvider - Session lifecycle via AddressBookSessionProvider Core cleanup removes address-book hardcodings from SearchSqlResourceProvider, SearchUiMetaProvider, SearchItemMapperProvider, appBuildLayoutNavContext(), and the aside templates. Permissions (ADDRESS_BOOK_VIEW) and business logic (AddressBookService) remain in Core as they gate general user visibility. Includes 38 new tests (894 total), PHPStan level 5 clean, and architecture tests verifying zero hardcoded address-book references in search/templates. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
75 lines
2.7 KiB
PHP
75 lines
2.7 KiB
PHP
<?php
|
|
|
|
namespace MintyPHP\Tests\Unit\Module;
|
|
|
|
use MintyPHP\App\AppContainer;
|
|
use MintyPHP\Module\AddressBook\Providers\AddressBookLayoutProvider;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
/**
|
|
* Verifies that the AddressBookLayoutProvider correctly contributes
|
|
* the 'addressBook' key to the layout context.
|
|
*/
|
|
final class LayoutContextProviderTest extends TestCase
|
|
{
|
|
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)) {
|
|
$container = require dirname(__DIR__, 3) . '/lib/App/registerContainer.php';
|
|
setAppContainer($container);
|
|
}
|
|
}
|
|
|
|
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', $result);
|
|
$ab = $result['addressBook'];
|
|
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', $result);
|
|
self::assertSame([], $result['addressBook']['peopleGroups']);
|
|
}
|
|
|
|
public function testProviderIsIncludedInLayoutNavWhenModuleActive(): void
|
|
{
|
|
// When the module is active, appBuildLayoutNavContext() should include
|
|
// addressBook via the provider loop
|
|
$layoutAuth = app(\MintyPHP\Service\Access\UiAccessService::class)->layoutCapabilities(0);
|
|
$layoutNav = appBuildLayoutNavContext($layoutAuth, [], []);
|
|
|
|
self::assertArrayHasKey('addressBook', $layoutNav,
|
|
'addressBook key must be present in layoutNav when module is active');
|
|
}
|
|
}
|