Add general abstract classes for tests, starting with test classes for

RSS feeds
This commit is contained in:
2023-08-18 15:09:58 +02:00
parent 9c49afe416
commit 88458df949
3 changed files with 598 additions and 0 deletions

View File

@ -419,6 +419,44 @@ final class MD_STD {
}
/**
* Check if a URL is reachable (200) using curl.
*
* @param string $url URL to validate.
*
* @return bool
*/
public static function checkUrlIsReachable(string $url):bool {
if (filter_var($url, FILTER_VALIDATE_URL) === false) {
throw new MDInvalidUrl("URL to check (" . $url . ") does not seem to be a valid URL");
}
$ch = curl_init($url);
curl_setopt_array($ch, [
CURLOPT_AUTOREFERER => true,
CURLOPT_CONNECTTIMEOUT => 5,
CURLOPT_ENCODING => "",
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_MAXREDIRS => 1,
CURLOPT_NOBODY => true,
CURLOPT_TIMEOUT => 5,
// It's very important to let other webmasters know who's probing their servers.
CURLOPT_USERAGENT => 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:10.0.2) Gecko/20100101 Firefox/10.0.2',
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_2_0,
CURLOPT_TCP_FASTOPEN => true,
]);
curl_exec($ch);
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($code !== 200) {
return false;
}
return true;
}
/**
* Sets and returns user language based on a session cookie.
*