You are here

public function TermLanguageTest::testDefaultTermLanguage in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/taxonomy/tests/src/Functional/TermLanguageTest.php \Drupal\Tests\taxonomy\Functional\TermLanguageTest::testDefaultTermLanguage()

File

core/modules/taxonomy/tests/src/Functional/TermLanguageTest.php, line 81

Class

TermLanguageTest
Tests the language functionality for the taxonomy terms.

Namespace

Drupal\Tests\taxonomy\Functional

Code

public function testDefaultTermLanguage() {

  // Configure the vocabulary to not hide the language selector, and make the
  // default language of the terms fixed.
  $edit = [
    'default_language[langcode]' => 'bb',
    'default_language[language_alterable]' => TRUE,
  ];
  $this
    ->drupalPostForm('admin/structure/taxonomy/manage/' . $this->vocabulary
    ->id(), $edit, t('Save'));
  $this
    ->drupalGet('admin/structure/taxonomy/manage/' . $this->vocabulary
    ->id() . '/add');
  $this
    ->assertOptionSelected('edit-langcode-0-value', 'bb', 'The expected langcode was selected.');

  // Make the default language of the terms to be the current interface.
  $edit = [
    'default_language[langcode]' => 'current_interface',
    'default_language[language_alterable]' => TRUE,
  ];
  $this
    ->drupalPostForm('admin/structure/taxonomy/manage/' . $this->vocabulary
    ->id(), $edit, t('Save'));
  $this
    ->drupalGet('aa/admin/structure/taxonomy/manage/' . $this->vocabulary
    ->id() . '/add');
  $this
    ->assertOptionSelected('edit-langcode-0-value', 'aa', "The expected langcode, 'aa', was selected.");
  $this
    ->drupalGet('bb/admin/structure/taxonomy/manage/' . $this->vocabulary
    ->id() . '/add');
  $this
    ->assertOptionSelected('edit-langcode-0-value', 'bb', "The expected langcode, 'bb', was selected.");

  // Change the default language of the site and check if the default terms
  // language is still correctly selected.
  $this
    ->config('system.site')
    ->set('default_langcode', 'cc')
    ->save();
  $edit = [
    'default_language[langcode]' => LanguageInterface::LANGCODE_SITE_DEFAULT,
    'default_language[language_alterable]' => TRUE,
  ];
  $this
    ->drupalPostForm('admin/structure/taxonomy/manage/' . $this->vocabulary
    ->id(), $edit, t('Save'));
  $this
    ->drupalGet('admin/structure/taxonomy/manage/' . $this->vocabulary
    ->id() . '/add');
  $this
    ->assertOptionSelected('edit-langcode-0-value', 'cc', "The expected langcode, 'cc', was selected.");
}