You are here

public function LanguageConfigurationElementTest::testLanguageConfigurationElement in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/language/src/Tests/LanguageConfigurationElementTest.php \Drupal\language\Tests\LanguageConfigurationElementTest::testLanguageConfigurationElement()

Tests the language settings have been saved.

File

core/modules/language/src/Tests/LanguageConfigurationElementTest.php, line 38
Contains \Drupal\language\Tests\LanguageConfigurationElementTest.

Class

LanguageConfigurationElementTest
Tests the features of the language configuration element field.

Namespace

Drupal\language\Tests

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 = array(
    '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');
}