function LanguageSelectElementTest::testHiddenLanguageSelectElement

Same name in other branches
  1. 8.9.x 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()
  3. 11.x 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 75

Class

LanguageSelectElementTest
Tests the language selection form element.

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->assertSession()
            ->fieldNotExists($id);
    }
    // Check that the submitted values were the default values of the language
    // field elements.
    $edit = [];
    $this->submitForm($edit, 'Submit');
    $values = Json::decode($this->getSession()
        ->getPage()
        ->getContent());
    $this->assertEquals('xx', $values['languages_all']);
    $this->assertEquals('en', $values['languages_configurable']);
    $this->assertEquals(LanguageInterface::LANGCODE_NOT_SPECIFIED, $values['languages_locked']);
    $this->assertEquals('dummy_value', $values['languages_config_and_locked']);
    $this->assertEquals('opt2', $values['language_custom_options']);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.