View source
<?php
namespace Drupal\Tests\locale\Functional;
use Drupal\Core\Url;
use Drupal\Component\Render\FormattableMarkup;
class LocaleUpdateInterfaceTest extends LocaleUpdateBase {
public static $modules = [
'locale_test_translate',
];
protected $defaultTheme = 'stark';
protected function setUp() {
parent::setUp();
$admin_user = $this
->drupalCreateUser([
'administer modules',
'administer site configuration',
'administer languages',
'access administration pages',
'translate interface',
]);
$this
->drupalLogin($admin_user);
}
public function testInterface() {
$this
->drupalGet('admin/reports/status');
$this
->assertNoText(t('Translation update status'), 'No status message');
$this
->drupalGet('admin/reports/translations');
$this
->assertRaw(t('No translatable languages available. <a href=":add_language">Add a language</a> first.', [
':add_language' => Url::fromRoute('entity.configurable_language.collection')
->toString(),
]), 'Language message');
$this
->addLanguage('de');
$status = locale_translation_get_status();
$status['drupal']['de']->type = 'current';
\Drupal::keyValue('locale.translation_status')
->set('drupal', $status['drupal']);
$this
->drupalGet('admin/reports/status');
$this
->assertText(t('Translation update status'), 'Status message');
$this
->assertText(t('Up to date'), 'Translations up to date');
$this
->drupalGet('admin/reports/translations');
$this
->assertText(t('All translations up to date.'), 'Translations up to date');
$status = locale_translation_get_status();
$status['locale_test_translate']['de']->type = 'local';
\Drupal::keyValue('locale.translation_status')
->set('locale_test_translate', $status['locale_test_translate']);
$this
->drupalGet('admin/reports/status');
$this
->assertText(t('Translation update status'), 'Status message');
$this
->assertRaw(t('Updates available for: @languages. See the <a href=":updates">Available translation updates</a> page for more information.', [
'@languages' => t('German'),
':updates' => Url::fromRoute('locale.translate_status')
->toString(),
]), 'Updates available message');
$this
->drupalGet('admin/reports/translations');
$this
->assertText(t('Updates for: @modules', [
'@modules' => 'Locale test translate',
]), 'Translations available');
$status = locale_translation_get_status();
$status['locale_test_translate']['de']->version = '1.3-dev';
$status['locale_test_translate']['de']->type = '';
\Drupal::keyValue('locale.translation_status')
->set('locale_test_translate', $status['locale_test_translate']);
$this
->drupalGet('admin/reports/status');
$this
->assertText(t('Translation update status'), 'Status message');
$this
->assertRaw(t('Missing translations for: @languages. See the <a href=":updates">Available translation updates</a> page for more information.', [
'@languages' => t('German'),
':updates' => Url::fromRoute('locale.translate_status')
->toString(),
]), 'Missing translations message');
$this
->drupalGet('admin/reports/translations');
$this
->assertText(t('Missing translations for one project'), 'No translations found');
$release_details = new FormattableMarkup('@module (@version). @info', [
'@module' => 'Locale test translate',
'@version' => '1.3-dev',
'@info' => t('File not found at %local_path', [
'%local_path' => 'core/modules/locale/tests/test.de.po',
]),
]);
$this
->assertRaw($release_details
->__toString(), 'Release details');
$status = locale_translation_get_status();
$status['drupal']['de']->type = '';
$status['drupal']['de']->timestamp = 0;
$status['drupal']['de']->version = '8.1.1';
\Drupal::keyValue('locale.translation_status')
->set('drupal', $status['drupal']);
$this
->drupalGet('admin/reports/translations');
$this
->assertText(t('Missing translations for 2 projects'), 'No translations found');
$this
->assertText(t('@module (@version).', [
'@module' => t('Drupal core'),
'@version' => '8.1.1',
]), 'Release details');
$status = locale_translation_get_status();
$status['drupal']['de']->type = 'local';
$status['drupal']['de']->files['local']->timestamp = REQUEST_TIME;
$status['drupal']['de']->files['local']->info['version'] = '8.1.1';
\Drupal::keyValue('locale.translation_status')
->set('drupal', $status['drupal']);
$this
->drupalGet('admin/reports/translations');
$this
->assertText(t('Updates for: @project', [
'@project' => t('Drupal core'),
]), 'Translations found');
$this
->assertText(new FormattableMarkup('@module (@date)', [
'@module' => t('Drupal core'),
'@date' => $this->container
->get('date.formatter')
->format(REQUEST_TIME, 'html_date'),
]), 'Core translation update');
$update_button = $this
->xpath('//input[@type="submit"][@value="' . t('Update translations') . '"]');
$this
->assertNotEmpty($update_button, 'Update translations button');
}
}