2008-05-30 11:40:08 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2010-01-10 02:24:27 +00:00
|
|
|
* TestManager for CakePHP Test suite.
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
|
|
|
* PHP versions 4 and 5
|
|
|
|
*
|
|
|
|
* CakePHP(tm) Tests <https://trac.cakephp.org/wiki/Developement/TestSuite>
|
2010-01-26 19:18:20 +00:00
|
|
|
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
|
|
|
* Licensed under The Open Group Test Suite License
|
|
|
|
* Redistributions of files must retain the above copyright notice.
|
|
|
|
*
|
2010-01-26 19:18:20 +00:00
|
|
|
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2008-10-30 17:30:26 +00:00
|
|
|
* @link https://trac.cakephp.org/wiki/Developement/TestSuite CakePHP(tm) Tests
|
|
|
|
* @package cake
|
|
|
|
* @subpackage cake.cake.tests.lib
|
|
|
|
* @since CakePHP(tm) v 1.2.0.4433
|
|
|
|
* @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2008-11-08 02:58:37 +00:00
|
|
|
define('CORE_TEST_CASES', TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'cases');
|
|
|
|
define('CORE_TEST_GROUPS', TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'groups');
|
|
|
|
define('APP_TEST_CASES', TESTS . 'cases');
|
|
|
|
define('APP_TEST_GROUPS', TESTS . 'groups');
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
2010-01-26 14:14:47 +00:00
|
|
|
* TestManager is the base class that handles loading and initiating the running
|
2010-01-04 03:48:03 +00:00
|
|
|
* of TestCase and TestSuite classes that the user has selected.
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2008-10-30 17:30:26 +00:00
|
|
|
* @package cake
|
|
|
|
* @subpackage cake.cake.tests.lib
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
|
|
|
class TestManager {
|
2010-01-04 03:48:03 +00:00
|
|
|
/**
|
|
|
|
* Extension suffix for test case files.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
2010-04-04 06:36:12 +00:00
|
|
|
protected $_testExtension = '.test.php';
|
2010-01-04 03:48:03 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Extension suffix for group test case files.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
2010-04-04 06:36:12 +00:00
|
|
|
protected $_groupExtension = '.group.php';
|
2010-01-04 03:48:03 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Is this test an AppTest?
|
|
|
|
*
|
|
|
|
* @var boolean
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $appTest = false;
|
2010-01-04 03:48:03 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Is this test a plugin test?
|
|
|
|
*
|
|
|
|
* @var mixed boolean false or string name of the plugin being used.
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $pluginTest = false;
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-07-30 13:37:06 +00:00
|
|
|
/**
|
|
|
|
* Constructor for the TestManager class
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2010-04-15 02:56:51 +00:00
|
|
|
public function __construct() {
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->_installSimpleTest();
|
|
|
|
if (isset($_GET['app'])) {
|
|
|
|
$this->appTest = true;
|
|
|
|
}
|
|
|
|
if (isset($_GET['plugin'])) {
|
2010-04-23 03:17:11 +00:00
|
|
|
$this->pluginTest = htmlentities($_GET['plugin']);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-07-30 13:37:06 +00:00
|
|
|
/**
|
|
|
|
* Includes the required simpletest files in order for the testsuite to run
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function _installSimpleTest() {
|
2008-11-07 11:33:13 +00:00
|
|
|
App::import('Vendor', array(
|
|
|
|
'simpletest' . DS . 'unit_tester',
|
|
|
|
'simpletest' . DS . 'mock_objects',
|
|
|
|
'simpletest' . DS . 'web_tester'
|
|
|
|
));
|
2008-05-30 11:40:08 +00:00
|
|
|
require_once(CAKE_TESTS_LIB . 'cake_web_test_case.php');
|
|
|
|
require_once(CAKE_TESTS_LIB . 'cake_test_case.php');
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-07-30 13:37:06 +00:00
|
|
|
/**
|
|
|
|
* Runs all tests in the Application depending on the current appTest setting
|
|
|
|
*
|
2010-01-04 03:48:03 +00:00
|
|
|
* @param Object $reporter Reporter object for the tests being run.
|
|
|
|
* @param boolean $testing Are tests supposed to be auto run. Set to true to return testcase list.
|
|
|
|
* @return mixed
|
2008-07-30 13:37:06 +00:00
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function runAllTests(&$reporter, $testing = false) {
|
2010-04-15 02:56:51 +00:00
|
|
|
$testCases = $this->_getTestFileList($this->_getTestsPath());
|
2010-01-10 01:20:13 +00:00
|
|
|
if ($this->appTest) {
|
2010-04-15 02:56:51 +00:00
|
|
|
$test = new TestSuite(__('All App Tests', true));
|
2010-01-10 01:20:13 +00:00
|
|
|
} else if ($this->pluginTest) {
|
2010-04-15 02:56:51 +00:00
|
|
|
$test = new TestSuite(sprintf(__('All %s Plugin Tests', true), Inflector::humanize($this->pluginTest)));
|
2008-05-30 11:40:08 +00:00
|
|
|
} else {
|
2010-04-15 02:56:51 +00:00
|
|
|
$test = new TestSuite(__('All Core Tests', true));
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
|
|
|
|
2008-11-07 16:17:18 +00:00
|
|
|
if ($testing) {
|
|
|
|
return $testCases;
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2008-11-07 11:33:13 +00:00
|
|
|
|
2008-11-07 16:17:18 +00:00
|
|
|
foreach ($testCases as $testCase) {
|
|
|
|
$test->addTestFile($testCase);
|
2008-11-07 11:33:13 +00:00
|
|
|
}
|
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
return $test->run($reporter);
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-07-30 13:37:06 +00:00
|
|
|
/**
|
|
|
|
* Runs a specific test case file
|
|
|
|
*
|
2010-01-04 03:48:03 +00:00
|
|
|
* @param string $testCaseFile Filename of the test to be run.
|
|
|
|
* @param Object $reporter Reporter instance to attach to the test case.
|
|
|
|
* @param boolean $testing Set to true if testing, otherwise test case will be run.
|
2010-01-10 02:22:41 +00:00
|
|
|
* @return mixed Result of test case being run.
|
2008-07-30 13:37:06 +00:00
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function runTestCase($testCaseFile, &$reporter, $testing = false) {
|
2010-01-05 05:09:07 +00:00
|
|
|
$testCaseFileWithPath = $this->_getTestsPath() . DS . $testCaseFile;
|
2008-11-07 11:47:59 +00:00
|
|
|
|
2010-04-23 03:17:11 +00:00
|
|
|
if (!file_exists($testCaseFileWithPath) || strpos($testCaseFileWithPath, '..')) {
|
|
|
|
trigger_error(
|
|
|
|
sprintf(__("Test case %s cannot be found", true), htmlentities($testCaseFile)),
|
|
|
|
E_USER_ERROR
|
|
|
|
);
|
2008-11-07 11:47:59 +00:00
|
|
|
return false;
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2008-11-07 11:47:59 +00:00
|
|
|
|
|
|
|
if ($testing) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-04-15 02:56:51 +00:00
|
|
|
$test = new TestSuite(sprintf(__('Individual test case: %s', true), $testCaseFile));
|
2008-05-30 11:40:08 +00:00
|
|
|
$test->addTestFile($testCaseFileWithPath);
|
|
|
|
return $test->run($reporter);
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-07-30 13:37:06 +00:00
|
|
|
/**
|
|
|
|
* Runs a specific group test file
|
|
|
|
*
|
2010-01-04 03:48:03 +00:00
|
|
|
* @param string $groupTestName GroupTest that you want to run.
|
|
|
|
* @param Object $reporter Reporter instance to use with the group test being run.
|
2010-01-10 02:22:41 +00:00
|
|
|
* @return mixed Results of group test being run.
|
2008-07-30 13:37:06 +00:00
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function runGroupTest($groupTestName, &$reporter) {
|
2010-01-05 05:09:07 +00:00
|
|
|
$filePath = $this->_getTestsPath('groups') . DS . strtolower($groupTestName) . $this->_groupExtension;
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2010-04-23 03:17:11 +00:00
|
|
|
if (!file_exists($filePath) || strpos($testCaseFileWithPath, '..')) {
|
|
|
|
trigger_error(sprintf(
|
|
|
|
__("Group test %s cannot be found at %s", true),
|
|
|
|
htmlentities($groupTestName),
|
|
|
|
htmlentities($filePath)
|
|
|
|
),
|
|
|
|
E_USER_ERROR
|
|
|
|
);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
require_once $filePath;
|
2010-04-15 02:56:51 +00:00
|
|
|
$test = new TestSuite(sprintf(__('%s group test', true), $groupTestName));
|
2010-01-05 05:09:07 +00:00
|
|
|
foreach ($this->_getGroupTestClassNames($filePath) as $groupTest) {
|
2008-05-30 11:40:08 +00:00
|
|
|
$testCase = new $groupTest();
|
|
|
|
$test->addTestCase($testCase);
|
|
|
|
if (isset($testCase->label)) {
|
|
|
|
$test->_label = $testCase->label;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $test->run($reporter);
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-07-30 13:37:06 +00:00
|
|
|
/**
|
|
|
|
* Adds all testcases in a given directory to a given GroupTest object
|
|
|
|
*
|
2010-01-04 03:48:03 +00:00
|
|
|
* @param object $groupTest Instance of TestSuite/GroupTest that files are to be added to.
|
|
|
|
* @param string $directory The directory to add tests from.
|
2008-07-30 13:37:06 +00:00
|
|
|
* @return void
|
|
|
|
* @access public
|
2010-01-10 00:52:52 +00:00
|
|
|
* @static
|
2008-07-30 13:37:06 +00:00
|
|
|
*/
|
2010-04-15 03:24:44 +00:00
|
|
|
public static function addTestCasesFromDirectory(&$groupTest, $directory = '.') {
|
2010-04-15 02:56:51 +00:00
|
|
|
$manager = new TestManager();
|
|
|
|
$testCases = $manager->_getTestFileList($directory);
|
2008-05-30 11:40:08 +00:00
|
|
|
foreach ($testCases as $testCase) {
|
|
|
|
$groupTest->addTestFile($testCase);
|
|
|
|
}
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-07-30 13:37:06 +00:00
|
|
|
/**
|
|
|
|
* Adds a specific test file and thereby all of its test cases and group tests to a given group test file
|
|
|
|
*
|
2010-01-04 03:48:03 +00:00
|
|
|
* @param object $groupTest Instance of TestSuite/GroupTest that a file should be added to.
|
|
|
|
* @param string $file The file name, minus the suffix to add.
|
2008-07-30 13:37:06 +00:00
|
|
|
* @return void
|
|
|
|
* @access public
|
2010-01-10 00:52:52 +00:00
|
|
|
* @static
|
2008-07-30 13:37:06 +00:00
|
|
|
*/
|
2010-04-15 03:24:44 +00:00
|
|
|
public static function addTestFile(&$groupTest, $file) {
|
2010-04-15 02:56:51 +00:00
|
|
|
$manager = new TestManager();
|
2008-06-10 22:38:05 +00:00
|
|
|
|
2010-01-05 05:13:03 +00:00
|
|
|
if (file_exists($file . $manager->_testExtension)) {
|
|
|
|
$file .= $manager->_testExtension;
|
|
|
|
} elseif (file_exists($file . $manager->_groupExtension)) {
|
|
|
|
$file .= $manager->_groupExtension;
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
|
|
|
$groupTest->addTestFile($file);
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-07-30 13:37:06 +00:00
|
|
|
/**
|
|
|
|
* Returns a list of test cases found in the current valid test case path
|
|
|
|
*
|
|
|
|
* @access public
|
2010-01-10 02:22:41 +00:00
|
|
|
* @static
|
2008-07-30 13:37:06 +00:00
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function &getTestCaseList() {
|
2010-04-15 02:56:51 +00:00
|
|
|
$manager = new TestManager();
|
2008-05-30 11:40:08 +00:00
|
|
|
$return = $manager->_getTestCaseList($manager->_getTestsPath());
|
|
|
|
return $return;
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-07-30 13:37:06 +00:00
|
|
|
/**
|
2008-09-07 14:21:21 +00:00
|
|
|
* Builds the list of test cases from a given directory
|
2008-07-30 13:37:06 +00:00
|
|
|
*
|
2010-01-10 00:52:52 +00:00
|
|
|
* @param string $directory Directory to get test case list from.
|
2008-07-30 13:37:06 +00:00
|
|
|
*/
|
2010-04-05 03:21:28 +00:00
|
|
|
protected function &_getTestCaseList($directory = '.') {
|
2010-04-15 02:56:51 +00:00
|
|
|
$fileList = $this->_getTestFileList($directory);
|
2008-05-30 11:40:08 +00:00
|
|
|
$testCases = array();
|
|
|
|
foreach ($fileList as $testCaseFile) {
|
|
|
|
$testCases[$testCaseFile] = str_replace($directory . DS, '', $testCaseFile);
|
|
|
|
}
|
|
|
|
return $testCases;
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-07-30 13:37:06 +00:00
|
|
|
/**
|
2008-09-07 14:21:21 +00:00
|
|
|
* Returns a list of test files from a given directory
|
2008-07-30 13:37:06 +00:00
|
|
|
*
|
2010-01-10 00:52:52 +00:00
|
|
|
* @param string $directory Directory to get test case files from.
|
2008-07-30 13:37:06 +00:00
|
|
|
*/
|
2010-04-05 03:21:28 +00:00
|
|
|
protected function &_getTestFileList($directory = '.') {
|
2008-05-30 11:40:08 +00:00
|
|
|
$return = $this->_getRecursiveFileList($directory, array(&$this, '_isTestCaseFile'));
|
|
|
|
return $return;
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-07-30 13:37:06 +00:00
|
|
|
/**
|
|
|
|
* Returns a list of group tests found in the current valid test case path
|
|
|
|
*
|
|
|
|
* @access public
|
2010-01-10 00:52:52 +00:00
|
|
|
* @static
|
2008-07-30 13:37:06 +00:00
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function &getGroupTestList() {
|
2010-04-15 02:56:51 +00:00
|
|
|
$manager = new TestManager();
|
2008-05-30 11:40:08 +00:00
|
|
|
$return = $manager->_getTestGroupList($manager->_getTestsPath('groups'));
|
|
|
|
return $return;
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-07-30 13:37:06 +00:00
|
|
|
/**
|
|
|
|
* Returns a list of group test files from a given directory
|
|
|
|
*
|
2010-01-04 03:48:03 +00:00
|
|
|
* @param string $directory The directory to get group test files from.
|
2008-07-30 13:37:06 +00:00
|
|
|
*/
|
2010-04-05 03:21:28 +00:00
|
|
|
protected function &_getTestGroupFileList($directory = '.') {
|
2008-05-30 11:40:08 +00:00
|
|
|
$return = $this->_getRecursiveFileList($directory, array(&$this, '_isTestGroupFile'));
|
|
|
|
return $return;
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-07-30 13:37:06 +00:00
|
|
|
/**
|
|
|
|
* Returns a list of group test files from a given directory
|
|
|
|
*
|
2010-01-04 03:48:03 +00:00
|
|
|
* @param string $directory The directory to get group tests from.
|
2008-07-30 13:37:06 +00:00
|
|
|
*/
|
2010-04-05 03:21:28 +00:00
|
|
|
protected function &_getTestGroupList($directory = '.') {
|
2010-04-15 02:56:51 +00:00
|
|
|
$fileList = $this->_getTestGroupFileList($directory);
|
2008-05-30 11:40:08 +00:00
|
|
|
$groupTests = array();
|
|
|
|
|
|
|
|
foreach ($fileList as $groupTestFile) {
|
|
|
|
$groupTests[$groupTestFile] = str_replace($this->_groupExtension, '', basename($groupTestFile));
|
|
|
|
}
|
|
|
|
sort($groupTests);
|
|
|
|
return $groupTests;
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-07-30 13:37:06 +00:00
|
|
|
/**
|
2008-09-07 14:21:21 +00:00
|
|
|
* Returns a list of class names from a group test file
|
2008-07-30 13:37:06 +00:00
|
|
|
*
|
2010-01-04 03:48:03 +00:00
|
|
|
* @param string $groupTestFile The groupTest file to scan for TestSuite classnames.
|
2008-07-30 13:37:06 +00:00
|
|
|
*/
|
2010-04-05 03:21:28 +00:00
|
|
|
protected function &_getGroupTestClassNames($groupTestFile) {
|
2008-05-30 11:40:08 +00:00
|
|
|
$file = implode("\n", file($groupTestFile));
|
2009-09-12 01:43:53 +00:00
|
|
|
preg_match("~lass\s+?(.*)\s+?extends TestSuite~", $file, $matches);
|
2008-11-07 11:33:13 +00:00
|
|
|
if (!empty($matches)) {
|
2008-05-30 11:40:08 +00:00
|
|
|
unset($matches[0]);
|
|
|
|
return $matches;
|
|
|
|
}
|
2009-09-12 01:43:53 +00:00
|
|
|
$matches = array();
|
|
|
|
return $matches;
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-07-30 13:37:06 +00:00
|
|
|
/**
|
|
|
|
* Gets a recursive list of files from a given directory and matches then against
|
|
|
|
* a given fileTestFunction, like isTestCaseFile()
|
|
|
|
*
|
2010-01-04 03:48:03 +00:00
|
|
|
* @param string $directory The directory to scan for files.
|
|
|
|
* @param mixed $fileTestFunction
|
2008-07-30 13:37:06 +00:00
|
|
|
*/
|
2010-04-05 03:21:28 +00:00
|
|
|
protected function &_getRecursiveFileList($directory = '.', $fileTestFunction) {
|
2008-05-30 11:40:08 +00:00
|
|
|
$fileList = array();
|
|
|
|
if (!is_dir($directory)) {
|
|
|
|
return $fileList;
|
|
|
|
}
|
|
|
|
|
2008-11-06 23:35:08 +00:00
|
|
|
$files = glob($directory . DS . '*');
|
2009-02-16 00:45:50 +00:00
|
|
|
$files = $files ? $files : array();
|
|
|
|
|
2008-11-06 23:35:08 +00:00
|
|
|
foreach ($files as $file) {
|
|
|
|
if (is_dir($file)) {
|
|
|
|
$fileList = array_merge($fileList, $this->_getRecursiveFileList($file, $fileTestFunction));
|
|
|
|
} elseif ($fileTestFunction[0]->$fileTestFunction[1]($file)) {
|
|
|
|
$fileList[] = $file;
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return $fileList;
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-07-30 13:37:06 +00:00
|
|
|
/**
|
|
|
|
* Tests if a file has the correct test case extension
|
|
|
|
*
|
2008-09-07 14:21:21 +00:00
|
|
|
* @param string $file
|
2010-01-10 02:22:41 +00:00
|
|
|
* @return boolean Whether $file is a test case.
|
2008-07-30 13:37:06 +00:00
|
|
|
*/
|
2010-04-05 03:21:28 +00:00
|
|
|
protected function _isTestCaseFile($file) {
|
2008-05-30 11:40:08 +00:00
|
|
|
return $this->_hasExpectedExtension($file, $this->_testExtension);
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-07-30 13:37:06 +00:00
|
|
|
/**
|
|
|
|
* Tests if a file has the correct group test extension
|
|
|
|
*
|
2008-09-07 14:21:21 +00:00
|
|
|
* @param string $file
|
2010-01-10 02:22:41 +00:00
|
|
|
* @return boolean Whether $file is a group
|
2008-07-30 13:37:06 +00:00
|
|
|
*/
|
2010-04-05 03:21:28 +00:00
|
|
|
protected function _isTestGroupFile($file) {
|
2008-05-30 11:40:08 +00:00
|
|
|
return $this->_hasExpectedExtension($file, $this->_groupExtension);
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-07-30 13:37:06 +00:00
|
|
|
/**
|
|
|
|
* Check if a file has a specific extension
|
|
|
|
*
|
2008-09-07 14:21:21 +00:00
|
|
|
* @param string $file
|
|
|
|
* @param string $extension
|
2008-07-30 13:37:06 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2010-04-05 03:21:28 +00:00
|
|
|
protected function _hasExpectedExtension($file, $extension) {
|
2008-05-30 11:40:08 +00:00
|
|
|
return $extension == strtolower(substr($file, (0 - strlen($extension))));
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-07-30 13:37:06 +00:00
|
|
|
/**
|
|
|
|
* Returns the given path to the test files depending on a given type of tests (cases, group, ..)
|
|
|
|
*
|
2010-01-04 03:48:03 +00:00
|
|
|
* @param string $type either 'cases' or 'groups'
|
|
|
|
* @return string The path tests are located on
|
2008-07-30 13:37:06 +00:00
|
|
|
*/
|
2010-04-05 03:21:28 +00:00
|
|
|
protected function _getTestsPath($type = 'cases') {
|
2008-05-30 11:40:08 +00:00
|
|
|
if (!empty($this->appTest)) {
|
|
|
|
if ($type == 'cases') {
|
|
|
|
$result = APP_TEST_CASES;
|
|
|
|
} else if ($type == 'groups') {
|
|
|
|
$result = APP_TEST_GROUPS;
|
|
|
|
}
|
|
|
|
} else if (!empty($this->pluginTest)) {
|
2010-04-15 03:31:15 +00:00
|
|
|
$_pluginBasePath = APP . 'plugins/' . $this->pluginTest . '/tests';
|
2009-10-14 13:47:07 +00:00
|
|
|
$pluginPath = App::pluginPath($this->pluginTest);
|
|
|
|
if (file_exists($pluginPath . DS . 'tests')) {
|
|
|
|
$_pluginBasePath = $pluginPath . DS . 'tests';
|
2008-07-30 13:37:06 +00:00
|
|
|
}
|
2008-05-30 11:40:08 +00:00
|
|
|
$result = $_pluginBasePath . DS . $type;
|
|
|
|
} else {
|
|
|
|
if ($type == 'cases') {
|
|
|
|
$result = CORE_TEST_CASES;
|
|
|
|
} else if ($type == 'groups') {
|
|
|
|
$result = CORE_TEST_GROUPS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $result;
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-11-07 11:33:13 +00:00
|
|
|
/**
|
2010-01-04 03:48:03 +00:00
|
|
|
* Get the extension for either 'group' or 'test' types.
|
2008-11-07 11:33:13 +00:00
|
|
|
*
|
2010-01-04 03:48:03 +00:00
|
|
|
* @param string $type Type of test to get, either 'test' or 'group'
|
|
|
|
* @return string Extension suffix for test.
|
2008-11-07 11:33:13 +00:00
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function getExtension($type = 'test') {
|
2010-01-10 02:29:57 +00:00
|
|
|
if ($type == 'test' || $type == 'case') {
|
2010-01-10 02:22:41 +00:00
|
|
|
return $this->_testExtension;
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2010-01-10 02:22:41 +00:00
|
|
|
return $this->_groupExtension;
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
?>
|