Функция:
Код: Выделить всё
function ValidateToken(string $key, string $token): array {
if (!empty($key) || !empty($token)) {
$email = "%".htmlspecialchars($key)."%";
$token = htmlspecialchars($token);
$stmt = $this->c->prepare("SELECT expDate FROM `authuser` WHERE `reset_link_token`= ? AND `email1` LIKE ?");
$stmt->bind_param('ss',$token,$email);
$stmt->execute();
$result = $stmt->get_result();
$row = $result->fetch_array(MYSQLI_ASSOC);
$curDate = date("Y-m-d H:i:s");
if ($result->num_rows > 0) {
if($row['expDate'] >= $curDate){
return array("response"=>1,"email"=>$key,"token"=>$token);
} else {
return array("response"=>2);
}
} else {
return array("response"=>0);
}
} else {
return array("response"=>0);
}
}
Код: Выделить всё
public function testExpiredTokenSuccess() {
$successToken = new stdClass();
$successToken->expDate = '2099-12-31 23:59:59'; // y2.1k bug
$this->mockLF = array();
$this->mockLF[0] = $successToken ;
$this->dbMock = $this->getMockBuilder(Connection::class)
->disableOriginalConstructor()
->getMock();
$curDate = date("Y-m-d H:i:s");
$this->authuserloginclass = new LoginFormClass();
$returnVal = $this->authuserloginclass->ValidateToken('key','token');
$this->assertEquals("1", $returnVal);
}
Выявляется ли что-нибудь как проблема?
Подробнее здесь: https://stackoverflow.com/questions/791 ... statements