/** * Start test plan. * * @param string $size size of the site. */ public static function start_testplan($size) { global $CFG; $urlcomponents = parse_url($CFG->wwwroot); if (empty($urlcomponents['path'])) { $urlcomponents['path'] = ''; } // Update fixed attributes. $propertiestoupdate = array('moodleversion' => $CFG->version, 'dataplansize' => get_config('core', 'performancesitedata'), 'host' => $urlcomponents['host'], 'sitepath' => $urlcomponents['path'], 'dataplanversion' => dataplanutil::get_tool_version(), 'testplansize' => $size, 'testplanversion' => util::get_tool_version()); foreach ($propertiestoupdate as $prop => $value) { $list['//elementProp[@name=\'' . $prop . '\']//stringProp[@name=\'Argument.value\']'] = $value; } // Update throughput and any other global value found. $globalconfig = util::get_config(); $globalconfig = $globalconfig['global']; foreach ($globalconfig as $key => $value) { if (is_array($value)) { $value = $value[$size]; } $list['//stringProp[@name=\'' . $key . '\']'] = '${__property(throughput,throughput,' . $value . ')}'; } self::replace_append_xml_in_testplan($list); }
/** * Enables test mode * * It uses CFG->dataroot/performance * * Starts the test mode checking the composer installation and * the test environment and updating the available * features and steps definitions. * * Stores a file in dataroot/performance to allow Moodle to switch * to the test environment when using cli-server. * * @param string $sitesize size of site * @param string $optionaltestdata (optional), replace default template with this value. * @throws performance_exception * @return int */ public static function enable_performance_sitemode($sitesize, $optionaltestdata = '') { global $CFG; if (!defined('PERFORMANCE_SITE_GENERATOR')) { self::performance_exception('This method can be only used by performance site generator.'); } // Checks the behat set up and the PHP version. if ($errorcode = self::check_setup_problem()) { return $errorcode; } // Check that test environment is correctly set up. if (self::test_environment_problem() !== self::SITE_ERROR_INSTALLED) { return $errorcode; } // Make it a performance site, we have already checked for tables. if (!self::is_performance_site() && empty(get_config('core', 'perfromancesitehash'))) { self::store_versions_hash(); } util::get_performance_dir(true); // Add moodle release and tool hash to performancesite.txt. $release = null; require "{$CFG->dirroot}/version.php"; $contents = "release=" . $release . PHP_EOL; if ($hash = util::get_performance_tool_hash()) { $contents .= "hash=" . $hash . PHP_EOL; } // Add tool version to the file. This will help identify the tool version used to generate site. $generatorconfig = util::get_tool_version(); $contents .= "generatorversion=" . $generatorconfig . PHP_EOL; // Add feature data hash. $featuresethash = md5(serialize($optionaltestdata)); $contents .= "featurehash=" . $featuresethash . PHP_EOL; // Finally add site size. $contents .= "sitesize=" . $sitesize . PHP_EOL; $filepath = util::get_tool_dir() . DIRECTORY_SEPARATOR . 'performancesite.txt'; if (!file_put_contents($filepath, $contents)) { echo 'File ' . $filepath . ' can not be created' . PHP_EOL; exit(1); } util::create_test_feature($sitesize, $optionaltestdata); return 0; }