Ejemplo n.º 1
0
// All session and cookie related stuff
require_once $CFG->libdir . '/editorlib.php';
// All text editor related functions and classes
require_once $CFG->libdir . '/messagelib.php';
// Messagelib functions
require_once $CFG->libdir . '/modinfolib.php';
// Cached information on course-module instances
require_once $CFG->dirroot . '/cache/lib.php';
// Cache API
// make sure PHP is not severly misconfigured
setup_validate_php_configuration();
// Connect to the database
setup_DB();
if (PHPUNIT_TEST and !PHPUNIT_UTIL) {
    // make sure tests do not run in parallel
    test_lock::acquire('phpunit');
    $dbhash = null;
    try {
        if ($dbhash = $DB->get_field('config', 'value', array('name' => 'phpunittest'))) {
            // reset DB tables
            phpunit_util::reset_database();
        }
    } catch (Exception $e) {
        if ($dbhash) {
            // we ned to reinit if reset fails
            $DB->set_field('config', 'value', 'na', array('name' => 'phpunittest'));
        }
    }
    unset($dbhash);
}
// Load up any configuration from the config table or MUC cache.
Ejemplo n.º 2
0
 /**
  * Gives access to moodle codebase, ensures all is ready and sets up the test lock.
  *
  * Includes config.php to use moodle codebase with $CFG->behat_*
  * instead of $CFG->prefix and $CFG->dataroot, called once per suite.
  *
  * @param BeforeSuiteScope $scope scope passed by event fired before suite.
  * @static
  * @throws behat_stop_exception
  */
 public static function before_suite(BeforeSuiteScope $scope)
 {
     global $CFG;
     // Defined only when the behat CLI command is running, the moodle init setup process will
     // read this value and switch to $CFG->behat_dataroot and $CFG->behat_prefix instead of
     // the normal site.
     if (!defined('BEHAT_TEST')) {
         define('BEHAT_TEST', 1);
     }
     if (!defined('CLI_SCRIPT')) {
         define('CLI_SCRIPT', 1);
     }
     // With BEHAT_TEST we will be using $CFG->behat_* instead of $CFG->dataroot, $CFG->prefix and $CFG->wwwroot.
     require_once __DIR__ . '/../../../config.php';
     // Now that we are MOODLE_INTERNAL.
     require_once __DIR__ . '/../../behat/classes/behat_command.php';
     require_once __DIR__ . '/../../behat/classes/behat_selectors.php';
     require_once __DIR__ . '/../../behat/classes/behat_context_helper.php';
     require_once __DIR__ . '/../../behat/classes/util.php';
     require_once __DIR__ . '/../../testing/classes/test_lock.php';
     require_once __DIR__ . '/../../testing/classes/nasty_strings.php';
     // Avoids vendor/bin/behat to be executed directly without test environment enabled
     // to prevent undesired db & dataroot modifications, this is also checked
     // before each scenario (accidental user deletes) in the BeforeScenario hook.
     if (!behat_util::is_test_mode_enabled()) {
         throw new behat_stop_exception('Behat only can run if test mode is enabled. More info in ' . behat_command::DOCS_URL . '#Running_tests');
     }
     // Reset all data, before checking for check_server_status.
     // If not done, then it can return apache error, while running tests.
     behat_util::clean_tables_updated_by_scenario_list();
     behat_util::reset_all_data();
     // Check if server is running and using same version for cli and apache.
     behat_util::check_server_status();
     // Prevents using outdated data, upgrade script would start and tests would fail.
     if (!behat_util::is_test_data_updated()) {
         $commandpath = 'php admin/tool/behat/cli/init.php';
         throw new behat_stop_exception("Your behat test site is outdated, please run\n\n    " . $commandpath . "\n\nfrom your moodle dirroot to drop and install the behat test site again.");
     }
     // Avoid parallel tests execution, it continues when the previous lock is released.
     test_lock::acquire('behat');
     // Store the browser reset time if reset after N seconds is specified in config.php.
     if (!empty($CFG->behat_restart_browser_after)) {
         // Store the initial browser session opening.
         self::$lastbrowsersessionstart = time();
     }
     if (!empty($CFG->behat_faildump_path) && !is_writable($CFG->behat_faildump_path)) {
         throw new behat_stop_exception('You set $CFG->behat_faildump_path to a non-writable directory');
     }
     // Handle interrupts on PHP7.
     if (extension_loaded('pcntl')) {
         $disabled = explode(',', ini_get('disable_functions'));
         if (!in_array('pcntl_signal', $disabled)) {
             declare (ticks=1);
         }
     }
 }
Ejemplo n.º 3
0
 /**
  * Gives access to moodle codebase, ensures all is ready and sets up the test lock.
  *
  * Includes config.php to use moodle codebase with $CFG->behat_*
  * instead of $CFG->prefix and $CFG->dataroot, called once per suite.
  *
  * @static
  * @throws Exception
  * @BeforeSuite
  */
 public static function before_suite($event)
 {
     global $CFG;
     // Defined only when the behat CLI command is running, the moodle init setup process will
     // read this value and switch to $CFG->behat_dataroot and $CFG->behat_prefix instead of
     // the normal site.
     define('BEHAT_TEST', 1);
     define('CLI_SCRIPT', 1);
     // With BEHAT_TEST we will be using $CFG->behat_* instead of $CFG->dataroot, $CFG->prefix and $CFG->wwwroot.
     require_once __DIR__ . '/../../../config.php';
     // Now that we are MOODLE_INTERNAL.
     require_once __DIR__ . '/../../behat/classes/behat_command.php';
     require_once __DIR__ . '/../../behat/classes/behat_selectors.php';
     require_once __DIR__ . '/../../behat/classes/behat_context_helper.php';
     require_once __DIR__ . '/../../behat/classes/util.php';
     require_once __DIR__ . '/../../testing/classes/test_lock.php';
     require_once __DIR__ . '/../../testing/classes/nasty_strings.php';
     // Avoids vendor/bin/behat to be executed directly without test environment enabled
     // to prevent undesired db & dataroot modifications, this is also checked
     // before each scenario (accidental user deletes) in the BeforeScenario hook.
     if (!behat_util::is_test_mode_enabled()) {
         throw new Exception('Behat only can run if test mode is enabled. More info in ' . behat_command::DOCS_URL . '#Running_tests');
     }
     if (!behat_util::is_server_running()) {
         throw new Exception($CFG->behat_wwwroot . ' is not available, ensure you specified correct url and that the server is set up and started.' . ' More info in ' . behat_command::DOCS_URL . '#Running_tests');
     }
     // Prevents using outdated data, upgrade script would start and tests would fail.
     if (!behat_util::is_test_data_updated()) {
         $commandpath = 'php admin/tool/behat/cli/init.php';
         throw new Exception("Your behat test site is outdated, please run\n\n    " . $commandpath . "\n\nfrom your moodle dirroot to drop and install the behat test site again.");
     }
     // Avoid parallel tests execution, it continues when the previous lock is released.
     test_lock::acquire('behat');
     // Store the browser reset time if reset after N seconds is specified in config.php.
     if (!empty($CFG->behat_restart_browser_after)) {
         // Store the initial browser session opening.
         self::$lastbrowsersessionstart = time();
     }
     if (!empty($CFG->behat_faildump_path) && !is_writable($CFG->behat_faildump_path)) {
         throw new Exception('You set $CFG->behat_faildump_path to a non-writable directory');
     }
 }
Ejemplo n.º 4
0
require_once $CFG->libdir . '/testing/classes/test_lock.php';
if ($unrecognized) {
    $unrecognized = implode("\n  ", $unrecognized);
    cli_error(get_string('cliunknowoption', 'admin', $unrecognized));
}
// Behat utilities.
require_once $CFG->libdir . '/behat/classes/util.php';
require_once $CFG->libdir . '/behat/classes/behat_command.php';
// Run command (only one per time).
if ($options['install']) {
    behat_util::install_site();
    mtrace("Acceptance tests site installed");
} else {
    if ($options['drop']) {
        // Ensure no tests are running.
        test_lock::acquire('behat');
        behat_util::drop_site();
        mtrace("Acceptance tests site dropped");
    } else {
        if ($options['enable']) {
            behat_util::start_test_mode();
            $runtestscommand = behat_command::get_behat_command(true) . ' --config ' . behat_config_manager::get_behat_cli_config_filepath();
            mtrace("Acceptance tests environment enabled, to run the tests use:\n " . $runtestscommand);
        } else {
            if ($options['disable']) {
                behat_util::stop_test_mode();
                mtrace("Acceptance tests environment disabled");
            } else {
                if ($options['diag']) {
                    $code = behat_util::get_behat_status();
                    exit($code);
Ejemplo n.º 5
0
    /**
     * Gives access to moodle codebase, ensures all is ready and sets up the test lock.
     *
     * Includes config.php to use moodle codebase with $CFG->behat_*
     * instead of $CFG->prefix and $CFG->dataroot, called once per suite.
     *
     * @static
     * @throws Exception
     * @BeforeSuite
     */
    public static function before_suite($event) {
        global $CFG;

        // Defined only when the behat CLI command is running, the moodle init setup process will
        // read this value and switch to $CFG->behat_dataroot and $CFG->behat_prefix instead of
        // the normal site.
        define('BEHAT_TEST', 1);

        define('CLI_SCRIPT', 1);

        // With BEHAT_TEST we will be using $CFG->behat_* instead of $CFG->dataroot, $CFG->prefix and $CFG->wwwroot.
        require_once(__DIR__ . '/../../../config.php');

        // Now that we are MOODLE_INTERNAL.
        require_once(__DIR__ . '/../../behat/classes/behat_command.php');
        require_once(__DIR__ . '/../../behat/classes/util.php');
        require_once(__DIR__ . '/../../testing/classes/test_lock.php');
        require_once(__DIR__ . '/../../testing/classes/nasty_strings.php');

        // Avoids vendor/bin/behat to be executed directly without test environment enabled
        // to prevent undesired db & dataroot modifications, this is also checked
        // before each scenario (accidental user deletes) in the BeforeScenario hook.

        if (!behat_util::is_test_mode_enabled()) {
            throw new Exception('Behat only can run if test mode is enabled. More info in ' . behat_command::DOCS_URL . '#Running_tests');
        }

        if (!behat_util::is_server_running()) {
            throw new Exception($CFG->behat_wwwroot . ' is not available, ensure you started your PHP built-in server. More info in ' . behat_command::DOCS_URL . '#Running_tests');
        }

        // Prevents using outdated data, upgrade script would start and tests would fail.
        if (!behat_util::is_test_data_updated()) {
            $commandpath = 'php admin/tool/behat/cli/init.php';
            throw new Exception('Your behat test site is outdated, please run ' . $commandpath . ' from your moodle dirroot to drop and install the behat test site again.');
        }
        // Avoid parallel tests execution, it continues when the previous lock is released.
        test_lock::acquire('behat');
    }