/** * testCase * * Find the test case for the passed file. The file could itself be a test. * * @param mixed $file * @access public * @return array(type, case) */ function testCase($file) { if (!preg_match('@\\.php$@', $file) || preg_match('@(config|test_app)[\\\\/]@', $file)) { return false; } $return = array('category' => testCategory($file), 'case' => str_replace('.php', '', $file), 'testFile' => false, 'testFileExists' => false); $ds = DIRECTORY_SEPARATOR; if (preg_match('@tests[\\\\/]@', $file)) { if (preg_match('@Test\\.php$@', $file)) { $return['testFile'] = $file; $return['testFileExists'] = true; if ($return['case'] = preg_replace('@.*tests[\\\\/]cases[\\\\/]@', '', $return['case'])) { $return['case'] = str_replace('Test', '', $return['case']); if ($return['category'] === 'core') { $return['case'] = str_replace('/', DIRECTORY_SEPARATOR, str_replace('lib/Cake/tests/Case/', '', $return['case'])); } } } } elseif ($return['category'] === 'core') { $return['testFile'] = preg_replace('@.*lib[\\\\/]Cake[\\\\/]@', 'lib/Cake/tests/Case/', $return['case']) . 'Test.php'; $return['case'] = preg_replace('@.*lib[\\\\/]Cake[\\\\/]@', '', $return['case']); $return['case'][0] = strtoupper($return['case'][0]); } else { $return['testFile'] = preg_replace('@(.*)((?:(?:config|Console|Controller|Lib|locale|Model|plugins|tests|vendors|View|webroot)[\\\\/]).*$|App[-a-z]*$)@', '\\1tests/Case/\\2Test.php', $return['case']); $return['case'] = preg_replace('@.*((?:(?:config|Console|Controller|Lib|locale|Model|plugins|tests|vendors|View|webroot)[\\\\/])|App[-a-z]*$)@', '\\1', $return['case']); } $return['testFileExists'] = file_exists($return['testFile']); return $return; }
/** * testCase * * Find the test case for the passed file. The file could itself be a test. * * @param mixed $file * @access public * @return array(type, case) */ function testCase($file) { if (!preg_match('@\\.php$@', $file) || preg_match('@(config|test_app)[\\\\/]@', $file)) { return false; } $return = array('category' => testCategory($file), 'case' => str_replace('.php', '', $file), 'testFile' => false, 'testFileExists' => false); if (preg_match('@tests[\\\\/]@', $file)) { if (preg_match('@.test\\.php$@', $file)) { $return['testFile'] = $file; $return['testFileExists'] = true; if ($return['case'] = preg_replace('@.*tests[\\\\/]cases[\\\\/]@', '', $return['case'])) { $return['case'] = str_replace('.test', '', $return['case']); } } } elseif ($return['category'] === 'core') { $return['testFile'] = preg_replace('@(.*cake[\\\\/])@', '\\1tests/cases/', $return['case']) . '.test.php'; $return['case'] = str_replace('/', DIRECTORY_SEPARATOR, preg_replace('@.*cake[\\\\/]?@', '', $return['case'])); } else { $return['testFile'] = preg_replace('@(.*)((?:(?:config|controllers|libs|locale|models|plugins|tests|vendors|views)[\\\\/]).*$|app[-a-z]*$)@', '\\1tests/cases/\\2.test.php', $return['case']); $return['case'] = preg_replace('@.*((?:(?:config|controllers|libs|locale|models|plugins|tests|vendors|views)[\\\\/]).*$|app[-a-z]*$)@', '\\1', $return['case']); $map = array('controllers/components' => 'components', 'models/behaviors' => 'behaviors', 'models/datasources' => 'datasources', 'views/helpers' => 'helpers', 'vendors/shells' => 'shells'); foreach ($map as $path => $_type) { if (strpos($return['case'], $path) === 0) { $path = str_replace('/', DIRECTORY_SEPARATOR, $path); $return['case'] = str_replace($path, $_type, $return['case']); break; } } } if ($return['category'] === 'core') { $return['case'] = str_replace('lib/', '', $return['case']); } $return['testFileExists'] = file_exists($return['testFile']); return $return; }