prepareEnvironment example

// Set the update URL. This must be set here rather than in     // self::__construct() or the old URL generator will leak additional test     // sites. Additionally, we need to prevent the path alias processor from     // running because we might not have a working alias system before running     // the updates.     $this->updateUrl = Url::fromRoute('system.db_update', []['path_processing' => FALSE]);

    $this->setupBaseUrl();

    // Install Drupal test site.     $this->prepareEnvironment();
    $this->runDbTasks();

    // We are going to set a missing zlib requirement property for usage     // during the performUpgrade() and tearDown() methods. Also set that the     // tests failed.     if (!$this->zlibInstalled) {
      parent::setUp();
      return;
    }
    $this->installDrupal();

    
/** * The expected file perms of the folder. * * @var int */
  protected $expectedFilePerms;

  /** * {@inheritdoc} */
  protected function prepareEnvironment() {
    parent::prepareEnvironment();
    mkdir($this->root . DIRECTORY_SEPARATOR . $this->siteDirectory . '/config_read_only', 0444);
    $this->expectedFilePerms = fileperms($this->siteDirectory . '/config_read_only');
    $this->settings['settings']['config_sync_directory'] = (object) [
      'value' => $this->siteDirectory . '/config_read_only',
      'required' => TRUE,
    ];
  }

  /** * Verifies that installation succeeded. */
  
class InstallerBrokenDatabasePortSettingsTest extends InstallerTestBase {

  /** * {@inheritdoc} */
  protected $defaultTheme = 'stark';

  /** * {@inheritdoc} */
  protected function prepareEnvironment() {
    parent::prepareEnvironment();
    // Pre-configure database credentials in settings.php.     $connection_info = Database::getConnectionInfo();

    if ($connection_info['default']['driver'] !== 'mysql') {
      $this->markTestSkipped('This test relies on overriding the mysql driver');
    }

    // Override the port number to random port.     $connection_info['default']['port'] = 1234;

    $this->settings['databases']['default'] = (object) [
      
/** * {@inheritdoc} */
  protected function getConfigTarball() {
    return __DIR__ . '/../../../fixtures/config_install/multilingual.tar.gz';
  }

  /** * {@inheritdoc} */
  protected function prepareEnvironment() {
    parent::prepareEnvironment();
    // Place custom local translations in the translations directory and fix up     // configuration.     mkdir($this->publicFilesDirectory . '/translations', 0777, TRUE);
    file_put_contents($this->publicFilesDirectory . '/translations/drupal-8.0.0.es.po', $this->getPo('es'));
    $locale_settings = Yaml::decode(file_get_contents($this->siteDirectory . '/config/sync/locale.settings.yml'));
    $locale_settings['translation']['use_source'] = 'local';
    $locale_settings['translation']['path'] = $this->publicFilesDirectory . '/translations';
    file_put_contents($this->siteDirectory . '/config/sync/locale.settings.yml', Yaml::encode($locale_settings));
  }

  /** * Confirms that the installation installed the configuration correctly. */
class InstallerSkipPermissionHardeningTest extends InstallerTestBase {

  /** * {@inheritdoc} */
  protected $defaultTheme = 'stark';

  /** * {@inheritdoc} */
  protected function prepareEnvironment() {
    parent::prepareEnvironment();
    $this->settings['settings']['skip_permissions_hardening'] = (object) ['value' => TRUE, 'required' => TRUE];
  }

  /** * {@inheritdoc} */
  protected function setUpSite() {
    $site_directory = $this->container->getParameter('app.root') . '/' . $this->siteDirectory;
    $this->assertDirectoryIsWritable($site_directory);
    $this->assertFileIsWritable($site_directory . '/settings.php');

    

  protected function setUp(): void {
    parent::setUpAppRoot();

    $this->isInstalled = FALSE;

    $this->setupBaseUrl();

    $this->prepareDatabasePrefix();

    // Install Drupal test site.     $this->prepareEnvironment();

    // Define information about the user 1 account.     $this->rootUser = new UserSession([
      'uid' => 1,
      'name' => 'admin',
      'mail' => 'admin@example.com',
      'pass_raw' => $this->randomMachineName(),
    ]);

    // If any $settings are defined for this test, copy and prepare an actual     // settings.php, so as to resemble a regular installation.
protected function setUp(): void {
    parent::setUp();

    $this->setUpAppRoot();

    // Allow tests to compare MarkupInterface objects via assertEquals().     $this->registerComparator(new MarkupInterfaceComparator());

    $this->setupBaseUrl();

    // Install Drupal test site.     $this->prepareEnvironment();
    $this->installDrupal();

    // Setup Mink.     $this->initMink();

    // Set up the browser test output file.     $this->initBrowserOutputFile();

    // Ensure that the test is not marked as risky because of no assertions. In     // PHPUnit 6 tests that only make assertions using $this->assertSession()     // can be marked as risky.
/** * Testing installing from config without system.site. * * @group Installer */
class InstallerExistingConfigNoSystemSiteTest extends InstallerExistingConfigTestBase {

  /** * {@inheritdoc} */
  protected function prepareEnvironment() {
    parent::prepareEnvironment();
    // File API functions are not available yet.     unlink($this->siteDirectory . '/profiles/' . $this->profile . '/config/sync/system.site.yml');
  }

  /** * {@inheritdoc} */
  public function setUpSite() {
    // There are errors. Therefore, there is nothing to do here.   }

  
/** * Tests the isolation_level setting with existing database settings. * * @group Installer */
class InstallerIsolationLevelExistingSettingsTest extends InstallerExistingSettingsTest {

  /** * {@inheritdoc} */
  protected function prepareEnvironment() {
    parent::prepareEnvironment();

    $connection_info = Database::getConnectionInfo();
    // The isolation_level option is only available for MySQL.     if ($connection_info['default']['driver'] !== 'mysql') {
      $this->markTestSkipped("This test does not support the {$connection_info['default']['driver']} database driver.");
    }
  }

  /** * Verifies that isolation_level is not set in the database settings. */
  
/** * The distribution profile info. * * @var array */
  protected $info;

  /** * {@inheritdoc} */
  protected function prepareEnvironment() {
    parent::prepareEnvironment();
    $this->info = [
      'type' => 'profile',
      'core_version_requirement' => '*',
      'name' => 'Distribution profile',
      'distribution' => [
        'name' => 'My Distribution',
        'langcode' => $this->langcode,
        'install' => [
          'theme' => 'claro',
        ],
      ],
    ];
protected $info;

  /** * {@inheritdoc} */
  protected $defaultTheme = 'stark';

  /** * {@inheritdoc} */
  protected function prepareEnvironment() {
    parent::prepareEnvironment();
    $this->info = [
      'type' => 'profile',
      'core_version_requirement' => '*',
      'name' => 'Distribution profile',
      'distribution' => [
        'name' => 'My Distribution',
        'install' => [
          'theme' => 'olivero',
        ],
      ],
    ];
    

  public function setup($profile = 'testing', $setup_class = NULL, $langcode = 'en') {
    $this->profile = $profile;
    $this->langcode = $langcode;
    $this->setupBaseUrl();
    $this->prepareEnvironment();
    $this->executePreinstallClass($setup_class);
    $this->installDrupal();
    $this->executeSetupClass($setup_class);
  }

  /** * Installs Drupal into the test site. */
  protected function installDrupal() {
    $this->initUserSession();
    $this->prepareSettings();
    
protected $info;

  /** * {@inheritdoc} */
  protected $defaultTheme = 'stark';

  /** * {@inheritdoc} */
  protected function prepareEnvironment() {
    parent::prepareEnvironment();
    // Create two distributions.     foreach (['distribution_one', 'distribution_two'] as $name) {
      $info = [
        'type' => 'profile',
        'core_version_requirement' => '*',
        'name' => $name . ' profile',
        'distribution' => [
          'name' => $name,
          'install' => [
            'theme' => 'claro',
          ],
        ],
protected $profile = NULL;

  /** * {@inheritdoc} */
  protected $defaultTheme = 'stark';

  /** * {@inheritdoc} */
  protected function prepareEnvironment() {
    parent::prepareEnvironment();
    $profiles = ['standard', 'demo_umami'];
    foreach ($profiles as $profile) {
      $info = [
        'type' => 'profile',
        'core_version_requirement' => '^8 || ^9 || ^10',
        'name' => 'Override ' . $profile,
        'hidden' => TRUE,
      ];
      // File API functions are not available yet.       $path = $this->siteDirectory . '/profiles/' . $profile;
      mkdir($path, 0777, TRUE);
      
protected $defaultTheme = 'stark';

  /** * {@inheritdoc} */
  protected $profile = 'cache_flush_test';

  /** * {@inheritdoc} */
  protected function prepareEnvironment() {
    parent::prepareEnvironment();
    $info = [
      'type' => 'profile',
      'core_version_requirement' => '*',
      'name' => 'Cache flush test',
      'install' => ['language'],
    ];
    // File API functions are not available yet.     $path = $this->siteDirectory . '/profiles/cache_flush_test';
    mkdir($path, 0777, TRUE);
    file_put_contents("$path/cache_flush_test.info.yml", Yaml::encode($info));
    $php_code = <<<EOF
Home | Imprint | This part of the site doesn't use cookies.