InstallerTranslationTest.php 2.49 KB
Newer Older
1 2 3 4 5 6 7 8 9
<?php

/**
 * @file
 * Contains \Drupal\system\Tests\Installer\InstallerTranslationTest.
 */

namespace Drupal\system\Tests\Installer;

10
use Drupal\simpletest\InstallerTestBase;
11
use Drupal\user\Entity\User;
12 13

/**
14 15 16 17
 * Selects German as the installation language and verifies the following page
 * is not in English.
 *
 * @group Installer
18
 */
19
class InstallerTranslationTest extends InstallerTestBase {
20

21
  /**
22
   * Overrides the language code in which to install Drupal.
23
   *
24
   * @var string
25
   */
26
  protected $langcode = 'de';
27

28 29 30 31
  /**
   * Overrides InstallerTest::setUpLanguage().
   */
  protected function setUpLanguage() {
32
    // Place a custom local translation in the translations directory.
33 34
    mkdir(\Drupal::root() . '/' . $this->siteDirectory . '/files/translations', 0777, TRUE);
    file_put_contents(\Drupal::root() . '/' . $this->siteDirectory . '/files/translations/drupal-8.0.0.de.po', "msgid \"\"\nmsgstr \"\"\nmsgid \"Save and continue\"\nmsgstr \"Save and continue German\"");
35

36 37 38 39
    parent::setUpLanguage();
    // After selecting a different language than English, all following screens
    // should be translated already.
    $elements = $this->xpath('//input[@type="submit"]/@value');
40 41
    $this->assertEqual((string) current($elements), 'Save and continue German');
    $this->translations['Save and continue'] = 'Save and continue German';
42 43 44 45

    // Check the language direction.
    $direction = (string) current($this->xpath('/html/@dir'));
    $this->assertEqual($direction, 'ltr');
46
  }
47

48 49 50 51 52 53
  /**
   * Verifies that installation succeeded.
   */
  public function testInstaller() {
    $this->assertUrl('user/1');
    $this->assertResponse(200);
54

55
    $account = User::load(0);
56
    $this->assertEqual($account->language()->getId(), 'en', 'Anonymous user is English.');
57
    $account = User::load(1);
58 59 60
    $this->assertEqual($account->language()->getId(), 'en', 'Administrator user is English.');
    $account = $this->drupalCreateUser();
    $this->assertEqual($account->language()->getId(), 'de', 'New user is German.');
61

62 63 64
    // 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('Save configuration'));
    $this->assertResponse(200);
65 66 67 68 69

    // 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>');
70
    $this->assertRaw('classy/css/layout.css');
71 72
  }

73
}