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>
2026-03-18 15:43:25 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace MintyPHP\Tests\Unit\Module;
|
|
|
|
|
|
|
|
|
|
use MintyPHP\App\Module\ModuleRegistry;
|
|
|
|
|
use MintyPHP\Module\AddressBook\Providers\AddressBookSearchProvider;
|
|
|
|
|
use MintyPHP\Support\SearchConfig;
|
feat: extend module platform with UI slots, runtime components, CLI tooling and {{userId}} search support
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>
2026-03-18 22:19:56 +01:00
|
|
|
use MintyPHP\Tests\Support\AppContainerIsolationTrait;
|
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>
2026-03-18 15:43:25 +01:00
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Verifies that module search providers are correctly integrated into SearchConfig.
|
|
|
|
|
*/
|
|
|
|
|
final class SearchProviderCollectionTest extends TestCase
|
|
|
|
|
{
|
feat: extend module platform with UI slots, runtime components, CLI tooling and {{userId}} search support
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>
2026-03-18 22:19:56 +01:00
|
|
|
use AppContainerIsolationTrait;
|
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>
2026-03-18 15:43:25 +01:00
|
|
|
|
|
|
|
|
protected function setUp(): void
|
|
|
|
|
{
|
|
|
|
|
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';
|
feat: extend module platform with UI slots, runtime components, CLI tooling and {{userId}} search support
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>
2026-03-18 22:19:56 +01:00
|
|
|
$this->pushAppContainer($container);
|
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>
2026-03-18 15:43:25 +01:00
|
|
|
setAppContainer($container);
|
|
|
|
|
}
|
|
|
|
|
SearchConfig::resetModuleProviders();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function tearDown(): void
|
|
|
|
|
{
|
feat: extend module platform with UI slots, runtime components, CLI tooling and {{userId}} search support
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>
2026-03-18 22:19:56 +01:00
|
|
|
$this->restoreAppContainer();
|
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>
2026-03-18 15:43:25 +01:00
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|