annotate core/modules/taxonomy/tests/src/Functional/VocabularyLanguageTest.php @ 6:875880e46745

Styling
author Chris Cannam
date Fri, 08 Dec 2017 13:21:27 +0000
parents 4c8ae668cc8c
children 129ea1e6d783
rev   line source
Chris@0 1 <?php
Chris@0 2
Chris@0 3 namespace Drupal\Tests\taxonomy\Functional;
Chris@0 4
Chris@0 5 use Drupal\Component\Utility\Unicode;
Chris@0 6 use Drupal\language\Entity\ConfigurableLanguage;
Chris@0 7 use Drupal\language\Entity\ContentLanguageSettings;
Chris@0 8
Chris@0 9 /**
Chris@0 10 * Tests the language functionality for vocabularies.
Chris@0 11 *
Chris@0 12 * @group taxonomy
Chris@0 13 */
Chris@0 14 class VocabularyLanguageTest extends TaxonomyTestBase {
Chris@0 15
Chris@0 16 public static $modules = ['language'];
Chris@0 17
Chris@0 18 protected function setUp() {
Chris@0 19 parent::setUp();
Chris@0 20
Chris@0 21 // Create an administrative user.
Chris@0 22 $this->drupalLogin($this->drupalCreateUser(['administer taxonomy']));
Chris@0 23
Chris@0 24 // Add some custom languages.
Chris@0 25 ConfigurableLanguage::create([
Chris@0 26 'id' => 'aa',
Chris@0 27 'label' => $this->randomMachineName(),
Chris@0 28 ])->save();
Chris@0 29
Chris@0 30 ConfigurableLanguage::create([
Chris@0 31 'id' => 'bb',
Chris@0 32 'label' => $this->randomMachineName(),
Chris@0 33 ])->save();
Chris@0 34 }
Chris@0 35
Chris@0 36 /**
Chris@0 37 * Tests language settings for vocabularies.
Chris@0 38 */
Chris@0 39 public function testVocabularyLanguage() {
Chris@0 40 $this->drupalGet('admin/structure/taxonomy/add');
Chris@0 41
Chris@0 42 // Check that we have the language selector available.
Chris@0 43 $this->assertField('edit-langcode', 'The language selector field was found on the page.');
Chris@0 44
Chris@0 45 // Create the vocabulary.
Chris@0 46 $vid = Unicode::strtolower($this->randomMachineName());
Chris@0 47 $edit['name'] = $this->randomMachineName();
Chris@0 48 $edit['description'] = $this->randomMachineName();
Chris@0 49 $edit['langcode'] = 'aa';
Chris@0 50 $edit['vid'] = $vid;
Chris@0 51 $this->drupalPostForm(NULL, $edit, t('Save'));
Chris@0 52
Chris@0 53 // Check the language on the edit page.
Chris@0 54 $this->drupalGet('admin/structure/taxonomy/manage/' . $vid);
Chris@0 55 $this->assertOptionSelected('edit-langcode', $edit['langcode'], 'The vocabulary language was correctly selected.');
Chris@0 56
Chris@0 57 // Change the language and save again.
Chris@0 58 $edit['langcode'] = 'bb';
Chris@0 59 unset($edit['vid']);
Chris@0 60 $this->drupalPostForm(NULL, $edit, t('Save'));
Chris@0 61
Chris@0 62 // Check again the language on the edit page.
Chris@0 63 $this->drupalGet('admin/structure/taxonomy/manage/' . $vid);
Chris@0 64 $this->assertOptionSelected('edit-langcode', $edit['langcode'], 'The vocabulary language was correctly selected.');
Chris@0 65 }
Chris@0 66
Chris@0 67 /**
Chris@0 68 * Tests term language settings for vocabulary terms are saved and updated.
Chris@0 69 */
Chris@0 70 public function testVocabularyDefaultLanguageForTerms() {
Chris@0 71 // Add a new vocabulary and check that the default language settings are for
Chris@0 72 // the terms are saved.
Chris@0 73 $edit = [
Chris@0 74 'name' => $this->randomMachineName(),
Chris@0 75 'vid' => Unicode::strtolower($this->randomMachineName()),
Chris@0 76 'default_language[langcode]' => 'bb',
Chris@0 77 'default_language[language_alterable]' => TRUE,
Chris@0 78 ];
Chris@0 79 $vid = $edit['vid'];
Chris@0 80 $this->drupalPostForm('admin/structure/taxonomy/add', $edit, t('Save'));
Chris@0 81
Chris@0 82 // Check that the vocabulary was actually created.
Chris@0 83 $this->drupalGet('admin/structure/taxonomy/manage/' . $edit['vid']);
Chris@0 84 $this->assertResponse(200, 'The vocabulary has been created.');
Chris@0 85
Chris@0 86 // Check that the language settings were saved.
Chris@0 87 $language_settings = ContentLanguageSettings::loadByEntityTypeBundle('taxonomy_term', $edit['vid']);
Chris@0 88 $this->assertEqual($language_settings->getDefaultLangcode(), 'bb', 'The langcode was saved.');
Chris@0 89 $this->assertTrue($language_settings->isLanguageAlterable(), 'The visibility setting was saved.');
Chris@0 90
Chris@0 91 // Check that the correct options are selected in the interface.
Chris@0 92 $this->assertOptionSelected('edit-default-language-langcode', 'bb', 'The correct default language for the terms of this vocabulary is selected.');
Chris@0 93 $this->assertFieldChecked('edit-default-language-language-alterable', 'Show language selection option is checked.');
Chris@0 94
Chris@0 95 // Edit the vocabulary and check that the new settings are updated.
Chris@0 96 $edit = [
Chris@0 97 'default_language[langcode]' => 'aa',
Chris@0 98 'default_language[language_alterable]' => FALSE,
Chris@0 99 ];
Chris@0 100 $this->drupalPostForm('admin/structure/taxonomy/manage/' . $vid, $edit, t('Save'));
Chris@0 101
Chris@0 102 // And check again the settings and also the interface.
Chris@0 103 $language_settings = ContentLanguageSettings::loadByEntityTypeBundle('taxonomy_term', $vid);
Chris@0 104 $this->assertEqual($language_settings->getDefaultLangcode(), 'aa', 'The langcode was saved.');
Chris@0 105 $this->assertFalse($language_settings->isLanguageAlterable(), 'The visibility setting was saved.');
Chris@0 106
Chris@0 107 $this->drupalGet('admin/structure/taxonomy/manage/' . $vid);
Chris@0 108 $this->assertOptionSelected('edit-default-language-langcode', 'aa', 'The correct default language for the terms of this vocabulary is selected.');
Chris@0 109 $this->assertNoFieldChecked('edit-default-language-language-alterable', 'Show language selection option is not checked.');
Chris@0 110
Chris@0 111 // Check that language settings are changed after editing vocabulary.
Chris@0 112 $edit = [
Chris@0 113 'name' => $this->randomMachineName(),
Chris@0 114 'default_language[langcode]' => 'authors_default',
Chris@0 115 'default_language[language_alterable]' => FALSE,
Chris@0 116 ];
Chris@0 117 $this->drupalPostForm('admin/structure/taxonomy/manage/' . $vid, $edit, t('Save'));
Chris@0 118
Chris@0 119 // Check that we have the new settings.
Chris@0 120 $new_settings = ContentLanguageSettings::loadByEntityTypeBundle('taxonomy_term', $vid);
Chris@0 121 $this->assertEqual($new_settings->getDefaultLangcode(), 'authors_default', 'The langcode was saved.');
Chris@0 122 $this->assertFalse($new_settings->isLanguageAlterable(), 'The new visibility setting was saved.');
Chris@0 123 }
Chris@0 124
Chris@0 125 }