function UnishTestCase::setUpDrupal

8.0.x UnishTestCase.php UnishTestCase::setUpDrupal($num_sites = 1, $install = FALSE, $version_string = UNISH_DRUPAL_MAJOR_VERSION, $profile = NULL)
7.x UnishTestCase.php UnishTestCase::setUpDrupal($num_sites = 1, $install = FALSE, $version_string = UNISH_DRUPAL_MAJOR_VERSION, $profile = NULL)
master UnishTestCase.php UnishTestCase::setUpDrupal($num_sites = 1, $install = FALSE, $version_string = UNISH_DRUPAL_MAJOR_VERSION, $profile = NULL)
30 calls to UnishTestCase::setUpDrupal()

File

tests/Unish/UnishTestCase.php, line 266

Namespace

Unish

Class

UnishTestCase

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);
    }
    $options = array(
      'destination' => $source,
      'root' => $root,
      'uri' => reset($sites_subdirs),
      'overwrite' => NULL,
    );
    if ($install) {
      $this->drush('archive-dump', array('@sites'), $options);
    }
  }
  // Write an empty sites.php if we are on D7+. Needed for multi-site on D8 and
  // used on D7 in \Unish\saCase::testBackendHonorsAliasOverride.
  if ($major_version >= 7 && !file_exists($root . '/sites/sites.php')) {
    copy($root . '/sites/example.sites.php', $root . '/sites/sites.php');
  }

  // Stash details about each site.
  foreach ($sites_subdirs as $subdir) {
    self::$sites[$subdir] = array(
      'root' => $root,
      'uri' => $subdir,
      'db_url' => $this->db_url($subdir),
    );
    // Make an alias for the site
    $this->writeSiteAlias($subdir, $root, $subdir);
  }
  return self::$sites;
}