32928b1d8bf3ec39b9f2f7f425053ecd7e979f72
[yaffs-website] / web / core / modules / locale / src / Tests / LocaleUpdateInterfaceTest.php
1 <?php
2
3 namespace Drupal\locale\Tests;
4
5 use Drupal\Component\Render\FormattableMarkup;
6 use Drupal\Component\Utility\SafeMarkup;
7
8 /**
9  * Tests for the user interface of project interface translations.
10  *
11  * @group locale
12  */
13 class LocaleUpdateInterfaceTest extends LocaleUpdateBase {
14
15   /**
16    * Modules to enable.
17    *
18    * @var array
19    */
20   public static $modules = ['locale_test_translate'];
21
22   /**
23    * {@inheritdoc}
24    */
25   protected function setUp() {
26     parent::setUp();
27     $admin_user = $this->drupalCreateUser(['administer modules', 'administer site configuration', 'administer languages', 'access administration pages', 'translate interface']);
28     $this->drupalLogin($admin_user);
29   }
30
31   /**
32    * Tests the user interfaces of the interface translation update system.
33    *
34    * Testing the Available updates summary on the side wide status page and the
35    * Available translation updates page.
36    */
37   public function testInterface() {
38     // No language added.
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');
42
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');
45
46     // Add German language.
47     $this->addLanguage('de');
48
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']);
53
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');
60
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']);
65
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');
72
73     // Set locale_test_translate module to have a dev release and no
74     // translation found.
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']);
79
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'])
90     ]);
91     $this->assertRaw($release_details->__toString(), 'Release details');
92
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']);
99
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');
104
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']);
111
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');
118   }
119
120 }