Description
Scans urls for a series of specified strings and “passes” or “fails” the specified tests. Give it a URL of a YAML file in the format:
-
name: first_test
url: http://www.google.com
match: /google/
-
name: second_test
url: http://www.google.com
match: /blabla.com/
like “http://run.kogbox.com/php/1/test_suite&yaml=example.com”
Run
| View code [+] |
Create a snippet based on this »
View in new window »
<?php
include_snippet(1,"curl_pure_function");
include_snippet(1,"spyc_yaml");
include_snippet(1,'make_pretty'); ?>
<h1>Kogbox Test Suite</h1>
<p>Test URLs for a particular string to confirm uptime.</p>
<form method="post" action="http://run.kogbox.com/php/1/test_suite">
<label for="url">Enter test YAML url:</label>
<input style="font-size:1.4em;width:400px;" type="text" name="yaml" value="<?php echo $_REQUEST['yaml'];?>" />
</form>
<p>Ex: "http://example.com, yahoo.com"</p>
<?php
$test_yaml = getUrlText($_REQUEST['yaml']);
function test_for_string($name,$url,$match) {
$url_text = getUrlText($url);
$pass = preg_match($match, $url_text, $out);
if ($pass == 1) {
$color = "green";
$status = "passed";
$error = "";
} else {
$color = "red";
$status = "failed";
$error = "<p><small>(Expected '".$match."', but it was not found at '".$url."'.) : ".$pass."</small></p>";
}
echo "<p style='color:white;font-weight:bold;background:".$color."'>Test '".$name."': ".$status."</p>";
echo $error;
}
$tests = Spyc::YAMLLoad($test_yaml);
foreach ($tests as $test) {
test_for_string($test['name'],$test['url'],$test['match']);
}
?>
Comments (0) | View comments for all versions (2)
Log in if you have a Kogbox account.