3 namespace Drupal\locale\Tests;
5 use Drupal\Component\Render\FormattableMarkup;
6 use Drupal\Component\Utility\SafeMarkup;
9 * Tests for the user interface of project interface translations.
13 class LocaleUpdateInterfaceTest extends LocaleUpdateBase {
20 public static $modules = ['locale_test_translate'];
25 protected function setUp() {
27 $admin_user = $this->drupalCreateUser(['administer modules', 'administer site configuration', 'administer languages', 'access administration pages', 'translate interface']);
28 $this->drupalLogin($admin_user);
32 * Tests the user interfaces of the interface translation update system.
34 * Testing the Available updates summary on the side wide status page and the
35 * Available translation updates page.
37 public function testInterface() {
39 // Check status page and Available translation updates page.
40 $this->drupalGet('admin/reports/status');
41 $this->assertNoText(t('Translation update status'), 'No status message');
43 $this->drupalGet('admin/reports/translations');
44 $this->assertRaw(t('No translatable languages available. <a href=":add_language">Add a language</a> first.', [':add_language' => \Drupal::url('entity.configurable_language.collection')]), 'Language message');
46 // Add German language.
47 $this->addLanguage('de');
49 // Override Drupal core translation status as 'up-to-date'.
50 $status = locale_translation_get_status();
51 $status['drupal']['de']->type = 'current';
52 \Drupal::keyValue('locale.translation_status')->set('drupal', $status['drupal']);
54 // One language added, all translations up to date.
55 $this->drupalGet('admin/reports/status');
56 $this->assertText(t('Translation update status'), 'Status message');
57 $this->assertText(t('Up to date'), 'Translations up to date');
58 $this->drupalGet('admin/reports/translations');
59 $this->assertText(t('All translations up to date.'), 'Translations up to date');
61 // Set locale_test_translate module to have a local translation available.
62 $status = locale_translation_get_status();
63 $status['locale_test_translate']['de']->type = 'local';
64 \Drupal::keyValue('locale.translation_status')->set('locale_test_translate', $status['locale_test_translate']);
66 // Check if updates are available for German.
67 $this->drupalGet('admin/reports/status');
68 $this->assertText(t('Translation update status'), 'Status message');
69 $this->assertRaw(t('Updates available for: @languages. See the <a href=":updates">Available translation updates</a> page for more information.', ['@languages' => t('German'), ':updates' => \Drupal::url('locale.translate_status')]), 'Updates available message');
70 $this->drupalGet('admin/reports/translations');
71 $this->assertText(t('Updates for: @modules', ['@modules' => 'Locale test translate']), 'Translations available');
73 // Set locale_test_translate module to have a dev release and no
75 $status = locale_translation_get_status();
76 $status['locale_test_translate']['de']->version = '1.3-dev';
77 $status['locale_test_translate']['de']->type = '';
78 \Drupal::keyValue('locale.translation_status')->set('locale_test_translate', $status['locale_test_translate']);
80 // Check if no updates were found.
81 $this->drupalGet('admin/reports/status');
82 $this->assertText(t('Translation update status'), 'Status message');
83 $this->assertRaw(t('Missing translations for: @languages. See the <a href=":updates">Available translation updates</a> page for more information.', ['@languages' => t('German'), ':updates' => \Drupal::url('locale.translate_status')]), 'Missing translations message');
84 $this->drupalGet('admin/reports/translations');
85 $this->assertText(t('Missing translations for one project'), 'No translations found');
86 $release_details = new FormattableMarkup('@module (@version). @info', [
87 '@module' => 'Locale test translate',
88 '@version' => '1.3-dev',
89 '@info' => t('File not found at %local_path', ['%local_path' => 'core/modules/locale/tests/test.de.po'])
91 $this->assertRaw($release_details->__toString(), 'Release details');
93 // Override Drupal core translation status as 'no translations found'.
94 $status = locale_translation_get_status();
95 $status['drupal']['de']->type = '';
96 $status['drupal']['de']->timestamp = 0;
97 $status['drupal']['de']->version = '8.1.1';
98 \Drupal::keyValue('locale.translation_status')->set('drupal', $status['drupal']);
100 // Check if Drupal core is not translated.
101 $this->drupalGet('admin/reports/translations');
102 $this->assertText(t('Missing translations for 2 projects'), 'No translations found');
103 $this->assertText(t('@module (@version).', ['@module' => t('Drupal core'), '@version' => '8.1.1']), 'Release details');
105 // Override Drupal core translation status as 'translations available'.
106 $status = locale_translation_get_status();
107 $status['drupal']['de']->type = 'local';
108 $status['drupal']['de']->files['local']->timestamp = REQUEST_TIME;
109 $status['drupal']['de']->files['local']->info['version'] = '8.1.1';
110 \Drupal::keyValue('locale.translation_status')->set('drupal', $status['drupal']);
112 // Check if translations are available for Drupal core.
113 $this->drupalGet('admin/reports/translations');
114 $this->assertText(t('Updates for: @project', ['@project' => t('Drupal core')]), 'Translations found');
115 $this->assertText(SafeMarkup::format('@module (@date)', ['@module' => t('Drupal core'), '@date' => format_date(REQUEST_TIME, 'html_date')]), 'Core translation update');
116 $update_button = $this->xpath('//input[@type="submit"][@value="' . t('Update translations') . '"]');
117 $this->assertTrue($update_button, 'Update translations button');