comparison core/modules/locale/tests/src/Functional/LocaleTranslationUiTest.php @ 5:12f9dff5fda9 tip

Update to Drupal core 8.7.1
author Chris Cannam
date Thu, 09 May 2019 15:34:47 +0100
parents a9cd425dd02b
children
comparison
equal deleted inserted replaced
4:a9cd425dd02b 5:12f9dff5fda9
1 <?php 1 <?php
2 2
3 namespace Drupal\Tests\locale\Functional; 3 namespace Drupal\Tests\locale\Functional;
4 4
5 use Drupal\Core\Url;
6 use Drupal\Core\Database\Database;
5 use Drupal\language\Entity\ConfigurableLanguage; 7 use Drupal\language\Entity\ConfigurableLanguage;
6 use Drupal\Tests\BrowserTestBase; 8 use Drupal\Tests\BrowserTestBase;
7 use Drupal\Core\Language\LanguageInterface; 9 use Drupal\Core\Language\LanguageInterface;
8 use Drupal\Component\Render\FormattableMarkup; 10 use Drupal\Component\Render\FormattableMarkup;
9 11
94 $lid => $translation, 96 $lid => $translation,
95 ]; 97 ];
96 $this->drupalPostForm('admin/config/regional/translate', $edit, t('Save translations')); 98 $this->drupalPostForm('admin/config/regional/translate', $edit, t('Save translations'));
97 $this->assertText(t('The strings have been saved.'), 'The strings have been saved.'); 99 $this->assertText(t('The strings have been saved.'), 'The strings have been saved.');
98 $url_bits = explode('?', $this->getUrl()); 100 $url_bits = explode('?', $this->getUrl());
99 $this->assertEqual($url_bits[0], \Drupal::url('locale.translate_page', [], ['absolute' => TRUE]), 'Correct page redirection.'); 101 $this->assertEqual($url_bits[0], Url::fromRoute('locale.translate_page', [], ['absolute' => TRUE])->toString(), 'Correct page redirection.');
100 $search = [ 102 $search = [
101 'string' => $name, 103 'string' => $name,
102 'langcode' => $langcode, 104 'langcode' => $langcode,
103 'translation' => 'translated', 105 'translation' => 'translated',
104 ]; 106 ];
230 232
231 // Build the JavaScript translation file. 233 // Build the JavaScript translation file.
232 234
233 // Retrieve the source string of the first string available in the 235 // Retrieve the source string of the first string available in the
234 // {locales_source} table and translate it. 236 // {locales_source} table and translate it.
235 $query = db_select('locales_source', 's'); 237 $query = Database::getConnection()->select('locales_source', 's');
236 $query->addJoin('INNER', 'locales_location', 'l', 's.lid = l.lid'); 238 $query->addJoin('INNER', 'locales_location', 'l', 's.lid = l.lid');
237 $source = $query->fields('s', ['source']) 239 $source = $query->fields('s', ['source'])
238 ->condition('l.type', 'javascript') 240 ->condition('l.type', 'javascript')
239 ->range(0, 1) 241 ->range(0, 1)
240 ->execute() 242 ->execute()
260 $locale_javascripts = \Drupal::state()->get('locale.translation.javascript') ?: []; 262 $locale_javascripts = \Drupal::state()->get('locale.translation.javascript') ?: [];
261 $js_file = 'public://' . $config->get('javascript.directory') . '/' . $langcode . '_' . $locale_javascripts[$langcode] . '.js'; 263 $js_file = 'public://' . $config->get('javascript.directory') . '/' . $langcode . '_' . $locale_javascripts[$langcode] . '.js';
262 $this->assertTrue($result = file_exists($js_file), new FormattableMarkup('JavaScript file created: %file', ['%file' => $result ? $js_file : 'not found'])); 264 $this->assertTrue($result = file_exists($js_file), new FormattableMarkup('JavaScript file created: %file', ['%file' => $result ? $js_file : 'not found']));
263 265
264 // Test JavaScript translation rebuilding. 266 // Test JavaScript translation rebuilding.
265 file_unmanaged_delete($js_file); 267 \Drupal::service('file_system')->delete($js_file);
266 $this->assertTrue($result = !file_exists($js_file), new FormattableMarkup('JavaScript file deleted: %file', ['%file' => $result ? $js_file : 'found'])); 268 $this->assertTrue($result = !file_exists($js_file), new FormattableMarkup('JavaScript file deleted: %file', ['%file' => $result ? $js_file : 'found']));
267 _locale_rebuild_js($langcode); 269 _locale_rebuild_js($langcode);
268 $this->assertTrue($result = file_exists($js_file), new FormattableMarkup('JavaScript file rebuilt: %file', ['%file' => $result ? $js_file : 'not found'])); 270 $this->assertTrue($result = file_exists($js_file), new FormattableMarkup('JavaScript file rebuilt: %file', ['%file' => $result ? $js_file : 'not found']));
269 } 271 }
270 272