run(); } //file patterns to accept for test public function acceptPattern() { return '/\w+\.php/'; } public function rejectPattern() { return null; } public function getTestCase() { return isset($_GET['file']) ? $_GET['file'] : ''; } } //set up the PradoApplication Testing stub. class PradoApplicationTester extends TApplication { protected $appUrl; protected $testConfig; public function __construct($config, $appUrl) { $this->appUrl = $appUrl; $this->testConfig = $config; parent::__construct(); } public function run() { $this->initApplication(); } public function getTestPage($file) { $parameter = $this->getTestServiceParameter($file); return $this->appUrl.'?page='.$parameter; } protected function getTestServiceParameter($file) { $file = realpath($file); $base = realpath($this->testConfig->tests_directory().'/pages/'); $search = array($base, '.php'); $replace = array('', ''); $pagePath = str_replace($search, $replace, $file); $separator = array("/", "\\"); if(in_array($pagePath[0], $separator)) $pagePath = substr($pagePath, 1); return str_replace($separator, array('.','.'), $pagePath); } } /** set up the tests **/ class PradoSimpleTester { protected $tester; function __construct($tester) { $this->tester = $tester; $this->tester->runApplication(); } function getTests($name='All Tests') { $unit_tests = new GroupTest($name); foreach($this->tester->unit_test_groups() as $group => $dir) { $unit_tests->addTestCase($this->testSuits($group, $dir)); } return $unit_tests; } protected function testSuits($group, $path) { $suite = new GroupTest($group); $dir = dir($path); while (false !== ($entry = $dir->read())) { $file = realpath($path.'/'.$entry); $matchFile = $this->tester->getTestCase(); if(is_file($file) && $this->filePatternMatch($file)) { if(empty($matchFile) || (!empty($matchFile) && is_int(strpos($file, $matchFile)))) $suite->addTestFile($file); } } $dir->close(); return $suite; } protected function filePatternMatch($file) { $accept = $this->tester->acceptPattern(); $reject = $this->tester->rejectPattern(); $valid = true; if(!is_null($accept)) $valid = $valid && preg_match($accept, $file); if(!is_null($reject)) $valid = $valid && !preg_match($reject, $file); return $valid; } } ?>