3 namespace Drupal\Tests\config_translation\Functional;
5 use Drupal\block_content\Entity\BlockContentType;
6 use Drupal\Component\Utility\Unicode;
7 use Drupal\field\Entity\FieldConfig;
8 use Drupal\field\Entity\FieldStorageConfig;
9 use Drupal\language\Entity\ConfigurableLanguage;
10 use Drupal\Tests\BrowserTestBase;
11 use Drupal\shortcut\Entity\ShortcutSet;
12 use Drupal\contact\Entity\ContactForm;
13 use Drupal\filter\Entity\FilterFormat;
14 use Drupal\taxonomy\Entity\Vocabulary;
19 * @group config_translation
20 * @see \Drupal\config_translation\Tests\ConfigTranslationViewListUiTest
22 class ConfigTranslationListUiTest extends BrowserTestBase {
29 public static $modules = [
46 * Admin user with all needed permissions.
48 * @var \Drupal\user\Entity\User
52 protected function setUp() {
56 'access site-wide contact form',
58 'administer contact forms',
59 'administer content types',
60 'administer block_content fields',
63 'administer node fields',
64 'administer permissions',
65 'administer shortcuts',
66 'administer site configuration',
67 'administer taxonomy',
68 'administer account settings',
69 'administer languages',
70 'administer image styles',
71 'administer responsive images',
72 'translate configuration',
75 // Create and log in user.
76 $this->adminUser = $this->drupalCreateUser($permissions);
77 $this->drupalLogin($this->adminUser);
79 // Enable import of translations. By default this is disabled for automated
81 $this->config('locale.settings')
82 ->set('translation.import_enabled', TRUE)
84 $this->drupalPlaceBlock('local_tasks_block');
88 * Tests the block listing for the translate operation.
90 * There are no blocks placed in the testing profile. Add one, then check
91 * for Translate operation.
93 protected function doBlockListTest() {
94 // Add a test block, any block will do.
95 // Set the machine name so the translate link can be built later.
96 $id = Unicode::strtolower($this->randomMachineName(16));
97 $this->drupalPlaceBlock('system_powered_by_block', ['id' => $id]);
99 // Get the Block listing.
100 $this->drupalGet('admin/structure/block');
102 $translate_link = 'admin/structure/block/manage/' . $id . '/translate';
103 // Test if the link to translate the block is on the page.
104 $this->assertLinkByHref($translate_link);
106 // Test if the link to translate actually goes to the translate page.
107 $this->drupalGet($translate_link);
108 $this->assertRaw('<th>' . t('Language') . '</th>');
112 * Tests the menu listing for the translate operation.
114 protected function doMenuListTest() {
115 // Create a test menu to decouple looking for translate operations link so
116 // this does not test more than necessary.
117 $this->drupalGet('admin/structure/menu/add');
118 // Lowercase the machine name.
119 $menu_name = Unicode::strtolower($this->randomMachineName(16));
120 $label = $this->randomMachineName(16);
126 // Create the menu by posting the form.
127 $this->drupalPostForm('admin/structure/menu/add', $edit, t('Save'));
129 // Get the Menu listing.
130 $this->drupalGet('admin/structure/menu');
132 $translate_link = 'admin/structure/menu/manage/' . $menu_name . '/translate';
133 // Test if the link to translate the menu is on the page.
134 $this->assertLinkByHref($translate_link);
136 // Check if the Link is not added if you are missing 'translate
137 // configuration' permission.
141 $this->drupalLogin($this->drupalCreateUser($permissions));
143 // Get the Menu listing.
144 $this->drupalGet('admin/structure/menu');
146 $translate_link = 'admin/structure/menu/manage/' . $menu_name . '/translate';
147 // Test if the link to translate the menu is NOT on the page.
148 $this->assertNoLinkByHref($translate_link);
150 // Log in as Admin again otherwise the rest will fail.
151 $this->drupalLogin($this->adminUser);
153 // Test if the link to translate actually goes to the translate page.
154 $this->drupalGet($translate_link);
155 $this->assertRaw('<th>' . t('Language') . '</th>');
159 * Tests the vocabulary listing for the translate operation.
161 protected function doVocabularyListTest() {
162 // Create a test vocabulary to decouple looking for translate operations
163 // link so this does not test more than necessary.
164 $vocabulary = Vocabulary::create([
165 'name' => $this->randomMachineName(),
166 'description' => $this->randomMachineName(),
167 'vid' => Unicode::strtolower($this->randomMachineName()),
171 // Get the Taxonomy listing.
172 $this->drupalGet('admin/structure/taxonomy');
174 $translate_link = 'admin/structure/taxonomy/manage/' . $vocabulary->id() . '/translate';
175 // Test if the link to translate the vocabulary is on the page.
176 $this->assertLinkByHref($translate_link);
178 // Test if the link to translate actually goes to the translate page.
179 $this->drupalGet($translate_link);
180 $this->assertRaw('<th>' . t('Language') . '</th>');
184 * Tests the custom block listing for the translate operation.
186 public function doCustomContentTypeListTest() {
187 // Create a test custom block type to decouple looking for translate
188 // operations link so this does not test more than necessary.
189 $block_content_type = BlockContentType::create([
190 'id' => Unicode::strtolower($this->randomMachineName(16)),
191 'label' => $this->randomMachineName(),
194 $block_content_type->save();
196 // Get the custom block type listing.
197 $this->drupalGet('admin/structure/block/block-content/types');
199 $translate_link = 'admin/structure/block/block-content/manage/' . $block_content_type->id() . '/translate';
200 // Test if the link to translate the custom block type is on the page.
201 $this->assertLinkByHref($translate_link);
203 // Test if the link to translate actually goes to the translate page.
204 $this->drupalGet($translate_link);
205 $this->assertRaw('<th>' . t('Language') . '</th>');
209 * Tests the contact forms listing for the translate operation.
211 public function doContactFormsListTest() {
212 // Create a test contact form to decouple looking for translate operations
213 // link so this does not test more than necessary.
214 $contact_form = ContactForm::create([
215 'id' => Unicode::strtolower($this->randomMachineName(16)),
216 'label' => $this->randomMachineName(),
218 $contact_form->save();
220 // Get the contact form listing.
221 $this->drupalGet('admin/structure/contact');
223 $translate_link = 'admin/structure/contact/manage/' . $contact_form->id() . '/translate';
224 // Test if the link to translate the contact form is on the page.
225 $this->assertLinkByHref($translate_link);
227 // Test if the link to translate actually goes to the translate page.
228 $this->drupalGet($translate_link);
229 $this->assertRaw('<th>' . t('Language') . '</th>');
233 * Tests the content type listing for the translate operation.
235 public function doContentTypeListTest() {
236 // Create a test content type to decouple looking for translate operations
237 // link so this does not test more than necessary.
238 $content_type = $this->drupalCreateContentType([
239 'type' => Unicode::strtolower($this->randomMachineName(16)),
240 'name' => $this->randomMachineName(),
243 // Get the content type listing.
244 $this->drupalGet('admin/structure/types');
246 $translate_link = 'admin/structure/types/manage/' . $content_type->id() . '/translate';
247 // Test if the link to translate the content type is on the page.
248 $this->assertLinkByHref($translate_link);
250 // Test if the link to translate actually goes to the translate page.
251 $this->drupalGet($translate_link);
252 $this->assertRaw('<th>' . t('Language') . '</th>');
256 * Tests the formats listing for the translate operation.
258 public function doFormatsListTest() {
259 // Create a test format to decouple looking for translate operations
260 // link so this does not test more than necessary.
261 $filter_format = FilterFormat::create([
262 'format' => Unicode::strtolower($this->randomMachineName(16)),
263 'name' => $this->randomMachineName(),
265 $filter_format->save();
267 // Get the format listing.
268 $this->drupalGet('admin/config/content/formats');
270 $translate_link = 'admin/config/content/formats/manage/' . $filter_format->id() . '/translate';
271 // Test if the link to translate the format is on the page.
272 $this->assertLinkByHref($translate_link);
274 // Test if the link to translate actually goes to the translate page.
275 $this->drupalGet($translate_link);
276 $this->assertRaw('<th>' . t('Language') . '</th>');
280 * Tests the shortcut listing for the translate operation.
282 public function doShortcutListTest() {
283 // Create a test shortcut to decouple looking for translate operations
284 // link so this does not test more than necessary.
285 $shortcut = ShortcutSet::create([
286 'id' => Unicode::strtolower($this->randomMachineName(16)),
287 'label' => $this->randomString(),
291 // Get the shortcut listing.
292 $this->drupalGet('admin/config/user-interface/shortcut');
294 $translate_link = 'admin/config/user-interface/shortcut/manage/' . $shortcut->id() . '/translate';
295 // Test if the link to translate the shortcut is on the page.
296 $this->assertLinkByHref($translate_link);
298 // Test if the link to translate actually goes to the translate page.
299 $this->drupalGet($translate_link);
300 $this->assertRaw('<th>' . t('Language') . '</th>');
304 * Tests the role listing for the translate operation.
306 public function doUserRoleListTest() {
307 // Create a test role to decouple looking for translate operations
308 // link so this does not test more than necessary.
309 $role_id = Unicode::strtolower($this->randomMachineName(16));
310 $this->drupalCreateRole([], $role_id);
312 // Get the role listing.
313 $this->drupalGet('admin/people/roles');
315 $translate_link = 'admin/people/roles/manage/' . $role_id . '/translate';
316 // Test if the link to translate the role is on the page.
317 $this->assertLinkByHref($translate_link);
319 // Test if the link to translate actually goes to the translate page.
320 $this->drupalGet($translate_link);
321 $this->assertRaw('<th>' . t('Language') . '</th>');
325 * Tests the language listing for the translate operation.
327 public function doLanguageListTest() {
328 // Create a test language to decouple looking for translate operations
329 // link so this does not test more than necessary.
330 ConfigurableLanguage::createFromLangcode('ga')->save();
332 // Get the language listing.
333 $this->drupalGet('admin/config/regional/language');
335 $translate_link = 'admin/config/regional/language/edit/ga/translate';
336 // Test if the link to translate the language is on the page.
337 $this->assertLinkByHref($translate_link);
339 // Test if the link to translate actually goes to the translate page.
340 $this->drupalGet($translate_link);
341 $this->assertRaw('<th>' . t('Language') . '</th>');
345 * Tests the image style listing for the translate operation.
347 public function doImageStyleListTest() {
348 // Get the image style listing.
349 $this->drupalGet('admin/config/media/image-styles');
351 $translate_link = 'admin/config/media/image-styles/manage/medium/translate';
352 // Test if the link to translate the style is on the page.
353 $this->assertLinkByHref($translate_link);
355 // Test if the link to translate actually goes to the translate page.
356 $this->drupalGet($translate_link);
357 $this->assertRaw('<th>' . t('Language') . '</th>');
361 * Tests the responsive image mapping listing for the translate operation.
363 public function doResponsiveImageListTest() {
365 $edit['label'] = $this->randomMachineName();
366 $edit['id'] = strtolower($edit['label']);
367 $edit['fallback_image_style'] = 'thumbnail';
369 $this->drupalPostForm('admin/config/media/responsive-image-style/add', $edit, t('Save'));
370 $this->assertRaw(t('Responsive image style %label saved.', ['%label' => $edit['label']]));
372 // Get the responsive image style listing.
373 $this->drupalGet('admin/config/media/responsive-image-style');
375 $translate_link = 'admin/config/media/responsive-image-style/' . $edit['id'] . '/translate';
376 // Test if the link to translate the style is on the page.
377 $this->assertLinkByHref($translate_link);
379 // Test if the link to translate actually goes to the translate page.
380 $this->drupalGet($translate_link);
381 $this->assertRaw('<th>' . t('Language') . '</th>');
385 * Tests the field listing for the translate operation.
387 public function doFieldListTest() {
388 // Create a base content type.
389 $content_type = $this->drupalCreateContentType([
390 'type' => Unicode::strtolower($this->randomMachineName(16)),
391 'name' => $this->randomMachineName(),
394 // Create a block content type.
395 $block_content_type = BlockContentType::create([
400 $block_content_type->save();
401 $field = FieldConfig::create([
402 // The field storage is guaranteed to exist because it is supplied by the
403 // block_content module.
404 'field_storage' => FieldStorageConfig::loadByName('block_content', 'body'),
405 'bundle' => $block_content_type->id(),
407 'settings' => ['display_summary' => FALSE],
411 // Look at a few fields on a few entity types.
414 'list' => 'admin/structure/types/manage/' . $content_type->id() . '/fields',
415 'field' => 'node.' . $content_type->id() . '.body',
418 'list' => 'admin/structure/block/block-content/manage/basic/fields',
419 'field' => 'block_content.basic.body',
423 foreach ($pages as $values) {
424 // Get fields listing.
425 $this->drupalGet($values['list']);
427 $translate_link = $values['list'] . '/' . $values['field'] . '/translate';
428 // Test if the link to translate the field is on the page.
429 $this->assertLinkByHref($translate_link);
431 // Test if the link to translate actually goes to the translate page.
432 $this->drupalGet($translate_link);
433 $this->assertRaw('<th>' . t('Language') . '</th>');
438 * Tests the date format listing for the translate operation.
440 public function doDateFormatListTest() {
441 // Get the date format listing.
442 $this->drupalGet('admin/config/regional/date-time');
444 $translate_link = 'admin/config/regional/date-time/formats/manage/long/translate';
445 // Test if the link to translate the format is on the page.
446 $this->assertLinkByHref($translate_link);
448 // Test if the link to translate actually goes to the translate page.
449 $this->drupalGet($translate_link);
450 $this->assertRaw('<th>' . t('Language') . '</th>');
454 * Tests a given settings page for the translate operation.
456 * @param string $link
457 * URL of the settings page to test.
459 public function doSettingsPageTest($link) {
460 // Get the settings page.
461 $this->drupalGet($link);
463 $translate_link = $link . '/translate';
464 // Test if the link to translate the settings page is present.
465 $this->assertLinkByHref($translate_link);
467 // Test if the link to translate actually goes to the translate page.
468 $this->drupalGet($translate_link);
469 $this->assertRaw('<th>' . t('Language') . '</th>');
473 * Tests if translate link is added to operations in all configuration lists.
475 public function testTranslateOperationInListUi() {
476 // All lists based on paths provided by the module.
477 $this->doBlockListTest();
478 $this->doMenuListTest();
479 $this->doVocabularyListTest();
480 $this->doCustomContentTypeListTest();
481 $this->doContactFormsListTest();
482 $this->doContentTypeListTest();
483 $this->doFormatsListTest();
484 $this->doShortcutListTest();
485 $this->doUserRoleListTest();
486 $this->doLanguageListTest();
487 $this->doImageStyleListTest();
488 $this->doResponsiveImageListTest();
489 $this->doDateFormatListTest();
490 $this->doFieldListTest();
492 // Views is tested in Drupal\config_translation\Tests\ConfigTranslationViewListUiTest
494 // Test the maintenance settings page.
495 $this->doSettingsPageTest('admin/config/development/maintenance');
496 // Test the site information settings page.
497 $this->doSettingsPageTest('admin/config/system/site-information');
498 // Test the account settings page.
499 $this->doSettingsPageTest('admin/config/people/accounts');
500 // Test the RSS settings page.
501 $this->doSettingsPageTest('admin/config/services/rss-publishing');