| 1 |
lars |
1 |
<?php
|
|
|
2 |
/* SVN FILE: $Id: test_manager.php 7945 2008-12-19 02:16:01Z gwoo $ */
|
|
|
3 |
/**
|
|
|
4 |
* Short description for file.
|
|
|
5 |
*
|
|
|
6 |
* Long description for file
|
|
|
7 |
*
|
|
|
8 |
* PHP versions 4 and 5
|
|
|
9 |
*
|
|
|
10 |
* CakePHP(tm) Tests <https://trac.cakephp.org/wiki/Developement/TestSuite>
|
|
|
11 |
* Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
|
|
|
12 |
*
|
|
|
13 |
* Licensed under The Open Group Test Suite License
|
|
|
14 |
* Redistributions of files must retain the above copyright notice.
|
|
|
15 |
*
|
|
|
16 |
* @filesource
|
|
|
17 |
* @copyright Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
|
|
|
18 |
* @link https://trac.cakephp.org/wiki/Developement/TestSuite CakePHP(tm) Tests
|
|
|
19 |
* @package cake
|
|
|
20 |
* @subpackage cake.cake.tests.lib
|
|
|
21 |
* @since CakePHP(tm) v 1.2.0.4433
|
|
|
22 |
* @version $Revision: 7945 $
|
|
|
23 |
* @modifiedby $LastChangedBy: gwoo $
|
|
|
24 |
* @lastmodified $Date: 2008-12-18 18:16:01 -0800 (Thu, 18 Dec 2008) $
|
|
|
25 |
* @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
|
|
|
26 |
*/
|
|
|
27 |
define('CORE_TEST_CASES', TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'cases');
|
|
|
28 |
define('CORE_TEST_GROUPS', TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'groups');
|
|
|
29 |
define('APP_TEST_CASES', TESTS . 'cases');
|
|
|
30 |
define('APP_TEST_GROUPS', TESTS . 'groups');
|
|
|
31 |
/**
|
|
|
32 |
* Short description for class.
|
|
|
33 |
*
|
|
|
34 |
* @package cake
|
|
|
35 |
* @subpackage cake.cake.tests.lib
|
|
|
36 |
*/
|
|
|
37 |
class TestManager {
|
|
|
38 |
var $_testExtension = '.test.php';
|
|
|
39 |
var $_groupExtension = '.group.php';
|
|
|
40 |
var $appTest = false;
|
|
|
41 |
var $pluginTest = false;
|
|
|
42 |
/**
|
|
|
43 |
* Constructor for the TestManager class
|
|
|
44 |
*
|
|
|
45 |
* @return void
|
|
|
46 |
* @access public
|
|
|
47 |
*/
|
|
|
48 |
function TestManager() {
|
|
|
49 |
$this->_installSimpleTest();
|
|
|
50 |
if (isset($_GET['app'])) {
|
|
|
51 |
$this->appTest = true;
|
|
|
52 |
}
|
|
|
53 |
if (isset($_GET['plugin'])) {
|
|
|
54 |
$this->pluginTest = $_GET['plugin'];
|
|
|
55 |
}
|
|
|
56 |
}
|
|
|
57 |
/**
|
|
|
58 |
* Includes the required simpletest files in order for the testsuite to run
|
|
|
59 |
*
|
|
|
60 |
* @return void
|
|
|
61 |
* @access public
|
|
|
62 |
*/
|
|
|
63 |
function _installSimpleTest() {
|
|
|
64 |
App::import('Vendor', array(
|
|
|
65 |
'simpletest' . DS . 'unit_tester',
|
|
|
66 |
'simpletest' . DS . 'mock_objects',
|
|
|
67 |
'simpletest' . DS . 'web_tester'
|
|
|
68 |
));
|
|
|
69 |
require_once(CAKE_TESTS_LIB . 'cake_web_test_case.php');
|
|
|
70 |
require_once(CAKE_TESTS_LIB . 'cake_test_case.php');
|
|
|
71 |
}
|
|
|
72 |
/**
|
|
|
73 |
* Runs all tests in the Application depending on the current appTest setting
|
|
|
74 |
*
|
|
|
75 |
* @param string $reporter
|
|
|
76 |
* @return void
|
|
|
77 |
* @access public
|
|
|
78 |
*/
|
|
|
79 |
function runAllTests(&$reporter, $testing = false) {
|
|
|
80 |
$manager =& new TestManager();
|
|
|
81 |
|
|
|
82 |
$testCases =& $manager->_getTestFileList($manager->_getTestsPath());
|
|
|
83 |
if ($manager->appTest) {
|
|
|
84 |
$test =& new GroupTest('All App Tests');
|
|
|
85 |
} else if ($manager->pluginTest) {
|
|
|
86 |
$test =& new GroupTest('All ' . Inflector::humanize($manager->pluginTest) . ' Plugin Tests');
|
|
|
87 |
} else {
|
|
|
88 |
$test =& new GroupTest('All Core Tests');
|
|
|
89 |
}
|
|
|
90 |
|
|
|
91 |
if ($testing) {
|
|
|
92 |
return $testCases;
|
|
|
93 |
}
|
|
|
94 |
|
|
|
95 |
foreach ($testCases as $testCase) {
|
|
|
96 |
$test->addTestFile($testCase);
|
|
|
97 |
}
|
|
|
98 |
|
|
|
99 |
return $test->run($reporter);
|
|
|
100 |
}
|
|
|
101 |
/**
|
|
|
102 |
* Runs a specific test case file
|
|
|
103 |
*
|
|
|
104 |
* @param string $testCaseFile
|
|
|
105 |
* @param string $reporter
|
|
|
106 |
* @return void
|
|
|
107 |
* @access public
|
|
|
108 |
*/
|
|
|
109 |
function runTestCase($testCaseFile, &$reporter, $testing = false) {
|
|
|
110 |
$manager =& new TestManager();
|
|
|
111 |
|
|
|
112 |
$testCaseFileWithPath = $manager->_getTestsPath() . DS . $testCaseFile;
|
|
|
113 |
|
|
|
114 |
if (!file_exists($testCaseFileWithPath)) {
|
|
|
115 |
trigger_error("Test case {$testCaseFile} cannot be found", E_USER_ERROR);
|
|
|
116 |
return false;
|
|
|
117 |
}
|
|
|
118 |
|
|
|
119 |
if ($testing) {
|
|
|
120 |
return true;
|
|
|
121 |
}
|
|
|
122 |
|
|
|
123 |
$test =& new GroupTest("Individual test case: " . $testCaseFile);
|
|
|
124 |
$test->addTestFile($testCaseFileWithPath);
|
|
|
125 |
return $test->run($reporter);
|
|
|
126 |
}
|
|
|
127 |
/**
|
|
|
128 |
* Runs a specific group test file
|
|
|
129 |
*
|
|
|
130 |
* @param string $groupTestName
|
|
|
131 |
* @param string $reporter
|
|
|
132 |
* @return void
|
|
|
133 |
* @access public
|
|
|
134 |
*/
|
|
|
135 |
function runGroupTest($groupTestName, &$reporter) {
|
|
|
136 |
$manager =& new TestManager();
|
|
|
137 |
$filePath = $manager->_getTestsPath('groups') . DS . strtolower($groupTestName) . $manager->_groupExtension;
|
|
|
138 |
|
|
|
139 |
if (!file_exists($filePath)) {
|
|
|
140 |
trigger_error("Group test {$groupTestName} cannot be found at {$filePath}", E_USER_ERROR);
|
|
|
141 |
}
|
|
|
142 |
|
|
|
143 |
require_once $filePath;
|
|
|
144 |
$test =& new GroupTest($groupTestName . ' group test');
|
|
|
145 |
foreach ($manager->_getGroupTestClassNames($filePath) as $groupTest) {
|
|
|
146 |
$testCase = new $groupTest();
|
|
|
147 |
$test->addTestCase($testCase);
|
|
|
148 |
if (isset($testCase->label)) {
|
|
|
149 |
$test->_label = $testCase->label;
|
|
|
150 |
}
|
|
|
151 |
}
|
|
|
152 |
return $test->run($reporter);
|
|
|
153 |
}
|
|
|
154 |
/**
|
|
|
155 |
* Adds all testcases in a given directory to a given GroupTest object
|
|
|
156 |
*
|
|
|
157 |
* @param string $groupTest
|
|
|
158 |
* @param string $directory
|
|
|
159 |
* @return void
|
|
|
160 |
* @access public
|
|
|
161 |
*/
|
|
|
162 |
function addTestCasesFromDirectory(&$groupTest, $directory = '.') {
|
|
|
163 |
$manager =& new TestManager();
|
|
|
164 |
$testCases =& $manager->_getTestFileList($directory);
|
|
|
165 |
foreach ($testCases as $testCase) {
|
|
|
166 |
$groupTest->addTestFile($testCase);
|
|
|
167 |
}
|
|
|
168 |
}
|
|
|
169 |
/**
|
|
|
170 |
* Adds a specific test file and thereby all of its test cases and group tests to a given group test file
|
|
|
171 |
*
|
|
|
172 |
* @param string $groupTest
|
|
|
173 |
* @param string $file
|
|
|
174 |
* @return void
|
|
|
175 |
* @access public
|
|
|
176 |
*/
|
|
|
177 |
function addTestFile(&$groupTest, $file) {
|
|
|
178 |
$manager =& new TestManager();
|
|
|
179 |
|
|
|
180 |
if (file_exists($file.'.test.php')) {
|
|
|
181 |
$file .= '.test.php';
|
|
|
182 |
} elseif (file_exists($file.'.group.php')) {
|
|
|
183 |
$file .= '.group.php';
|
|
|
184 |
}
|
|
|
185 |
$groupTest->addTestFile($file);
|
|
|
186 |
}
|
|
|
187 |
/**
|
|
|
188 |
* Returns a list of test cases found in the current valid test case path
|
|
|
189 |
*
|
|
|
190 |
* @access public
|
|
|
191 |
*/
|
|
|
192 |
function &getTestCaseList() {
|
|
|
193 |
$manager =& new TestManager();
|
|
|
194 |
$return = $manager->_getTestCaseList($manager->_getTestsPath());
|
|
|
195 |
return $return;
|
|
|
196 |
}
|
|
|
197 |
/**
|
|
|
198 |
* Builds the list of test cases from a given directory
|
|
|
199 |
*
|
|
|
200 |
* @access public
|
|
|
201 |
*/
|
|
|
202 |
function &_getTestCaseList($directory = '.') {
|
|
|
203 |
$fileList =& $this->_getTestFileList($directory);
|
|
|
204 |
$testCases = array();
|
|
|
205 |
foreach ($fileList as $testCaseFile) {
|
|
|
206 |
$testCases[$testCaseFile] = str_replace($directory . DS, '', $testCaseFile);
|
|
|
207 |
}
|
|
|
208 |
return $testCases;
|
|
|
209 |
}
|
|
|
210 |
/**
|
|
|
211 |
* Returns a list of test files from a given directory
|
|
|
212 |
*
|
|
|
213 |
* @access public
|
|
|
214 |
*/
|
|
|
215 |
function &_getTestFileList($directory = '.') {
|
|
|
216 |
$return = $this->_getRecursiveFileList($directory, array(&$this, '_isTestCaseFile'));
|
|
|
217 |
return $return;
|
|
|
218 |
}
|
|
|
219 |
/**
|
|
|
220 |
* Returns a list of group tests found in the current valid test case path
|
|
|
221 |
*
|
|
|
222 |
* @access public
|
|
|
223 |
*/
|
|
|
224 |
function &getGroupTestList() {
|
|
|
225 |
$manager =& new TestManager();
|
|
|
226 |
$return = $manager->_getTestGroupList($manager->_getTestsPath('groups'));
|
|
|
227 |
return $return;
|
|
|
228 |
}
|
|
|
229 |
/**
|
|
|
230 |
* Returns a list of group test files from a given directory
|
|
|
231 |
*
|
|
|
232 |
* @access public
|
|
|
233 |
*/
|
|
|
234 |
function &_getTestGroupFileList($directory = '.') {
|
|
|
235 |
$return = $this->_getRecursiveFileList($directory, array(&$this, '_isTestGroupFile'));
|
|
|
236 |
return $return;
|
|
|
237 |
}
|
|
|
238 |
/**
|
|
|
239 |
* Returns a list of group test files from a given directory
|
|
|
240 |
*
|
|
|
241 |
* @access public
|
|
|
242 |
*/
|
|
|
243 |
function &_getTestGroupList($directory = '.') {
|
|
|
244 |
$fileList =& $this->_getTestGroupFileList($directory);
|
|
|
245 |
$groupTests = array();
|
|
|
246 |
|
|
|
247 |
foreach ($fileList as $groupTestFile) {
|
|
|
248 |
$groupTests[$groupTestFile] = str_replace($this->_groupExtension, '', basename($groupTestFile));
|
|
|
249 |
}
|
|
|
250 |
sort($groupTests);
|
|
|
251 |
return $groupTests;
|
|
|
252 |
}
|
|
|
253 |
/**
|
|
|
254 |
* Returns a list of class names from a group test file
|
|
|
255 |
*
|
|
|
256 |
* @access public
|
|
|
257 |
*/
|
|
|
258 |
function &_getGroupTestClassNames($groupTestFile) {
|
|
|
259 |
$file = implode("\n", file($groupTestFile));
|
|
|
260 |
preg_match("~lass\s+?(.*)\s+?extends GroupTest~", $file, $matches);
|
|
|
261 |
if (!empty($matches)) {
|
|
|
262 |
unset($matches[0]);
|
|
|
263 |
return $matches;
|
|
|
264 |
}
|
|
|
265 |
return array();
|
|
|
266 |
}
|
|
|
267 |
/**
|
|
|
268 |
* Gets a recursive list of files from a given directory and matches then against
|
|
|
269 |
* a given fileTestFunction, like isTestCaseFile()
|
|
|
270 |
*
|
|
|
271 |
* @access public
|
|
|
272 |
*/
|
|
|
273 |
function &_getRecursiveFileList($directory = '.', $fileTestFunction) {
|
|
|
274 |
$fileList = array();
|
|
|
275 |
if (!is_dir($directory)) {
|
|
|
276 |
return $fileList;
|
|
|
277 |
}
|
|
|
278 |
|
|
|
279 |
$files = glob($directory . DS . '*');
|
|
|
280 |
foreach ($files as $file) {
|
|
|
281 |
if (is_dir($file)) {
|
|
|
282 |
$fileList = array_merge($fileList, $this->_getRecursiveFileList($file, $fileTestFunction));
|
|
|
283 |
} elseif ($fileTestFunction[0]->$fileTestFunction[1]($file)) {
|
|
|
284 |
$fileList[] = $file;
|
|
|
285 |
}
|
|
|
286 |
}
|
|
|
287 |
return $fileList;
|
|
|
288 |
}
|
|
|
289 |
/**
|
|
|
290 |
* Tests if a file has the correct test case extension
|
|
|
291 |
*
|
|
|
292 |
* @param string $file
|
|
|
293 |
* @return void
|
|
|
294 |
* @access public
|
|
|
295 |
*/
|
|
|
296 |
function _isTestCaseFile($file) {
|
|
|
297 |
return $this->_hasExpectedExtension($file, $this->_testExtension);
|
|
|
298 |
}
|
|
|
299 |
/**
|
|
|
300 |
* Tests if a file has the correct group test extension
|
|
|
301 |
*
|
|
|
302 |
* @param string $file
|
|
|
303 |
* @return void
|
|
|
304 |
* @access public
|
|
|
305 |
*/
|
|
|
306 |
function _isTestGroupFile($file) {
|
|
|
307 |
return $this->_hasExpectedExtension($file, $this->_groupExtension);
|
|
|
308 |
}
|
|
|
309 |
/**
|
|
|
310 |
* Check if a file has a specific extension
|
|
|
311 |
*
|
|
|
312 |
* @param string $file
|
|
|
313 |
* @param string $extension
|
|
|
314 |
* @return void
|
|
|
315 |
* @access public
|
|
|
316 |
*/
|
|
|
317 |
function _hasExpectedExtension($file, $extension) {
|
|
|
318 |
return $extension == strtolower(substr($file, (0 - strlen($extension))));
|
|
|
319 |
}
|
|
|
320 |
/**
|
|
|
321 |
* Returns the given path to the test files depending on a given type of tests (cases, group, ..)
|
|
|
322 |
*
|
|
|
323 |
* @param string $type
|
|
|
324 |
* @return void
|
|
|
325 |
* @access public
|
|
|
326 |
*/
|
|
|
327 |
function _getTestsPath($type = 'cases') {
|
|
|
328 |
if (!empty($this->appTest)) {
|
|
|
329 |
if ($type == 'cases') {
|
|
|
330 |
$result = APP_TEST_CASES;
|
|
|
331 |
} else if ($type == 'groups') {
|
|
|
332 |
$result = APP_TEST_GROUPS;
|
|
|
333 |
}
|
|
|
334 |
} else if (!empty($this->pluginTest)) {
|
|
|
335 |
$_pluginBasePath = APP . 'plugins' . DS . $this->pluginTest . DS . 'tests';
|
|
|
336 |
$pluginPaths = Configure::read('pluginPaths');
|
|
|
337 |
foreach ($pluginPaths as $path) {
|
|
|
338 |
if (file_exists($path . $this->pluginTest . DS . 'tests')) {
|
|
|
339 |
$_pluginBasePath = $path . $this->pluginTest . DS . 'tests';
|
|
|
340 |
break;
|
|
|
341 |
}
|
|
|
342 |
}
|
|
|
343 |
$result = $_pluginBasePath . DS . $type;
|
|
|
344 |
} else {
|
|
|
345 |
if ($type == 'cases') {
|
|
|
346 |
$result = CORE_TEST_CASES;
|
|
|
347 |
} else if ($type == 'groups') {
|
|
|
348 |
$result = CORE_TEST_GROUPS;
|
|
|
349 |
}
|
|
|
350 |
}
|
|
|
351 |
return $result;
|
|
|
352 |
}
|
|
|
353 |
/**
|
|
|
354 |
* undocumented function
|
|
|
355 |
*
|
|
|
356 |
* @param string $type
|
|
|
357 |
* @return void
|
|
|
358 |
* @access public
|
|
|
359 |
*/
|
|
|
360 |
function getExtension($type = 'test') {
|
|
|
361 |
$manager =& new TestManager();
|
|
|
362 |
if ($type == 'test') {
|
|
|
363 |
return $manager->_testExtension;
|
|
|
364 |
}
|
|
|
365 |
return $manager->_groupExtension;
|
|
|
366 |
}
|
|
|
367 |
}
|
|
|
368 |
/**
|
|
|
369 |
* The CliTestManager ensures that the list of available files are printed in the correct cli format
|
|
|
370 |
*
|
|
|
371 |
* @package cake
|
|
|
372 |
* @subpackage cake.cake.tests.lib
|
|
|
373 |
*/
|
|
|
374 |
class CliTestManager extends TestManager {
|
|
|
375 |
/**
|
|
|
376 |
* Prints the list of group tests in a cli friendly format
|
|
|
377 |
*
|
|
|
378 |
* @access public
|
|
|
379 |
*/
|
|
|
380 |
function &getGroupTestList() {
|
|
|
381 |
$manager =& new CliTestManager();
|
|
|
382 |
$groupTests =& $manager->_getTestGroupList($manager->_getTestsPath('groups'));
|
|
|
383 |
$buffer = "Available Group Test:\n";
|
|
|
384 |
|
|
|
385 |
foreach ($groupTests as $groupTest) {
|
|
|
386 |
$buffer .= " " . $groupTest . "\n";
|
|
|
387 |
}
|
|
|
388 |
return $buffer . "\n";
|
|
|
389 |
}
|
|
|
390 |
/**
|
|
|
391 |
* Prints the list of test cases in a cli friendly format
|
|
|
392 |
*
|
|
|
393 |
* @access public
|
|
|
394 |
*/
|
|
|
395 |
function &getTestCaseList() {
|
|
|
396 |
$manager =& new CliTestManager();
|
|
|
397 |
$testCases =& $manager->_getTestCaseList($manager->_getTestsPath());
|
|
|
398 |
$buffer = "Available Test Cases:\n";
|
|
|
399 |
|
|
|
400 |
foreach ($testCases as $testCaseFile => $testCase) {
|
|
|
401 |
$buffer .= " " . $testCaseFile . "\n";
|
|
|
402 |
}
|
|
|
403 |
return $buffer . "\n";
|
|
|
404 |
}
|
|
|
405 |
}
|
|
|
406 |
/**
|
|
|
407 |
* The TextTestManager ensures that the list of available tests is printed as a list of urls in a text-friendly format
|
|
|
408 |
*
|
|
|
409 |
* @package cake
|
|
|
410 |
* @subpackage cake.cake.tests.lib
|
|
|
411 |
*/
|
|
|
412 |
class TextTestManager extends TestManager {
|
|
|
413 |
var $_url;
|
|
|
414 |
/**
|
|
|
415 |
* Constructor
|
|
|
416 |
*
|
|
|
417 |
* @return void
|
|
|
418 |
* @access public
|
|
|
419 |
*/
|
|
|
420 |
function TextTestManager() {
|
|
|
421 |
parent::TestManager();
|
|
|
422 |
$this->_url = $_SERVER['PHP_SELF'];
|
|
|
423 |
}
|
|
|
424 |
/**
|
|
|
425 |
* Returns the base url
|
|
|
426 |
*
|
|
|
427 |
* @return void
|
|
|
428 |
* @access public
|
|
|
429 |
*/
|
|
|
430 |
function getBaseURL() {
|
|
|
431 |
return $this->_url;
|
|
|
432 |
}
|
|
|
433 |
/**
|
|
|
434 |
* Returns a list of available group tests in a text-friendly format
|
|
|
435 |
*
|
|
|
436 |
* @access public
|
|
|
437 |
*/
|
|
|
438 |
function &getGroupTestList() {
|
|
|
439 |
$manager =& new TextTestManager();
|
|
|
440 |
$groupTests =& $manager->_getTestGroupList($manager->_getTestsPath('groups'));
|
|
|
441 |
|
|
|
442 |
$buffer = "Core Test Groups:\n";
|
|
|
443 |
$urlExtra = '';
|
|
|
444 |
if ($manager->appTest) {
|
|
|
445 |
$buffer = "App Test Groups:\n";
|
|
|
446 |
$urlExtra = '&app=true';
|
|
|
447 |
} else if ($manager->pluginTest) {
|
|
|
448 |
$buffer = Inflector::humanize($manager->pluginTest) . " Test Groups:\n";
|
|
|
449 |
$urlExtra = '&plugin=' . $manager->pluginTest;
|
|
|
450 |
}
|
|
|
451 |
|
|
|
452 |
$buffer .= "All tests\n" . $_SERVER['SERVER_NAME'] . $manager->getBaseURL() . "?group=all&output=txt{$urlExtra}\n";
|
|
|
453 |
|
|
|
454 |
foreach ((array)$groupTests as $groupTest) {
|
|
|
455 |
$buffer .= $_SERVER['SERVER_NAME']. $manager->getBaseURL()."?group=" . $groupTest . "&output=txt{$urlExtra}"."\n";
|
|
|
456 |
}
|
|
|
457 |
|
|
|
458 |
return $buffer;
|
|
|
459 |
}
|
|
|
460 |
/**
|
|
|
461 |
* Returns a list of available test cases in a text-friendly format
|
|
|
462 |
*
|
|
|
463 |
* @access public
|
|
|
464 |
*/
|
|
|
465 |
function &getTestCaseList() {
|
|
|
466 |
$manager =& new TextTestManager();
|
|
|
467 |
$testCases =& $manager->_getTestCaseList($manager->_getTestsPath());
|
|
|
468 |
|
|
|
469 |
$buffer = "Core Test Cases:\n";
|
|
|
470 |
$urlExtra = '';
|
|
|
471 |
if ($manager->appTest) {
|
|
|
472 |
$buffer = "App Test Cases:\n";
|
|
|
473 |
$urlExtra = '&app=true';
|
|
|
474 |
} else if ($manager->pluginTest) {
|
|
|
475 |
$buffer = Inflector::humanize($manager->pluginTest) . " Test Cases:\n";
|
|
|
476 |
$urlExtra = '&plugin=' . $manager->pluginTest;
|
|
|
477 |
}
|
|
|
478 |
|
|
|
479 |
if (1 > count($testCases)) {
|
|
|
480 |
$buffer .= "EMPTY";
|
|
|
481 |
return $buffer;
|
|
|
482 |
}
|
|
|
483 |
|
|
|
484 |
foreach ($testCases as $testCaseFile => $testCase) {
|
|
|
485 |
$buffer .= $_SERVER['SERVER_NAME']. $manager->getBaseURL()."?case=" . $testCase . "&output=txt"."\n";
|
|
|
486 |
}
|
|
|
487 |
|
|
|
488 |
$buffer .= "\n";
|
|
|
489 |
return $buffer;
|
|
|
490 |
}
|
|
|
491 |
}
|
|
|
492 |
/**
|
|
|
493 |
* The HtmlTestManager provides the foundation for the web-based CakePHP testsuite.
|
|
|
494 |
* It prints the different lists of tests and provides the interface for CodeCoverage, etc.
|
|
|
495 |
*
|
|
|
496 |
* @package cake
|
|
|
497 |
* @subpackage cake.cake.tests.lib
|
|
|
498 |
*/
|
|
|
499 |
class HtmlTestManager extends TestManager {
|
|
|
500 |
var $_url;
|
|
|
501 |
/**
|
|
|
502 |
* Constructor
|
|
|
503 |
*
|
|
|
504 |
* @return void
|
|
|
505 |
* @access public
|
|
|
506 |
*/
|
|
|
507 |
function HtmlTestManager() {
|
|
|
508 |
parent::TestManager();
|
|
|
509 |
$this->_url = $_SERVER['PHP_SELF'];
|
|
|
510 |
}
|
|
|
511 |
/**
|
|
|
512 |
* Returns the current base url
|
|
|
513 |
*
|
|
|
514 |
* @return void
|
|
|
515 |
* @access public
|
|
|
516 |
*/
|
|
|
517 |
function getBaseURL() {
|
|
|
518 |
return $this->_url;
|
|
|
519 |
}
|
|
|
520 |
/**
|
|
|
521 |
* Prints the links to the available group tests
|
|
|
522 |
*
|
|
|
523 |
* @access public
|
|
|
524 |
*/
|
|
|
525 |
function &getGroupTestList() {
|
|
|
526 |
$urlExtra = '';
|
|
|
527 |
$manager =& new HtmlTestManager();
|
|
|
528 |
$groupTests =& $manager->_getTestGroupList($manager->_getTestsPath('groups'));
|
|
|
529 |
|
|
|
530 |
$buffer = "<h3>Core Test Groups:</h3>\n<ul>";
|
|
|
531 |
$urlExtra = null;
|
|
|
532 |
if ($manager->appTest) {
|
|
|
533 |
$buffer = "<h3>App Test Groups:</h3>\n<ul>";
|
|
|
534 |
$urlExtra = '&app=true';
|
|
|
535 |
} else if ($manager->pluginTest) {
|
|
|
536 |
$buffer = "<h3>" . Inflector::humanize($manager->pluginTest) . " Test Groups:</h3>\n<ul>";
|
|
|
537 |
$urlExtra = '&plugin=' . $manager->pluginTest;
|
|
|
538 |
}
|
|
|
539 |
|
|
|
540 |
$buffer .= "<li><a href='" . $manager->getBaseURL() . "?group=all$urlExtra'>All tests</a></li>\n";
|
|
|
541 |
|
|
|
542 |
foreach ($groupTests as $groupTest) {
|
|
|
543 |
$buffer .= "<li><a href='" . $manager->getBaseURL() . "?group={$groupTest}" . "{$urlExtra}'>" . $groupTest . "</a></li>\n";
|
|
|
544 |
}
|
|
|
545 |
$buffer .= "</ul>\n";
|
|
|
546 |
return $buffer;
|
|
|
547 |
}
|
|
|
548 |
/**
|
|
|
549 |
* Prints the links to the available test cases
|
|
|
550 |
*
|
|
|
551 |
* @access public
|
|
|
552 |
*/
|
|
|
553 |
function &getTestCaseList() {
|
|
|
554 |
$urlExtra = '';
|
|
|
555 |
$manager =& new HtmlTestManager();
|
|
|
556 |
$testCases =& $manager->_getTestCaseList($manager->_getTestsPath());
|
|
|
557 |
|
|
|
558 |
$buffer = "<h3>Core Test Cases:</h3>\n<ul>";
|
|
|
559 |
$urlExtra = null;
|
|
|
560 |
if ($manager->appTest) {
|
|
|
561 |
$buffer = "<h3>App Test Cases:</h3>\n<ul>";
|
|
|
562 |
$urlExtra = '&app=true';
|
|
|
563 |
} else if ($manager->pluginTest) {
|
|
|
564 |
$buffer = "<h3>" . Inflector::humanize($manager->pluginTest) . " Test Cases:</h3>\n<ul>";
|
|
|
565 |
$urlExtra = '&plugin=' . $manager->pluginTest;
|
|
|
566 |
}
|
|
|
567 |
|
|
|
568 |
if (1 > count($testCases)) {
|
|
|
569 |
$buffer .= "<strong>EMPTY</strong>";
|
|
|
570 |
return $buffer;
|
|
|
571 |
}
|
|
|
572 |
|
|
|
573 |
foreach ($testCases as $testCaseFile => $testCase) {
|
|
|
574 |
$title = explode(strpos($testCase, '\\') ? '\\' : '/', str_replace('.test.php', '', $testCase));
|
|
|
575 |
$title[count($title) - 1] = Inflector::camelize($title[count($title) - 1]);
|
|
|
576 |
$title = join(' / ', $title);
|
|
|
577 |
|
|
|
578 |
$buffer .= "<li><a href='" . $manager->getBaseURL() . "?case=" . urlencode($testCase) . $urlExtra ."'>" . $title . "</a></li>\n";
|
|
|
579 |
}
|
|
|
580 |
$buffer .= "</ul>\n";
|
|
|
581 |
return $buffer;
|
|
|
582 |
}
|
|
|
583 |
}
|
|
|
584 |
if (function_exists('caketestsgetreporter')) {
|
|
|
585 |
echo "You need a new test.php. \n";
|
|
|
586 |
echo "Try this one: " . CONSOLE_LIBS . "templates" . DS . "skel" . DS . "webroot" . DS . "test.php";
|
|
|
587 |
exit();
|
|
|
588 |
} else {
|
|
|
589 |
/**
|
|
|
590 |
* Returns an object of the currently needed reporter
|
|
|
591 |
*
|
|
|
592 |
* @access public
|
|
|
593 |
*/
|
|
|
594 |
function &CakeTestsGetReporter() {
|
|
|
595 |
static $Reporter = NULL;
|
|
|
596 |
if (!$Reporter) {
|
|
|
597 |
switch (CAKE_TEST_OUTPUT) {
|
|
|
598 |
case CAKE_TEST_OUTPUT_HTML:
|
|
|
599 |
require_once CAKE_TESTS_LIB . 'cake_reporter.php';
|
|
|
600 |
$Reporter =& new CakeHtmlReporter();
|
|
|
601 |
break;
|
|
|
602 |
default:
|
|
|
603 |
$Reporter =& new TextReporter();
|
|
|
604 |
break;
|
|
|
605 |
}
|
|
|
606 |
}
|
|
|
607 |
return $Reporter;
|
|
|
608 |
}
|
|
|
609 |
/**
|
|
|
610 |
* Provides the "Run More" links in the testsuite interface
|
|
|
611 |
*
|
|
|
612 |
* @return void
|
|
|
613 |
* @access public
|
|
|
614 |
*/
|
|
|
615 |
function CakePHPTestRunMore() {
|
|
|
616 |
switch (CAKE_TEST_OUTPUT) {
|
|
|
617 |
case CAKE_TEST_OUTPUT_HTML:
|
|
|
618 |
if (isset($_GET['group'])) {
|
|
|
619 |
if (isset($_GET['app'])) {
|
|
|
620 |
$show = '?show=groups&app=true';
|
|
|
621 |
} else if (isset($_GET['plugin'])) {
|
|
|
622 |
$show = '?show=groups&plugin=' . $_GET['plugin'];
|
|
|
623 |
} else {
|
|
|
624 |
$show = '?show=groups';
|
|
|
625 |
}
|
|
|
626 |
$query = '?group='.$_GET['group'];
|
|
|
627 |
if (isset($_GET['app'])) {
|
|
|
628 |
$query .= '&app=true';
|
|
|
629 |
} elseif (isset($_GET['plugin'])) {
|
|
|
630 |
$query .= '&plugin=' . $_GET['plugin'];
|
|
|
631 |
}
|
|
|
632 |
}
|
|
|
633 |
if (isset($_GET['case'])) {
|
|
|
634 |
if (isset($_GET['app'])) {
|
|
|
635 |
$show = '?show=cases&app=true';
|
|
|
636 |
} else if (isset($_GET['plugin'])) {
|
|
|
637 |
$show = '?show=cases&plugin=' . $_GET['plugin'];
|
|
|
638 |
} else {
|
|
|
639 |
$show = '?show=cases';
|
|
|
640 |
}
|
|
|
641 |
$query = '?case='.$_GET['case'];
|
|
|
642 |
if (isset($_GET['app'])) {
|
|
|
643 |
$query .= '&app=true';
|
|
|
644 |
} elseif (isset($_GET['plugin'])) {
|
|
|
645 |
$query .= '&plugin=' . $_GET['plugin'];
|
|
|
646 |
}
|
|
|
647 |
}
|
|
|
648 |
ob_start();
|
|
|
649 |
echo "<p><a href='" . RUN_TEST_LINK . $show . "'>Run more tests</a> | <a href='" . RUN_TEST_LINK . $query . "&show_passes=1'>Show Passes</a> | \n";
|
|
|
650 |
|
|
|
651 |
break;
|
|
|
652 |
}
|
|
|
653 |
}
|
|
|
654 |
/**
|
|
|
655 |
* Provides the links to analyzing code coverage
|
|
|
656 |
*
|
|
|
657 |
* @return void
|
|
|
658 |
* @access public
|
|
|
659 |
*/
|
|
|
660 |
function CakePHPTestAnalyzeCodeCoverage() {
|
|
|
661 |
switch (CAKE_TEST_OUTPUT) {
|
|
|
662 |
case CAKE_TEST_OUTPUT_HTML:
|
|
|
663 |
if (isset($_GET['case'])) {
|
|
|
664 |
$query = '?case='.$_GET['case'];
|
|
|
665 |
if (isset($_GET['app'])) {
|
|
|
666 |
$query .= '&app=true';
|
|
|
667 |
} elseif (isset($_GET['plugin'])) {
|
|
|
668 |
$query .= '&plugin=' . $_GET['plugin'];
|
|
|
669 |
}
|
|
|
670 |
} else {
|
|
|
671 |
$query = '?group='.$_GET['group'];
|
|
|
672 |
if (isset($_GET['app'])) {
|
|
|
673 |
$query .= '&app=true';
|
|
|
674 |
} elseif (isset($_GET['plugin'])) {
|
|
|
675 |
$query .= '&plugin=' . $_GET['plugin'];
|
|
|
676 |
}
|
|
|
677 |
}
|
|
|
678 |
$query .= '&code_coverage=true';
|
|
|
679 |
ob_start();
|
|
|
680 |
echo " <a href='" . RUN_TEST_LINK . $query . "'>Analyze Code Coverage</a></p>\n";
|
|
|
681 |
|
|
|
682 |
break;
|
|
|
683 |
}
|
|
|
684 |
}
|
|
|
685 |
/**
|
|
|
686 |
* Prints a list of test cases
|
|
|
687 |
*
|
|
|
688 |
* @return void
|
|
|
689 |
* @access public
|
|
|
690 |
*/
|
|
|
691 |
function CakePHPTestCaseList() {
|
|
|
692 |
switch (CAKE_TEST_OUTPUT) {
|
|
|
693 |
case CAKE_TEST_OUTPUT_HTML:
|
|
|
694 |
ob_start();
|
|
|
695 |
echo HtmlTestManager::getTestCaseList();
|
|
|
696 |
break;
|
|
|
697 |
case CAKE_TEST_OUTPUT_TEXT:
|
|
|
698 |
default:
|
|
|
699 |
echo TextTestManager::getTestCaseList();
|
|
|
700 |
break;
|
|
|
701 |
}
|
|
|
702 |
}
|
|
|
703 |
/**
|
|
|
704 |
* Prints a list of group tests
|
|
|
705 |
*
|
|
|
706 |
* @return void
|
|
|
707 |
* @access public
|
|
|
708 |
*/
|
|
|
709 |
function CakePHPTestGroupTestList() {
|
|
|
710 |
switch (CAKE_TEST_OUTPUT) {
|
|
|
711 |
case CAKE_TEST_OUTPUT_HTML:
|
|
|
712 |
echo HtmlTestManager::getGroupTestList();
|
|
|
713 |
break;
|
|
|
714 |
case CAKE_TEST_OUTPUT_TEXT:
|
|
|
715 |
default:
|
|
|
716 |
echo TextTestManager::getGroupTestList();
|
|
|
717 |
break;
|
|
|
718 |
}
|
|
|
719 |
}
|
|
|
720 |
/**
|
|
|
721 |
* Includes the Testsuite Header
|
|
|
722 |
*
|
|
|
723 |
* @return void
|
|
|
724 |
* @access public
|
|
|
725 |
*/
|
|
|
726 |
function CakePHPTestHeader() {
|
|
|
727 |
switch (CAKE_TEST_OUTPUT) {
|
|
|
728 |
case CAKE_TEST_OUTPUT_HTML:
|
|
|
729 |
ob_start();
|
|
|
730 |
if (!class_exists('dispatcher')) {
|
|
|
731 |
require CAKE . 'dispatcher.php';
|
|
|
732 |
}
|
|
|
733 |
$dispatch =& new Dispatcher();
|
|
|
734 |
$dispatch->baseUrl();
|
|
|
735 |
define('BASE', $dispatch->webroot);
|
|
|
736 |
$baseUrl = BASE;
|
|
|
737 |
$characterSet = 'charset=utf-8';
|
|
|
738 |
include CAKE_TESTS_LIB . 'header.php';
|
|
|
739 |
|
|
|
740 |
break;
|
|
|
741 |
case CAKE_TEST_OUTPUT_TEXT:
|
|
|
742 |
default:
|
|
|
743 |
header('content-type: text/plain');
|
|
|
744 |
break;
|
|
|
745 |
}
|
|
|
746 |
}
|
|
|
747 |
/**
|
|
|
748 |
* Provides the left hand navigation for the testsuite
|
|
|
749 |
*
|
|
|
750 |
* @return void
|
|
|
751 |
* @access public
|
|
|
752 |
*/
|
|
|
753 |
function CakePHPTestSuiteHeader() {
|
|
|
754 |
switch (CAKE_TEST_OUTPUT) {
|
|
|
755 |
case CAKE_TEST_OUTPUT_HTML:
|
|
|
756 |
ob_start();
|
|
|
757 |
$groups = $_SERVER['PHP_SELF'].'?show=groups';
|
|
|
758 |
$cases = $_SERVER['PHP_SELF'].'?show=cases';
|
|
|
759 |
$plugins = Configure::listObjects('plugin');
|
|
|
760 |
include CAKE_TESTS_LIB . 'content.php';
|
|
|
761 |
break;
|
|
|
762 |
}
|
|
|
763 |
}
|
|
|
764 |
/**
|
|
|
765 |
* Provides the testsuite footer text
|
|
|
766 |
*
|
|
|
767 |
* @return void
|
|
|
768 |
* @access public
|
|
|
769 |
*/
|
|
|
770 |
function CakePHPTestSuiteFooter() {
|
|
|
771 |
switch ( CAKE_TEST_OUTPUT) {
|
|
|
772 |
case CAKE_TEST_OUTPUT_HTML:
|
|
|
773 |
ob_start();
|
|
|
774 |
$baseUrl = BASE;
|
|
|
775 |
include CAKE_TESTS_LIB . 'footer.php';
|
|
|
776 |
break;
|
|
|
777 |
}
|
|
|
778 |
}
|
|
|
779 |
}
|
|
|
780 |
?>
|