示例#1
0
 /**
  * setId
  *
  * @param mixed $id id
  *
  * @return void
  * @throws \RcmUser\Exception\RcmUserReadOnlyException
  */
 public function setId($id)
 {
     if (!$this->locked) {
         return parent::setId($id);
     }
     throw new RcmUserReadOnlyException('Object is READ ONLY');
 }
 public function testGetUserProperty()
 {
     $key = 'propertyX';
     $value = 'XXXXX';
     $user = new User();
     $user->setId('123');
     $user->setProperty($key, 'XXXXX');
     $newValue = $this->getUserPropertyService()->getUserProperty($user, $key);
     $this->assertEquals($value, $newValue, 'Property value did not come back.');
 }
示例#3
0
 /**
  * prepareUserCreate
  *
  * @param User $requestUser  requestUser
  * @param User $responseUser responseUser
  *
  * @return Result
  */
 public function prepareUserCreate(User $requestUser, User $responseUser)
 {
     $responseUser->setId($this->buildId());
     $responseUser->setPassword($this->getEncryptor()->create($requestUser->getPassword()));
     $state = $responseUser->getState();
     if (empty($state)) {
         $responseUser->setState(User::STATE_DISABLED);
     }
     return new Result($responseUser);
 }
 public function buildUserAuthenticationServiceUserResult()
 {
     $user = new User();
     $user->setId('123');
     $responseCollection = $this->getMockBuilder('\\Zend\\EventManager\\ResponseCollection')->disableOriginalConstructor()->getMock();
     $responseCollection->expects($this->any())->method('last')->will($this->returnValue($user));
     $responseCollection->expects($this->any())->method('stopped')->will($this->returnValue(false));
     $eventManager = $this->getMockBuilder('\\Zend\\EventManager\\EventManagerInterface')->disableOriginalConstructor()->getMock();
     $eventManager->expects($this->any())->method('trigger')->will($this->returnValue($responseCollection));
     $this->userAuthenticationServiceUserResult = new UserAuthenticationService($eventManager);
 }
示例#5
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);
 }
示例#6
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");
     }
 }
示例#7
0
 public function testGetIdentity()
 {
     $result = $this->getRcmUserService()->getIdentity();
     $this->assertInstanceOf('\\RcmUser\\User\\Entity\\User', $result, 'Did not return instance of Result.');
     $result = $this->getRcmUserService()->getCurrentUser();
     $this->assertInstanceOf('\\RcmUser\\User\\Entity\\User', $result, 'Did not return instance of Result.');
     $hasIdentity = $this->getRcmUserService()->hasIdentity();
     $this->assertTrue($hasIdentity, 'Did not return true.');
     $this->getRcmUserService()->refreshIdentity();
     $result = $this->getRcmUserService()->getIdentity();
     $this->assertInstanceOf('\\RcmUser\\User\\Entity\\User', $result, 'Did not return instance of Result.');
     $this->getRcmUserService()->setIdentity($result);
     $userException = null;
     try {
         $newUser = new User();
         $newUser->setId('newguy');
         $this->getRcmUserService()->setIdentity($newUser);
     } catch (\Exception $e) {
         $userException = $e;
     }
     $this->assertInstanceOf('\\Exception', $userException);
 }