Refactor architecture test contracts
This commit is contained in:
124
tests/Architecture/AuthzUiContractSupport.php
Normal file
124
tests/Architecture/AuthzUiContractSupport.php
Normal file
@@ -0,0 +1,124 @@
|
||||
<?php
|
||||
|
||||
namespace MintyPHP\Tests\Architecture;
|
||||
|
||||
trait AuthzUiContractSupport
|
||||
{
|
||||
/**
|
||||
* @return array<string, array{0: string, 1: string, 2: string|null}>
|
||||
*/
|
||||
public static function adminPageAuthWiringProvider(): array
|
||||
{
|
||||
return [
|
||||
'users index' => [
|
||||
'pages/admin/users/index(default).phtml',
|
||||
'pages/admin/users/index().php',
|
||||
'UiCapabilityMap::PAGE_USERS_INDEX',
|
||||
],
|
||||
'users create' => [
|
||||
'pages/admin/users/create(default).phtml',
|
||||
'pages/admin/users/create().php',
|
||||
'UiCapabilityMap::PAGE_USERS_CREATE',
|
||||
],
|
||||
'tenants edit' => [
|
||||
'pages/admin/tenants/edit(default).phtml',
|
||||
'pages/admin/tenants/edit($id).php',
|
||||
null,
|
||||
],
|
||||
'departments edit' => [
|
||||
'pages/admin/departments/edit(default).phtml',
|
||||
'pages/admin/departments/edit($id).php',
|
||||
null,
|
||||
],
|
||||
'stats index' => [
|
||||
'pages/admin/stats/index(default).phtml',
|
||||
'pages/admin/stats/index().php',
|
||||
'UiCapabilityMap::PAGE_STATS_INDEX',
|
||||
],
|
||||
'api audit index' => [
|
||||
'pages/admin/api-audit/index(default).phtml',
|
||||
'pages/admin/api-audit/index().php',
|
||||
'UiCapabilityMap::PAGE_AUDIT_PURGE',
|
||||
],
|
||||
'import audit index' => [
|
||||
'pages/admin/import-audit/index(default).phtml',
|
||||
'pages/admin/import-audit/index().php',
|
||||
'UiCapabilityMap::PAGE_AUDIT_PURGE',
|
||||
],
|
||||
'scheduled jobs index' => [
|
||||
'pages/admin/scheduled-jobs/index(default).phtml',
|
||||
'pages/admin/scheduled-jobs/index().php',
|
||||
'UiCapabilityMap::PAGE_AUDIT_PURGE',
|
||||
],
|
||||
'system audit index' => [
|
||||
'pages/admin/system-audit/index(default).phtml',
|
||||
'pages/admin/system-audit/index().php',
|
||||
'UiCapabilityMap::PAGE_SYSTEM_AUDIT',
|
||||
],
|
||||
'user lifecycle index' => [
|
||||
'pages/admin/user-lifecycle-audit/index(default).phtml',
|
||||
'pages/admin/user-lifecycle-audit/index().php',
|
||||
'UiCapabilityMap::PAGE_AUDIT_PURGE',
|
||||
],
|
||||
'user lifecycle view' => [
|
||||
'pages/admin/user-lifecycle-audit/view(default).phtml',
|
||||
'pages/admin/user-lifecycle-audit/view($id).php',
|
||||
'UiCapabilityMap::PAGE_USER_LIFECYCLE_VIEW',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return list<string>
|
||||
*/
|
||||
private function extractPageAuthKeys(string $content): array
|
||||
{
|
||||
preg_match_all('/\\$pageAuth\\[[\'"]([a-z_]+)[\'"]\\]/', $content, $matches);
|
||||
$keys = array_values(array_unique($matches[1]));
|
||||
sort($keys);
|
||||
return $keys;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return list<string>
|
||||
*/
|
||||
private function extractViewAuthPageKeys(string $content): array
|
||||
{
|
||||
$keys = [];
|
||||
preg_match_all('/\\$viewAuth\\[\'page\'\\]\\s*=\\s*\\[(.*?)\\];/s', $content, $blocks);
|
||||
foreach ($blocks[1] as $block) {
|
||||
preg_match_all('/[\'"]([a-z_]+)[\'"]\\s*=>/', $block, $matches);
|
||||
foreach ($matches[1] as $key) {
|
||||
$keys[] = $key;
|
||||
}
|
||||
}
|
||||
|
||||
$keys = array_values(array_unique($keys));
|
||||
sort($keys);
|
||||
return $keys;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return list<string>
|
||||
*/
|
||||
private function extractUiCapabilityMapKeys(string $mapConstant): array
|
||||
{
|
||||
$parts = explode('::', $mapConstant);
|
||||
$constantName = trim((string) end($parts));
|
||||
$this->assertNotSame('', $constantName, 'Invalid UiCapabilityMap constant: ' . $mapConstant);
|
||||
|
||||
$mapContent = $this->readProjectFile('lib/Service/Access/UiCapabilityMap.php');
|
||||
$constantPattern = '/public const\\s+' . preg_quote($constantName, '/') . '\\s*=\\s*\\[(.*?)\\];/s';
|
||||
$matched = preg_match($constantPattern, $mapContent, $constantMatch);
|
||||
$this->assertSame(
|
||||
1,
|
||||
$matched,
|
||||
'Could not find UiCapabilityMap constant block: ' . $mapConstant
|
||||
);
|
||||
|
||||
preg_match_all('/[\'"]([a-z_]+)[\'"]\\s*=>/', (string) ($constantMatch[1] ?? ''), $keyMatches);
|
||||
$keys = array_values(array_unique($keyMatches[1]));
|
||||
sort($keys);
|
||||
return $keys;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user