comparison core/modules/taxonomy/tests/src/Functional/VocabularyLanguageTest.php @ 0:4c8ae668cc8c

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