You are here

public function TermLanguageTest::testDefaultTermLanguage in Drupal 9

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

File

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

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
    ->drupalGet('admin/structure/taxonomy/manage/' . $this->vocabulary
    ->id());
  $this
    ->submitForm($edit, 'Save');
  $this
    ->drupalGet('admin/structure/taxonomy/manage/' . $this->vocabulary
    ->id() . '/add');
  $this
    ->assertTrue($this
    ->assertSession()
    ->optionExists('edit-langcode-0-value', 'bb')
    ->isSelected());

  // Make the default language of the terms to be the current interface.
  $edit = [
    'default_language[langcode]' => 'current_interface',
    'default_language[language_alterable]' => TRUE,
  ];
  $this
    ->drupalGet('admin/structure/taxonomy/manage/' . $this->vocabulary
    ->id());
  $this
    ->submitForm($edit, 'Save');
  $this
    ->drupalGet('aa/admin/structure/taxonomy/manage/' . $this->vocabulary
    ->id() . '/add');
  $this
    ->assertTrue($this
    ->assertSession()
    ->optionExists('edit-langcode-0-value', 'aa')
    ->isSelected());
  $this
    ->drupalGet('bb/admin/structure/taxonomy/manage/' . $this->vocabulary
    ->id() . '/add');
  $this
    ->assertTrue($this
    ->assertSession()
    ->optionExists('edit-langcode-0-value', 'bb')
    ->isSelected());

  // 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
    ->drupalGet('admin/structure/taxonomy/manage/' . $this->vocabulary
    ->id());
  $this
    ->submitForm($edit, 'Save');
  $this
    ->drupalGet('admin/structure/taxonomy/manage/' . $this->vocabulary
    ->id() . '/add');
  $this
    ->assertTrue($this
    ->assertSession()
    ->optionExists('edit-langcode-0-value', 'cc')
    ->isSelected());
}