Chris@0: drupalLogin($this->drupalCreateUser(['administer taxonomy'])); Chris@0: Chris@0: // Create a vocabulary to which the terms will be assigned. Chris@0: $this->vocabulary = $this->createVocabulary(); Chris@0: Chris@0: // Add some custom languages. Chris@0: foreach (['aa', 'bb', 'cc'] as $language_code) { Chris@0: ConfigurableLanguage::create([ Chris@0: 'id' => $language_code, Chris@0: 'label' => $this->randomMachineName(), Chris@0: ])->save(); Chris@0: } Chris@0: } Chris@0: Chris@0: public function testTermLanguage() { Chris@0: // Configure the vocabulary to not hide the language selector. Chris@0: $edit = [ Chris@0: 'default_language[language_alterable]' => TRUE, Chris@0: ]; Chris@0: $this->drupalPostForm('admin/structure/taxonomy/manage/' . $this->vocabulary->id(), $edit, t('Save')); Chris@0: Chris@0: // Add a term. Chris@0: $this->drupalGet('admin/structure/taxonomy/manage/' . $this->vocabulary->id() . '/add'); Chris@0: // Check that we have the language selector. Chris@0: $this->assertField('edit-langcode-0-value', t('The language selector field was found on the page.')); Chris@0: // Submit the term. Chris@0: $edit = [ Chris@0: 'name[0][value]' => $this->randomMachineName(), Chris@0: 'langcode[0][value]' => 'aa', Chris@0: ]; Chris@0: $this->drupalPostForm(NULL, $edit, t('Save')); Chris@0: $terms = taxonomy_term_load_multiple_by_name($edit['name[0][value]']); Chris@0: $term = reset($terms); Chris@0: $this->assertEqual($term->language()->getId(), $edit['langcode[0][value]'], 'The term contains the correct langcode.'); Chris@0: Chris@0: // Check if on the edit page the language is correct. Chris@0: $this->drupalGet('taxonomy/term/' . $term->id() . '/edit'); Chris@0: $this->assertOptionSelected('edit-langcode-0-value', $edit['langcode[0][value]'], 'The term language was correctly selected.'); Chris@0: Chris@0: // Change the language of the term. Chris@0: $edit['langcode[0][value]'] = 'bb'; Chris@0: $this->drupalPostForm('taxonomy/term/' . $term->id() . '/edit', $edit, t('Save')); Chris@0: Chris@0: // Check again that on the edit page the language is correct. Chris@0: $this->drupalGet('taxonomy/term/' . $term->id() . '/edit'); Chris@0: $this->assertOptionSelected('edit-langcode-0-value', $edit['langcode[0][value]'], 'The term language was correctly selected.'); Chris@0: } Chris@0: Chris@0: public function testDefaultTermLanguage() { Chris@0: // Configure the vocabulary to not hide the language selector, and make the Chris@0: // default language of the terms fixed. Chris@0: $edit = [ Chris@0: 'default_language[langcode]' => 'bb', Chris@0: 'default_language[language_alterable]' => TRUE, Chris@0: ]; Chris@0: $this->drupalPostForm('admin/structure/taxonomy/manage/' . $this->vocabulary->id(), $edit, t('Save')); Chris@0: $this->drupalGet('admin/structure/taxonomy/manage/' . $this->vocabulary->id() . '/add'); Chris@0: $this->assertOptionSelected('edit-langcode-0-value', 'bb', 'The expected langcode was selected.'); Chris@0: Chris@0: // Make the default language of the terms to be the current interface. Chris@0: $edit = [ Chris@0: 'default_language[langcode]' => 'current_interface', Chris@0: 'default_language[language_alterable]' => TRUE, Chris@0: ]; Chris@0: $this->drupalPostForm('admin/structure/taxonomy/manage/' . $this->vocabulary->id(), $edit, t('Save')); Chris@0: $this->drupalGet('aa/admin/structure/taxonomy/manage/' . $this->vocabulary->id() . '/add'); Chris@0: $this->assertOptionSelected('edit-langcode-0-value', 'aa', "The expected langcode, 'aa', was selected."); Chris@0: $this->drupalGet('bb/admin/structure/taxonomy/manage/' . $this->vocabulary->id() . '/add'); Chris@0: $this->assertOptionSelected('edit-langcode-0-value', 'bb', "The expected langcode, 'bb', was selected."); Chris@0: Chris@0: // Change the default language of the site and check if the default terms Chris@0: // language is still correctly selected. Chris@0: $this->config('system.site')->set('default_langcode', 'cc')->save(); Chris@0: $edit = [ Chris@0: 'default_language[langcode]' => LanguageInterface::LANGCODE_SITE_DEFAULT, Chris@0: 'default_language[language_alterable]' => TRUE, Chris@0: ]; Chris@0: $this->drupalPostForm('admin/structure/taxonomy/manage/' . $this->vocabulary->id(), $edit, t('Save')); Chris@0: $this->drupalGet('admin/structure/taxonomy/manage/' . $this->vocabulary->id() . '/add'); Chris@0: $this->assertOptionSelected('edit-langcode-0-value', 'cc', "The expected langcode, 'cc', was selected."); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Tests that translated terms are displayed correctly on the term overview. Chris@0: */ Chris@0: public function testTermTranslatedOnOverviewPage() { Chris@0: // Configure the vocabulary to not hide the language selector. Chris@0: $edit = [ Chris@0: 'default_language[language_alterable]' => TRUE, Chris@0: ]; Chris@0: $this->drupalPostForm('admin/structure/taxonomy/manage/' . $this->vocabulary->id(), $edit, t('Save')); Chris@0: Chris@0: // Add a term. Chris@0: $this->drupalGet('admin/structure/taxonomy/manage/' . $this->vocabulary->id() . '/add'); Chris@0: // Submit the term. Chris@0: $edit = [ Chris@0: 'name[0][value]' => $this->randomMachineName(), Chris@0: 'langcode[0][value]' => 'aa', Chris@0: ]; Chris@0: $this->drupalPostForm(NULL, $edit, t('Save')); Chris@0: $terms = taxonomy_term_load_multiple_by_name($edit['name[0][value]']); Chris@0: $term = reset($terms); Chris@0: Chris@0: // Add a translation for that term. Chris@0: $translated_title = $this->randomMachineName(); Chris@0: $term->addTranslation('bb', [ Chris@0: 'name' => $translated_title, Chris@0: ]); Chris@0: $term->save(); Chris@0: Chris@0: // Overview page in the other language shows the translated term Chris@0: $this->drupalGet('bb/admin/structure/taxonomy/manage/' . $this->vocabulary->id() . '/overview'); Chris@0: $this->assertPattern('|]*>' . $translated_title . '|', 'The term language is correct'); Chris@0: } Chris@0: Chris@0: }