function Drush_TestCase::setUpDrupal

6.x drush_testcase.inc Drush_TestCase::setUpDrupal($num_sites = 1, $install = FALSE, $version_string = UNISH_DRUPAL_MAJOR_VERSION, $profile = NULL)
4.x drush_testcase.inc Drush_TestCase::setUpDrupal($env = 'dev', $install = FALSE, $version_string = '7.x', $profile = NULL)
5.x drush_testcase.inc Drush_TestCase::setUpDrupal($num_sites = 1, $install = FALSE, $version_string = UNISH_DRUPAL_MAJOR_VERSION, $profile = NULL)
28 calls to Drush_TestCase::setUpDrupal()
batchCase::testBatch in tests/batchTest.php
cacheCommandCase::testCacheGetSetClear in tests/cacheCommandTest.php
commandCase::testDisabledModule in tests/commandTest.php
Assert that commands in disabled modules are detected.
completeCase::testComplete in tests/completeTest.php
contextCase::setUp in tests/contextTest.php
Try to write a tiny drushrc.php to each place that drush checks. Also write a sites/dev/aliases.drushrc.php file to the sandbox.

... See full list

File

tests/drush_testcase.inc, line 238
Initialize a sandboxed environment. Starts with call unish_init() at bottom.

Class

Drush_TestCase

Code

function setUpDrupal($num_sites = 1, $install = FALSE, $version_string = UNISH_DRUPAL_MAJOR_VERSION, $profile = NULL) {
  $sites_subdirs_all = array(
    'dev',
    'stage',
    'prod',
    'retired',
    'elderly',
    'dead',
    'dust',
  );
  $sites_subdirs = array_slice($sites_subdirs_all, 0, $num_sites);
  $root = $this->webroot();
  $major_version = substr($version_string, 0, 1);

  if (!isset($profile)) {
    $profile = $major_version >= 7 ? 'testing' : 'default';
  }
  $db_driver = $this->db_driver(UNISH_DB_URL);

  $cache_keys = array(
    $num_sites,
    $install ? 'install' : 'noinstall',
    $version_string,
    $profile,
    $db_driver,
  );
  $source = $this->directory_cache('environments') . '/' . implode('-', $cache_keys) . '.tar.gz';
  if (file_exists($source)) {
    $this->log('Cache HIT. Environment: ' . $source, 'verbose');
    $this->drush('archive-restore', array($source), array('destination' => $root, 'overwrite' => NULL));
  }
  else {
    $this->log('Cache MISS. Environment: ' . $source, 'verbose');
    // Build the site(s), install (if needed), then cache.
    foreach ($sites_subdirs as $subdir) {
      $this->fetchInstallDrupal($subdir, $install, $version_string, $profile);
    }
    // Write an empty sites.php if we are on D8+. Needed for multi-site.
    if ($major_version >= 8 && !file_exists($root . '/sites/sites.php')) {
      copy($root . '/sites/example.sites.php', $root . '/sites/sites.php');
    }
    $options = array(
      'destination' => $source,
      'root' => $root,
      'uri' => reset($sites_subdirs),
      'overwrite' => NULL,
    );
    if ($install) {
      $this->drush('archive-dump', array('@sites'), $options);
    }
  }

  // Stash details about each site.
  foreach ($sites_subdirs as $subdir) {
    $this->sites[$subdir] = array(
      'db_url' => $this->db_url($subdir),
    );
    // Make an alias for the site
    $alias_definition = array($subdir => array(
      'root' => $root,
      'uri' => $subdir,
    ));
    file_put_contents(UNISH_SANDBOX . '/etc/drush/' . $subdir . '.alias.drushrc.php', unish_file_aliases($alias_definition));
  }
  return $this->sites;
}