annotate core/modules/taxonomy/tests/src/Functional/VocabularyLanguageTest.php @ 19:fa3358dc1485 tip

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