Exemplo n.º 1
0
 protected function addUsers($username, $password, $fullname, $email)
 {
     $sm = $this->getServiceLocator();
     /** @var \RcmUser\Service\RcmUserService $userService */
     $userService = $sm->get('RcmUser\\Service\\RcmUserService');
     /** @var \RcmUser\User\Service\UserRoleService $userRoleService */
     $userRoleService = $sm->get('RcmUser\\User\\Service\\UserRoleService');
     /** @var \RcmUser\Acl\Service\AclDataService $aclDataService */
     $aclDataService = $sm->get('RcmUser\\Acl\\AclDataService');
     $user = new User();
     $user->setUsername($username);
     $user->setPassword($password);
     $user->setEmail($email);
     $user->setName($fullname);
     $user->setState('enabled');
     $response = $userService->createUser($user);
     if (!$response->isSuccess()) {
         throw new \Exception(implode("<br />", $response->getMessages()));
     }
     $user = $response->getData();
     $suRoleIdResponse = $aclDataService->getSuperAdminRoleId();
     $suRoleId = $suRoleIdResponse->getData();
     $suRole = new AclRole();
     $suRole->setRoleId($suRoleId);
     $suRole->setDescription('Super Admin Role');
     $response = $aclDataService->createRole($suRole);
     if (!$response->isSuccess()) {
         throw new \Exception(implode("<br />", $response->getMessages()));
     }
     $guestRoleIdResponse = $aclDataService->getGuestRoleId();
     $guestRoleId = $guestRoleIdResponse->getData();
     $guestRole = new AclRole();
     $guestRole->setRoleId($guestRoleId);
     $guestRole->setDescription('Default Guest');
     $response = $aclDataService->createRole($guestRole);
     if (!$response->isSuccess()) {
         throw new \Exception(implode("<br />", $response->getMessages()));
     }
     $response = $userRoleService->addRole($user, $suRoleId);
     if (!$response->isSuccess()) {
         throw new \Exception(implode("<br />", $response->getMessages()));
     }
 }
Exemplo n.º 2
0
 /**
  * testArrayIterator
  *
  * @covers \RcmUser\Acl\Entity\AclRole::getIterator
  *
  * @return void
  */
 public function testArrayIterator()
 {
     $aclRole = new AclRole();
     $aclRole->setRoleId('role');
     $aclRole->setParentRoleId('role');
     $aclRole->setDescription('role');
     $iter = $aclRole->getIterator();
     $aclRoleArr = iterator_to_array($aclRole);
     $aclRoleArr2 = iterator_to_array($iter);
     $this->assertTrue($aclRoleArr == $aclRoleArr2, 'Iterator failed work.');
     $this->assertTrue(is_array($aclRoleArr), 'Iterator failed work.');
     $this->assertArrayHasKey('roleId', $aclRoleArr, 'Iterator did not populate correctly.');
 }