Beispiel #1
0
 /**
  * Gives access to mahara codebase, ensures all are ready.
  *
  * @static
  * @throws Exception
  * @BeforeSuite
  */
 public static function before_suite($event)
 {
     global $CFG, $db, $SESSION, $USER, $THEME;
     // Defined only when the behat CLI command is running, the mahara init setup process will
     // read this value and switch to $CFG->behat_dataroot and $CFG->behat_dbprefix instead of
     // the normal site.
     define('BEHAT_TEST', 1);
     define('CLI', 1);
     define('INTERNAL', 1);
     // With BEHAT_TEST we will be using $CFG->behat_* instead of $CFG->dataroot, $CFG->dbprefix and $CFG->wwwroot.
     require_once dirname(dirname(dirname(dirname(__DIR__)))) . '/init.php';
     // Now that we are in Mahara env.
     require_once get_config('docroot') . '/lib/upgrade.php';
     require_once get_config('docroot') . '/lib/file.php';
     require_once get_config('docroot') . '/testing/classes/TestLock.php';
     require_once get_config('docroot') . '/testing/classes/NastyStrings.php';
     require_once get_config('docroot') . '/testing/frameworks/behat/classes/util.php';
     require_once get_config('docroot') . '/testing/frameworks/behat/classes/BehatCommand.php';
     require_once get_config('docroot') . '/testing/frameworks/behat/classes/BehatSelectors.php';
     require_once get_config('docroot') . '/testing/frameworks/behat/classes/BehatContextHelper.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 (!BehatTestingUtil::is_test_mode_enabled()) {
         throw new Exception('Behat only can run if test mode is enabled. More info in ' . BehatCommand::DOCS_URL . '#Running_tests');
     }
     if (!BehatTestingUtil::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 ' . BehatCommand::DOCS_URL . '#Running_tests');
     }
     // Prevents using outdated data, upgrade script would start and tests would fail.
     if (!BehatTestingUtil::is_test_data_updated()) {
         $commandpath = 'php testing/frameworks/behat/cli/init.php';
         throw new Exception('Your behat test site is outdated, please run ' . $commandpath . ' from your mahara docroot to drop and install the behat test site again.');
     }
     // Avoid parallel tests execution, it continues when the previous lock is released.
     TestLock::acquire('behat');
     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');
     }
 }
Beispiel #2
0
$options['config'] = new stdClass();
$options['config']->shortoptions = array('c');
$options['config']->description = 'Get behat YML config path';
$options['config']->required = false;
$options['config']->defaultvalue = false;
$settings = new stdClass();
$settings->options = $options;
$settings->info = 'CLI tool to manage Behat integration in Mahara';
$cli->setup($settings);
try {
    if ($cli->get_cli_param('install')) {
        BehatTestingUtil::install_site();
        cli::cli_exit("\nAcceptance test site is installed\n");
    } else {
        if ($cli->get_cli_param('drop')) {
            TestLock::acquire('behat');
            BehatTestingUtil::drop_site();
            cli::cli_exit("\nAcceptance tests site dropped\n");
        } else {
            if ($cli->get_cli_param('enable')) {
                BehatTestingUtil::start_test_mode();
                $runtestscommand = BehatCommand::get_behat_command(true) . ' --config ' . BehatConfigManager::get_behat_cli_config_filepath();
                cli::cli_exit("\nAcceptance tests environment enabled on {$CFG->behat_wwwroot}, to run the tests use:\n " . $runtestscommand . "\n");
            } else {
                if ($cli->get_cli_param('disable')) {
                    BehatTestingUtil::stop_test_mode();
                    cli::cli_exit("\nAcceptance test site is disabled\n");
                } else {
                    if ($cli->get_cli_param('diag')) {
                        $code = BehatTestingUtil::get_behat_status();
                        exit($code);