You are here

public function InstallerTranslationTest::testInstaller in Drupal 9

Same name and namespace in other branches
  1. 8 core/tests/Drupal/FunctionalTests/Installer/InstallerTranslationTest.php \Drupal\FunctionalTests\Installer\InstallerTranslationTest::testInstaller()

Verifies the expected behaviors of the installation result.

File

core/tests/Drupal/FunctionalTests/Installer/InstallerTranslationTest.php, line 82

Class

InstallerTranslationTest
Installs Drupal in German and checks resulting site.

Namespace

Drupal\FunctionalTests\Installer

Code

public function testInstaller() {
  $this
    ->assertSession()
    ->addressEquals('user/1');
  $this
    ->assertSession()
    ->statusCodeEquals(200);

  // Verify German was configured but not English.
  $this
    ->drupalGet('admin/config/regional/language');
  $this
    ->assertSession()
    ->pageTextContains('German');
  $this
    ->assertSession()
    ->pageTextNotContains('English');

  // The current container still has the english as current language, rebuild.
  $this
    ->rebuildContainer();

  /** @var \Drupal\user\Entity\User $account */
  $account = User::load(0);
  $this
    ->assertEquals('de', $account
    ->language()
    ->getId(), 'Anonymous user is German.');
  $account = User::load(1);
  $this
    ->assertEquals('de', $account
    ->language()
    ->getId(), 'Administrator user is German.');
  $account = $this
    ->drupalCreateUser();
  $this
    ->assertEquals('de', $account
    ->language()
    ->getId(), 'New user is German.');

  // Ensure that we can enable basic_auth on a non-english site.
  $this
    ->drupalGet('admin/modules');
  $this
    ->submitForm([
    'modules[basic_auth][enable]' => TRUE,
  ], 'Install');
  $this
    ->assertSession()
    ->statusCodeEquals(200);

  // Assert that the theme CSS was added to the page.
  $edit = [
    'preprocess_css' => FALSE,
  ];
  $this
    ->drupalGet('admin/config/development/performance');
  $this
    ->submitForm($edit, 'Save configuration');
  $this
    ->drupalGet('<front>');
  $this
    ->assertSession()
    ->responseContains('classy/css/components/action-links.css');

  // Verify the strings from the translation files were imported.
  $test_samples = [
    'Save and continue',
    'Anonymous',
  ];
  foreach ($test_samples as $sample) {
    $edit = [];
    $edit['langcode'] = 'de';
    $edit['translation'] = 'translated';
    $edit['string'] = $sample;
    $this
      ->drupalGet('admin/config/regional/translate');
    $this
      ->submitForm($edit, 'Filter');
    $this
      ->assertSession()
      ->pageTextContains($sample . ' de');
  }

  /** @var \Drupal\language\ConfigurableLanguageManager $language_manager */
  $language_manager = \Drupal::languageManager();

  // Installed in German, configuration should be in German. No German or
  // English overrides should be present.
  $config = \Drupal::config('user.settings');
  $override_de = $language_manager
    ->getLanguageConfigOverride('de', 'user.settings');
  $override_en = $language_manager
    ->getLanguageConfigOverride('en', 'user.settings');
  $this
    ->assertEquals('Anonymous de', $config
    ->get('anonymous'));
  $this
    ->assertEquals('de', $config
    ->get('langcode'));
  $this
    ->assertTrue($override_de
    ->isNew());
  $this
    ->assertTrue($override_en
    ->isNew());

  // Assert that adding English makes the English override available.
  $edit = [
    'predefined_langcode' => 'en',
  ];
  $this
    ->drupalGet('admin/config/regional/language/add');
  $this
    ->submitForm($edit, 'Add language');
  $override_en = $language_manager
    ->getLanguageConfigOverride('en', 'user.settings');
  $this
    ->assertFalse($override_en
    ->isNew());
  $this
    ->assertEquals('Anonymous', $override_en
    ->get('anonymous'));
}