You are here

public function InstallerTranslationTest::testInstaller in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/system/src/Tests/Installer/InstallerTranslationTest.php \Drupal\system\Tests\Installer\InstallerTranslationTest::testInstaller()

Verifies the expected behaviors of the installation result.

File

core/modules/system/src/Tests/Installer/InstallerTranslationTest.php, line 72
Contains \Drupal\system\Tests\Installer\InstallerTranslationTest.

Class

InstallerTranslationTest
Installs Drupal in German and checks resulting site.

Namespace

Drupal\system\Tests\Installer

Code

public function testInstaller() {
  $this
    ->assertUrl('user/1');
  $this
    ->assertResponse(200);

  // Verify German was configured but not English.
  $this
    ->drupalGet('admin/config/regional/language');
  $this
    ->assertText('German');
  $this
    ->assertNoText('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
    ->assertEqual($account
    ->language()
    ->getId(), 'en', 'Anonymous user is English.');
  $account = User::load(1);
  $this
    ->assertEqual($account
    ->language()
    ->getId(), 'en', 'Administrator user is English.');
  $account = $this
    ->drupalCreateUser();
  $this
    ->assertEqual($account
    ->language()
    ->getId(), 'de', 'New user is German.');

  // Ensure that we can enable basic_auth on a non-english site.
  $this
    ->drupalPostForm('admin/modules', array(
    'modules[Web services][basic_auth][enable]' => TRUE,
  ), t('Install'));
  $this
    ->assertResponse(200);

  // Assert that the theme CSS was added to the page.
  $edit = array(
    'preprocess_css' => FALSE,
  );
  $this
    ->drupalPostForm('admin/config/development/performance', $edit, t('Save configuration'));
  $this
    ->drupalGet('<front>');
  $this
    ->assertRaw('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 = array();
    $edit['langcode'] = 'de';
    $edit['translation'] = 'translated';
    $edit['string'] = $sample;
    $this
      ->drupalPostForm('admin/config/regional/translate', $edit, t('Filter'));
    $this
      ->assertText($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
    ->assertEqual($config
    ->get('anonymous'), 'Anonymous de');
  $this
    ->assertEqual($config
    ->get('langcode'), 'de');
  $this
    ->assertTrue($override_de
    ->isNew());
  $this
    ->assertTrue($override_en
    ->isNew());

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