TestsSuite.php 1.36 KB
<?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;
					$res["status"] = $test->$runFunc(webAlias);
				}
				$results[] = $res;
			}

		}
		return $results;
	}
}

?>