function TermLanguageTest::testTermLanguage

Same name and namespace in other branches
  1. 9 core/modules/taxonomy/tests/src/Functional/TermLanguageTest.php \Drupal\Tests\taxonomy\Functional\TermLanguageTest::testTermLanguage()
  2. 8.9.x core/modules/taxonomy/tests/src/Functional/TermLanguageTest.php \Drupal\Tests\taxonomy\Functional\TermLanguageTest::testTermLanguage()
  3. 11.x core/modules/taxonomy/tests/src/Functional/TermLanguageTest.php \Drupal\Tests\taxonomy\Functional\TermLanguageTest::testTermLanguage()

File

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

Class

TermLanguageTest
Tests the language functionality for the taxonomy terms.

Namespace

Drupal\Tests\taxonomy\Functional

Code

public function testTermLanguage() : void {
  // Configure the vocabulary to not hide the language selector.
  $edit = [
    'default_language[language_alterable]' => TRUE,
  ];
  $this->drupalGet('admin/structure/taxonomy/manage/' . $this->vocabulary
    ->id());
  $this->submitForm($edit, 'Save');
  // Add a term.
  $this->drupalGet('admin/structure/taxonomy/manage/' . $this->vocabulary
    ->id() . '/add');
  // Check that we have the language selector.
  $this->assertSession()
    ->fieldExists('edit-langcode-0-value');
  // Submit the term.
  $edit = [
    'name[0][value]' => $this->randomMachineName(),
    'langcode[0][value]' => 'aa',
  ];
  $this->submitForm($edit, 'Save');
  $terms = \Drupal::entityTypeManager()->getStorage('taxonomy_term')
    ->loadByProperties([
    'name' => $edit['name[0][value]'],
  ]);
  $term = reset($terms);
  $this->assertEquals($edit['langcode[0][value]'], $term->language()
    ->getId(), 'The term contains the correct langcode.');
  // Check if on the edit page the language is correct.
  $this->drupalGet('taxonomy/term/' . $term->id() . '/edit');
  $this->assertTrue($this->assertSession()
    ->optionExists('edit-langcode-0-value', $edit['langcode[0][value]'])
    ->isSelected());
  // Change the language of the term.
  $edit['langcode[0][value]'] = 'bb';
  $this->drupalGet('taxonomy/term/' . $term->id() . '/edit');
  $this->submitForm($edit, 'Save');
  // Check again that on the edit page the language is correct.
  $this->drupalGet('taxonomy/term/' . $term->id() . '/edit');
  $this->assertTrue($this->assertSession()
    ->optionExists('edit-langcode-0-value', $edit['langcode[0][value]'])
    ->isSelected());
}

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