Blame view

php/WebServices/Tests/Base/TestsSuite.php 1.36 KB
0c8a11ef   Benjamin Renard   Tests suits for W...
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
<?php

function cmpTest($a, $b) {
	if ($a == $b) {
		return 0;
	}

	list($prefix_a, $number_a) = sscanf($a, "%[A-Za-z]_%[0-9]");
	list($prefix_b, $number_b) = sscanf($b, "%[A-Za-z]_%[0-9]");

	if (empty($number_a)) {
		return -1;
	}
	else if (empty($number_b)) {
		return 1;
	}

	return (intval($number_a) < intval($number_b)) ? -1 : 1;
}

class TestsSuite {
	private $tests = NULL;

	function __construct() {
		$this->tests = array();
	}

	public function init($tests_path) {
		$this->tests = array();
		$files = array_diff(scandir($tests_path), array('.', '..'));
		foreach ($files as $file) {
			$name = basename($file, ".php");
			require_once($tests_path."/".$file);
			$this->tests[$name] = new $name();
		}
		uksort($this->tests, "cmpTest");
	}

	public function getDescriptions() {
		return $this->run(TRUE);
	}

	public function run($descriptionsOnly = FALSE) {
		$results = array();
		foreach ($this->tests as $name => $test) {
			$res = array();
			foreach ($test->getWSTypes() as $ws_type) {
				$res = array(
					"name" => $name,
					"description" => $test->getDescription(),
					"type" => $ws_type,
					"api" => $test->getAPI(),
					"params" => $test->getParams(),
					"status" => NULL,
				);
				if (!$descriptionsOnly) {
					$runFunc = "run".$ws_type;
e2644543   Benjamin Renard   Fix apache alias ...
58
					$res["status"] = $test->$runFunc(webAlias);
0c8a11ef   Benjamin Renard   Tests suits for W...
59
60
61
62
63
64
65
66
67
68
				}
				$results[] = $res;
			}

		}
		return $results;
	}
}

?>