PermissionCollection example



    private function isCrudPrivilege(string $privilege): bool
    {
        return substr_count($privilege, ':') === 1;
    }

    private function makeCategorizedPermissions(array $privilegesDelta): array
    {
        $permissions = $this->makePermissions($privilegesDelta);

        $permissionCollection = new PermissionCollection();

        foreach ($permissions as $permission) {
            $permissionCollection->add(PermissionStruct::fromArray([
                'entity' => $permission['entity'],
                'operation' => $permission['operation'],
            ]));
        }

        return $permissionCollection->getCategorizedPermissions();
    }
}
Context::createDefaultContext(),
            new AppCollection([$installedApp])
        );

        static::assertInstanceOf(ExtensionCollection::class$extensions);
        static::assertEquals([
            'German',
            'British English',
        ]$extensions->first()->getLanguages());

        static::assertSame($installedApp->getUpdatedAt()$extensions->first()->getUpdatedAt());
        static::assertEquals(new PermissionCollection([
            PermissionStruct::fromArray(['entity' => 'product', 'operation' => 'create']),
            PermissionStruct::fromArray(['entity' => 'product', 'operation' => 'read']),
            PermissionStruct::fromArray(['entity' => 'additional_privileges', 'operation' => 'additional:privilege']),
        ])$extensions->first()->getPermissions());

        foreach ($extensions as $extension) {
            static::assertEquals(ExtensionStruct::EXTENSION_TYPE_APP, $extension->getType());
        }
    }

    private function getInstalledApp(): AppEntity
    {

    public function testItThrowsOnMissingData(array $badValues): void
    {
        static::expectException(\InvalidArgumentException::class);
        ExtensionStruct::fromArray($badValues);
    }

    public function testItCategorizesThePermissionCollectionWhenStructIsSerialized(): void
    {
        $detailData = $this->getDetailFixture();
        $detailData['permissions'] = new PermissionCollection($detailData['permissions']);

        $extension = ExtensionStruct::fromArray($detailData);

        static::assertInstanceOf(PermissionCollection::class$extension->getPermissions());

        $serializedExtension = json_decode(json_encode($extension, \JSON_THROW_ON_ERROR), true, 512, \JSON_THROW_ON_ERROR);
        $categorizedPermissions = $serializedExtension['permissions'];

        static::assertCount(3, $categorizedPermissions);
        static::assertEquals([
            'product',
            
'entity' => 'xxx',
            'operation' => AclRoleDefinition::PRIVILEGE_DELETE,
        ],
        [
            'entity' => 'plugin',
            'operation' => AclRoleDefinition::PRIVILEGE_READ,
        ],
    ];

    public function testItCategorizesAPermissionCollection(): void
    {
        $permissionCollection = new PermissionCollection(self::PERMISSIONS);
        $categorizedCollection = $permissionCollection->getCategorizedPermissions();

        static::assertCount(3, $categorizedCollection);
        static::assertEquals([
            'product',
            'promotion',
            'other',
        ]array_keys($categorizedCollection));
    }

    public function testItAddsMissingReadPermissionDependencies(): void
    {
Home | Imprint | This part of the site doesn't use cookies.