forked from emfluencekc/emfl-api_php-lib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tests.php
63 lines (56 loc) · 1.47 KB
/
tests.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php
/**
* Page callback.
*/
function emfl_api_unit_tests_run_all() {
if(empty($_REQUEST['apitoken'])) {
?>
<form method="post">
<input name="apitoken" placeholder="Enter a valid API token" />
<input type="submit" />
</form>
<?php
die();
}
define('EMFL_API_TOKEN', $_REQUEST['apitoken']);
foreach( glob( __DIR__ . "/tests/*.php") as $filename ) {
try {
include $filename;
} catch(Exception $e) {
echo '<b style="color:red;">EXCEPTION in tests/' . $filename . ':' . $e->getMessage() . '</b>';
}
}
}
/**
* Helper for the tests.
* @return Emfl_Platform_API
*/
function emfl_api_get_instance() {
require_once 'api.class.php';
$instance = new Emfl_Platform_API(EMFL_API_TOKEN);
return $instance;
}
/**
* Helper for the tests.
* Standard test result output.
* @param string $test_name
* @param string[] $successes
* @param string[] $failures
*/
function emfl_api_test_output_results($test_name, $successes, $failures) {
echo '<div class="test"><h2>' . $test_name . '</h2>';
if(!empty($successes)) echo '<div class="success"><h3>SUCCESSES</h3><ol><li>' . implode('</li><li>', $successes) . '</li></ol></div>';
if(!empty($failures)) echo '<div class="fail"><h3>FAILURES</h3><ol><li>' . implode('</li><li>', $failures) . '</li></ol></div>';
echo '</div>';
}
?>
<!DOCTYPE html>
<html>
<body>
<style>
.success { color: green; }
.fail { color: red; }
</style>
<?php emfl_api_unit_tests_run_all(); ?>
</body>
</html>