1
0
Files
breadcrumb-the-shire/tests/Unit/Module/SearchProviderCollectionTest.php
fs c7b8fd516a 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

128 lines
4.5 KiB
PHP

<?php
namespace MintyPHP\Tests\Unit\Module;
use MintyPHP\App\Module\ModuleRegistry;
use MintyPHP\Module\AddressBook\Providers\AddressBookSearchProvider;
use MintyPHP\Support\SearchConfig;
use MintyPHP\Tests\Support\AppContainerIsolationTrait;
use PHPUnit\Framework\TestCase;
/**
* Verifies that module search providers are correctly integrated into SearchConfig.
*/
final class SearchProviderCollectionTest extends TestCase
{
use AppContainerIsolationTrait;
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';
$this->pushAppContainer($container);
setAppContainer($container);
}
SearchConfig::resetModuleProviders();
}
protected function tearDown(): void
{
$this->restoreAppContainer();
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);
}
}