page update
This commit is contained in:
56
tests/Architecture/PublicPageContractTest.php
Normal file
56
tests/Architecture/PublicPageContractTest.php
Normal file
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
namespace MintyPHP\Tests\Architecture;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class PublicPageContractTest extends TestCase
|
||||
{
|
||||
use ProjectFileAssertionSupport;
|
||||
|
||||
public function testPublicStaticPageRoutesPointToPublicPageTargets(): void
|
||||
{
|
||||
$routes = include $this->projectRootPath() . '/config/routes.php';
|
||||
$this->assertIsArray($routes);
|
||||
|
||||
$byPath = [];
|
||||
foreach ($routes as $route) {
|
||||
if (!is_array($route)) {
|
||||
continue;
|
||||
}
|
||||
$path = trim((string) ($route['path'] ?? ''));
|
||||
if ($path === '') {
|
||||
continue;
|
||||
}
|
||||
$byPath[$path] = $route;
|
||||
}
|
||||
|
||||
foreach (['imprint', 'privacy', 'terms'] as $slug) {
|
||||
$this->assertArrayHasKey($slug, $byPath);
|
||||
$this->assertSame('public-page/' . $slug, (string) ($byPath[$slug]['target'] ?? ''));
|
||||
$this->assertTrue((bool) ($byPath[$slug]['public'] ?? false));
|
||||
}
|
||||
}
|
||||
|
||||
public function testPageTemplatesAreSeparatedByContext(): void
|
||||
{
|
||||
$root = $this->projectRootPath();
|
||||
|
||||
$this->assertFileExists($root . '/pages/page/index(default).phtml');
|
||||
$this->assertFileDoesNotExist($root . '/pages/page/index(page).phtml');
|
||||
$this->assertFileExists($root . '/pages/public-page/index(page).phtml');
|
||||
}
|
||||
|
||||
public function testPageMutationsUseSettingsUpdateCapabilityGuard(): void
|
||||
{
|
||||
$indexAction = $this->readProjectFile('pages/page/index($slug).php');
|
||||
$copyAction = $this->readProjectFile('pages/page/copy-language().php');
|
||||
|
||||
$this->assertStringContainsString('UiAccessService::class', $indexAction);
|
||||
$this->assertStringContainsString('SettingsAuthorizationPolicy::ABILITY_ADMIN_SETTINGS_UPDATE', $indexAction);
|
||||
$this->assertStringNotContainsString('$canEdit = $currentUserId > 0;', $indexAction);
|
||||
|
||||
$this->assertStringContainsString('UiAccessService::class', $copyAction);
|
||||
$this->assertStringContainsString('SettingsAuthorizationPolicy::ABILITY_ADMIN_SETTINGS_UPDATE', $copyAction);
|
||||
}
|
||||
}
|
||||
33
tests/Http/AccessControlTest.php
Normal file
33
tests/Http/AccessControlTest.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace MintyPHP\Tests\Http;
|
||||
|
||||
use MintyPHP\Http\AccessControl;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class AccessControlTest extends TestCase
|
||||
{
|
||||
public function testConfiguredPublicPathIsAccessible(): void
|
||||
{
|
||||
$accessControl = new AccessControl(['imprint', 'privacy']);
|
||||
|
||||
$this->assertTrue($accessControl->isPublicPath('imprint'));
|
||||
$this->assertTrue($accessControl->isPublicPath('/privacy'));
|
||||
}
|
||||
|
||||
public function testPageSlugPathIsNotAutoPublic(): void
|
||||
{
|
||||
$accessControl = new AccessControl(['imprint']);
|
||||
|
||||
$this->assertTrue($accessControl->isPublicPath('imprint'));
|
||||
$this->assertFalse($accessControl->isPublicPath('page/imprint'));
|
||||
}
|
||||
|
||||
public function testAlwaysPublicPrefixesRemainAccessible(): void
|
||||
{
|
||||
$accessControl = new AccessControl([]);
|
||||
|
||||
$this->assertTrue($accessControl->isPublicPath('api/v1/health'));
|
||||
$this->assertTrue($accessControl->isPublicPath('auth/microsoft/callback'));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user