Ejemplo n.º 1
0
 /**
  * testConstruct
  *
  * @covers \RcmUser\User\Entity\ReadOnlyUser::__construct
  * @covers \RcmUser\User\Entity\ReadOnlyUser::populate
  *
  * @return void
  */
 public function testConstruct()
 {
     $user = new User();
     $user->setId('id');
     $user->setUsername('username');
     $user->setPassword('password');
     $user->setState('disabled');
     $user->setName('name');
     $user->setEmail('*****@*****.**');
     $user->setProperties(['A' => 'something']);
     return new ReadOnlyUser($user);
 }
Ejemplo n.º 2
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()));
     }
 }
Ejemplo n.º 3
0
 /**
  * setEmail
  *
  * @param string $email valid email
  *
  * @return void
  * @throws \RcmUser\Exception\RcmUserReadOnlyException
  */
 public function setEmail($email)
 {
     if (!$this->locked) {
         return parent::setEmail($email);
     }
     throw new RcmUserReadOnlyException('Object is READ ONLY');
 }
Ejemplo n.º 4
0
 /**
  * testSetGet
  *
  * @covers \RcmUser\User\Entity\User
  *
  * @return void
  */
 public function testSetGet()
 {
     $user = new User();
     $value = 'id123';
     $user->setId($value);
     $this->assertEquals($value, $user->getId(), 'Setter or getter failed.');
     $value = 'usernamexxx';
     $user->setUsername($value);
     $this->assertEquals($value, $user->getUsername(), 'Setter or getter failed.');
     $value = '';
     $user->setUsername($value);
     $this->assertNull($user->getUsername(), 'Setter or getter failed.');
     $value = 'passwordxxx';
     $user->setPassword($value);
     $this->assertEquals($value, $user->getPassword(), 'Setter or getter failed.');
     $value = '';
     $user->setPassword($value);
     $this->assertNull($user->getPassword(), 'Setter or getter failed.');
     $value = 'statexxx';
     $user->setState($value);
     $this->assertEquals($value, $user->getState(), 'Setter or getter failed.');
     $value = '';
     $user->setState($value);
     $this->assertNull($user->getState(), 'Setter or getter failed.');
     $value = '*****@*****.**';
     $user->setEmail($value);
     $this->assertEquals($value, $user->getEmail(), 'Setter or getter failed.');
     $value = '';
     $user->setEmail($value);
     $this->assertNull($user->getEmail(), 'Setter or getter failed.');
     $value = 'namesxxx';
     $user->setName($value);
     $this->assertEquals($value, $user->getName(), 'Setter or getter failed.');
     $this->assertEquals($value, $user->get('name', null), 'Getter failed.');
     $value = '';
     $user->setName($value);
     $this->assertNull($user->getName(), 'Setter or getter failed.');
     // cannot set or get iterator
     $hasSet = $user->set('iterator', 'something');
     $this->assertFalse($hasSet, 'Failed to stop iterator property set.');
     $this->assertNull($user->get('iterator', null), 'Getter failed to exclude.');
     $value = null;
     $user->setProperties($value);
     $this->assertTrue(is_array($user->getProperties()), 'Setter or getter failed.');
     $pvalue = ['Y' => 'propertyYYY'];
     $value = 'propertyXXX';
     $user->setProperties($pvalue);
     $this->assertArrayHasKey('Y', $user->getProperties(), 'Setter or getter failed.');
     $user->setProperty('X', $value);
     $this->assertEquals($value, $user->getProperty('X'), 'Setter or getter failed.');
     $this->assertArrayHasKey('Y', $user->getProperties(), 'Setter or getter failed.');
     $this->assertTrue($user->getProperty('nope', 'not_found') === 'not_found', 'Setter or getter failed.');
     $this->assertEquals('propertyYYY', $user->get('Y', null), 'Getter failed.');
     $badPropertyName = 'N*P#_^^^^';
     $hasSet = $user->set($badPropertyName, 'something');
     $this->assertFalse($hasSet, 'Failed to stop bad property set.');
     $hasException = false;
     try {
         $user->setProperty($badPropertyName, 'something');
     } catch (RcmUserException $e) {
         $hasException = true;
         $this->assertInstanceOf('\\RcmUser\\Exception\\RcmUserException', $e);
     }
     if (!$hasException) {
         $this->fail("Expected exception not thrown");
     }
 }