Skip to content
Snippets Groups Projects
Select Git revision
  • 8.9.x
  • 11.x default protected
  • 11.2.x protected
  • 10.5.x protected
  • 10.6.x protected
  • 11.1.x protected
  • 10.4.x protected
  • 11.0.x protected
  • 10.3.x protected
  • 7.x protected
  • 10.2.x protected
  • 10.1.x protected
  • 9.5.x protected
  • 10.0.x protected
  • 9.4.x protected
  • 9.3.x protected
  • 9.2.x protected
  • 9.1.x protected
  • 9.0.x protected
  • 8.8.x protected
  • 10.5.1 protected
  • 11.2.2 protected
  • 11.2.1 protected
  • 11.2.0 protected
  • 10.5.0 protected
  • 11.2.0-rc2 protected
  • 10.5.0-rc1 protected
  • 11.2.0-rc1 protected
  • 10.4.8 protected
  • 11.1.8 protected
  • 10.5.0-beta1 protected
  • 11.2.0-beta1 protected
  • 11.2.0-alpha1 protected
  • 10.4.7 protected
  • 11.1.7 protected
  • 10.4.6 protected
  • 11.1.6 protected
  • 10.3.14 protected
  • 10.4.5 protected
  • 11.0.13 protected
40 results

DistributionProfileExistingSettingsTest.php

Blame
  • catch's avatar
    Issue #3123120 by mondrake, mrinalini9, ridhimaabrol24, longwave, catch:...
    catch authored
    Issue #3123120 by mondrake, mrinalini9, ridhimaabrol24, longwave, catch: [backport] Properly deprecate AssertLegacyTrait::pass
    baab371f
    History
    Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    DistributionProfileExistingSettingsTest.php 3.93 KiB
    <?php
    
    namespace Drupal\FunctionalTests\Installer;
    
    use Drupal\Component\Serialization\Yaml;
    use Drupal\Core\Database\Database;
    use Drupal\Core\DrupalKernel;
    use Drupal\Core\Site\Settings;
    use Symfony\Component\HttpFoundation\Request;
    
    /**
     * Tests distribution profile support with existing settings.
     *
     * @group Installer
     */
    class DistributionProfileExistingSettingsTest extends InstallerTestBase {
    
      /**
       * The distribution profile info.
       *
       * @var array
       */
      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' => 'bartik',
            ],
          ],
        ];
        // File API functions are not available yet.
        $path = $this->siteDirectory . '/profiles/mydistro';
        mkdir($path, 0777, TRUE);
        file_put_contents("$path/mydistro.info.yml", Yaml::encode($this->info));
    
        // Pre-configure hash salt.
        // Any string is valid, so simply use the class name of this test.
        $this->settings['settings']['hash_salt'] = (object) [
          'value' => __CLASS__,
          'required' => TRUE,
        ];
    
        // Pre-configure database credentials.
        $connection_info = Database::getConnectionInfo();
        unset($connection_info['default']['pdo']);
        unset($connection_info['default']['init_commands']);
    
        $this->settings['databases']['default'] = (object) [
          'value' => $connection_info,
          'required' => TRUE,
        ];
    
        // Use the kernel to find the site path because the site.path service should
        // not be available at this point in the install process.
        $site_path = DrupalKernel::findSitePath(Request::createFromGlobals());
        // Pre-configure config directories.
        $this->settings['settings']['config_sync_directory'] = (object) [
          'value' => $site_path . '/files/config_staging',
          'required' => TRUE,
        ];
        mkdir($this->settings['settings']['config_sync_directory']->value, 0777, TRUE);
      }
    
      /**
       * {@inheritdoc}
       */
      protected function setUpLanguage() {
        // Make settings file not writable.
        $filename = $this->siteDirectory . '/settings.php';
        // Make the settings file read-only.
        // Not using File API; a potential error must trigger a PHP warning.
        chmod($filename, 0444);
    
        // Verify that the distribution name appears.
        $this->assertRaw($this->info['distribution']['name']);
        // Verify that the requested theme is used.
        $this->assertRaw($this->info['distribution']['install']['theme']);
        // Verify that the "Choose profile" step does not appear.
        $this->assertNoText('profile');
    
        parent::setUpLanguage();
      }
    
      /**
       * {@inheritdoc}
       */
      protected function setUpProfile() {
        // This step is skipped, because there is a distribution profile.
      }
    
      /**
       * {@inheritdoc}
       */
      protected function setUpSettings() {
        // This step should not appear, since settings.php is fully configured
        // already.
      }
    
      /**
       * Confirms that the installation succeeded.
       */
      public function testInstalled() {
        $this->assertUrl('user/1');
        $this->assertSession()->statusCodeEquals(200);
        // Confirm that we are logged-in after installation.
        $this->assertText($this->rootUser->getAccountName());
    
        // Confirm that Drupal recognizes this distribution as the current profile.
        $this->assertEqual(\Drupal::installProfile(), 'mydistro');
        $this->assertArrayNotHasKey('install_profile', Settings::getAll(), 'The install profile has not been written to settings.php.');
        $this->assertEqual($this->config('core.extension')->get('profile'), 'mydistro', 'The install profile has been written to core.extension configuration.');
    
        $this->rebuildContainer();
        $this->assertEqual(\Drupal::installProfile(), 'mydistro');
      }
    
    }