bootstrap.php 864 B

123456789101112131415161718192021222324252627282930
  1. <?php
  2. test_suite_read_and_set_environment_variables();
  3. $drupal_root = getenv('DRUPAL_ROOT');
  4. define('DRUPAL_ROOT', $drupal_root ?: __DIR__.'/../../../../..');
  5. require_once DRUPAL_ROOT.'/includes/bootstrap.inc';
  6. $_SERVER['REMOTE_ADDR'] = '127.0.0.1';
  7. $current_dir = getcwd();
  8. chdir(DRUPAL_ROOT);
  9. // Bootstrap Drupal.
  10. drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
  11. chdir($current_dir);
  12. /**
  13. * @throws \Exception
  14. */
  15. function test_suite_read_and_set_environment_variables() {
  16. $filename = __DIR__.'/.env';
  17. if(file_exists($filename)) {
  18. $file = fopen($filename, 'r');
  19. while ($line = str_replace("\n", '', fgets($file))) {
  20. // break line into key value
  21. $env = explode('=', $line);
  22. if(count($env) === 2) {
  23. putenv($line);
  24. } else {
  25. throw new Exception('Invalid environment line: ' . $line);
  26. }
  27. }
  28. fclose($file);
  29. }
  30. }