Exemplo n.º 1
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.º 2
0
$CFG->debugdeveloper = true;
$CFG->debugdisplay = 1;
error_reporting($CFG->debug);
ini_set('display_errors', '1');
ini_set('log_errors', '1');
$CFG->noemailever = true;
// better not mail anybody from tests, override temporarily if necessary
$CFG->cachetext = 0;
// disable this very nasty setting
// some ugly hacks
$CFG->themerev = 1;
$CFG->jsrev = 1;
// load test case stub classes and other stuff
require_once "{$CFG->dirroot}/lib/phpunit/lib.php";
// finish moodle init
define('ABORT_AFTER_CONFIG_CANCEL', true);
require "{$CFG->dirroot}/lib/setup.php";
raise_memory_limit(MEMORY_HUGE);
if (PHPUNIT_UTIL) {
    // we are not going to do testing, this is 'true' in utility scripts that only init database
    return;
}
// is database and dataroot ready for testing?
list($errorcode, $message) = phpunit_util::testing_ready_problem();
// print some version info
phpunit_util::bootstrap_moodle_info();
if ($errorcode) {
    phpunit_bootstrap_error($errorcode, $message);
}
// prepare for the first test run - store fresh globals, reset database and dataroot, etc.
phpunit_util::bootstrap_init();
Exemplo n.º 3
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.º 4
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);
 }