|
165 | 165 | $implementationReferences = readYaml($implementationReferenceFile)['implementations']; |
166 | 166 | $references = array("implementations" => $implementationReferences); |
167 | 167 | assertUniqueRefs($references, $errorMsg); |
| 168 | +assertLiveUrlsInRefs($references, $errorMsg); |
168 | 169 |
|
169 | 170 | resolveYamlReferences($dimensionsAggregated, $references, $errorMsg); |
170 | 171 |
|
@@ -215,6 +216,63 @@ function assertUniqueRefByKey($references, $keyToAssert, &$errorMsg) { |
215 | 216 | } |
216 | 217 |
|
217 | 218 |
|
| 219 | +function assertLiveUrlsInRefs($all_references, &$errorMsg) { |
| 220 | + if (TEST_REFERENCED_URLS) { |
| 221 | + echo "\nTesting referenced URLs:\n"; |
| 222 | + foreach ($all_references as $references) { |
| 223 | + foreach ($references as $key => $reference) { |
| 224 | + if (array_key_exists('url', $reference)) { |
| 225 | + $url = $reference['url']; |
| 226 | + echo " $key: $url\n"; |
| 227 | + $err = assertLiveUrl($reference['url']); |
| 228 | + if ($err) { |
| 229 | + echo " # $err\n"; |
| 230 | + array_push($errorMsg, "Dead ref URL ($key): $err"); |
| 231 | + } |
| 232 | + } |
| 233 | + } |
| 234 | + } |
| 235 | + echo "\n"; |
| 236 | + } |
| 237 | +} |
| 238 | + |
| 239 | + |
| 240 | +function assertLiveUrl($url):string { |
| 241 | + $useragent = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:135.0) Gecko/20100101 Firefox/135.0'; |
| 242 | + |
| 243 | + $curl = curl_init($url); |
| 244 | + curl_setopt($curl, CURLOPT_USERAGENT, $useragent); |
| 245 | + curl_setopt($curl, CURLOPT_NOBODY, true); |
| 246 | + curl_setopt($curl, CURLOPT_HEADER, true); |
| 247 | + curl_setopt($curl, CURLOPT_FOLLOWLOCATION, false); |
| 248 | + curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); |
| 249 | + curl_setopt($curl, CURLOPT_TIMEOUT, 5); |
| 250 | + curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 5); |
| 251 | + $response = curl_exec($curl); |
| 252 | + |
| 253 | + if (curl_errno($curl)) { |
| 254 | + echo curl_error($curl); |
| 255 | + curl_close($curl); |
| 256 | + return "No reply"; |
| 257 | + } |
| 258 | + |
| 259 | + // Extract header info |
| 260 | + $statusCode = curl_getinfo($curl, CURLINFO_HTTP_CODE); |
| 261 | + $redirectUrl = curl_getinfo($curl, CURLINFO_REDIRECT_URL ); |
| 262 | + |
| 263 | + curl_close($curl); |
| 264 | + |
| 265 | + if ($statusCode == 200) { |
| 266 | + return ""; |
| 267 | + } |
| 268 | + if ($statusCode == 301 || $statusCode == 302) { |
| 269 | + return "Status code $statusCode redirects to: $redirectUrl"; |
| 270 | + } |
| 271 | + return "Status code: $statusCode: $url"; |
| 272 | +} |
| 273 | + |
| 274 | + |
| 275 | + |
218 | 276 | /** |
219 | 277 | * |
220 | 278 | * @param unknown $dimensions |
|
0 commit comments