You are here

public function LanguageConfigurationElementTest::testLanguageConfigurationElement in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/language/tests/src/Functional/LanguageConfigurationElementTest.php \Drupal\Tests\language\Functional\LanguageConfigurationElementTest::testLanguageConfigurationElement()
  2. 10 core/modules/language/tests/src/Functional/LanguageConfigurationElementTest.php \Drupal\Tests\language\Functional\LanguageConfigurationElementTest::testLanguageConfigurationElement()

Tests the language settings have been saved.

File

core/modules/language/tests/src/Functional/LanguageConfigurationElementTest.php, line 49

Class

LanguageConfigurationElementTest
Tests the features of the language configuration element field.

Namespace

Drupal\Tests\language\Functional

Code

public function testLanguageConfigurationElement() {
  $this
    ->drupalGet('language-tests/language_configuration_element');
  $edit['lang_configuration[langcode]'] = 'current_interface';
  $edit['lang_configuration[language_alterable]'] = FALSE;
  $this
    ->drupalPostForm(NULL, $edit, 'Save');
  $lang_conf = ContentLanguageSettings::loadByEntityTypeBundle('entity_test', 'some_bundle');

  // Check that the settings have been saved.
  $this
    ->assertEqual($lang_conf
    ->getDefaultLangcode(), 'current_interface');
  $this
    ->assertFalse($lang_conf
    ->isLanguageAlterable());
  $this
    ->drupalGet('language-tests/language_configuration_element');
  $this
    ->assertOptionSelected('edit-lang-configuration-langcode', 'current_interface');
  $this
    ->assertNoFieldChecked('edit-lang-configuration-language-alterable');

  // Reload the page and save again.
  $this
    ->drupalGet('language-tests/language_configuration_element');
  $edit['lang_configuration[langcode]'] = 'authors_default';
  $edit['lang_configuration[language_alterable]'] = TRUE;
  $this
    ->drupalPostForm(NULL, $edit, 'Save');
  $lang_conf = ContentLanguageSettings::loadByEntityTypeBundle('entity_test', 'some_bundle');

  // Check that the settings have been saved.
  $this
    ->assertEqual($lang_conf
    ->getDefaultLangcode(), 'authors_default');
  $this
    ->assertTrue($lang_conf
    ->isLanguageAlterable());
  $this
    ->drupalGet('language-tests/language_configuration_element');
  $this
    ->assertOptionSelected('edit-lang-configuration-langcode', 'authors_default');
  $this
    ->assertFieldChecked('edit-lang-configuration-language-alterable');

  // Test if content type settings have been saved.
  $edit = [
    'name' => 'Page',
    'type' => 'page',
    'language_configuration[langcode]' => 'authors_default',
    'language_configuration[language_alterable]' => TRUE,
  ];
  $this
    ->drupalPostForm('admin/structure/types/add', $edit, 'Save and manage fields');

  // Make sure the settings are saved when creating the content type.
  $this
    ->drupalGet('admin/structure/types/manage/page');
  $this
    ->assertOptionSelected('edit-language-configuration-langcode', 'authors_default');
  $this
    ->assertFieldChecked('edit-language-configuration-language-alterable');
}