first commit

This commit is contained in:
CHIEFSOFT\ameye
2024-09-30 18:11:26 -04:00
commit e592ca6823
27270 changed files with 5002257 additions and 0 deletions
+126
View File
@@ -0,0 +1,126 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* CLI interface for creating a test course.
*
* @package tool_generator
* @copyright 2013 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
define('CLI_SCRIPT', true);
define('NO_OUTPUT_BUFFERING', true);
require(__DIR__ . '/../../../../config.php');
require_once($CFG->libdir. '/clilib.php');
// CLI options.
list($options, $unrecognized) = cli_get_params(
array(
'help' => false,
'shortname' => false,
'fullname' => false,
'summary' => false,
'size' => false,
'fixeddataset' => false,
'filesizelimit' => false,
'bypasscheck' => false,
'additionalmodules' => "",
'quiet' => false
),
array(
'h' => 'help'
)
);
// Display help.
if (!empty($options['help']) || empty($options['shortname']) || empty($options['size'])) {
echo "
Utility to create standard test course. (Also available in GUI interface.)
Not for use on live sites; only normally works if debugging is set to DEVELOPER
level.
Options:
--shortname Shortname of course to create (required)
--fullname Fullname of course to create (optional)
--summary Course summary, in double quotes (optional)
--size Size of course to create XS, S, M, L, XL, or XXL (required)
--fixeddataset Use a fixed data set instead of randomly generated data
--filesizelimit Limits the size of the generated files to the specified bytes
--bypasscheck Bypasses the developer-mode check (be careful!)
--additionalmodules Additional modules to be created when creating a course: a comma separated modules names without the mod_prefix
(like quiz, forum...)
--quiet Do not show any output
-h, --help Print out this help
Example from Moodle root directory:
\$ php admin/tool/generator/cli/maketestcourse.php --shortname=SIZE_S --size=S
";
// Exit with error unless we're showing this because they asked for it.
exit(empty($options['help']) ? 1 : 0);
}
// Check debugging is set to developer level.
if (empty($options['bypasscheck']) && !debugging('', DEBUG_DEVELOPER)) {
cli_error(get_string('error_notdebugging', 'tool_generator'));
}
// Get options.
$shortname = $options['shortname'];
$fullname = $options['fullname'];
$summary = $options['summary'];
$sizename = $options['size'];
$fixeddataset = $options['fixeddataset'];
$filesizelimit = $options['filesizelimit'];
// Check size.
try {
$size = tool_generator_course_backend::size_for_name($sizename);
} catch (coding_exception $e) {
cli_error("Invalid size ($sizename). Use --help for help.");
}
// Check shortname.
if ($error = tool_generator_course_backend::check_shortname_available($shortname)) {
cli_error($error);
}
// Switch to admin user account.
\core\session\manager::set_user(get_admin());
$additionalmodulesarray = [];
if (!empty($options['additionalmodules'])) {
$additionalmodulesarray = explode(',', trim($options['additionalmodules']));
}
// Do backend code to generate course.
$backend = new tool_generator_course_backend(
$shortname,
$size,
$fixeddataset,
$filesizelimit,
empty($options['quiet']),
$fullname,
$summary,
FORMAT_HTML,
$additionalmodulesarray
);
$id = $backend->make();
if (empty($options['quiet'])) {
echo PHP_EOL.'Generated course: '.course_get_url($id).PHP_EOL;
}
+122
View File
@@ -0,0 +1,122 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* CLI interface for creating a test plan
*
* @package tool_generator
* @copyright 2013 David Monllaó
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
define('CLI_SCRIPT', true);
define('NO_OUTPUT_BUFFERING', true);
require(__DIR__ . '/../../../../config.php');
require_once($CFG->libdir. '/clilib.php');
// CLI options.
list($options, $unrecognized) = cli_get_params(
array(
'help' => false,
'shortname' => false,
'size' => false,
'bypasscheck' => false,
'updateuserspassword' => false
),
array(
'h' => 'help'
)
);
$testplansizes = '* ' . implode(PHP_EOL . '* ', tool_generator_testplan_backend::get_size_choices());
// Display help.
if (!empty($options['help']) || empty($options['shortname']) || empty($options['size'])) {
echo get_string('testplanexplanation', 'tool_generator', tool_generator_testplan_backend::get_repourl()) .
"Options:
-h, --help Print out this help
--shortname Shortname of the test plan's target course (required)
--size Size of the test plan to create XS, S, M, L, XL, or XXL (required)
--bypasscheck Bypasses the developer-mode check (be careful!)
--updateuserspassword Updates the target course users password according to \$CFG->tool_generator_users_password
$testplansizes
Consider that, the server resources you will need to run the test plan will be higher as the test plan size is higher.
Example from Moodle root directory:
\$ sudo -u www-data /usr/bin/php admin/tool/generator/cli/maketestplan.php --shortname=\"testcourse_12\" --size=S
";
// Exit with error unless we're showing this because they asked for it.
exit(empty($options['help']) ? 1 : 0);
}
// Check debugging is set to developer level.
if (empty($options['bypasscheck']) && !$CFG->debugdeveloper) {
cli_error(get_string('error_notdebugging', 'tool_generator'));
}
// Get options.
$shortname = $options['shortname'];
$sizename = $options['size'];
// Check size.
try {
$size = tool_generator_testplan_backend::size_for_name($sizename);
} catch (coding_exception $e) {
cli_error("Error: Invalid size ($sizename). Use --help for help.");
}
// Check selected course.
if ($errors = tool_generator_testplan_backend::has_selected_course_any_problem($shortname, $size)) {
// Showing the first reported problem.
cli_error("Error: " . reset($errors));
}
// Checking if test users password is set.
if (empty($CFG->tool_generator_users_password) || is_bool($CFG->tool_generator_users_password)) {
cli_error("Error: " . get_string('error_nouserspassword', 'tool_generator'));
}
// Switch to admin user account.
\core\session\manager::set_user(get_admin());
// Create files.
$courseid = $DB->get_field('course', 'id', array('shortname' => $shortname));
$usersfile = tool_generator_testplan_backend::create_users_file($courseid, !empty($options['updateuserspassword']), $size);
$testplanfile = tool_generator_testplan_backend::create_testplan_file($courseid, $size);
// One file path per line so other CLI scripts can easily parse the output.
echo moodle_url::make_pluginfile_url(
$testplanfile->get_contextid(),
$testplanfile->get_component(),
$testplanfile->get_filearea(),
$testplanfile->get_itemid(),
$testplanfile->get_filepath(),
$testplanfile->get_filename()
) .
PHP_EOL .
moodle_url::make_pluginfile_url(
$usersfile->get_contextid(),
$usersfile->get_component(),
$usersfile->get_filearea(),
$usersfile->get_itemid(),
$usersfile->get_filepath(),
$usersfile->get_filename()
) .
PHP_EOL;
+98
View File
@@ -0,0 +1,98 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* CLI interface for creating a test site.
*
* @package tool_generator
* @copyright 2013 David Monllaó
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
define('CLI_SCRIPT', true);
define('NO_OUTPUT_BUFFERING', true);
require(__DIR__ . '/../../../../config.php');
require_once($CFG->libdir. '/clilib.php');
// CLI options.
list($options, $unrecognized) = cli_get_params(
array(
'help' => false,
'size' => false,
'fixeddataset' => false,
'filesizelimit' => false,
'bypasscheck' => false,
'quiet' => false
),
array(
'h' => 'help'
)
);
$sitesizes = '* ' . implode(PHP_EOL . '* ', tool_generator_site_backend::get_size_choices());
// Display help.
if (!empty($options['help']) || empty($options['size'])) {
echo "
Utility to generate a standard test site data set.
Not for use on live sites; only normally works if debugging is set to DEVELOPER
level.
Consider that, depending on the size you select, this CLI tool can really generate a lot of data, aproximated sizes:
$sitesizes
Options:
--size Size of the generated site, this value affects the number of courses and their size. Accepted values: XS, S, M, L, XL, or XXL (required)
--fixeddataset Use a fixed data set instead of randomly generated data
--filesizelimit Limits the size of the generated files to the specified bytes
--bypasscheck Bypasses the developer-mode check (be careful!)
--quiet Do not show any output
-h, --help Print out this help
Example from Moodle root directory:
\$ php admin/tool/generator/cli/maketestsite.php --size=S
";
// Exit with error unless we're showing this because they asked for it.
exit(empty($options['help']) ? 1 : 0);
}
// Check debugging is set to developer level.
if (empty($options['bypasscheck']) && !$CFG->debugdeveloper) {
cli_error(get_string('error_notdebugging', 'tool_generator'));
}
// Get options.
$sizename = $options['size'];
$fixeddataset = $options['fixeddataset'];
$filesizelimit = $options['filesizelimit'];
// Check size.
try {
$size = tool_generator_site_backend::size_for_name($sizename);
} catch (coding_exception $e) {
cli_error("Invalid size ($sizename). Use --help for help.");
}
// Switch to admin user account.
\core\session\manager::set_user(get_admin());
// Do backend code to generate site.
$backend = new tool_generator_site_backend($size, $options['bypasscheck'], $fixeddataset, $filesizelimit, empty($options['quiet']));
$backend->make();
@@ -0,0 +1,181 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Run a test scenario generator feature file.
*
* @package tool_generator
* @copyright 2023 Ferran Recio <ferran@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
if (isset($_SERVER['REMOTE_ADDR'])) {
die(); // No access from web!
}
define('CLI_SCRIPT', true);
require_once(__DIR__ . '/../../../../config.php');
require_once(__DIR__ . '/../../../../lib/clilib.php');
require_once(__DIR__ . '/../../../../lib/behat/classes/behat_config_manager.php');
require_once(__DIR__ . '/../../../../lib/testing/lib.php');
ini_set('display_errors', '1');
ini_set('log_errors', '1');
list($options, $unrecognised) = cli_get_params(
[
'help' => false,
'feature' => '',
'disable-composer' => false,
'composer-upgrade' => true,
'composer-self-update' => true,
],
[
'h' => 'help',
'f' => 'feature',
]
);
// Checking run.php CLI script usage.
$help = "
Run a feature file into the current Moodle instance. The feature file can only
contains scenarios with core_data_generator steps. It is not yet compatible
with scenario outlines. All scenarios will be executed at once, event background
steps.
Usage:
php runtestscenario.php [--feature=\"value\"] [--help]
[--no-composer-self-update] [--no-composer-upgrade]
[--disable-composer]
Options:
-f, --feature Execute specified feature file (Absolute path of feature file).
--no-composer-self-update
Prevent upgrade of the composer utility using its self-update command
--no-composer-upgrade
Prevent update development dependencies using composer
--disable-composer
A shortcut to disable composer self-update and dependency update
Note: Installation of composer and/or dependencies will still happen as required
-h, --help Print out this help
Example from Moodle root directory:
\$ php admin/tool/generator/cli/runtestscenario.php --feature=/path/to/some/testing/scenario.feature
";
if (!empty($options['help'])) {
echo $help;
exit(0);
}
// The command will install composer if not present. Usually composer libraries are
// installed when behat or phpunit are installed, but we do not want to force users
// to create all phpunit or behat databases tables just to run a test scenario locally.
if (!file_exists($CFG->dirroot . '/vendor/autoload.php')) {
// Force OPcache reset if used, we do not want any stale caches
// when preparing test environment.
if (function_exists('opcache_reset')) {
opcache_reset();
}
if ($options['disable-composer']) {
// Disable self-update and upgrade easily.
// Note: Installation will still occur regardless of this setting.
$options['composer-self-update'] = false;
$options['composer-upgrade'] = false;
}
// Install and update composer and dependencies as required.
testing_update_composer_dependencies($options['composer-self-update'], $options['composer-upgrade']);
}
if (empty($options['feature'])) {
echo "Missing feature file path.\n";
exit(0);
}
$featurefile = $options['feature'];
if (!file_exists($featurefile)) {
echo "Feature file not found.\n";
exit(0);
}
// Switch to admin user account.
\core\session\manager::set_user(get_admin());
$runner = new tool_generator\local\testscenario\runner();
try {
$runner->init();
} catch (Exception $e) {
echo "Something is wrong with the behat setup.\n";
echo " Please,try running \"php admin/tool/behat/cli/init.php\" from your Moodle root directory.\n";
exit(0);
}
$content = file_get_contents($featurefile);
if (empty($content)) {
echo "The feature file is empty.\n";
exit(0);
}
try {
$parsedfeature = $runner->parse_feature($content);
} catch (\Exception $error) {
echo "Error parsing feature file: {$error->getMessage()}\n";
echo "Use the web version of the tool to see the parsing details:\n";
echo " Site administration -> development -> Create testing scenarios\n";
exit(0);
}
if (!$parsedfeature->is_valid()) {
echo "The file is not valid: {$parsedfeature->get_general_error()}\n";
echo "Use the web version of the tool to see the details:\n";
echo " Site administration -> development -> Create testing scenarios\n";
exit(0);
}
$total = 0;
$success = 0;
foreach ($parsedfeature->get_all_steps() as $step) {
if ($step->execute()) {
echo "\nOK: {$step->get_text()}\n";
echo "{$step->get_arguments_string()}\n";
$success++;
} else {
echo "\nFAIL: {$step->get_text()}\n";
echo "{$step->get_arguments_string()}\n";
echo "{$step->get_error()}\n";
}
$total++;
}
echo "\n{$success}/{$total} steps executed successfully.\n";
if ($success < $total) {
echo "\nSome steps failed.\n";
exit(1);
} else {
echo "\nAll steps executed successfully.\n";
exit(0);
}