VocabularyTranslationTest.php in Drupal 10
File
core/modules/taxonomy/tests/src/Functional/VocabularyTranslationTest.php
View source
<?php
namespace Drupal\Tests\taxonomy\Functional;
use Drupal\language\Entity\ConfigurableLanguage;
class VocabularyTranslationTest extends TaxonomyTestBase {
protected static $modules = [
'content_translation',
'language',
'config_translation',
];
protected $defaultTheme = 'stark';
protected $additionalLangcodes = [
'es',
];
protected function setUp() : void {
parent::setUp();
$this
->drupalLogin($this
->drupalCreateUser([
'administer taxonomy',
'administer content translation',
'translate configuration',
]));
foreach ($this->additionalLangcodes as $langcode) {
ConfigurableLanguage::createFromLangcode($langcode)
->save();
}
}
public function testVocabularyLanguage() {
$this
->drupalGet('admin/structure/taxonomy/add');
$this
->assertSession()
->fieldExists('edit-default-language-content-translation');
$vid = mb_strtolower($this
->randomMachineName());
$edit['name'] = $this
->randomMachineName();
$edit['description'] = $this
->randomMachineName();
$edit['langcode'] = 'en';
$edit['vid'] = $vid;
$edit['default_language[content_translation]'] = TRUE;
$this
->submitForm($edit, 'Save');
$this
->drupalGet('admin/structure/taxonomy/manage/' . $vid);
$this
->assertSession()
->checkboxChecked('edit-default-language-content-translation');
}
public function testVocabularyTitleLabelTranslation() : void {
$this
->drupalGet('admin/structure/taxonomy/add');
$vid = mb_strtolower($this
->randomMachineName());
$edit['name'] = $this
->randomMachineName();
$edit['description'] = $this
->randomMachineName();
$edit['langcode'] = 'en';
$edit['vid'] = $vid;
$edit['default_language[content_translation]'] = TRUE;
$this
->submitForm($edit, 'Save');
$langcode = $this->additionalLangcodes[0];
$vid_name = $edit['name'];
$translated_vid_name = "Translated {$vid_name}";
$this
->assertSession()
->pageTextContains($vid_name);
$this
->drupalGet("admin/structure/taxonomy/manage/{$vid}/translate/{$langcode}/add");
$this
->submitForm([
"translation[config_names][taxonomy.vocabulary.{$vid}][name]" => $translated_vid_name,
], 'Save translation');
$this
->drupalGet("admin/structure/taxonomy/manage/{$vid}/overview");
$this
->assertSession()
->pageTextContains($vid_name);
$this
->drupalGet("{$langcode}/admin/structure/taxonomy/manage/{$vid}/overview");
$this
->assertSession()
->pageTextContains($translated_vid_name);
$this
->drupalGet("admin/structure/taxonomy/manage/{$vid}/reset");
$this
->assertSession()
->pageTextContains($vid_name);
$this
->drupalGet("{$langcode}/admin/structure/taxonomy/manage/{$vid}/reset");
$this
->assertSession()
->pageTextContains($translated_vid_name);
}
}