Chris@0: drupalLogin($this->drupalCreateUser(['administer taxonomy'])); Chris@0: Chris@0: // Add some custom languages. Chris@0: ConfigurableLanguage::create([ Chris@0: 'id' => 'aa', Chris@0: 'label' => $this->randomMachineName(), Chris@0: ])->save(); Chris@0: Chris@0: ConfigurableLanguage::create([ Chris@0: 'id' => 'bb', Chris@0: 'label' => $this->randomMachineName(), Chris@0: ])->save(); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Tests language settings for vocabularies. Chris@0: */ Chris@0: public function testVocabularyLanguage() { Chris@0: $this->drupalGet('admin/structure/taxonomy/add'); Chris@0: Chris@0: // Check that we have the language selector available. Chris@0: $this->assertField('edit-langcode', 'The language selector field was found on the page.'); Chris@0: Chris@0: // Create the vocabulary. Chris@17: $vid = mb_strtolower($this->randomMachineName()); Chris@0: $edit['name'] = $this->randomMachineName(); Chris@0: $edit['description'] = $this->randomMachineName(); Chris@0: $edit['langcode'] = 'aa'; Chris@0: $edit['vid'] = $vid; Chris@0: $this->drupalPostForm(NULL, $edit, t('Save')); Chris@0: Chris@0: // Check the language on the edit page. Chris@0: $this->drupalGet('admin/structure/taxonomy/manage/' . $vid); Chris@0: $this->assertOptionSelected('edit-langcode', $edit['langcode'], 'The vocabulary language was correctly selected.'); Chris@0: Chris@0: // Change the language and save again. Chris@0: $edit['langcode'] = 'bb'; Chris@0: unset($edit['vid']); Chris@0: $this->drupalPostForm(NULL, $edit, t('Save')); Chris@0: Chris@0: // Check again the language on the edit page. Chris@0: $this->drupalGet('admin/structure/taxonomy/manage/' . $vid); Chris@0: $this->assertOptionSelected('edit-langcode', $edit['langcode'], 'The vocabulary language was correctly selected.'); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Tests term language settings for vocabulary terms are saved and updated. Chris@0: */ Chris@0: public function testVocabularyDefaultLanguageForTerms() { Chris@0: // Add a new vocabulary and check that the default language settings are for Chris@0: // the terms are saved. Chris@0: $edit = [ Chris@0: 'name' => $this->randomMachineName(), Chris@17: 'vid' => mb_strtolower($this->randomMachineName()), Chris@0: 'default_language[langcode]' => 'bb', Chris@0: 'default_language[language_alterable]' => TRUE, Chris@0: ]; Chris@0: $vid = $edit['vid']; Chris@0: $this->drupalPostForm('admin/structure/taxonomy/add', $edit, t('Save')); Chris@0: Chris@0: // Check that the vocabulary was actually created. Chris@0: $this->drupalGet('admin/structure/taxonomy/manage/' . $edit['vid']); Chris@0: $this->assertResponse(200, 'The vocabulary has been created.'); Chris@0: Chris@0: // Check that the language settings were saved. Chris@0: $language_settings = ContentLanguageSettings::loadByEntityTypeBundle('taxonomy_term', $edit['vid']); Chris@0: $this->assertEqual($language_settings->getDefaultLangcode(), 'bb', 'The langcode was saved.'); Chris@0: $this->assertTrue($language_settings->isLanguageAlterable(), 'The visibility setting was saved.'); Chris@0: Chris@0: // Check that the correct options are selected in the interface. Chris@0: $this->assertOptionSelected('edit-default-language-langcode', 'bb', 'The correct default language for the terms of this vocabulary is selected.'); Chris@0: $this->assertFieldChecked('edit-default-language-language-alterable', 'Show language selection option is checked.'); Chris@0: Chris@0: // Edit the vocabulary and check that the new settings are updated. Chris@0: $edit = [ Chris@0: 'default_language[langcode]' => 'aa', Chris@0: 'default_language[language_alterable]' => FALSE, Chris@0: ]; Chris@0: $this->drupalPostForm('admin/structure/taxonomy/manage/' . $vid, $edit, t('Save')); Chris@0: Chris@0: // And check again the settings and also the interface. Chris@0: $language_settings = ContentLanguageSettings::loadByEntityTypeBundle('taxonomy_term', $vid); Chris@0: $this->assertEqual($language_settings->getDefaultLangcode(), 'aa', 'The langcode was saved.'); Chris@0: $this->assertFalse($language_settings->isLanguageAlterable(), 'The visibility setting was saved.'); Chris@0: Chris@0: $this->drupalGet('admin/structure/taxonomy/manage/' . $vid); Chris@0: $this->assertOptionSelected('edit-default-language-langcode', 'aa', 'The correct default language for the terms of this vocabulary is selected.'); Chris@0: $this->assertNoFieldChecked('edit-default-language-language-alterable', 'Show language selection option is not checked.'); Chris@0: Chris@0: // Check that language settings are changed after editing vocabulary. Chris@0: $edit = [ Chris@0: 'name' => $this->randomMachineName(), Chris@0: 'default_language[langcode]' => 'authors_default', Chris@0: 'default_language[language_alterable]' => FALSE, Chris@0: ]; Chris@0: $this->drupalPostForm('admin/structure/taxonomy/manage/' . $vid, $edit, t('Save')); Chris@0: Chris@0: // Check that we have the new settings. Chris@0: $new_settings = ContentLanguageSettings::loadByEntityTypeBundle('taxonomy_term', $vid); Chris@0: $this->assertEqual($new_settings->getDefaultLangcode(), 'authors_default', 'The langcode was saved.'); Chris@0: $this->assertFalse($new_settings->isLanguageAlterable(), 'The new visibility setting was saved.'); Chris@0: } Chris@0: Chris@0: }