You are here

public function LanguageSelectElementTest::testHiddenLanguageSelectElement in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/system/tests/src/Functional/Form/LanguageSelectElementTest.php \Drupal\Tests\system\Functional\Form\LanguageSelectElementTest::testHiddenLanguageSelectElement()
  2. 10 core/modules/system/tests/src/Functional/Form/LanguageSelectElementTest.php \Drupal\Tests\system\Functional\Form\LanguageSelectElementTest::testHiddenLanguageSelectElement()

Tests the case when the language select elements should not be printed.

This happens when the language module is disabled.

File

core/modules/system/tests/src/Functional/Form/LanguageSelectElementTest.php, line 77

Class

LanguageSelectElementTest
Tests that the language select form element prints and submits the right options.

Namespace

Drupal\Tests\system\Functional\Form

Code

public function testHiddenLanguageSelectElement() {

  // Disable the language module, so that the language select field will not
  // be rendered.
  $this->container
    ->get('module_installer')
    ->uninstall([
    'language',
  ]);
  $this
    ->drupalGet('form-test/language_select');

  // Check that the language fields were rendered on the page.
  $ids = [
    'edit-languages-all',
    'edit-languages-configurable',
    'edit-languages-locked',
    'edit-languages-config-and-locked',
  ];
  foreach ($ids as $id) {
    $this
      ->assertNoField($id, new FormattableMarkup('The @id field was not found on the page.', [
      '@id' => $id,
    ]));
  }

  // Check that the submitted values were the default values of the language
  // field elements.
  $edit = [];
  $this
    ->drupalPostForm(NULL, $edit, t('Submit'));
  $values = Json::decode($this
    ->getSession()
    ->getPage()
    ->getContent());
  $this
    ->assertEqual($values['languages_all'], 'xx');
  $this
    ->assertEqual($values['languages_configurable'], 'en');
  $this
    ->assertEqual($values['languages_locked'], LanguageInterface::LANGCODE_NOT_SPECIFIED);
  $this
    ->assertEqual($values['languages_config_and_locked'], 'dummy_value');
  $this
    ->assertEqual($values['language_custom_options'], 'opt2');
}