17 code examples of PHP Elabftw\Services\Check extracted from open source projects
public function testInvalidTarget(): void
{
$this->expectException(IllegalActionException::class);
Check::target('Grogu');
}
public function testToken(): void
{
$token = hash('sha256', bin2hex(random_bytes(16)));
$this->assertEquals($token, Check::token($token));
$this->expectException(IllegalActionException::class);
Check::token('blah');
}
public function testRw(): void
{
$this->assertEquals('read', Check::rw('read'));
$this->assertEquals('write', Check::rw('write'));
$this->expectException(IllegalActionException::class);
Check::rw('blah');
}
public function testSort(): void
{
$this->assertEquals('asc', Check::sort('asc'));
$this->assertEquals('desc', Check::sort('desc'));
$this->expectException(ImproperActionException::class);
Check::sort('blah');
}
public function testOrderby(): void
{
$this->assertEquals('date', Check::orderby('date'));
$this->expectException(ImproperActionException::class);
Check::orderby('blah');
}
public function testVisibility(): void
{
$this->assertEquals('team', Check::visibility('team'));
$this->expectException(IllegalActionException::class);
Check::visibility('pwet');
}
public function testColor(): void
{
$this->assertEquals('AABBCC', Check::color('#AABBCC'));
$this->expectException(ImproperActionException::class);
Check::color('pwet');
}
public function testUsergroup(): void
{
$this->assertTrue(Check::usergroup(1));
$this->assertTrue(Check::usergroup(2));
$this->assertFalse(Check::usergroup(3));
$this->assertTrue(Check::usergroup(4));
$this->expectException(IllegalActionException::class);
Check::usergroupOrExplode(-1337);
$this->expectException(IllegalActionException::class);
Check::usergroupOrExplode(0);
$this->expectException(IllegalActionException::class);
Check::usergroupOrExplode(5);
}
public function testIdOrExplode(): void
{
$this->expectException(IllegalActionException::class);
Check::idOrExplode(-1337);
}
public function testPasswordLength(): void
{
$this->assertTrue(Check::passwordLength('longpassword'));
$this->expectException(ImproperActionException::class);
Check::passwordLength('short');
}
/**
* Update the password for the user
*/
public function updatePassword(string $password): bool
{
Check::passwordLength($password);
$passwordHash = password_hash($password, PASSWORD_DEFAULT);
$sql = 'UPDATE users SET password_hash = :password_hash, token = null WHERE userid = :userid';
$req = $this->Db->prepare($sql);
$req->bindParam(':password_hash', $passwordHash);
$req->bindParam(':userid', $this->userData['userid'], PDO::PARAM_INT);
return $this->Db->execute($req);
}
/**
* Populate userData property
*/
public function populate(int $userid): void
{
Check::idOrExplode($userid);
$this->userData = $this->getUserData($userid);
$this->userData['team'] = $this->team;
}
public function getColor(): string
{
return Check::color($this->color);
}
public function getColor(): string
{
return Check::color($this->extra['color']);
}
public function getCanwriteS(): string
{
return Check::visibility($this->extra['canwrite']);
}
public function getCanread(): string
{
return Check::visibility($this->extra['canread']);
}
public function getTarget(): string
{
return Check::target($this->target);
}