View source
<?php
namespace Drupal\Tests\taxonomy\Functional;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\language\Entity\ContentLanguageSettings;
class VocabularyLanguageTest extends TaxonomyTestBase {
protected static $modules = [
'language',
];
protected $defaultTheme = 'stark';
protected function setUp() : void {
parent::setUp();
$this
->drupalLogin($this
->drupalCreateUser([
'administer taxonomy',
]));
ConfigurableLanguage::create([
'id' => 'aa',
'label' => $this
->randomMachineName(),
])
->save();
ConfigurableLanguage::create([
'id' => 'bb',
'label' => $this
->randomMachineName(),
])
->save();
}
public function testVocabularyLanguage() {
$this
->drupalGet('admin/structure/taxonomy/add');
$this
->assertSession()
->fieldExists('edit-langcode');
$vid = mb_strtolower($this
->randomMachineName());
$edit['name'] = $this
->randomMachineName();
$edit['description'] = $this
->randomMachineName();
$edit['langcode'] = 'aa';
$edit['vid'] = $vid;
$this
->submitForm($edit, 'Save');
$this
->drupalGet('admin/structure/taxonomy/manage/' . $vid);
$this
->assertTrue($this
->assertSession()
->optionExists('edit-langcode', $edit['langcode'])
->isSelected());
$edit['langcode'] = 'bb';
unset($edit['vid']);
$this
->submitForm($edit, 'Save');
$this
->drupalGet('admin/structure/taxonomy/manage/' . $vid);
$this
->assertTrue($this
->assertSession()
->optionExists('edit-langcode', $edit['langcode'])
->isSelected());
}
public function testVocabularyDefaultLanguageForTerms() {
$edit = [
'name' => $this
->randomMachineName(),
'vid' => mb_strtolower($this
->randomMachineName()),
'default_language[langcode]' => 'bb',
'default_language[language_alterable]' => TRUE,
];
$vid = $edit['vid'];
$this
->drupalGet('admin/structure/taxonomy/add');
$this
->submitForm($edit, 'Save');
$this
->drupalGet('admin/structure/taxonomy/manage/' . $edit['vid']);
$this
->assertSession()
->statusCodeEquals(200);
$language_settings = ContentLanguageSettings::loadByEntityTypeBundle('taxonomy_term', $edit['vid']);
$this
->assertEquals('bb', $language_settings
->getDefaultLangcode(), 'The langcode was saved.');
$this
->assertTrue($language_settings
->isLanguageAlterable(), 'The visibility setting was saved.');
$this
->assertTrue($this
->assertSession()
->optionExists('edit-default-language-langcode', 'bb')
->isSelected());
$this
->assertSession()
->checkboxChecked('edit-default-language-language-alterable');
$edit = [
'default_language[langcode]' => 'aa',
'default_language[language_alterable]' => FALSE,
];
$this
->drupalGet('admin/structure/taxonomy/manage/' . $vid);
$this
->submitForm($edit, 'Save');
$language_settings = ContentLanguageSettings::loadByEntityTypeBundle('taxonomy_term', $vid);
$this
->assertEquals('aa', $language_settings
->getDefaultLangcode(), 'The langcode was saved.');
$this
->assertFalse($language_settings
->isLanguageAlterable(), 'The visibility setting was saved.');
$this
->drupalGet('admin/structure/taxonomy/manage/' . $vid);
$this
->assertTrue($this
->assertSession()
->optionExists('edit-default-language-langcode', 'aa')
->isSelected());
$this
->assertSession()
->checkboxNotChecked('edit-default-language-language-alterable');
$edit = [
'name' => $this
->randomMachineName(),
'default_language[langcode]' => 'authors_default',
'default_language[language_alterable]' => FALSE,
];
$this
->drupalGet('admin/structure/taxonomy/manage/' . $vid);
$this
->submitForm($edit, 'Save');
$new_settings = ContentLanguageSettings::loadByEntityTypeBundle('taxonomy_term', $vid);
$this
->assertEquals('authors_default', $new_settings
->getDefaultLangcode(), 'The langcode was saved.');
$this
->assertFalse($new_settings
->isLanguageAlterable(), 'The new visibility setting was saved.');
}
}