Esempio n. 1
0
 public function testComputedNameFromProfile()
 {
     $user = new User();
     $user->setFirstname('original');
     $this->assertSame('original', $user->getName());
     $profile = new Profile();
     $user->fromProfile($profile);
     $this->assertSame('original', $user->getName(), 'nothing should have changed');
     $profile->displayName = 'displayName';
     $user->fromProfile($profile);
     $this->assertSame('displayName', $user->getFirstname(), 'displayName should be used as default firstname');
     $this->assertSame('displayName', $user->getName(), 'name should be the displayName');
     $profile->firstName = 'first';
     $user->fromProfile($profile);
     $this->assertSame('first', $user->getFirstname(), 'firstname should have been copied');
     $this->assertSame('first', $user->getName(), 'displayName should be ignored');
     $profile->lastName = 'last';
     $user->fromProfile($profile);
     $this->assertSame('last', $user->getLastname(), 'firstname should have been copied');
     $this->assertSame('first last', $user->getName(), 'displayName should be ignored');
 }
 public function save(User $user)
 {
     $data = array('username' => $user->getUsername(), 'password' => $user->getPassword(), 'name' => $user->getName(), 'valid' => $user->getValid(), 'role' => $user->getRole());
     $id = (int) $user->getId();
     if ($id == 0) {
         $this->tableGateway->insert($data);
     } else {
         if ($this->get($id)) {
             $this->tableGateway->update($data, array('id' => $id));
         } else {
             throw new \Exception('User não existe');
         }
     }
 }
Esempio n. 3
0
 /**
  * Assert that the user has the same information as the profile
  * @param Profile $profile
  * @param User $user
  */
 private function assertUser(Profile $profile, User $user, $message = null)
 {
     $expected = array_filter((array) $profile);
     // Slighlty adapt expected values
     unset($expected['identifier']);
     if (!isset($expected['email'])) {
         $expected['email'] = null;
     }
     $actual = ['photoURL' => $user->getPhoto(), 'displayName' => $user->getName(), 'email' => $user->getEmail(), 'phone' => $user->getPhone(), 'address' => $user->getStreet(), 'city' => $user->getLocality(), 'zip' => $user->getPostcode()];
     $this->assertEquals($expected, $actual, $message);
 }