Exemplo n.º 1
0
 /**
  * Installs a site using $CFG->dataroot and $CFG->prefix
  * @throws coding_exception
  * @return void
  */
 public static function install_site()
 {
     global $DB;
     if (!defined('BEHAT_UTIL')) {
         throw new coding_exception('This method can be only used by Behat CLI tool');
     }
     // New dataroot.
     self::reset_dataroot();
     $options = array();
     $options['adminuser'] = '******';
     $options['adminpass'] = '******';
     $options['fullname'] = 'Acceptance test site';
     install_cli_database($options, false);
     // Update admin user info.
     $user = $DB->get_record('user', array('username' => 'admin'));
     $user->email = '*****@*****.**';
     $user->firstname = 'Admin';
     $user->lastname = 'User';
     $user->city = 'Perth';
     $user->country = 'AU';
     $DB->update_record('user', $user);
     // Sets maximum debug level.
     set_config('debug', DEBUG_DEVELOPER);
     set_config('debugdisplay', true);
     // Keeps the current version of database and dataroot.
     self::store_versions_hash();
     // Stores the database contents for fast reset.
     self::store_database_state();
 }
Exemplo n.º 2
0
 /**
  * Installs a site using $CFG->dataroot and $CFG->prefix
  * @throws coding_exception
  * @return void
  */
 public static function install_site()
 {
     global $DB, $CFG;
     require_once $CFG->dirroot . '/user/lib.php';
     if (!defined('BEHAT_UTIL')) {
         throw new coding_exception('This method can be only used by Behat CLI tool');
     }
     // New dataroot.
     self::reset_dataroot();
     $options = array();
     $options['adminuser'] = '******';
     $options['adminpass'] = '******';
     $options['fullname'] = self::BEHATSITENAME;
     $options['shortname'] = self::BEHATSITENAME;
     install_cli_database($options, false);
     $frontpagesummary = new admin_setting_special_frontpagedesc();
     $frontpagesummary->write_setting(self::BEHATSITENAME);
     // Update admin user info.
     $user = $DB->get_record('user', array('username' => 'admin'));
     $user->email = '*****@*****.**';
     $user->firstname = 'Admin';
     $user->lastname = 'User';
     $user->city = 'Perth';
     $user->country = 'AU';
     user_update_user($user, false);
     // Disable email message processor.
     $DB->set_field('message_processors', 'enabled', '0', array('name' => 'email'));
     // Sets maximum debug level.
     set_config('debug', DEBUG_DEVELOPER);
     set_config('debugdisplay', true);
     // Keeps the current version of database and dataroot.
     self::store_versions_hash();
     // Stores the database contents for fast reset.
     self::store_database_state();
 }
Exemplo n.º 3
0
 /**
  * Installs a site using $CFG->dataroot and $CFG->prefix
  * @throws coding_exception
  * @return void
  */
 public static function install_site()
 {
     global $DB, $CFG;
     require_once $CFG->dirroot . '/user/lib.php';
     if (!defined('BEHAT_UTIL')) {
         throw new coding_exception('This method can be only used by Behat CLI tool');
     }
     $tables = $DB->get_tables(false);
     if (!empty($tables)) {
         behat_error(BEHAT_EXITCODE_INSTALLED);
     }
     // New dataroot.
     self::reset_dataroot();
     $options = array();
     $options['adminuser'] = '******';
     $options['adminpass'] = '******';
     $options['fullname'] = self::BEHATSITENAME;
     $options['shortname'] = self::BEHATSITENAME;
     install_cli_database($options, false);
     // We need to keep the installed dataroot filedir files.
     // So each time we reset the dataroot before running a test, the default files are still installed.
     self::save_original_data_files();
     $frontpagesummary = new admin_setting_special_frontpagedesc();
     $frontpagesummary->write_setting(self::BEHATSITENAME);
     // Update admin user info.
     $user = $DB->get_record('user', array('username' => 'admin'));
     $user->email = '*****@*****.**';
     $user->firstname = 'Admin';
     $user->lastname = 'User';
     $user->city = 'Perth';
     $user->country = 'AU';
     user_update_user($user, false);
     // Disable email message processor.
     $DB->set_field('message_processors', 'enabled', '0', array('name' => 'email'));
     // Sets maximum debug level.
     set_config('debug', DEBUG_DEVELOPER);
     set_config('debugdisplay', 1);
     // Disable some settings that are not wanted on test sites.
     set_config('noemailever', 1);
     // Enable web cron.
     set_config('cronclionly', 0);
     // Set editor autosave to high value, so as to avoid unwanted ajax.
     set_config('autosavefrequency', '604800', 'editor_atto');
     // Keeps the current version of database and dataroot.
     self::store_versions_hash();
     // Stores the database contents for fast reset.
     self::store_database_state();
 }
 /**
  * Install a site using $CFG->dataroot and $CFG->prefix
  *
  * @return string|bool true on success, else exception code.
  */
 public static function install_site($sitefullname = "Performance test site", $siteshortname = "Performance test site", $adminpass = "******", $adminemail = "*****@*****.**")
 {
     global $DB, $CFG;
     require_once $CFG->dirroot . '/user/lib.php';
     if (!defined('PERFORMANCE_SITE_GENERATOR')) {
         util::performance_exception('This method can be only used by performance site generator.');
     }
     // If already installed, then return with error.
     $tables = $DB->get_tables(false);
     if (!empty($tables)) {
         return self::SITE_ERROR_INSTALLED;
     }
     $options = array();
     $options['adminuser'] = '******';
     $options['adminpass'] = $adminpass;
     $options['fullname'] = $sitefullname;
     $options['shortname'] = $siteshortname;
     install_cli_database($options, false);
     $frontpagesummary = new \admin_setting_special_frontpagedesc();
     $frontpagesummary->write_setting($sitefullname);
     // Update admin user info.
     $user = $DB->get_record('user', array('username' => 'admin'));
     $user->email = $adminemail;
     $user->firstname = 'Admin';
     $user->lastname = 'User';
     $user->city = 'Perth';
     $user->country = 'AU';
     user_update_user($user, false);
     // Disable email message processor.
     $DB->set_field('message_processors', 'enabled', '0', array('name' => 'email'));
     // Disable some settings that are not wanted on test sites.
     set_config('noemailever', 1);
     // Enable web cron.
     set_config('cronclionly', 0);
     $CFG->dboptions = array('dbpersist' => 1);
     // Keeps the current version of components hash.
     self::store_versions_hash();
 }
Exemplo n.º 5
0
 /**
  * Perform a fresh test site installation
  *
  * Note: To be used from CLI scripts only.
  *
  * @static
  * @return void may terminate execution with exit code
  */
 public static function install_site()
 {
     global $DB, $CFG;
     if (!self::is_test_site()) {
         phpunit_bootstrap_error(PHPUNIT_EXITCODE_CONFIGERROR, 'Can not install on non-test site!!');
     }
     if ($DB->get_tables()) {
         list($errorcode, $message) = phpunit_util::testing_ready_problem();
         if ($errorcode) {
             phpunit_bootstrap_error(PHPUNIT_EXITCODE_REINSTALL, 'Database tables already present, Moodle PHPUnit test environment can not be initialised');
         } else {
             phpunit_bootstrap_error(0, 'Moodle PHPUnit test environment is already initialised');
         }
     }
     $options = array();
     $options['adminpass'] = '******';
     $options['shortname'] = 'phpunit';
     $options['fullname'] = 'PHPUnit test site';
     install_cli_database($options, false);
     // Disable all logging for performance and sanity reasons.
     set_config('enabled_stores', '', 'tool_log');
     // We need to keep the installed dataroot filedir files.
     // So each time we reset the dataroot before running a test, the default files are still installed.
     self::save_original_data_files();
     // install timezone info
     $timezones = get_records_csv($CFG->libdir . '/timezone.txt', 'timezone');
     update_timezone_records($timezones);
     // Store version hash in the database and in a file.
     self::store_versions_hash();
     // Store database data and structure.
     self::store_database_state();
 }
Exemplo n.º 6
0
 /**
  * Perform a fresh test site installation
  *
  * Note: To be used from CLI scripts only.
  *
  * @static
  * @return void may terminate execution with exit code
  */
 public static function install_site()
 {
     global $DB, $CFG;
     if (!self::is_test_site()) {
         phpunit_bootstrap_error(PHPUNIT_EXITCODE_CONFIGERROR, 'Can not install on non-test site!!');
     }
     if ($DB->get_tables()) {
         list($errorcode, $message) = phpunit_util::testing_ready_problem();
         if ($errorcode) {
             phpunit_bootstrap_error(PHPUNIT_EXITCODE_REINSTALL, 'Database tables already present, Moodle PHPUnit test environment can not be initialised');
         } else {
             phpunit_bootstrap_error(0, 'Moodle PHPUnit test environment is already initialised');
         }
     }
     $options = array();
     $options['adminpass'] = '******';
     $options['shortname'] = 'phpunit';
     $options['fullname'] = 'PHPUnit test site';
     install_cli_database($options, false);
     // install timezone info
     $timezones = get_records_csv($CFG->libdir . '/timezone.txt', 'timezone');
     update_timezone_records($timezones);
     // Store version hash in the database and in a file.
     self::store_versions_hash();
     // Store database data and structure.
     self::store_database_state();
 }
Exemplo n.º 7
0
$installlang = $CFG->lang;
// return back to original dir before executing setup.php which changes the dir again
chdir($olddir);
// We have config.php, it is a real php script from now on :-)
require $configfile;
// use selected language
$CFG->lang = $installlang;
$SESSION->lang = $CFG->lang;
require "{$CFG->dirroot}/version.php";
// Test environment first.
require_once $CFG->libdir . '/environmentlib.php';
list($envstatus, $environment_results) = check_moodle_environment(normalize_version($release), ENV_SELECT_RELEASE);
if (!$envstatus) {
    $errors = environment_get_errors($environment_results);
    cli_heading(get_string('environment', 'admin'));
    foreach ($errors as $error) {
        list($info, $report) = $error;
        echo "!! {$info} !!\n{$report}\n\n";
    }
    exit(1);
}
// Test plugin dependencies.
$failed = array();
if (!core_plugin_manager::instance()->all_plugins_ok($version, $failed)) {
    cli_problem(get_string('pluginscheckfailed', 'admin', array('pluginslist' => implode(', ', array_unique($failed)))));
    cli_error(get_string('pluginschecktodo', 'admin'));
}
install_cli_database($options, $interactive);
echo get_string('cliinstallfinished', 'install') . "\n";
exit(0);
// 0 means success
            $a->dest = $CFG->dataroot . '/lang';
            cli_problem(get_string('remotedownloaderror', 'error', $a));
        }
    }
}
// switch the string_manager instance to stop using install/lang/
$CFG->early_install_lang = false;
get_string_manager(true);
require "{$CFG->dirroot}/version.php";
// Test environment first.
require_once $CFG->libdir . '/environmentlib.php';
list($envstatus, $environment_results) = check_moodle_environment(normalize_version($release), ENV_SELECT_RELEASE);
if (!$envstatus) {
    $errors = environment_get_errors($environment_results);
    cli_heading(get_string('environment', 'admin'));
    foreach ($errors as $error) {
        list($info, $report) = $error;
        echo "!! {$info} !!\n{$report}\n\n";
    }
    exit(1);
}
// Test plugin dependencies.
$failed = array();
if (!core_plugin_manager::instance()->all_plugins_ok($version, $failed)) {
    cli_problem(get_string('pluginscheckfailed', 'admin', array('pluginslist' => implode(', ', array_unique($failed)))));
    cli_error(get_string('pluginschecktodo', 'admin'));
}
install_cli_database($options, true);
echo get_string('cliinstallfinished', 'install') . "\n";
exit(0);
// 0 means success
Exemplo n.º 9
0
 /**
  * Perform a fresh test site installation
  *
  * Note: To be used from CLI scripts only.
  *
  * @static
  * @return void may terminate execution with exit code
  */
 public static function install_site()
 {
     global $DB, $CFG;
     if (!self::is_test_site()) {
         phpunit_bootstrap_error(PHPUNIT_EXITCODE_CONFIGERROR, 'Can not install on non-test site!!');
     }
     if ($DB->get_tables()) {
         list($errorcode, $message) = phpunit_util::testing_ready_problem();
         if ($errorcode) {
             phpunit_bootstrap_error(PHPUNIT_EXITCODE_REINSTALL, 'Database tables already present, Moodle PHPUnit test environment can not be initialised');
         } else {
             phpunit_bootstrap_error(0, 'Moodle PHPUnit test environment is already initialised');
         }
     }
     $options = array();
     $options['adminpass'] = '******';
     $options['shortname'] = 'phpunit';
     $options['fullname'] = 'PHPUnit test site';
     install_cli_database($options, false);
     // install timezone info
     $timezones = get_records_csv($CFG->libdir . '/timezone.txt', 'timezone');
     update_timezone_records($timezones);
     // add test db flag
     $hash = phpunit_util::get_version_hash();
     set_config('phpunittest', $hash);
     // store data for all tables
     $data = array();
     $structure = array();
     $tables = $DB->get_tables();
     foreach ($tables as $table) {
         $columns = $DB->get_columns($table);
         $structure[$table] = $columns;
         if (isset($columns['id']) and $columns['id']->auto_increment) {
             $data[$table] = $DB->get_records($table, array(), 'id ASC');
         } else {
             // there should not be many of these
             $data[$table] = $DB->get_records($table, array());
         }
     }
     $data = serialize($data);
     file_put_contents("{$CFG->dataroot}/phpunit/tabledata.ser", $data);
     phpunit_boostrap_fix_file_permissions("{$CFG->dataroot}/phpunit/tabledata.ser");
     $structure = serialize($structure);
     file_put_contents("{$CFG->dataroot}/phpunit/tablestructure.ser", $structure);
     phpunit_boostrap_fix_file_permissions("{$CFG->dataroot}/phpunit/tablestructure.ser");
     // hash all plugin versions - helps with very fast detection of db structure changes
     file_put_contents("{$CFG->dataroot}/phpunit/versionshash.txt", $hash);
     phpunit_boostrap_fix_file_permissions("{$CFG->dataroot}/phpunit/versionshash.txt", $hash);
 }
Exemplo n.º 10
0
 /**
  * Perform a fresh test site installation
  *
  * Note: To be used from CLI scripts only.
  *
  * @static
  * @return void may terminate execution with exit code
  */
 public static function install_site()
 {
     global $DB, $CFG;
     if (!self::is_test_site()) {
         cli_error('Can not install non-test sites!!', 131);
     }
     if ($DB->get_tables()) {
         cli_error('Database tables already installed, drop the site first.', 133);
     }
     $options = array();
     $options['adminpass'] = '******';
     // removed later
     $options['shortname'] = 'phpunit';
     $options['fullname'] = 'PHPUnit test site';
     install_cli_database($options, false);
     // just in case remove admin password so that normal login is not possible
     $DB->set_field('user', 'password', 'not cached', array('username' => 'admin'));
     // add test db flag
     set_config('phpunittest', 'phpunittest');
     // store data for all tables
     $data = array();
     $tables = $DB->get_tables();
     foreach ($tables as $table) {
         $data[$table] = $DB->get_records($table, array());
     }
     $data = serialize($data);
     @unlink("{$CFG->dataroot}/phpunit/tabledata.ser");
     file_put_contents("{$CFG->dataroot}/phpunit/tabledata.ser", $data);
     // hash all plugin versions - helps with very fast detection of db structure changes
     $hash = phpunit_util::get_version_hash();
     @unlink("{$CFG->dataroot}/phpunit/versionshash.txt");
     file_put_contents("{$CFG->dataroot}/phpunit/versionshash.txt", $hash);
 }