Chris@0
|
1 <?php
|
Chris@0
|
2
|
Chris@0
|
3 namespace Drupal\Tests\taxonomy\Functional;
|
Chris@0
|
4
|
Chris@0
|
5 use Drupal\Tests\content_translation\Functional\ContentTranslationUITestBase;
|
Chris@0
|
6 use Drupal\Core\Language\LanguageInterface;
|
Chris@0
|
7 use Drupal\taxonomy\Entity\Vocabulary;
|
Chris@0
|
8
|
Chris@0
|
9 /**
|
Chris@0
|
10 * Tests the Term Translation UI.
|
Chris@0
|
11 *
|
Chris@0
|
12 * @group taxonomy
|
Chris@0
|
13 */
|
Chris@0
|
14 class TermTranslationUITest extends ContentTranslationUITestBase {
|
Chris@0
|
15
|
Chris@0
|
16 /**
|
Chris@0
|
17 * The vocabulary used for creating terms.
|
Chris@0
|
18 *
|
Chris@0
|
19 * @var \Drupal\taxonomy\VocabularyInterface
|
Chris@0
|
20 */
|
Chris@0
|
21 protected $vocabulary;
|
Chris@0
|
22
|
Chris@0
|
23 /**
|
Chris@0
|
24 * Modules to enable.
|
Chris@0
|
25 *
|
Chris@0
|
26 * @var array
|
Chris@0
|
27 */
|
Chris@0
|
28 public static $modules = ['language', 'content_translation', 'taxonomy'];
|
Chris@0
|
29
|
Chris@0
|
30 protected function setUp() {
|
Chris@0
|
31 $this->entityTypeId = 'taxonomy_term';
|
Chris@0
|
32 $this->bundle = 'tags';
|
Chris@0
|
33 parent::setUp();
|
Chris@0
|
34 }
|
Chris@0
|
35
|
Chris@0
|
36 /**
|
Chris@0
|
37 * {@inheritdoc}
|
Chris@0
|
38 */
|
Chris@0
|
39 protected function setupBundle() {
|
Chris@0
|
40 parent::setupBundle();
|
Chris@0
|
41
|
Chris@0
|
42 // Create a vocabulary.
|
Chris@0
|
43 $this->vocabulary = Vocabulary::create([
|
Chris@0
|
44 'name' => $this->bundle,
|
Chris@0
|
45 'description' => $this->randomMachineName(),
|
Chris@0
|
46 'vid' => $this->bundle,
|
Chris@0
|
47 'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
|
Chris@0
|
48 'weight' => mt_rand(0, 10),
|
Chris@0
|
49 ]);
|
Chris@0
|
50 $this->vocabulary->save();
|
Chris@0
|
51 }
|
Chris@0
|
52
|
Chris@0
|
53 /**
|
Chris@0
|
54 * {@inheritdoc}
|
Chris@0
|
55 */
|
Chris@0
|
56 protected function getTranslatorPermissions() {
|
Chris@0
|
57 return array_merge(parent::getTranslatorPermissions(), ['administer taxonomy']);
|
Chris@0
|
58 }
|
Chris@0
|
59
|
Chris@0
|
60 /**
|
Chris@0
|
61 * {@inheritdoc}
|
Chris@0
|
62 */
|
Chris@0
|
63 protected function getNewEntityValues($langcode) {
|
Chris@0
|
64 return ['name' => $this->randomMachineName()] + parent::getNewEntityValues($langcode);
|
Chris@0
|
65 }
|
Chris@0
|
66
|
Chris@0
|
67 /**
|
Chris@0
|
68 * Returns an edit array containing the values to be posted.
|
Chris@0
|
69 */
|
Chris@0
|
70 protected function getEditValues($values, $langcode, $new = FALSE) {
|
Chris@0
|
71 $edit = parent::getEditValues($values, $langcode, $new);
|
Chris@0
|
72
|
Chris@0
|
73 // To be able to post values for the configurable base fields (name,
|
Chris@0
|
74 // description) have to be suffixed with [0][value].
|
Chris@0
|
75 foreach ($edit as $property => $value) {
|
Chris@0
|
76 foreach (['name', 'description'] as $key) {
|
Chris@0
|
77 if ($property == $key) {
|
Chris@0
|
78 $edit[$key . '[0][value]'] = $value;
|
Chris@0
|
79 unset($edit[$property]);
|
Chris@0
|
80 }
|
Chris@0
|
81 }
|
Chris@0
|
82 }
|
Chris@0
|
83 return $edit;
|
Chris@0
|
84 }
|
Chris@0
|
85
|
Chris@0
|
86 /**
|
Chris@0
|
87 * {@inheritdoc}
|
Chris@0
|
88 */
|
Chris@0
|
89 public function testTranslationUI() {
|
Chris@0
|
90 parent::testTranslationUI();
|
Chris@0
|
91
|
Chris@0
|
92 // Make sure that no row was inserted for taxonomy vocabularies which do
|
Chris@0
|
93 // not have translations enabled.
|
Chris@0
|
94 $rows = db_query('SELECT tid, count(tid) AS count FROM {taxonomy_term_field_data} WHERE vid <> :vid GROUP BY tid', [':vid' => $this->bundle])->fetchAll();
|
Chris@0
|
95 foreach ($rows as $row) {
|
Chris@0
|
96 $this->assertTrue($row->count < 2, 'Term does not have translations.');
|
Chris@0
|
97 }
|
Chris@0
|
98 }
|
Chris@0
|
99
|
Chris@0
|
100 /**
|
Chris@0
|
101 * Tests translate link on vocabulary term list.
|
Chris@0
|
102 */
|
Chris@0
|
103 public function testTranslateLinkVocabularyAdminPage() {
|
Chris@0
|
104 $this->drupalLogin($this->drupalCreateUser(array_merge(parent::getTranslatorPermissions(), ['access administration pages', 'administer taxonomy'])));
|
Chris@0
|
105
|
Chris@0
|
106 $values = [
|
Chris@0
|
107 'name' => $this->randomMachineName(),
|
Chris@0
|
108 ];
|
Chris@0
|
109 $translatable_tid = $this->createEntity($values, $this->langcodes[0], $this->vocabulary->id());
|
Chris@0
|
110
|
Chris@0
|
111 // Create an untranslatable vocabulary.
|
Chris@0
|
112 $untranslatable_vocabulary = Vocabulary::create([
|
Chris@0
|
113 'name' => 'untranslatable_voc',
|
Chris@0
|
114 'description' => $this->randomMachineName(),
|
Chris@0
|
115 'vid' => 'untranslatable_voc',
|
Chris@0
|
116 'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
|
Chris@0
|
117 'weight' => mt_rand(0, 10),
|
Chris@0
|
118 ]);
|
Chris@0
|
119 $untranslatable_vocabulary->save();
|
Chris@0
|
120
|
Chris@0
|
121 $values = [
|
Chris@0
|
122 'name' => $this->randomMachineName(),
|
Chris@0
|
123 ];
|
Chris@0
|
124 $untranslatable_tid = $this->createEntity($values, $this->langcodes[0], $untranslatable_vocabulary->id());
|
Chris@0
|
125
|
Chris@0
|
126 // Verify translation links.
|
Chris@0
|
127 $this->drupalGet('admin/structure/taxonomy/manage/' . $this->vocabulary->id() . '/overview');
|
Chris@0
|
128 $this->assertResponse(200, 'The translatable vocabulary page was found.');
|
Chris@0
|
129 $this->assertLinkByHref('term/' . $translatable_tid . '/translations', 0, 'The translations link exists for a translatable vocabulary.');
|
Chris@0
|
130 $this->assertLinkByHref('term/' . $translatable_tid . '/edit', 0, 'The edit link exists for a translatable vocabulary.');
|
Chris@0
|
131
|
Chris@0
|
132 $this->drupalGet('admin/structure/taxonomy/manage/' . $untranslatable_vocabulary->id() . '/overview');
|
Chris@0
|
133 $this->assertResponse(200);
|
Chris@0
|
134 $this->assertLinkByHref('term/' . $untranslatable_tid . '/edit');
|
Chris@0
|
135 $this->assertNoLinkByHref('term/' . $untranslatable_tid . '/translations');
|
Chris@0
|
136 }
|
Chris@0
|
137
|
Chris@0
|
138 /**
|
Chris@0
|
139 * {@inheritdoc}
|
Chris@0
|
140 */
|
Chris@0
|
141 protected function doTestTranslationEdit() {
|
Chris@0
|
142 $storage = $this->container->get('entity_type.manager')
|
Chris@0
|
143 ->getStorage($this->entityTypeId);
|
Chris@0
|
144 $storage->resetCache([$this->entityId]);
|
Chris@0
|
145 $entity = $storage->load($this->entityId);
|
Chris@0
|
146 $languages = $this->container->get('language_manager')->getLanguages();
|
Chris@0
|
147
|
Chris@0
|
148 foreach ($this->langcodes as $langcode) {
|
Chris@0
|
149 // We only want to test the title for non-english translations.
|
Chris@0
|
150 if ($langcode != 'en') {
|
Chris@0
|
151 $options = ['language' => $languages[$langcode]];
|
Chris@18
|
152 $url = $entity->toUrl('edit-form', $options);
|
Chris@0
|
153 $this->drupalGet($url);
|
Chris@0
|
154
|
Chris@0
|
155 $title = t('@title [%language translation]', [
|
Chris@0
|
156 '@title' => $entity->getTranslation($langcode)->label(),
|
Chris@0
|
157 '%language' => $languages[$langcode]->getName(),
|
Chris@0
|
158 ]);
|
Chris@0
|
159 $this->assertRaw($title);
|
Chris@0
|
160 }
|
Chris@0
|
161 }
|
Chris@0
|
162 }
|
Chris@0
|
163
|
Chris@0
|
164 }
|