feat: introduce module system and extract address book as first module (MODULAR-MONOLITH-V1-001)
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>
This commit is contained in:
74
tests/Unit/Module/LayoutContextProviderTest.php
Normal file
74
tests/Unit/Module/LayoutContextProviderTest.php
Normal file
@@ -0,0 +1,74 @@
|
||||
<?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');
|
||||
}
|
||||
}
|
||||
128
tests/Unit/Module/SearchProviderCollectionTest.php
Normal file
128
tests/Unit/Module/SearchProviderCollectionTest.php
Normal file
@@ -0,0 +1,128 @@
|
||||
<?php
|
||||
|
||||
namespace MintyPHP\Tests\Unit\Module;
|
||||
|
||||
use MintyPHP\App\Module\ModuleRegistry;
|
||||
use MintyPHP\Module\AddressBook\Providers\AddressBookSearchProvider;
|
||||
use MintyPHP\Support\SearchConfig;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Verifies that module search providers are correctly integrated into SearchConfig.
|
||||
*/
|
||||
final class SearchProviderCollectionTest extends TestCase
|
||||
{
|
||||
private static ?\MintyPHP\App\AppContainer $originalContainer = null;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
// Guard against other tests overwriting the global container (e.g. ThemeResolutionTest)
|
||||
if (self::$originalContainer === null) {
|
||||
self::$originalContainer = $GLOBALS['minty_app_container'] ?? null;
|
||||
}
|
||||
if (!($GLOBALS['minty_app_container'] ?? null) instanceof \MintyPHP\App\AppContainer
|
||||
|| !($GLOBALS['minty_app_container'])->has(ModuleRegistry::class)) {
|
||||
// Restore the bootstrap container that has the module registry
|
||||
$container = require dirname(__DIR__, 3) . '/lib/App/registerContainer.php';
|
||||
setAppContainer($container);
|
||||
}
|
||||
SearchConfig::resetModuleProviders();
|
||||
}
|
||||
|
||||
protected function tearDown(): void
|
||||
{
|
||||
SearchConfig::resetModuleProviders();
|
||||
}
|
||||
|
||||
public function testAddressBookModuleIsActiveInRegistry(): void
|
||||
{
|
||||
/** @var ModuleRegistry $registry */
|
||||
$registry = app(ModuleRegistry::class);
|
||||
self::assertTrue($registry->hasModule('addressbook'));
|
||||
self::assertNotEmpty($registry->getSearchResources());
|
||||
}
|
||||
|
||||
public function testCoreResourcesDoNotContainAddressBook(): void
|
||||
{
|
||||
$coreResources = SearchConfig::resources('test', 'en');
|
||||
$coreKeys = array_column($coreResources, 'key');
|
||||
|
||||
self::assertNotContains('address-book', $coreKeys,
|
||||
'address-book must not be in Core search resources (moved to module)');
|
||||
}
|
||||
|
||||
public function testAddressBookSearchProviderDirectly(): void
|
||||
{
|
||||
$provider = new AddressBookSearchProvider();
|
||||
$resources = $provider->resources();
|
||||
|
||||
self::assertArrayHasKey('address-book', $resources);
|
||||
|
||||
$resource = $resources['address-book'];
|
||||
self::assertSame('address_book.view', $resource['permission']);
|
||||
self::assertStringContainsString('select count', $resource['count_sql']);
|
||||
self::assertStringContainsString('select uuid', $resource['preview_sql']);
|
||||
self::assertStringContainsString('select uuid', $resource['result_sql']);
|
||||
self::assertArrayHasKey('tenant_filter', $resource);
|
||||
}
|
||||
|
||||
public function testAddressBookSearchProviderMapResultItem(): void
|
||||
{
|
||||
$provider = new AddressBookSearchProvider();
|
||||
|
||||
$result = $provider->mapResultItem('address-book', [
|
||||
'uuid' => 'abc-123',
|
||||
'first_name' => 'Max',
|
||||
'last_name' => 'Mustermann',
|
||||
'email' => 'max@example.com',
|
||||
]);
|
||||
|
||||
self::assertNotNull($result);
|
||||
self::assertSame('Max Mustermann', $result['title']);
|
||||
self::assertSame('max@example.com', $result['subtitle']);
|
||||
self::assertStringContainsString('address-book/view/abc-123', $result['url']);
|
||||
self::assertSame('bi-people', $result['icon']);
|
||||
}
|
||||
|
||||
public function testAddressBookSearchProviderListUrl(): void
|
||||
{
|
||||
$provider = new AddressBookSearchProvider();
|
||||
|
||||
$url = $provider->listUrl('address-book', 'test%20query');
|
||||
|
||||
self::assertStringContainsString('address-book', $url);
|
||||
self::assertStringContainsString('search=test%20query', $url);
|
||||
}
|
||||
|
||||
public function testAddressBookSearchProviderIgnoresUnknownKey(): void
|
||||
{
|
||||
$provider = new AddressBookSearchProvider();
|
||||
|
||||
self::assertNull($provider->mapResultItem('unknown', []));
|
||||
self::assertSame('', $provider->listUrl('unknown', 'test'));
|
||||
}
|
||||
|
||||
public function testModuleResourcesMergedIntoSearchConfig(): void
|
||||
{
|
||||
$moduleResources = SearchConfig::moduleResources();
|
||||
|
||||
self::assertArrayHasKey('address-book', $moduleResources,
|
||||
'address-book resource must come from module provider via SearchConfig');
|
||||
}
|
||||
|
||||
public function testTenantFilterMergedFromModule(): void
|
||||
{
|
||||
$filters = SearchConfig::tenantScopeFilters();
|
||||
|
||||
self::assertArrayHasKey('address-book', $filters,
|
||||
'address-book tenant scope filter must be provided by module');
|
||||
}
|
||||
|
||||
public function testSearchConfigListUrlDelegatesToModule(): void
|
||||
{
|
||||
$url = SearchConfig::listUrl('address-book', 'test query');
|
||||
|
||||
self::assertStringContainsString('address-book', $url);
|
||||
self::assertStringContainsString('search=', $url);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user