Skip to content

Instantly share code, notes, and snippets.

@yann-yinn
Last active October 10, 2019 01:42
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save yann-yinn/d501293c1f019df29632 to your computer and use it in GitHub Desktop.
Save yann-yinn/d501293c1f019df29632 to your computer and use it in GitHub Desktop.
Drupal 7 bootstrap for php unit
/**
* Script to bootstrap Drupal 7 for PHPUnit tests.
* On multisite installation, set $http_host variable
* to the site you want to test.
*/
/*=====================
SETTINGS
====================*/
// set here drupal root path
$drupal_root = guessDrupalRootPath();
// in a multisite installation, set here the domain name you are testing.
$http_host = 'localhost';
/*=====================
DRUPAL BOOTSTRAP
====================*/
// try to guess drupal root path if not specified.
function guessDrupalRootPath() {
$path = getcwd();
while ($path != '/') {
if (file_exists($path . '/includes/bootstrap.inc')) {
break;
}
$path = dirname($path);
}
return $path;
}
$_SERVER['HTTP_HOST'] = $http_host;
$_SERVER['SCRIPT_NAME'] = '/index.php';
$_SERVER['REMOTE_ADDR'] = '127.0.0.1';
$_SERVER['REQUEST_METHOD'] = 'GET';
$_SERVER['SERVER_NAME'] = NULL;
$_SERVER['SERVER_SOFTWARE'] = NULL;
$_SERVER['HTTP_USER_AGENT'] = NULL;
define('DRUPAL_ROOT', $drupal_root);
require_once DRUPAL_ROOT . '/includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
@permanovd
Copy link

thanks, helped me a lot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment