00001 <?php
00002 include_once('FOUnitTestBase.class.php');
00003
00020 class FOUnitTest
00021 {
00030 public function FOUnitTest($testCaseRoot_)
00031 {
00032 $this->_retriveURLArguments();
00033 $this->_initializeSkin();
00034
00035 $this->_testCaseFilesArr = array();
00036 $this->_testCaseRoot = $testCaseRoot_;
00037 }
00038
00042 public function writeTestSuiteGui()
00043 {
00044 $this->_doRetriveAllTestCases();
00045
00046 $this->_begin();
00047 if ($this->_bRunAllTests)
00048 {
00049 $this->_runAllTests();
00050 }
00051 else
00052 {
00053 $this->_runTest($this->_currentTestCase);
00054 }
00055
00056 $this->_end();
00057 }
00058
00062 public function getOnlyReportFailes()
00063 {
00064 return $this->_bOnlyReportFailes;
00065 }
00066
00070 public function getReportFailDetails()
00071 {
00072 return $this->_bReportFailDetails;
00073 }
00074
00080 public function getCurrentTestCase()
00081 {
00082 return $this->_currentTestCase;
00083 }
00084
00088 public function getNumOfTestCases()
00089 {
00090 return $this->_numOfTestCases;
00091 }
00092
00096 public function getTestCaseFiles()
00097 {
00098 return $this->_testCaseFilesArr;
00099 }
00100
00104 private function _retriveURLArguments()
00105 {
00106
00107 if ($_GET['formOnlyReportFailes'] == '1')
00108 {
00109 $this->_bOnlyReportFailes = true;
00110 }
00111 else
00112 {
00113 $this->_bOnlyReportFailes = false;
00114 }
00115
00116
00117 if ($_GET['formEchoDetails'] == '1' || !array_key_exists('formEchoDetails', $_GET))
00118 {
00119 $this->_bReportFailDetails = true;
00120 }
00121 else
00122 {
00123 $this->_bReportFailDetails = false;
00124 }
00125
00126
00127 if ($_GET['formRunAllTests'] == '1')
00128 {
00129 $this->_bRunAllTests = true;
00130 }
00131 else
00132 {
00133 $this->_bRunAllTests = false;
00134 }
00135
00136
00137 $this->_currentTestCase = $_GET['formTestCase'];
00138
00139 if (empty($this->_currentTestCase))
00140 {
00141 $this->_currentTestCase = 0;
00142 }
00143 }
00144
00148 private function _initializeSkin()
00149 {
00150 $this->_skin = 'Standard';
00151 include('Skins/'.$this->_skin.'.class.php');
00152 $this->_skinObj = & new $this->_skin;
00153 $this->_skinObj->setParent($this);
00154 }
00155
00159 private function _runAllTests()
00160 {
00161 foreach($this->_testCaseFilesArr as $key => $row)
00162 {
00163 $this->_runTest($key);
00164 }
00165 }
00166
00174 private function _runTest($testCaseNumber_)
00175 {
00176 if ($testCaseNumber_ > 0)
00177 {
00178 include_once($this->_testCaseFilesArr[$testCaseNumber_]['path']);
00179 $obj = &new $this->_testCaseFilesArr[$testCaseNumber_]['class_name'];
00180 $obj->doTest();
00181
00182 $this->_writeGuiResult($obj->getTestResult());
00183 unset($obj);
00184 }
00185 }
00186
00191 private function _doRetriveAllTestCases()
00192 {
00193 $files = array();
00194 $this->_fillWithFilesFromDir($files, $this->_testCaseRoot);
00195
00196 if (!empty($files))
00197 {
00198 asort($files);
00199
00200 $testCase = count($this->_testCaseFilesArr);
00201 foreach($files as $file)
00202 {
00203 $testCase++;
00204 $pathParts = pathinfo($file);
00205
00206 $this->_testCaseFilesArr[$testCase] = array
00207 (
00208 'package' => $pathParts['dirname'],
00209 'path' => $file,
00210 'class_name' => substr($pathParts['basename'], 0, strpos($pathParts['basename'], '.'))
00211 );
00212 $this->_numOfTestCases++;
00213 }
00214 }
00215 }
00216
00220 private function _fillWithFilesFromDir(&$files_InOut, $path_, $addFiles_ = FALSE)
00221 {
00222 if (is_dir($path_))
00223 {
00224 $result = dir($path_);
00225
00226 while($entry = $result->read())
00227 {
00228 if (is_file($path_.$entry) && $addFiles_)
00229 {
00230 if (strtolower(substr($entry,-4)) == '.php')
00231 {
00232 $files_InOut[] = $path_.$entry;
00233 }
00234 }
00235 elseif(is_dir($path_.'/'.$entry) && $entry != '.' && $entry != '..')
00236 {
00237 $this->_fillWithFilesFromDir($files_InOut, $path_ . $entry . '/', TRUE);
00238 }
00239 }
00240 }
00241 }
00242
00246 private function _begin()
00247 {
00248 $this->_skinObj->begin();
00249 }
00250
00254 private function _end()
00255 {
00256 $this->_skinObj->end();
00257 }
00258
00262 private function _writeGuiResult(&$testResult_)
00263 {
00264 $this->_skinObj->writeGuiResult($testResult_);
00265 }
00266
00270 private $_skin;
00271
00275 private $_skinObj;
00276
00280 private $_testCaseRoot;
00281
00285 private $_testCaseFilesArr;
00286
00290 private $_numOfTestCases;
00291
00296 private $_currentTestCase;
00297
00301 private $_bOnlyReportFailes;
00302
00306 private $_bReportFailDetails;
00307
00311 private $_bRunAllTests;
00312 }
00313 ?>