feat(core) : aggregate module permissions and add sync-permissions command
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Tests\Functional\Module\Core;
|
||||
|
||||
use App\Module\Core\Domain\Repository\PermissionRepositoryInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Console\Application;
|
||||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
||||
use Symfony\Component\Console\Tester\CommandTester;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
final class SyncPermissionsCommandTest extends KernelTestCase
|
||||
{
|
||||
public function testSyncCreatesCorePermissions(): void
|
||||
{
|
||||
$kernel = self::bootKernel();
|
||||
$app = new Application($kernel);
|
||||
$tester = new CommandTester($app->find('app:sync-permissions'));
|
||||
$tester->execute([]);
|
||||
$tester->assertCommandIsSuccessful();
|
||||
|
||||
$repo = self::getContainer()->get(PermissionRepositoryInterface::class);
|
||||
self::assertNotNull($repo->findByCode('core.users.manage'));
|
||||
self::assertContains('core.roles.manage', $repo->findAllCodes());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Tests\Unit\Shared\Module;
|
||||
|
||||
use App\Module\Core\CoreModule;
|
||||
use App\Shared\Domain\Module\ModuleRegistry;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
final class ModuleRegistryPermissionsTest extends TestCase
|
||||
{
|
||||
public function testAggregatesPermissionsWithModuleId(): void
|
||||
{
|
||||
$perms = ModuleRegistry::permissions([CoreModule::class]);
|
||||
|
||||
self::assertNotEmpty($perms);
|
||||
foreach ($perms as $perm) {
|
||||
self::assertArrayHasKey('code', $perm);
|
||||
self::assertArrayHasKey('label', $perm);
|
||||
self::assertArrayHasKey('module', $perm);
|
||||
self::assertSame('core', $perm['module']);
|
||||
self::assertStringStartsWith('core.', $perm['code']);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user