actionAccessControl = $this->createMock(ActionAccessControl::class); $this->permissionChecker = $this->createMock(PermissionChecker::class); $this->subject = new MediaSourcePermissionsMapper(); $this->subject->setServiceLocator( $this->getServiceLocatorMock( [ ActionAccessControl::SERVICE_ID => $this->actionAccessControl, PermissionChecker::class => $this->permissionChecker, ] ) ); } public function testMapWithAllPermissions(): void { $data = []; $resourceUri = 'resourceUri'; $this->actionAccessControl ->method('contextHasReadAccess') ->willReturn(true); $this->actionAccessControl ->method('hasReadAccess') ->willReturn(true); $this->actionAccessControl ->method('contextHasWriteAccess') ->willReturn(true); $this->actionAccessControl ->method('hasWriteAccess') ->willReturn(true); $this->assertEquals( [ 'permissions' => [ 'READ', 'WRITE', 'PREVIEW', 'DOWNLOAD', 'DELETE', 'UPLOAD', ], ], $this->subject->map($data, $resourceUri) ); } public function testMapWithOnlyReadAndWritePermissions(): void { $this->actionAccessControl ->method('contextHasReadAccess') ->willReturnCallback( function (Context $context) { if ($context->getParameter(Context::PARAM_ACTION) === 'viewAsset') { return true; } return false; } ); $this->actionAccessControl ->method('contextHasWriteAccess') ->willReturnCallback( function (Context $context) { if ($context->getParameter(Context::PARAM_ACTION) === 'deleteAsset') { return true; } if ($context->getParameter(Context::PARAM_ACTION) === 'uploadAsset') { return true; } return false; } ); $this->assertEquals( [ 'permissions' => [ 'READ', 'WRITE', 'DELETE', 'UPLOAD', ], ], $this->subject->map([], 'resourceUri') ); } }