/** * Creates a role for user registration test. * * It always has the minimal set of policies to operate (user/login and content/read). * * @param bool $withUserRegisterPolicy Determines if the role gets the user/register policy * * @return Role */ private function createRegistrationRole($withUserRegisterPolicy = true) { $roleIdentifier = uniqid('anonymous_role_' . ($withUserRegisterPolicy ? 'with' : 'without') . '_register'); $roleService = $this->getRepository()->getRoleService(); $roleCreateStruct = new RoleCreateStruct(['identifier' => $roleIdentifier]); $roleCreateStruct->addPolicy($roleService->newPolicyCreateStruct('user', 'login')); $roleCreateStruct->addPolicy($roleService->newPolicyCreateStruct('content', 'read')); if ($withUserRegisterPolicy === true) { $roleCreateStruct->addPolicy($roleService->newPolicyCreateStruct('user', 'register')); } $roleService->publishRoleDraft($roleService->createRole($roleCreateStruct)); return $roleService->loadRoleByIdentifier($roleIdentifier); }