/** * Updates a config file * * @param array $featurestoadd list of features to add. * @param string $proxy proxy url which will be used for test plan generation example: "localhost:9090" * @return void */ protected static function update_config_file($featurestoadd, $proxy = "") { global $CFG; // Behat must have a separate behat.yml to have access to the whole set of features and steps definitions. $configfilepath = self::get_tool_dir() . DIRECTORY_SEPARATOR . 'behat.yml'; $featurepath = self::get_tool_dir(); // Gets all the components with features. $featureslist = glob("{$featurepath}/*.feature"); $features = array(); foreach ($featurestoadd as $featuretoadd) { $feature = preg_grep('/.\\/' . $featuretoadd . '\\.feature/', $featureslist); if (!empty($feature)) { if (count($feature) > 1) { echo "Found more then 1 feature for the requested order set: ", $featuretoadd . PHP_EOL; } $features = array_merge($features, $feature); } } // Gets all the components with steps definitions. $stepsdefinitions = array(); $steps = \behat_config_manager::get_components_steps_definitions(); if ($steps) { foreach ($steps as $key => $filepath) { $stepsdefinitions[$key] = $filepath; } } // We don't want the deprecated steps definitions here. unset($stepsdefinitions['behat_deprecated']); // Remove default hooks. unset($stepsdefinitions['behat_hooks']); // Add generator contexts. $classname = get_called_class(); preg_match('/.*\\\\([a-z-_]+)\\\\[a-z]+$/i', $classname, $behatcontextdir); $contexts = glob(__DIR__ . "/../" . $behatcontextdir[1] . "/classes/behat_*.php"); foreach ($contexts as $context) { preg_match('/.*\\/(behat_[a-z_].*)\\.php$/', $context, $matches); $classname = $matches[1]; $stepsdefinitions[$classname] = $context; } // Add any other context file defined in config. $generatorconfig = self::get_config(); foreach ($featurestoadd as $featurename) { if (!empty($generatorconfig[$featurename]['contextpath'])) { if (!is_array($generatorconfig[$featurename]['contextpath'])) { $customcontextspaths = array($generatorconfig[$featurename]['contextpath']); } else { $customcontextspaths = $generatorconfig[$featurename]['contextpath']; } foreach ($customcontextspaths as $customcontextpath) { preg_match('/.*\\/(behat_[a-z_].*)\\.php$/', $customcontextpath, $matches); $classname = $matches[1]; $stepsdefinitions[$classname] = $customcontextpath; } } } // Behat config file specifing the main context class, // the required Behat extensions and Moodle test wwwroot. $contents = self::get_config_file_contents($features, $stepsdefinitions, $proxy); // Stores the file. if (!file_put_contents($configfilepath, $contents)) { self::performance_exception('File ' . $configfilepath . ' can not be created'); } }
/** * Web interface to list and filter steps * * @package tool_behat * @copyright 2012 David Monllaó * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ require __DIR__ . '/../../../config.php'; require_once $CFG->libdir . '/adminlib.php'; require_once $CFG->dirroot . '/' . $CFG->admin . '/tool/behat/locallib.php'; require_once $CFG->libdir . '/behat/classes/behat_config_manager.php'; $filter = optional_param('filter', '', PARAM_ALPHANUMEXT); $type = optional_param('type', false, PARAM_ALPHAEXT); $component = optional_param('component', '', PARAM_ALPHAEXT); admin_externalpage_setup('toolbehat'); // Getting available steps definitions from behat. $steps = tool_behat::stepsdefinitions($type, $component, $filter); // Form. $componentswithsteps = array('' => get_string('allavailablesteps', 'tool_behat')); // Complete the components list with the moodle steps definitions. $components = behat_config_manager::get_components_steps_definitions(); if ($components) { foreach ($components as $component => $filepath) { // TODO Use a class static attribute instead of the class name. $componentswithsteps[$component] = 'Moodle ' . substr($component, 6); } } $form = new steps_definitions_form(null, array('components' => $componentswithsteps)); // Output contents. $renderer = $PAGE->get_renderer('tool_behat'); echo $renderer->render_stepsdefinitions($steps, $form);