2026-03-19 18:25:19 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace MintyPHP\Tests\Architecture;
|
|
|
|
|
|
|
|
|
|
use PHPUnit\Framework\Attributes\DataProvider;
|
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
|
|
|
|
|
|
class AuthzUiActionContractTest extends TestCase
|
|
|
|
|
{
|
|
|
|
|
use AuthzUiContractSupport;
|
|
|
|
|
use ProjectFileAssertionSupport;
|
|
|
|
|
|
|
|
|
|
#[DataProvider('adminPageAuthWiringProvider')]
|
|
|
|
|
public function testAdminPageAuthKeysAreWiredFromActions(
|
|
|
|
|
string $templateFile,
|
|
|
|
|
string $actionFile,
|
|
|
|
|
?string $uiCapabilityMapConstant
|
|
|
|
|
): void {
|
|
|
|
|
$templateContent = $this->readProjectFile($templateFile);
|
|
|
|
|
$requiredKeys = $this->extractPageAuthKeys($templateContent);
|
|
|
|
|
$this->assertNotEmpty($requiredKeys, $templateFile . ' must read at least one $pageAuth key.');
|
|
|
|
|
|
|
|
|
|
$actionContent = $this->readProjectFile($actionFile);
|
|
|
|
|
$this->assertStringContainsString("\$viewAuth['page']", $actionContent, $actionFile);
|
|
|
|
|
|
|
|
|
|
$wiredKeys = $this->extractViewAuthPageKeys($actionContent);
|
|
|
|
|
if ($uiCapabilityMapConstant !== null) {
|
|
|
|
|
$this->assertStringContainsString('->pageCapabilities(', $actionContent, $actionFile);
|
|
|
|
|
$this->assertStringContainsString($uiCapabilityMapConstant, $actionContent, $actionFile);
|
|
|
|
|
$wiredKeys = array_values(array_unique([
|
|
|
|
|
...$wiredKeys,
|
|
|
|
|
...$this->extractUiCapabilityMapKeys($uiCapabilityMapConstant),
|
|
|
|
|
]));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$missingKeys = array_values(array_diff($requiredKeys, $wiredKeys));
|
|
|
|
|
$this->assertSame(
|
|
|
|
|
[],
|
|
|
|
|
$missingKeys,
|
|
|
|
|
sprintf(
|
|
|
|
|
'Missing $pageAuth wiring in %s (from %s): %s',
|
|
|
|
|
$templateFile,
|
|
|
|
|
$actionFile,
|
|
|
|
|
implode(', ', $missingKeys)
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testTenantEditActionExposesDeleteCapabilityForTemplate(): void
|
|
|
|
|
{
|
|
|
|
|
$content = $this->readProjectFile('pages/admin/tenants/edit($id).php');
|
|
|
|
|
$this->assertStringContainsString("'can_delete_tenant' =>", $content);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testMapDrivenHardCutActionsUseUiCapabilityMaps(): void
|
|
|
|
|
{
|
|
|
|
|
$actions = [
|
|
|
|
|
'pages/admin/users/index().php' => 'UiCapabilityMap::PAGE_USERS_INDEX',
|
|
|
|
|
'pages/admin/users/create().php' => 'UiCapabilityMap::PAGE_USERS_CREATE',
|
|
|
|
|
'pages/admin/stats/index().php' => 'UiCapabilityMap::PAGE_STATS_INDEX',
|
refactor(audit): extract audit domain into self-contained module
Move the entire audit subsystem (system audit, API audit, import audit,
user lifecycle audit, frontend telemetry) from core into modules/audit/.
Core decoupling via interface-based injection:
- AuditRecorderInterface replaces SystemAuditService in 10+ core services
- UserLifecycleAuditInterface / ImportAuditInterface for specialized flows
- NullAuditRecorder fallback when audit module is disabled
- ApiBootstrap/ApiResponse use null-safe callable resolvers
Module structure (modules/audit/):
- Manifest with routes, permissions, scheduler jobs, authorization policy
- 9 services, 8 repositories, 6 domain enums, 4 job handlers
- 33 page files, 4 JS files, 8 test files, migration scripts, i18n
Core cleanup:
- OperationsAuthorizationPolicy, UiCapabilityMap, PermissionService
surgically cleaned of audit-specific constants
- Sidebar template cleared of hardcoded audit navigation
- AuditModuleIsolationContractTest ensures no future core→module coupling
All quality gates pass: 1346 tests (19,276 assertions), PHPStan level 5
clean, architecture contracts verified.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-25 21:12:49 +01:00
|
|
|
'pages/admin/scheduled-jobs/index().php' => 'UiCapabilityMap::PAGE_JOBS_PURGE',
|
2026-03-19 18:25:19 +01:00
|
|
|
];
|
|
|
|
|
|
|
|
|
|
foreach ($actions as $action => $mapConstant) {
|
|
|
|
|
$content = $this->readProjectFile($action);
|
|
|
|
|
$this->assertStringContainsString('->pageCapabilities(', $content, $action);
|
|
|
|
|
$this->assertStringContainsString($mapConstant, $content, $action);
|
|
|
|
|
}
|
|
|
|
|
}
|
refactor(audit): extract audit domain into self-contained module
Move the entire audit subsystem (system audit, API audit, import audit,
user lifecycle audit, frontend telemetry) from core into modules/audit/.
Core decoupling via interface-based injection:
- AuditRecorderInterface replaces SystemAuditService in 10+ core services
- UserLifecycleAuditInterface / ImportAuditInterface for specialized flows
- NullAuditRecorder fallback when audit module is disabled
- ApiBootstrap/ApiResponse use null-safe callable resolvers
Module structure (modules/audit/):
- Manifest with routes, permissions, scheduler jobs, authorization policy
- 9 services, 8 repositories, 6 domain enums, 4 job handlers
- 33 page files, 4 JS files, 8 test files, migration scripts, i18n
Core cleanup:
- OperationsAuthorizationPolicy, UiCapabilityMap, PermissionService
surgically cleaned of audit-specific constants
- Sidebar template cleared of hardcoded audit navigation
- AuditModuleIsolationContractTest ensures no future core→module coupling
All quality gates pass: 1346 tests (19,276 assertions), PHPStan level 5
clean, architecture contracts verified.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-25 21:12:49 +01:00
|
|
|
|
|
|
|
|
public function testModuleAuditActionsUseInlinePageCapabilities(): void
|
|
|
|
|
{
|
|
|
|
|
$actions = [
|
2026-03-26 08:13:37 +01:00
|
|
|
'modules/audit/pages/audit/api-audit/index().php',
|
|
|
|
|
'modules/audit/pages/audit/system-audit/index().php',
|
|
|
|
|
'modules/audit/pages/audit/import-audit/index().php',
|
2026-04-26 18:03:42 +02:00
|
|
|
'modules/audit/pages/audit/settings-user-lifecycle/audit-fragment($id).php',
|
refactor(audit): extract audit domain into self-contained module
Move the entire audit subsystem (system audit, API audit, import audit,
user lifecycle audit, frontend telemetry) from core into modules/audit/.
Core decoupling via interface-based injection:
- AuditRecorderInterface replaces SystemAuditService in 10+ core services
- UserLifecycleAuditInterface / ImportAuditInterface for specialized flows
- NullAuditRecorder fallback when audit module is disabled
- ApiBootstrap/ApiResponse use null-safe callable resolvers
Module structure (modules/audit/):
- Manifest with routes, permissions, scheduler jobs, authorization policy
- 9 services, 8 repositories, 6 domain enums, 4 job handlers
- 33 page files, 4 JS files, 8 test files, migration scripts, i18n
Core cleanup:
- OperationsAuthorizationPolicy, UiCapabilityMap, PermissionService
surgically cleaned of audit-specific constants
- Sidebar template cleared of hardcoded audit navigation
- AuditModuleIsolationContractTest ensures no future core→module coupling
All quality gates pass: 1346 tests (19,276 assertions), PHPStan level 5
clean, architecture contracts verified.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-25 21:12:49 +01:00
|
|
|
];
|
|
|
|
|
|
|
|
|
|
foreach ($actions as $action) {
|
|
|
|
|
$content = $this->readProjectFile($action);
|
|
|
|
|
$this->assertStringContainsString('->pageCapabilities(', $content, $action);
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-03-19 18:25:19 +01:00
|
|
|
}
|