View source
<?php
namespace Drupal\taxonomy\Tests;
use Drupal\Component\Utility\Unicode;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\language\Entity\ContentLanguageSettings;
class VocabularyLanguageTest extends TaxonomyTestBase {
public static $modules = array(
'language',
);
protected function setUp() {
parent::setUp();
$this
->drupalLogin($this
->drupalCreateUser([
'administer taxonomy',
]));
ConfigurableLanguage::create(array(
'id' => 'aa',
'label' => $this
->randomMachineName(),
))
->save();
ConfigurableLanguage::create(array(
'id' => 'bb',
'label' => $this
->randomMachineName(),
))
->save();
}
function testVocabularyLanguage() {
$this
->drupalGet('admin/structure/taxonomy/add');
$this
->assertField('edit-langcode', 'The language selector field was found on the page.');
$vid = Unicode::strtolower($this
->randomMachineName());
$edit['name'] = $this
->randomMachineName();
$edit['description'] = $this
->randomMachineName();
$edit['langcode'] = 'aa';
$edit['vid'] = $vid;
$this
->drupalPostForm(NULL, $edit, t('Save'));
$this
->drupalGet('admin/structure/taxonomy/manage/' . $vid);
$this
->assertOptionSelected('edit-langcode', $edit['langcode'], 'The vocabulary language was correctly selected.');
$edit['langcode'] = 'bb';
unset($edit['vid']);
$this
->drupalPostForm(NULL, $edit, t('Save'));
$this
->drupalGet('admin/structure/taxonomy/manage/' . $vid);
$this
->assertOptionSelected('edit-langcode', $edit['langcode'], 'The vocabulary language was correctly selected.');
}
function testVocabularyDefaultLanguageForTerms() {
$edit = array(
'name' => $this
->randomMachineName(),
'vid' => Unicode::strtolower($this
->randomMachineName()),
'default_language[langcode]' => 'bb',
'default_language[language_alterable]' => TRUE,
);
$vid = $edit['vid'];
$this
->drupalPostForm('admin/structure/taxonomy/add', $edit, t('Save'));
$this
->drupalGet('admin/structure/taxonomy/manage/' . $edit['vid']);
$this
->assertResponse(200, 'The vocabulary has been created.');
$language_settings = ContentLanguageSettings::loadByEntityTypeBundle('taxonomy_term', $edit['vid']);
$this
->assertEqual($language_settings
->getDefaultLangcode(), 'bb', 'The langcode was saved.');
$this
->assertTrue($language_settings
->isLanguageAlterable(), 'The visibility setting was saved.');
$this
->assertOptionSelected('edit-default-language-langcode', 'bb', 'The correct default language for the terms of this vocabulary is selected.');
$this
->assertFieldChecked('edit-default-language-language-alterable', 'Show language selection option is checked.');
$edit = array(
'default_language[langcode]' => 'aa',
'default_language[language_alterable]' => FALSE,
);
$this
->drupalPostForm('admin/structure/taxonomy/manage/' . $vid, $edit, t('Save'));
$language_settings = ContentLanguageSettings::loadByEntityTypeBundle('taxonomy_term', $vid);
$this
->assertEqual($language_settings
->getDefaultLangcode(), 'aa', 'The langcode was saved.');
$this
->assertFalse($language_settings
->isLanguageAlterable(), 'The visibility setting was saved.');
$this
->drupalGet('admin/structure/taxonomy/manage/' . $vid);
$this
->assertOptionSelected('edit-default-language-langcode', 'aa', 'The correct default language for the terms of this vocabulary is selected.');
$this
->assertNoFieldChecked('edit-default-language-language-alterable', 'Show language selection option is not checked.');
$edit = array(
'name' => $this
->randomMachineName(),
'default_language[langcode]' => 'authors_default',
'default_language[language_alterable]' => FALSE,
);
$this
->drupalPostForm('admin/structure/taxonomy/manage/' . $vid, $edit, t('Save'));
$new_settings = ContentLanguageSettings::loadByEntityTypeBundle('taxonomy_term', $vid);
$this
->assertEqual($new_settings
->getDefaultLangcode(), 'authors_default', 'The langcode was saved.');
$this
->assertFalse($new_settings
->isLanguageAlterable(), 'The new visibility setting was saved.');
}
}