Example #1
0
 // Check that the directory does not contains other things.
 if (!file_exists("{$CFG->behat_dataroot}/behattestdir.txt")) {
     if ($dh = opendir($CFG->behat_dataroot)) {
         while (($file = readdir($dh)) !== false) {
             if ($file === 'behat' or $file === '.' or $file === '..' or $file === '.DS_Store') {
                 continue;
             }
             behat_error(BEHAT_EXITCODE_CONFIG, '$CFG->behat_dataroot directory is not empty, ensure this is the directory where you want to install behat test dataroot');
         }
         closedir($dh);
         unset($dh);
         unset($file);
     }
     if (defined('BEHAT_UTIL')) {
         // Now we create dataroot directory structure for behat tests.
         testing_initdataroot($CFG->behat_dataroot, 'behat');
     } else {
         behat_error(BEHAT_EXITCODE_INSTALL);
     }
 }
 if (!defined('BEHAT_UTIL') and !defined('BEHAT_TEST')) {
     // Somebody tries to access test site directly, tell them if not enabled.
     if (!file_exists($CFG->behat_dataroot . '/behat/test_environment_enabled.txt')) {
         behat_error(BEHAT_EXITCODE_CONFIG, 'Behat is configured but not enabled on this test site.');
     }
 }
 // Constant used to inform that the behat test site is being used,
 // this includes all the processes executed by the behat CLI command like
 // the site reset, the steps executed by the browser drivers when simulating
 // a user session and a real session when browsing manually to $CFG->behat_wwwroot
 // like the browser driver does automatically.
Example #2
0
 /**
  * Drop all test site data.
  *
  * Note: To be used from CLI scripts only.
  *
  * @static
  * @param bool $displayprogress if true, this method will echo progress information.
  * @return void may terminate execution with exit code
  */
 public static function drop_site($displayprogress = false)
 {
     global $DB, $CFG;
     if (!self::is_test_site()) {
         phpunit_bootstrap_error(PHPUNIT_EXITCODE_CONFIGERROR, 'Can not drop non-test site!!');
     }
     // Purge dataroot
     if ($displayprogress) {
         echo "Purging dataroot:\n";
     }
     self::reset_dataroot();
     testing_initdataroot($CFG->dataroot, 'phpunit');
     self::drop_dataroot();
     // drop all tables
     self::drop_database($displayprogress);
 }
Example #3
0
    }
}
if (!file_exists("{$CFG->phpunit_dataroot}/phpunittestdir.txt")) {
    if ($dh = opendir($CFG->phpunit_dataroot)) {
        while (($file = readdir($dh)) !== false) {
            if ($file === 'phpunit' or $file === '.' or $file === '..' or $file === '.DS_Store') {
                continue;
            }
            phpunit_bootstrap_error(PHPUNIT_EXITCODE_CONFIGERROR, '$CFG->phpunit_dataroot directory is not empty, can not run tests! Is it used for anything else?');
        }
        closedir($dh);
        unset($dh);
        unset($file);
    }
    // now we are 100% sure this dir is used only for phpunit tests
    testing_initdataroot($CFG->phpunit_dataroot, 'phpunit');
}
// verify db prefix
if (!isset($CFG->phpunit_prefix)) {
    phpunit_bootstrap_error(PHPUNIT_EXITCODE_CONFIGERROR, 'Missing $CFG->phpunit_prefix in config.php, can not run tests!');
}
if ($CFG->phpunit_prefix === '') {
    phpunit_bootstrap_error(PHPUNIT_EXITCODE_CONFIGERROR, '$CFG->phpunit_prefix can not be empty, can not run tests!');
}
if (isset($CFG->prefix) and $CFG->prefix === $CFG->phpunit_prefix) {
    phpunit_bootstrap_error(PHPUNIT_EXITCODE_CONFIGERROR, '$CFG->prefix and $CFG->phpunit_prefix must not be identical, can not run tests!');
}
// override CFG settings if necessary and throw away extra CFG settings
$CFG->wwwroot = 'http://www.example.com/moodle';
$CFG->dataroot = $CFG->phpunit_dataroot;
$CFG->prefix = $CFG->phpunit_prefix;