Ejemplo n.º 1
0
 protected function getNewUser($prefix = 'A')
 {
     $user = new User();
     $user->setId($prefix . '_id');
     $user->setUsername($prefix . '_username');
     $user->setPassword($prefix . '_password');
     $user->setState($prefix . '_state');
     $user->setProperties(['property1', $prefix . '_property1']);
     $user->setProperty('property2', $prefix . '_property2');
     return $user;
 }
Ejemplo n.º 2
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.º 3
0
 /**
  * setProperties
  *
  * @param array $properties properties
  *
  * @return void
  * @throws \RcmUser\Exception\RcmUserReadOnlyException
  */
 public function setProperties($properties)
 {
     if (!$this->locked) {
         return parent::setProperties($properties);
     }
     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");
     }
 }