2017-02-18 00:22:50 +00:00
|
|
|
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace JKingWeb\NewsSync\Test\User;
|
2017-02-21 00:04:08 +00:00
|
|
|
use JKingWeb\NewsSync\User\Driver;
|
2017-02-18 00:22:50 +00:00
|
|
|
|
2017-02-26 17:09:44 +00:00
|
|
|
class DriverInternalMock extends Database implements Driver {
|
2017-02-18 00:22:50 +00:00
|
|
|
|
2017-02-20 22:04:13 +00:00
|
|
|
protected $db = [];
|
2017-02-18 00:22:50 +00:00
|
|
|
protected $data;
|
|
|
|
protected $functions = [
|
|
|
|
"auth" => Driver::FUNC_INTERNAL,
|
|
|
|
"userList" => Driver::FUNC_INTERNAL,
|
|
|
|
"userExists" => Driver::FUNC_INTERNAL,
|
|
|
|
"userAdd" => Driver::FUNC_INTERNAL,
|
|
|
|
"userRemove" => Driver::FUNC_INTERNAL,
|
|
|
|
"userPasswordSet" => Driver::FUNC_INTERNAL,
|
|
|
|
"userPropertiesGet" => Driver::FUNC_INTERNAL,
|
|
|
|
"userPropertiesSet" => Driver::FUNC_INTERNAL,
|
|
|
|
"userRightsGet" => Driver::FUNC_INTERNAL,
|
|
|
|
"userRightsSet" => Driver::FUNC_INTERNAL,
|
|
|
|
];
|
|
|
|
|
|
|
|
static public function create(\JKingWeb\NewsSync\RuntimeData $data): Driver {
|
|
|
|
return new static($data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static public function driverName(): string {
|
|
|
|
return "Mock Internal Driver";
|
|
|
|
}
|
|
|
|
|
|
|
|
public function driverFunctions(string $function = null) {
|
|
|
|
if($function===null) return $this->functions;
|
|
|
|
if(array_key_exists($function, $this->functions)) {
|
|
|
|
return $this->functions[$function];
|
|
|
|
} else {
|
|
|
|
return Driver::FUNC_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function __construct(\JKingWeb\NewsSync\RuntimeData $data) {
|
|
|
|
$this->data = $data;
|
|
|
|
}
|
|
|
|
|
|
|
|
function auth(string $user, string $password): bool {
|
2017-02-19 05:22:16 +00:00
|
|
|
if(!$this->userExists($user)) return false;
|
2017-02-20 22:04:13 +00:00
|
|
|
if(password_verify($password, $this->db[$user]['password'])) return true;
|
2017-02-19 05:22:16 +00:00
|
|
|
return false;
|
2017-02-18 00:22:50 +00:00
|
|
|
}
|
|
|
|
}
|