Пример #1
0
function behat_config($restore = false)
{
    $arguments = ['<DRUPAL_HOST>' => DRUPAL_HOST, '<DRUPAL_PATH>' => DRUPAL_ROOT];
    if ($restore) {
        $arguments = array_flip($arguments);
    }
    return file_put_contents(CONFIG_FILE, strtr(file_get_contents(CONFIG_FILE), $arguments));
}
// Drop and create database.
(new Drupal\TqExtension\Utils\Database\Operator(DRUPAL_DB_USER, DRUPAL_DB_PASS, DRUPAL_DB_HOST))->clear(DRUPAL_DB_NAME);
// Download Drupal and rename the folder.
if (!file_exists(DRUPAL_ROOT)) {
    drush('dl drupal-7 --drupal-project-rename=%s --destination=%s', [DRUPAL_DB_NAME, dirname(DRUPAL_ROOT)]);
}
// Install Drupal.
drush('si standard --db-url=mysql://%s:%s@%s/%s --account-name=%s --account-pass=%s', [DRUPAL_DB_USER, DRUPAL_DB_PASS, DRUPAL_DB_HOST, DRUPAL_DB_NAME, DRUPAL_USER, DRUPAL_PASS]);
if (!file_exists(ROUTER_FILE)) {
    $index = sprintf('%s/index.php', DRUPAL_ROOT);
    shell_exec(sprintf('wget -O %s %s', ROUTER_FILE, ROUTER_URL));
    file_put_contents($index, str_replace('getcwd()', "'" . DRUPAL_ROOT . "'", file_get_contents($index)));
}
// Run built-in PHP web-server.
$processId = shell_exec(sprintf('php -S %s -t %s %s >/dev/null 2>&1 & echo $!', DRUPAL_HOST, DRUPAL_ROOT, ROUTER_FILE));
// Bootstrap Drupal to make available an API.
$_SERVER['REMOTE_ADDR'] = 'localhost';
require_once DRUPAL_ROOT . '/includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
// Initialize Behat configuration.
behat_config();
register_shutdown_function(function () use($processId) {
    shell_exec("kill {$processId}");
/**
 * Login to the site as User 1 for Drupal
 */
function drush_user_login($site_id, $env_id)
{
    $login_url = drush($site_id, $env_id, "user-login 1");
    return browser_open($login_url);
}