| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
function JUTcompareTestName($a,$b){ |
|---|
| 15 |
return strcmp($a[0], $b[0]); |
|---|
| 16 |
} |
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
class defaultCtrl extends jController { |
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
* |
|---|
| 23 |
*/ |
|---|
| 24 |
function index() { |
|---|
| 25 |
if(!isset($GLOBALS['gJConfig']->enableTests) || !$GLOBALS['gJConfig']->enableTests){ |
|---|
| 26 |
|
|---|
| 27 |
$rep = $this->getResponse('html', true); |
|---|
| 28 |
$rep->title = 'Error'; |
|---|
| 29 |
$rep->setHttpStatus('404', 'Not found'); |
|---|
| 30 |
$rep->addContent('<p>404 Not Found</p>'); |
|---|
| 31 |
return $rep; |
|---|
| 32 |
} |
|---|
| 33 |
|
|---|
| 34 |
$rep = $this->_prepareResponse(); |
|---|
| 35 |
|
|---|
| 36 |
return $this->_finishResponse($rep); |
|---|
| 37 |
} |
|---|
| 38 |
|
|---|
| 39 |
function all() { |
|---|
| 40 |
if(!isset($GLOBALS['gJConfig']->enableTests) || !$GLOBALS['gJConfig']->enableTests){ |
|---|
| 41 |
|
|---|
| 42 |
$rep = $this->getResponse('html', true); |
|---|
| 43 |
$rep->title = 'Error'; |
|---|
| 44 |
$rep->setHttpStatus('404', 'Not found'); |
|---|
| 45 |
$rep->addContent('<p>404 Not Found</p>'); |
|---|
| 46 |
return $rep; |
|---|
| 47 |
} |
|---|
| 48 |
|
|---|
| 49 |
|
|---|
| 50 |
$rep = $this->_prepareResponse(); |
|---|
| 51 |
|
|---|
| 52 |
|
|---|
| 53 |
$reporter = jClasses::create("jhtmlrespreporter"); |
|---|
| 54 |
jClasses::inc('junittestcase'); |
|---|
| 55 |
jClasses::inc('junittestcasedb'); |
|---|
| 56 |
$reporter->setResponse($rep); |
|---|
| 57 |
|
|---|
| 58 |
|
|---|
| 59 |
|
|---|
| 60 |
foreach($this->testsList as $module=>$tests){ |
|---|
| 61 |
jContext::push($module); |
|---|
| 62 |
$group = new GroupTest('Tests on module '.$module); |
|---|
| 63 |
foreach($this->testsList[$module] as $test){ |
|---|
| 64 |
$group->addTestFile($GLOBALS['gJConfig']->_modulesPathList[$module].'tests/'.$test[0]); |
|---|
| 65 |
} |
|---|
| 66 |
$group->run($reporter); |
|---|
| 67 |
jContext::pop(); |
|---|
| 68 |
} |
|---|
| 69 |
|
|---|
| 70 |
|
|---|
| 71 |
|
|---|
| 72 |
|
|---|
| 73 |
return $this->_finishResponse($rep); |
|---|
| 74 |
} |
|---|
| 75 |
|
|---|
| 76 |
|
|---|
| 77 |
function module() { |
|---|
| 78 |
if(!isset($GLOBALS['gJConfig']->enableTests) || !$GLOBALS['gJConfig']->enableTests){ |
|---|
| 79 |
|
|---|
| 80 |
$rep = $this->getResponse('html', true); |
|---|
| 81 |
$rep->title = 'Error'; |
|---|
| 82 |
$rep->setHttpStatus('404', 'Not found'); |
|---|
| 83 |
$rep->addContent('<p>404 Not Found</p>'); |
|---|
| 84 |
return $rep; |
|---|
| 85 |
} |
|---|
| 86 |
$rep = $this->_prepareResponse(); |
|---|
| 87 |
|
|---|
| 88 |
$module = $this->param('mod'); |
|---|
| 89 |
if(isset($this->testsList[$module])){ |
|---|
| 90 |
$reporter = jClasses::create("jhtmlrespreporter"); |
|---|
| 91 |
jClasses::inc('junittestcase'); |
|---|
| 92 |
jClasses::inc('junittestcasedb'); |
|---|
| 93 |
$reporter->setResponse($rep); |
|---|
| 94 |
|
|---|
| 95 |
$group = new GroupTest('All tests in "'.$module. '" module'); |
|---|
| 96 |
foreach($this->testsList[$module] as $test){ |
|---|
| 97 |
$group->addTestFile($GLOBALS['gJConfig']->_modulesPathList[$module].'tests/'.$test[0]); |
|---|
| 98 |
} |
|---|
| 99 |
jContext::push($module); |
|---|
| 100 |
$group->run($reporter); |
|---|
| 101 |
jContext::pop(); |
|---|
| 102 |
} |
|---|
| 103 |
return $this->_finishResponse($rep); |
|---|
| 104 |
} |
|---|
| 105 |
|
|---|
| 106 |
|
|---|
| 107 |
function single() { |
|---|
| 108 |
if(!isset($GLOBALS['gJConfig']->enableTests) || !$GLOBALS['gJConfig']->enableTests){ |
|---|
| 109 |
|
|---|
| 110 |
$rep = $this->getResponse('html', true); |
|---|
| 111 |
$rep->title = 'Error'; |
|---|
| 112 |
$rep->setHttpStatus('404', 'Not found'); |
|---|
| 113 |
$rep->addContent('<p>404 Not Found</p>'); |
|---|
| 114 |
return $rep; |
|---|
| 115 |
} |
|---|
| 116 |
$rep = $this->_prepareResponse(); |
|---|
| 117 |
|
|---|
| 118 |
$module = $this->param('mod'); |
|---|
| 119 |
$testname = $this->param('test'); |
|---|
| 120 |
|
|---|
| 121 |
if(isset($this->testsList[$module])){ |
|---|
| 122 |
$reporter = jClasses::create("jhtmlrespreporter"); |
|---|
| 123 |
jClasses::inc('junittestcase'); |
|---|
| 124 |
jClasses::inc('junittestcasedb'); |
|---|
| 125 |
$reporter->setResponse($rep); |
|---|
| 126 |
|
|---|
| 127 |
foreach($this->testsList[$module] as $test){ |
|---|
| 128 |
if($test[1] == $testname){ |
|---|
| 129 |
$group = new GroupTest('"'.$module. '" module , '.$test[2]); |
|---|
| 130 |
$group->addTestFile($GLOBALS['gJConfig']->_modulesPathList[$module].'tests/'.$test[0]); |
|---|
| 131 |
jContext::push($module); |
|---|
| 132 |
$group->run($reporter); |
|---|
| 133 |
jContext::pop(); |
|---|
| 134 |
break; |
|---|
| 135 |
} |
|---|
| 136 |
} |
|---|
| 137 |
}else |
|---|
| 138 |
$rep->body->assign ('MAIN','<p>no tests for "'.$module.'" module.</p>'); |
|---|
| 139 |
return $this->_finishResponse($rep); |
|---|
| 140 |
} |
|---|
| 141 |
|
|---|
| 142 |
|
|---|
| 143 |
|
|---|
| 144 |
protected $testsList = array(); |
|---|
| 145 |
|
|---|
| 146 |
|
|---|
| 147 |
protected function _prepareResponse(){ |
|---|
| 148 |
$rep = $this->getResponse('html', true); |
|---|
| 149 |
$rep->bodyTpl = 'main'; |
|---|
| 150 |
|
|---|
| 151 |
$rep->body->assign('page_title', 'Unit Tests'); |
|---|
| 152 |
$rep->body->assign('versionphp',phpversion()); |
|---|
| 153 |
$rep->body->assign('versionjelix',JELIX_VERSION); |
|---|
| 154 |
$rep->body->assign('basepath',$GLOBALS['gJConfig']->urlengine['basePath']); |
|---|
| 155 |
$rep->body->assign('isurlsig', $GLOBALS['gJConfig']->urlengine['engine'] == 'significant'); |
|---|
| 156 |
|
|---|
| 157 |
$rep->addCSSLink($GLOBALS['gJConfig']->urlengine['basePath'].'tests/design.css'); |
|---|
| 158 |
|
|---|
| 159 |
foreach($GLOBALS['gJConfig']->_modulesPathList as $module=>$path){ |
|---|
| 160 |
if(file_exists($path.'tests/')){ |
|---|
| 161 |
$dir = new DirectoryIterator($path.'tests/'); |
|---|
| 162 |
foreach ($dir as $dirContent) { |
|---|
| 163 |
if ($dirContent->isFile() && preg_match("/^(.+)\\.html(_cli)?\\.php$/", $dirContent->getFileName(), $m) ) { |
|---|
| 164 |
$lib = str_replace('.',': ',$m[1]); |
|---|
| 165 |
$lib = str_replace('_',' ',$lib); |
|---|
| 166 |
|
|---|
| 167 |
$this->testsList[$module][] = array($dirContent->getFileName(), $m[1], $lib) ; |
|---|
| 168 |
} |
|---|
| 169 |
} |
|---|
| 170 |
if(isset($this->testsList[$module])){ |
|---|
| 171 |
usort($this->testsList[$module], "JUTcompareTestName"); |
|---|
| 172 |
} |
|---|
| 173 |
} |
|---|
| 174 |
} |
|---|
| 175 |
|
|---|
| 176 |
$rep->body->assign('modules', $this->testsList); |
|---|
| 177 |
|
|---|
| 178 |
return $rep; |
|---|
| 179 |
} |
|---|
| 180 |
|
|---|
| 181 |
protected function _finishResponse($rep){ |
|---|
| 182 |
|
|---|
| 183 |
$rep->title .= ($rep->title !=''?' - ':'').' Unit Tests'; |
|---|
| 184 |
$rep->body->assignIfNone('MAIN','<p>Welcome to unit tests</p>'); |
|---|
| 185 |
return $rep; |
|---|
| 186 |
} |
|---|
| 187 |
} |
|---|
| 188 |
?> |
|---|
| 189 |
|
|---|