1
1
Fork 0
mirror of https://code.mensbeam.com/MensBeam/Arsse.git synced 2024-12-22 13:12:41 +00:00

Last of the basic tests for the User class

This commit is contained in:
J. King 2017-02-25 12:59:39 -05:00
parent be9ebf9ca1
commit 1834cb9963
2 changed files with 39 additions and 2 deletions

View file

@ -274,7 +274,7 @@ class User {
public function propertiesSet(string $user, array $properties): array {
// remove from the array any values which should be set specially
foreach(['password', 'rights'] as $key) {
foreach(['id', 'domain', 'password', 'rights'] as $key) {
if(array_key_exists($key, $properties)) unset($properties[$key]);
}
$func = "userPropertiesSet";
@ -363,7 +363,7 @@ class User {
// create the user
$out = $this->data->db->userAdd($user, $password);
// set the user rights
$this->data->db->userRightsSet($user, $level);
$this->data->db->userRightsSet($user, $rights);
// set the user properties...
if($properties===null) {
// if nothing is provided but the driver uses an external function, try to get the current values from the external source
@ -374,6 +374,7 @@ class User {
// otherwise if values are provided, use those
$this->data->db->userPropertiesSet($user, $properties);
}
// re-enable authorization and return
$this->authorizationEnabled($authz);
return $out;
}

View file

@ -87,8 +87,44 @@ class TestUser extends \PHPUnit\Framework\TestCase {
function testGetThePropertiesOfAUser() {
$this->data->user->add(self::USER1, "secret");
$p = $this->data->user->propertiesGet(self::USER1);
$this->assertArrayHasKey('id', $p);
$this->assertArrayHasKey('name', $p);
$this->assertArrayHasKey('domain', $p);
$this->assertArrayHasKey('rights', $p);
$this->assertArrayNotHasKey('password', $p);
$this->assertEquals(self::USER1, $p['name']);
}
function testSetThePropertiesOfAUser() {
$pSet = [
'name' => 'John Doe',
'id' => 'invalid',
'domain' => 'localhost',
'rights' => User\Driver::RIGHTS_GLOBAL_ADMIN,
'password' => 'superman',
];
$pGet = [
'name' => 'John Doe',
'id' => self::USER1,
'domain' => 'example.com',
'rights' => User\Driver::RIGHTS_NONE,
];
$this->data->user->add(self::USER1, "secret");
$this->data->user->propertiesSet(self::USER1, $pSet);
$p = $this->data->user->propertiesGet(self::USER1);
$this->assertArraySubset($pGet, $p);
$this->assertArrayNotHasKey('password', $p);
$this->assertFalse($this->data->user->auth(self::USER1, "superman"));
}
function testGetTheRightsOfAUser() {
$this->data->user->add(self::USER1, "secret");
$this->assertEquals(User\Driver::RIGHTS_NONE, $this->data->user->rightsGet(self::USER1));
}
function testSetTheRightsOfAUser() {
$this->data->user->add(self::USER1, "secret");
$this->data->user->rightsSet(self::USER1, User\Driver::RIGHTS_GLOBAL_ADMIN);
$this->assertEquals(User\Driver::RIGHTS_GLOBAL_ADMIN, $this->data->user->rightsGet(self::USER1));
}
}