/** * @test */ public function setRolesWorks() { $roles = [$this->administratorRole, $this->customerRole]; $expectedRoles = [$this->administratorRole->getIdentifier() => $this->administratorRole, $this->customerRole->getIdentifier() => $this->customerRole]; $this->account->setRoles($roles); $this->assertSame($expectedRoles, $this->account->getRoles()); }
/** * Overrides any assigned roles of the given account and potentially carries out further actions which are needed * to properly reflect these changes. * * @param Account $account The account to assign the roles to * @param array $newRoleIdentifiers A list of fully qualified role identifiers, or role identifiers relative to the Neos.Neos namespace * @return void * @api */ public function setRolesForAccount(Account $account, array $newRoleIdentifiers) { $currentRoles = $account->getRoles(); foreach ($currentRoles as $roleIdentifier => $role) { $roleIdentifier = $this->normalizeRoleIdentifier($roleIdentifier); if (!in_array($roleIdentifier, $newRoleIdentifiers)) { $this->removeRoleFromAccount($account, $roleIdentifier); } } foreach ($newRoleIdentifiers as $roleIdentifier) { if (!in_array($roleIdentifier, array_keys($currentRoles))) { $this->addRoleToAccount($account, $roleIdentifier); } } }