Commit bb8be56e authored by effulgentsia's avatar effulgentsia

Issue #1832946 by Sutharsan, Jose Reyero, Gábor Hojtsy, Wim Leers, vijaycs85:...

Issue #1832946 by Sutharsan, Jose Reyero, Gábor Hojtsy, Wim Leers, vijaycs85: Runtime translation download fallback works different from installer translation download fallback
parent 866be5fb
......@@ -17,7 +17,7 @@
*/
class LanguageNegotiationFormOverrideTest extends WebTestBase {
public static $modules = array('language', 'locale');
public static $modules = array('language', 'locale', 'locale_test');
/**
* Tests that overrides do not affect language-negotiation form values.
......
......@@ -25,7 +25,7 @@ class LanguageSwitchingTest extends WebTestBase {
*
* @var array
*/
public static $modules = array('locale', 'language', 'block', 'language_test', 'menu_ui');
public static $modules = array('locale', 'locale_test', 'language', 'block', 'language_test', 'menu_ui');
protected function setUp() {
parent::setUp();
......
......@@ -44,11 +44,6 @@ function locale_translation_flush_projects() {
* - "status": Project status, 1 = enabled.
*/
function locale_translation_build_projects() {
// This function depends on Update module. We degrade gracefully.
if (!\Drupal::moduleHandler()->moduleExists('update')) {
return array();
}
// Get the project list based on .info.yml files.
$projects = locale_translation_project_list();
......@@ -57,33 +52,18 @@ function locale_translation_build_projects() {
$default_server = locale_translation_default_translation_server();
// If project is a dev release, or core, find the latest available release.
$project_updates = update_get_available(TRUE);
foreach ($projects as $name => $data) {
if (isset($project_updates[$name]['releases']) && $project_updates[$name]['project_status'] != 'not-fetched') {
// Find out if a dev version is installed.
if (preg_match("/^\d+\.x-(\d+)\..*-dev$/", $data['info']['version'], $matches) ||
preg_match("/^(\d+)\.\d+\.\d+.*-dev$/", $data['info']['version'], $matches)) {
// Find a suitable release to use as alternative translation.
foreach ($project_updates[$name]['releases'] as $project_release) {
// The first release with the same major release number which is not a
// dev release is the one. Releases are sorted the most recent first.
// For example the major release number for a contrib module
// 8.x-2.x-dev is "2", for core 8.1.0-dev is "8".
// @todo https://www.drupal.org/node/1774024 Make a helper function.
if ($project_release['version_major'] == $matches[1] &&
(!isset($project_release['version_extra']) || $project_release['version_extra'] != 'dev')) {
$release = $project_release;
break;
}
}
// For dev releases, remove the '-dev' part and trust the translation server
// to fall back to the latest stable release for that branch.
if (isset($data['info']['version']) && strpos($data['info']['version'], '-dev')) {
if (preg_match("/^(\d+\.x-\d+\.).*$/", $data['info']['version'], $matches)) {
// Example matches: 8.x-1.x-dev, 8.x-1.0-alpha1+5-dev => 8.x-1.x
$data['info']['version'] = $matches[1] . 'x';
}
if (!empty($release['version'])) {
$data['info']['version'] = $release['version'];
elseif (preg_match("/^(\d+\.\d+\.).*$/", $data['info']['version'], $matches)) {
// Example match: 8.0.0-dev => 8.0.x (Drupal core)
$data['info']['version'] = $matches[1] . 'x';
}
unset($release);
}
// For every project store information.
......@@ -96,6 +76,7 @@ function locale_translation_build_projects() {
'server_pattern' => isset($data['info']['interface translation server pattern']) && $data['info']['interface translation server pattern'] ? $data['info']['interface translation server pattern'] : $default_server['pattern'],
'status' => !empty($data['project_status']) ? 1 : 0,
);
$project = (object) $data;
$projects[$name] = $project;
......@@ -117,8 +98,6 @@ function locale_translation_build_projects() {
function locale_translation_project_list() {
$projects = &drupal_static(__FUNCTION__, array());
if (empty($projects)) {
module_load_include('compare.inc', 'update');
$config = \Drupal::config('locale.settings');
$projects = array();
$additional_whitelist = array(
......
......@@ -60,7 +60,7 @@ function locale_translation_get_projects(array $project_names = array()) {
$row_count = \Drupal::service('locale.project')->countProjects();
// https://www.drupal.org/node/1777106 is a follow-up issue to make the
// check for possible out-of-date project information more robust.
if ($row_count == 0 && \Drupal::moduleHandler()->moduleExists('update')) {
if ($row_count == 0) {
module_load_include('compare.inc', 'locale');
// At least the core project should be in the database, so we build the
// data if none are found.
......
......@@ -232,9 +232,6 @@ protected function prepareUpdateData(array $status) {
* This method will produce debug information including the respective path(s)
* based on this setting.
*
* Translations for development versions are never fetched, so the debug info
* for that is a fixed message.
*
* @param array $project_info
* An array which is the project information of the source.
*
......@@ -245,9 +242,6 @@ protected function createInfoString($project_info) {
$remote_path = isset($project_info->files['remote']->uri) ? $project_info->files['remote']->uri : FALSE;
$local_path = isset($project_info->files['local']->uri) ? $project_info->files['local']->uri : FALSE;
if (strpos($project_info->version, 'dev') !== FALSE) {
return $this->t('No translation files are provided for development releases.');
}
if (locale_translation_use_remote_source() && $remote_path && $local_path) {
return $this->t('File not found at %remote_path nor at %local_path', array(
'%remote_path' => $remote_path,
......
......@@ -23,7 +23,7 @@ class LocaleConfigTranslationImportTest extends WebTestBase {
*
* @var array
*/
public static $modules = array('language', 'update', 'locale_test_translate');
public static $modules = array('language', 'locale_test_translate');
/**
* {@inheritdoc}
......@@ -33,10 +33,6 @@ protected function setUp() {
$admin_user = $this->drupalCreateUser(array('administer modules', 'administer site configuration', 'administer languages', 'access administration pages', 'administer permissions'));
$this->drupalLogin($admin_user);
// Update module should not go out to d.o to check for updates. We override
// the url to an invalid update source. No update data will be found.
$this->config('update.settings')->set('fetch.url', (string) Url::fromRoute('<front>')->setAbsolute()->toString())->save();
}
/**
......
......@@ -23,7 +23,7 @@ class LocaleJavascriptTranslationTest extends WebTestBase {
*
* @var array
*/
public static $modules = array('locale');
public static $modules = array('locale', 'locale_test');
public function testFileParsing() {
$filename = drupal_get_path('module', 'locale') . '/tests/locale_test.js';
......
......@@ -19,7 +19,7 @@ class LocaleTranslationProjectsTest extends KernelTestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['locale'];
public static $modules = ['locale', 'locale_test'];
/**
* The module handler used in this test.
......@@ -43,6 +43,7 @@ protected function setUp() {
$this->moduleHandler = $this->container->get('module_handler');
$this->projectStorage = $this->container->get('locale.project');
\Drupal::state()->set('locale.remove_core_project', TRUE);
}
......
......@@ -50,7 +50,7 @@ abstract class LocaleUpdateBase extends WebTestBase {
*
* @var array
*/
public static $modules = array('update', 'update_test', 'locale', 'locale_test');
public static $modules = array('locale', 'locale_test');
/**
* {@inheritdoc}
......@@ -58,11 +58,6 @@ abstract class LocaleUpdateBase extends WebTestBase {
protected function setUp() {
parent::setUp();
// Update module should not go out to d.o to check for updates. We override
// the url to the default update_test xml path. But without providing
// a mock xml file, no update data will be found.
$this->config('update.settings')->set('fetch.url', Url::fromRoute('update_test.update_test', [], ['absolute' => TRUE])->toString())->save();
// Setup timestamps to identify old and new translation sources.
$this->timestampOld = REQUEST_TIME - 300;
$this->timestampMedium = REQUEST_TIME - 200;
......@@ -186,6 +181,7 @@ protected function setTranslationFiles() {
// A flag is set to let the locale_test module replace the project data with
// a set of test projects which match the below project files.
\Drupal::state()->set('locale.test_projects_alter', TRUE);
\Drupal::state()->set('locale.remove_core_project', FALSE);
// Setup the environment.
$public_path = PublicStream::basePath();
......
<?php
/**
* @file
* Contains \Drupal\locale\Tests\LocaleUpdateDevelopmentReleaseTest.
*/
namespace Drupal\locale\Tests;
use Drupal\simpletest\WebTestBase;
/**
* Test for proper version fallback in case of a development release.
*
* @group language
*/
class LocaleUpdateDevelopmentReleaseTest extends WebTestBase {
public static $modules = array('locale', 'locale_test_development_release');
protected function setUp() {
parent::setUp();
module_load_include('compare.inc', 'locale');
$admin_user = $this->drupalCreateUser(array('administer modules', 'administer languages', 'access administration pages', 'translate interface'));
$this->drupalLogin($admin_user);
$this->drupalPostForm('admin/config/regional/language/add', array('predefined_langcode' => 'hu'), t('Add language'));
}
public function testLocaleUpdateDevelopmentRelease() {
$projects = locale_translation_build_projects();
$this->verbose($projects['drupal']->info['version']);
$this->assertEqual($projects['drupal']->info['version'], '8.0.x', 'The branch of the core dev release.');
$this->verbose($projects['contrib']->info['version']);
$this->assertEqual($projects['contrib']->info['version'], '12.x-10.x', 'The branch of the contrib module dev release.');
}
}
......@@ -7,6 +7,7 @@
namespace Drupal\locale\Tests;
use Drupal\Component\Render\FormattableMarkup;
use Drupal\Component\Utility\SafeMarkup;
/**
......@@ -87,8 +88,12 @@ public function testInterface() {
$this->assertRaw(t('Missing translations for: @languages. See the <a href=":updates">Available translation updates</a> page for more information.', array('@languages' => t('German'), ':updates' => \Drupal::url('locale.translate_status'))), 'Missing translations message');
$this->drupalGet('admin/reports/translations');
$this->assertText(t('Missing translations for one project'), 'No translations found');
$this->assertText(SafeMarkup::format('@module (@version). @info', array('@module' => 'Locale test translate', '@version' => '1.3-dev', '@info' => t('No translation files are provided for development releases.'))), 'Release details');
$this->assertText(t('No translation files are provided for development releases.'), 'Release info');
$release_details = new FormattableMarkup('@module (@version). @info', [
'@module' => 'Locale test translate',
'@version' => '1.3-dev',
'@info' => t('File not found at %local_path', array('%local_path' => 'core/modules/locale/tests/test.de.po'))
]);
$this->assertRaw($release_details->__toString(), 'Release details');
// Override Drupal core translation status as 'no translations found'.
$status = locale_translation_get_status();
......
<?php
/**
* @file
* Contains \Drupal\locale\Tests\LocaleUpdateNotDevelopmentReleaseTest.
*/
namespace Drupal\locale\Tests;
use Drupal\simpletest\WebTestBase;
/**
* Test for finding the first available normal core release version,
* in case of core is a development release.
*
* @group language
*/
class LocaleUpdateNotDevelopmentReleaseTest extends WebTestBase {
public static $modules = array('update', 'locale', 'locale_test_not_development_release');
protected function setUp() {
parent::setUp();
module_load_include('compare.inc', 'locale');
$admin_user = $this->drupalCreateUser(array('administer modules', 'administer languages', 'access administration pages', 'translate interface'));
$this->drupalLogin($admin_user);
$this->drupalPostForm('admin/config/regional/language/add', array('predefined_langcode' => 'hu'), t('Add language'));
}
public function testLocaleUpdateNotDevelopmentRelease() {
// Set available Drupal releases for test.
$available = array(
'title' => 'Drupal core',
'short_name' => 'drupal',
'type' => 'project_core',
'api_version' => '8.x',
'project_status' => 'unsupported',
'link' => 'https://www.drupal.org/project/drupal',
'terms' => '',
'releases' => array(
'8.0.0-alpha110' => array(
'name' => 'drupal 8.0.0-alpha110',
'version' => '8.0.0-alpha110',
'tag' => '8.0.0-alpha110',
'version_major' => '8',
'version_minor' => '0',
'version_patch' => '0',
'version_extra' => 'alpha110',
'status' => 'published',
'release_link' => 'https://www.drupal.org/node/2316617',
'download_link' => 'http://ftp.drupal.org/files/projects/drupal-8.0.0-alpha110.tar.gz',
'date' => '1407344628',
'mdhash' => '9d71afdd0ce541f2ff5ca2fbbca00df7',
'filesize' => '9172832',
'files' => '',
'terms' => array(),
),
'8.0.0-alpha100' => array(
'name' => 'drupal 8.0.0-alpha100',
'version' => '8.0.0-alpha100',
'tag' => '8.0.0-alpha100',
'version_major' => '8',
'version_minor' => '0',
'version_patch' => '0',
'version_extra' => 'alpha100',
'status' => 'published',
'release_link' => 'https://www.drupal.org/node/2316617',
'download_link' => 'http://ftp.drupal.org/files/projects/drupal-8.0.0-alpha100.tar.gz',
'date' => '1407344628',
'mdhash' => '9d71afdd0ce541f2ff5ca2fbbca00df7',
'filesize' => '9172832',
'files' => '',
'terms' => array(),
),
),
);
$available['last_fetch'] = REQUEST_TIME;
\Drupal::keyValueExpirable('update_available_releases')->setWithExpire('drupal', $available, 10);
$projects = locale_translation_build_projects();
$this->verbose($projects['drupal']->info['version']);
$this->assertEqual($projects['drupal']->info['version'], '8.0.0-alpha110', 'The first release with the same major release number which is not a development release.');
}
}
......@@ -45,6 +45,10 @@ function locale_test_locale_translation_projects_alter(&$projects) {
// translation update system will not go out to l.d.o to check.
$projects['drupal']['server_pattern'] = 'translations://';
if (\Drupal::state()->get('locale.remove_core_project')) {
unset($projects['drupal']);
}
if (\Drupal::state()->get('locale.test_projects_alter')) {
// Instead of the default ftp.drupal.org we use the file system of the test
......
name: 'Locale Test Not Development Release'
name: 'Locale Test Development Release'
type: module
description: 'The first release with the same major release number which is not a development release.'
description: 'Helper module to test the behaviour when the core verison is a development release.'
package: Testing
version: VERSION
core: 8.x
......
......@@ -13,8 +13,30 @@
* Change the core version number to a development one for testing.
* 8.0.0-alpha102-dev is the simulated version.
*/
function locale_test_not_development_release_system_info_alter(&$info, Extension $file, $type) {
function locale_test_development_release_system_info_alter(&$info, Extension $file, $type) {
if (isset($info['package']) && $info['package'] == 'Core') {
$info['version'] = '8.0.0-alpha102-dev';
}
}
/**
* Implements hook_locale_translation_projects_alter().
*
* Add a contrib module with a dev release to list of translatable modules.
*/
function locale_test_development_release_locale_translation_projects_alter(&$projects) {
$projects['contrib'] = [
'name' => 'contrib',
'info' => array(
'name' => 'Contributed module',
'package' => 'Other',
'version' => '12.x-10.4-unstable11+14-dev',
'project' => 'contrib_module',
'datestamp' => '0',
'_info_file_ctime' => 1442933959,
),
'datestamp' => '0',
'project_type' => 'module',
'project_status' => TRUE,
];
}
......@@ -19,7 +19,7 @@ class PathLanguageTest extends PathTestBase {
*
* @var array
*/
public static $modules = array('path', 'locale', 'content_translation');
public static $modules = array('path', 'locale', 'locale_test', 'content_translation');
/**
* An user with permissions to administer content types.
......
......@@ -19,7 +19,7 @@ class PathLanguageUiTest extends PathTestBase {
*
* @var array
*/
public static $modules = array('path', 'locale');
public static $modules = array('path', 'locale', 'locale_test');
protected function setUp() {
parent::setUp();
......
......@@ -28,7 +28,7 @@ class ToolbarMenuTranslationTest extends WebTestBase {
*
* @var array
*/
public static $modules = array('toolbar', 'toolbar_test', 'locale');
public static $modules = array('toolbar', 'toolbar_test', 'locale', 'locale_test');
protected function setUp() {
parent::setUp();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment