/** * Create a skeleton for a unit test. * * @return void */ public function create_skeleton() { $input = JFactory::getApplication()->input; $folder = $input->getString('folder'); $file = $input->getString('file'); $ecr_project = $input->get('ecr_project'); $path = JPATH_ROOT . '/' . $folder . '/' . $file; $response = new stdClass(); $arguments = array(); if (!JFile::exists($path)) { $response->text = jgettext('File not found'); $response->status = 1; } else { if (JFile::getExt($path) != 'php') { $response->text = jgettext('Only PHP files are allowed'); $response->console = $response->text; } else { $classes = get_declared_classes(); include $path; ob_start(); $includedOutput = ob_get_contents(); ob_end_clean(); $foundClasses = array_diff(get_declared_classes(), $classes); if (!count($foundClasses)) { $response->text = jgettext('No classes found'); $response->console = $response->text; } else { $class = array_pop($foundClasses); $resultPath = JPATH_ROOT . '/' . $folder . '/' . $class . 'Test.php'; //-- Joomla! bootstrap $arguments[] = '--bootstrap ' . JPATH_ROOT . '/bootstrap.php'; $arguments[] = '--skeleton-test ' . $class . ' ' . $path; $phpUnit = new EcrPearHelperPhpunit(); ob_start(); $results = $phpUnit->skeleton($arguments); $add = ob_get_contents(); ob_end_clean(); $subFolder = ''; if (JFile::exists($resultPath)) { $scope = strpos($resultPath, JPATH_ADMINISTRATOR) === false ? 'site' : 'admin'; $test = str_replace(basename($resultPath), '', $resultPath); //-- Ensure forward slashes $test = str_replace(DIRECTORY_SEPARATOR, '/', $test); if (strpos($test, JPATH_ADMINISTRATOR) === false) { if ($test != JPATH_SITE . '/components/' . $ecr_project) { //-- Subfolder $subFolder = str_replace(JPATH_SITE . '/components/' . $ecr_project . '/', '', $test); } } else { if ($test != JPATH_ADMINISTRATOR . '/components/' . $ecr_project) { //-- Subfolder $subFolder = str_replace(JPATH_ADMINISTRATOR . '/components/' . $ecr_project . '/', '', $test); } } $destFolder = JPATH_ADMINISTRATOR . '/components/' . $ecr_project . '/tests/' . $scope; $destFolder .= $subFolder ? '/' . $subFolder : ''; $destFileName = $class . 'Test.php'; if (!JFolder::exists($destFolder)) { JFolder::create($destFolder); } if (JFile::move($resultPath, $destFolder . DS . $destFileName)) { $response->status = 1; } else { } } else { } $response->text = $add . $includedOutput; $response->console = htmlentities($results); } } } echo json_encode($response); jexit(); }
<?php /** * @package EasyCreator * @subpackage Views * @author Nikolai Plath * @author Created on 02-Oct-2009 * @license GNU/GPL, see JROOT/LICENSE.php */ //-- No direct access defined('_JEXEC') || die('=;)'); $phpUnit = new EcrPearHelperPhpunit(); if (!$phpUnit->checkEnv()) { echo 'Env check failed.. cannot continue :('; return; } $timeStamp = date('Ymd_his'); ecrLoadMedia('php_file_tree'); $jsFile = ''; $jsFile .= " onclick=\"doSelenium('[link]', '[file]', '{$timeStamp}', '[id]');\""; $jsFolder = ''; $fileTree = new EcrFileTree(JPATH_ROOT . DS . $this->testsBase, '', $jsFile, $jsFolder); ?> <div class="ecr_floatbox"> <strong><?php echo jgettext('Project'); ?> </strong> <div class="ecrBigInfo"> <?php