/**
  * onPopulateUserProperty
  *
  * @param Event $e e
  *
  * @return bool|Result
  */
 public function onPopulateUserProperty($e)
 {
     $propertyNameSpace = $e->getParam('propertyNameSpace');
     $data = $e->getParam('data');
     $thisPropertyNameSpace = $this->getUserPropertyKey();
     if ($propertyNameSpace !== $thisPropertyNameSpace) {
         return false;
     }
     $property = new UserRoleProperty();
     try {
         $property->populate($data);
     } catch (\Exception $e) {
         return new \RcmUser\Result($property, Result::CODE_FAIL, 'Property failed to populate with error: ' . $e->getMessage());
     }
     return new Result($property);
 }
Exemplo n.º 2
0
 /**
  * test
  *
  * @return void
  */
 public function test()
 {
     $roles = ['TestRole1', 'TestRole2'];
     $userRoleProperty = new UserRoleProperty($roles);
     $this->assertTrue($userRoleProperty->hasRoles());
     $this->assertEquals($roles, $userRoleProperty->getRoles());
     $userRoleProperty->setRole('TestRole3');
     $this->assertTrue($userRoleProperty->hasRole('TestRole3'));
     $this->assertEquals('TestRole3', $userRoleProperty->getRole('TestRole3'));
     $this->assertJson(json_encode($userRoleProperty));
     $userRoleProperty2 = new UserRoleProperty($roles);
     $userRoleProperty2->populate($userRoleProperty);
     $this->assertTrue($userRoleProperty2->hasRole('TestRole2'));
     $userRoleProperty3 = new UserRoleProperty($roles);
     $userRoleProperty3->populate($roles);
     $this->assertTrue($userRoleProperty3->hasRole('TestRole2'));
     try {
         $userRoleProperty3->populate('NOPE');
     } catch (RcmUserException $e) {
         $this->assertInstanceOf('\\RcmUser\\Exception\\RcmUserException', $e);
         return;
     }
     $this->fail("Expected exception not thrown");
 }
Exemplo n.º 3
0
 /**
  * buildUser
  *
  * @param array $data data
  *
  * @return void
  */
 protected function buildUser($data)
 {
     $user = new User();
     $user->populate($data, ['properties']);
     $properties = [];
     if (isset($data['properties'])) {
         $properties = $data['properties'];
     }
     if (isset($properties[UserRoleProperty::PROPERTY_KEY])) {
         $roles = $properties[UserRoleProperty::PROPERTY_KEY];
         $userRoleProperty = new UserRoleProperty();
         $userRoleProperty->populate($roles);
         $user->setProperty(UserRoleProperty::PROPERTY_KEY, $userRoleProperty);
     }
     return $user;
 }