commit 1c70a2b3aaf854281e6bbb8fc6d6361bd6cb70f5 Author: Erik Stielstra Date: Thu Jun 6 07:49:40 2013 +0200 #23 diff --git a/core/modules/locale/lib/Drupal/locale/Tests/LocaleUpdateBase.php b/core/modules/locale/lib/Drupal/locale/Tests/LocaleUpdateBase.php new file mode 100644 index 0000000..62c023e --- /dev/null +++ b/core/modules/locale/lib/Drupal/locale/Tests/LocaleUpdateBase.php @@ -0,0 +1,290 @@ +timestamp_old = REQUEST_TIME - 300; + $this->timestamp_medium = REQUEST_TIME - 200; + $this->timestamp_new = REQUEST_TIME - 100; + $this->timestamp_now = REQUEST_TIME; + } + + /** + * Sets the value of the default translations directory. + * + * @param string $path + * Path of the translations directory relative to the drupal installation + * directory. + */ + protected function setTranslationsDirectory($path) { + $this->tranlations_directory = $path; + file_prepare_directory($path, FILE_CREATE_DIRECTORY); + config('locale.settings')->set('translation.path', $path)->save(); + } + + /** + * Adds a language. + * + * @param $langcode + * The language code of the language to add. + */ + protected function addLanguage($langcode) { + $edit = array('predefined_langcode' => $langcode); + $this->drupalPost('admin/config/regional/language/add', $edit, t('Add language')); + drupal_static_reset('language_list'); + $this->assertTrue(language_load($langcode), t('Language %langcode added.', array('%langcode' => $langcode))); + } + + /** + * Creates a translation file and tests its timestamp. + * + * @param string $path + * Path of the file relative to the public file path. + * @param string $filename + * Name of the file to create. + * @param integer $timestamp + * Timestamp to set the file to. Defaults to current time. + * @param array $translations + * Array of source/target value translation strings. Only singular strings + * are supported, no plurals. No double quotes are allowed in source and + * translations strings. + */ + protected function makePoFile($path, $filename, $timestamp = NULL, $translations = array()) { + $timestamp = $timestamp ? $timestamp : REQUEST_TIME; + $path = 'public://' . $path; + $text = ''; + $po_header = << 1);\\n" + +EOF; + + // Convert array of translations to Gettext source and translation strings. + if ($translations) { + foreach ($translations as $source => $target) { + $text .= 'msgid "'. $source . '"' . "\n"; + $text .= 'msgstr "'. $target . '"' . "\n"; + } + } + + file_prepare_directory($path, FILE_CREATE_DIRECTORY); + $file = entity_create('file', array( + 'uid' => 1, + 'filename' => $filename, + 'uri' => $path . '/' . $filename, + 'filemime' => 'text/x-gettext-translation', + 'timestamp' => $timestamp, + 'status' => FILE_STATUS_PERMANENT, + )); + file_put_contents($file->uri, $po_header . $text); + touch(drupal_realpath($file->uri), $timestamp); + $file->save(); + } + + /** + * Setup the environment containting local and remote translation files. + * + * Update tests require a simulated environment for local and remote files. + * Normally remote files are located at a remote server (e.g. ftp.drupal.org). + * For testing we can not rely on this. A directory in the file system of the + * test site is designated for remote files and is addressed using an absolute + * URL. Because Drupal does not allow files with a po extension to be accessed + * (denied in .htaccess) the translation files get a _po extension. Another + * directory is designated for local translation files. + * + * The environment is set up with the following files. File creation times are + * set to create different variations in test conditions. + * contrib_module_one + * - remote file: timestamp new + * - local file: timestamp old + * contrib_module_two + * - remote file: timestamp old + * - local file: timestamp new + * contrib_module_three + * - remote file: timestamp old + * - local file: timestamp old + * custom_module_one + * - local file: timestamp new + * Time stamp of current translation set by setCurrentTranslations() is always + * timestamp medium. This makes it easy to predict which translation will be + * imported. + */ + protected function setTranslationFiles() { + $config = config('locale.settings'); + + // 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); + + // Setup the environment. + $public_path = variable_get('file_public_path', conf_path() . '/files'); + $this->setTranslationsDirectory($public_path . '/local'); + $config->set('translation.default_filename', '%project-%version.%language._po')->save(); + + // Setting up sets of translations for the translation files. + $translations_one = array('January' => 'Januar_1', 'February' => 'Februar_1', 'March' => 'Marz_1'); + $translations_two = array( 'February' => 'Februar_2', 'March' => 'Marz_2', 'April' => 'April_2'); + $translations_three = array('April' => 'April_3', 'May' => 'Mai_3', 'June' => 'Juni_3'); + + // Add a number of files to the local file system to serve as remote + // translation server and match the project definitions set in + // locale_test_locale_translation_projects_alter(). + $this->makePoFile('remote/8.x/contrib_module_one', 'contrib_module_one-8.x-1.1.de._po', $this->timestamp_new, $translations_one); + $this->makePoFile('remote/8.x/contrib_module_two', 'contrib_module_two-8.x-2.0-beta4.de._po', $this->timestamp_old, $translations_two); + $this->makePoFile('remote/8.x/contrib_module_three', 'contrib_module_three-8.x-1.0.de._po', $this->timestamp_old, $translations_three); + + // Add a number of files to the local file system to serve as local + // translation files and match the project definitions set in + // locale_test_locale_translation_projects_alter(). + $this->makePoFile('local', 'contrib_module_one-8.x-1.1.de._po', $this->timestamp_old, $translations_one); + $this->makePoFile('local', 'contrib_module_two-8.x-2.0-beta4.de._po', $this->timestamp_new, $translations_two); + $this->makePoFile('local', 'contrib_module_three-8.x-1.0.de._po', $this->timestamp_old, $translations_three); + $this->makePoFile('local', 'custom_module_one.de.po', $this->timestamp_new); + } + + /** + * Setup existing translations in the database and set up the status of + * existing translations. + */ + protected function setCurrentTranslations() { + // Add non customized translations to the database. + $langcode = 'de'; + $context = ''; + $non_customized_translations = array( + 'March' => 'Marz', + 'June' => 'Juni', + ); + foreach ($non_customized_translations as $source => $translation) { + $string = locale_storage()->createString(array('source' => $source, 'context' => $context)) + ->save(); + locale_storage()->createTranslation(array( + 'lid' => $string->getId(), + 'language' => $langcode, + 'translation' => $translation, + 'customized' => LOCALE_NOT_CUSTOMIZED, + ))->save(); + } + + // Add customized translations to the database. + $customized_translations = array( + 'January' => 'Januar_customized', + 'February' => 'Februar_customized', + 'May' => 'Mai_customized', + ); + foreach ($customized_translations as $source => $translation) { + $string = locale_storage()->createString(array('source' => $source, 'context' => $context)) + ->save(); + locale_storage()->createTranslation(array( + 'lid' => $string->getId(), + 'language' => $langcode, + 'translation' => $translation, + 'customized' => LOCALE_CUSTOMIZED, + ))->save(); + } + + // Add a state of current translations in locale_files. + $default = array( + 'langcode' => $langcode, + 'uri' => '', + 'timestamp' => $this->timestamp_medium, + 'last_checked' => $this->timestamp_medium, + ); + $data[] = array( + 'project' => 'contrib_module_one', + 'filename' => 'contrib_module_one-8.x-1.1.de._po', + 'version' => '8.x-1.1', + ); + $data[] = array( + 'project' => 'contrib_module_two', + 'filename' => 'contrib_module_two-8.x-2.0-beta4.de._po', + 'version' => '8.x-2.0-beta4', + ); + $data[] = array( + 'project' => 'contrib_module_three', + 'filename' => 'contrib_module_three-8.x-1.0.de._po', + 'version' => '8.x-1.0', + ); + $data[] = array( + 'project' => 'custom_module_one', + 'filename' => 'custom_module_one.de.po', + 'version' => '', + ); + foreach ($data as $file) { + $file = (object) array_merge($default, $file); + drupal_write_record('locale_file', $file); + } + } + + /** + * Checks the translation of a string. + * + * @param string $source + * Translation source string + * @param string $translation + * Translation to check. Use empty string to check for a not existing + * translation. + * @param string $langcode + * Language code of the language to translate to. + * @param string $message + * (optional) A message to display with the assertion. + */ + protected function assertTranslation($source, $translation, $langcode, $message = '') { + $db_translation = db_query('SELECT translation FROM {locales_target} lt INNER JOIN {locales_source} ls ON ls.lid = lt.lid WHERE ls.source = :source AND lt.language = :langcode', array(':source' => $source, ':langcode' => $langcode))->fetchField(); + $db_translation = $db_translation == FALSE ? '' : $db_translation; + $this->assertEqual($translation, $db_translation, $message ? $message : format_string('Correct translation of %source (%language)', array('%source' => $source, '%language' => $langcode))); + } +} diff --git a/core/modules/locale/lib/Drupal/locale/Tests/LocaleUpdateCronTest.php b/core/modules/locale/lib/Drupal/locale/Tests/LocaleUpdateCronTest.php new file mode 100644 index 0000000..d71cc7f --- /dev/null +++ b/core/modules/locale/lib/Drupal/locale/Tests/LocaleUpdateCronTest.php @@ -0,0 +1,126 @@ + 'Update translations using cron', + 'description' => 'Tests for using cron to update project interface translations.', + 'group' => 'Locale', + ); + } + + function setUp() { + parent::setUp(); + $admin_user = $this->drupalCreateUser(array('administer modules', 'administer site configuration', 'administer languages', 'access administration pages', 'translate interface')); + $this->drupalLogin($admin_user); + $this->addLanguage('de'); + } + + /** + * Tests interface translation update using cron. + */ + function testUpdateCron() { + // Set a flag to let the locale_test module replace the project data with a + // set of test projects. + \Drupal::state()->set('locale.test_projects_alter', TRUE); + + // Setup local and remote translations files. + $this->setTranslationFiles(); + config('locale.settings')->set('translation.default_filename', '%project-%version.%language._po')->save(); + + // Update translations using batch to ensure a clean test starting point. + $this->drupalGet('admin/reports/translations/check'); + $this->drupalPost('admin/reports/translations', array(), t('Update translations')); + + // Store translation status for comparison. + $initial_history = locale_translation_get_file_history(); + + // Prepare for test: Simulate new translations being availabe. + // Change the last updated timestamp of a translation file. + $contrib_module_two_uri = 'public://local/contrib_module_two-8.x-2.0-beta4.de._po'; + touch(drupal_realpath($contrib_module_two_uri), REQUEST_TIME); + + // Prepare for test: Simulate that the file has not been checked for a long + // time. Set the last_check timestamp to zero. + $query = db_update('locale_file'); + $query->fields(array('last_checked' => 0)); + $query->condition('project', 'contrib_module_two'); + $query->condition('langcode', 'de'); + $query->execute(); + + // Test: Disable cron update and verify that no tasks are added to the + // queue. + $edit = array( + 'update_interval_days' => 0, + ); + $this->drupalPost('admin/config/regional/translate/settings', $edit, t('Save configuration')); + + // Execute locale cron taks to add tasks to the queue. + locale_cron(); + + // Check whether no tasks are added to the queue. + $queue = \Drupal::queue('locale_translation', TRUE); + $this->assertEqual($queue->numberOfItems(), 0, 'Queue is empty'); + + // Test: Enable cron update and check if update tasks are added to the + // queue. + // Set cron update to Weekly. + $edit = array( + 'update_interval_days' => 7, + ); + $this->drupalPost('admin/config/regional/translate/settings', $edit, t('Save configuration')); + + // Execute locale cron taks to add tasks to the queue. + locale_cron(); + + // Check whether tasks are added to the queue. + $queue = \Drupal::queue('locale_translation', TRUE); + // @todo Make follow-up issue: Mask the 'drupal' project so it will not show up in this test. When fixed, we expect only 3 tasks in the queue. + //$this->assertEqual($queue->numberOfItems(), 3, 'Queue holds tasks for one project.'); + $this->assertEqual($queue->numberOfItems(), 6, 'Queue holds tasks for two projects.'); + $item = $queue->claimItem(); + $queue->releaseItem($item); + $this->assertEqual($item->data[1][0], 'contrib_module_two', 'Queue holds tasks for contrib module one.'); + + // Test: Run cron for a second time and check if tasks are not added to + // the queue twice. + locale_cron(); + + // Check whether no more tasks are added to the queue. + $queue = \Drupal::queue('locale_translation', TRUE); + // @todo Make follow-up issue: Mask the 'drupal' project so it will not show up in this test. When fixed, we expect only 3 tasks in the queue. + //$this->assertEqual($queue->numberOfItems(), 3, 'Queue holds tasks for one project.'); + $this->assertEqual($queue->numberOfItems(), 6, 'Queue holds tasks for two projects.'); + + // Test: Execute cron and check if tasks are executed correctly. + // Run cron to process the tasks in the queue. + $this->drupalGet('admin/reports/status/run-cron'); + + drupal_static_reset('locale_translation_get_file_history'); + $history = locale_translation_get_file_history(); + $initial = $initial_history['contrib_module_two']['de']; + $current = $history['contrib_module_two']['de']; + $this->assertTrue($current->timestamp > $initial->timestamp, 'Timestamp is updated'); + $this->assertTrue($current->last_checked > $initial->last_checked, 'Last checked is updated'); + } +} diff --git a/core/modules/locale/lib/Drupal/locale/Tests/LocaleUpdateInterfaceTest.php b/core/modules/locale/lib/Drupal/locale/Tests/LocaleUpdateInterfaceTest.php index 9ccfb2c..0a502b6 100644 --- a/core/modules/locale/lib/Drupal/locale/Tests/LocaleUpdateInterfaceTest.php +++ b/core/modules/locale/lib/Drupal/locale/Tests/LocaleUpdateInterfaceTest.php @@ -12,7 +12,7 @@ /** * Tests for the locale translation update status user interfaces. */ -class LocaleUpdateInterfaceTest extends WebTestBase { +class LocaleUpdateInterfaceTest extends LocaleUpdateBase { /** * Modules to enable. @@ -36,19 +36,6 @@ function setUp() { } /** - * Adds a language. - * - * @param $langcode - * The language code of the language to add. - */ - function addLanguage($langcode) { - $edit = array('predefined_langcode' => $langcode); - $this->drupalPost('admin/config/regional/language/add', $edit, t('Add language')); - drupal_static_reset('language_list'); - $this->assertTrue(language_load($langcode), t('Language %langcode added.', array('%langcode' => $langcode))); - } - - /** * Tests the user interfaces of the interface translation update system. * * Testing the Available updates summary on the side wide status page and the @@ -68,10 +55,9 @@ function testInterface() { // Drupal core is probably in 8.x, but tests may also be executed with // stable releases. As this is an uncontrolled factor in the test, we will - // ignore Drupal core here and continue with the prepared modules. - unset($status['drupal']); + // mark Drupal core as translated and continue with the prepared modules. $status = locale_translation_get_status(); - unset($status['drupal']); + $status['drupal']['de']->type = 'current'; \Drupal::state()->set('locale.translation_status', $status); // One language added, all translations up to date. diff --git a/core/modules/locale/lib/Drupal/locale/Tests/LocaleUpdateTest.php b/core/modules/locale/lib/Drupal/locale/Tests/LocaleUpdateTest.php index 3ef56cf..44bfabe 100644 --- a/core/modules/locale/lib/Drupal/locale/Tests/LocaleUpdateTest.php +++ b/core/modules/locale/lib/Drupal/locale/Tests/LocaleUpdateTest.php @@ -12,35 +12,7 @@ /** * Tests for update translations. */ -class LocaleUpdateTest extends WebTestBase { - - /** - * The path of the translations directory where local translations are stored. - * - * @var string - */ - private $tranlations_directory; - - /** - * Timestamp for an old translation. - * - * @var integer - */ - private $timestamp_old; - - /** - * Timestamp for a medium aged translation. - * - * @var integer - */ - private $timestamp_medium; - - /** - * Timestamp for a new translation. - * - * @var integer - */ - private $timestamp_new; +class LocaleUpdateTest extends LocaleUpdateBase { /** * Modules to enable. @@ -67,242 +39,6 @@ function setUp() { // file that come with the locale_test module (test.de.po) and can therefore // not be chosen randomly. $this->addLanguage('de'); - - // Setup timestamps to identify old and new translation sources. - $this->timestamp_old = REQUEST_TIME - 300; - $this->timestamp_medium = REQUEST_TIME - 200; - $this->timestamp_new = REQUEST_TIME - 100; - $this->timestamp_now = REQUEST_TIME; - } - - /** - * Sets the value of the default translations directory. - * - * @param string $path - * Path of the translations directory relative to the drupal installation - * directory. - */ - private function setTranslationsDirectory($path) { - $this->tranlations_directory = $path; - file_prepare_directory($path, FILE_CREATE_DIRECTORY); - config('locale.settings')->set('translation.path', $path)->save(); - } - - /** - * Adds a language. - * - * @param $langcode - * The language code of the language to add. - */ - function addLanguage($langcode) { - $edit = array('predefined_langcode' => $langcode); - $this->drupalPost('admin/config/regional/language/add', $edit, t('Add language')); - drupal_static_reset('language_list'); - $this->assertTrue(language_load($langcode), t('Language %langcode added.', array('%langcode' => $langcode))); - } - - /** - * Creates a translation file and tests its timestamp. - * - * @param string $path - * Path of the file relative to the public file path. - * @param string $filename - * Name of the file to create. - * @param integer $timestamp - * Timestamp to set the file to. Defaults to current time. - * @param array $translations - * Array of source/target value translation strings. Only singular strings - * are supported, no plurals. No double quotes are allowed in source and - * translations strings. - */ - private function makePoFile($path, $filename, $timestamp = NULL, $translations = array()) { - $timestamp = $timestamp ? $timestamp : REQUEST_TIME; - $path = 'public://' . $path; - $text = ''; - $po_header = << 1);\\n" - -EOF; - - // Convert array of translations to Gettext source and translation strings. - if ($translations) { - foreach ($translations as $source => $target) { - $text .= 'msgid "'. $source . '"' . "\n"; - $text .= 'msgstr "'. $target . '"' . "\n"; - } - } - - file_prepare_directory($path, FILE_CREATE_DIRECTORY); - $file = entity_create('file', array( - 'uid' => 1, - 'filename' => $filename, - 'uri' => $path . '/' . $filename, - 'filemime' => 'text/x-gettext-translation', - 'timestamp' => $timestamp, - 'status' => FILE_STATUS_PERMANENT, - )); - file_put_contents($file->uri, $po_header . $text); - touch(drupal_realpath($file->uri), $timestamp); - $file->save(); - } - - /** - * Setup the environment containting local and remote translation files. - * - * Update tests require a simulated environment for local and remote files. - * Normally remote files are located at a remote server (e.g. ftp.drupal.org). - * For testing we can not rely on this. A directory in the file system of the - * test site is designated for remote files and is addressed using an absolute - * URL. Because Drupal does not allow files with a po extension to be accessed - * (denied in .htaccess) the translation files get a _po extension. Another - * directory is designated for local translation files. - * - * The environment is set up with the following files. File creation times are - * set to create different variations in test conditions. - * contrib_module_one - * - remote file: timestamp new - * - local file: timestamp old - * contrib_module_two - * - remote file: timestamp old - * - local file: timestamp new - * contrib_module_three - * - remote file: timestamp old - * - local file: timestamp old - * custom_module_one - * - local file: timestamp new - * Time stamp of current translation set by setCurrentTranslations() is always - * timestamp medium. This makes it easy to predict which translation will be - * imported. - */ - private function setTranslationFiles() { - $config = config('locale.settings'); - - // 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); - - // Setup the environment. - $public_path = variable_get('file_public_path', conf_path() . '/files'); - $this->setTranslationsDirectory($public_path . '/local'); - $config->set('translation.default_filename', '%project-%version.%language._po')->save(); - - // Setting up sets of translations for the translation files. - $translations_one = array('January' => 'Januar_1', 'February' => 'Februar_1', 'March' => 'Marz_1'); - $translations_two = array( 'February' => 'Februar_2', 'March' => 'Marz_2', 'April' => 'April_2'); - $translations_three = array('April' => 'April_3', 'May' => 'Mai_3', 'June' => 'Juni_3'); - - // Add a number of files to the local file system to serve as remote - // translation server and match the project definitions set in - // locale_test_locale_translation_projects_alter(). - $this->makePoFile('remote/8.x/contrib_module_one', 'contrib_module_one-8.x-1.1.de._po', $this->timestamp_new, $translations_one); - $this->makePoFile('remote/8.x/contrib_module_two', 'contrib_module_two-8.x-2.0-beta4.de._po', $this->timestamp_old, $translations_two); - $this->makePoFile('remote/8.x/contrib_module_three', 'contrib_module_three-8.x-1.0.de._po', $this->timestamp_old, $translations_three); - - // Add a number of files to the local file system to serve as local - // translation files and match the project definitions set in - // locale_test_locale_translation_projects_alter(). - $this->makePoFile('local', 'contrib_module_one-8.x-1.1.de._po', $this->timestamp_old, $translations_one); - $this->makePoFile('local', 'contrib_module_two-8.x-2.0-beta4.de._po', $this->timestamp_new, $translations_two); - $this->makePoFile('local', 'contrib_module_three-8.x-1.0.de._po', $this->timestamp_old, $translations_three); - $this->makePoFile('local', 'custom_module_one.de.po', $this->timestamp_new); - } - - /** - * Setup existing translations in the database and set up the status of - * existing translations. - */ - private function setCurrentTranslations() { - // Add non customized translations to the database. - $langcode = 'de'; - $context = ''; - $non_customized_translations = array( - 'March' => 'Marz', - 'June' => 'Juni', - ); - foreach ($non_customized_translations as $source => $translation) { - $string = locale_storage()->createString(array('source' => $source, 'context' => $context)) - ->save(); - $target = locale_storage()->createTranslation(array( - 'lid' => $string->getId(), - 'language' => $langcode, - 'translation' => $translation, - 'customized' => LOCALE_NOT_CUSTOMIZED, - ))->save(); - } - - // Add customized translations to the database. - $customized_translations = array( - 'January' => 'Januar_customized', - 'February' => 'Februar_customized', - 'May' => 'Mai_customized', - ); - foreach ($customized_translations as $source => $translation) { - $string = locale_storage()->createString(array('source' => $source, 'context' => $context)) - ->save(); - $target = locale_storage()->createTranslation(array( - 'lid' => $string->getId(), - 'language' => $langcode, - 'translation' => $translation, - 'customized' => LOCALE_CUSTOMIZED, - ))->save(); - } - - // Add a state of current translations in locale_files. - $default = array( - 'langcode' => $langcode, - 'uri' => '', - 'timestamp' => $this->timestamp_medium, - 'last_checked' => $this->timestamp_medium, - ); - $data[] = array( - 'project' => 'contrib_module_one', - 'filename' => 'contrib_module_one-8.x-1.1.de._po', - 'version' => '8.x-1.1', - ); - $data[] = array( - 'project' => 'contrib_module_two', - 'filename' => 'contrib_module_two-8.x-2.0-beta4.de._po', - 'version' => '8.x-2.0-beta4', - ); - $data[] = array( - 'project' => 'contrib_module_three', - 'filename' => 'contrib_module_three-8.x-1.0.de._po', - 'version' => '8.x-1.0', - ); - $data[] = array( - 'project' => 'custom_module_one', - 'filename' => 'custom_module_one.de.po', - 'version' => '', - ); - foreach ($data as $file) { - $file = (object) array_merge($default, $file); - drupal_write_record('locale_file', $file); - } - } - - /** - * Checks the translation of a string. - * - * @param string $source - * Translation source string - * @param string $translation - * Translation to check. Use empty string to check for a not existing - * translation. - * @param string $langcode - * Language code of the language to translate to. - * @param string $message - * (optional) A message to display with the assertion. - */ - function assertTranslation($source, $translation, $langcode, $message = '') { - $db_translation = db_query('SELECT translation FROM {locales_target} lt INNER JOIN {locales_source} ls ON ls.lid = lt.lid WHERE ls.source = :source AND lt.language = :langcode', array(':source' => $source, ':langcode' => $langcode))->fetchField(); - $db_translation = $db_translation == FALSE ? '' : $db_translation; - $this->assertEqual($translation, $db_translation, $message ? $message : format_string('Correct translation of %source (%language)', array('%source' => $source, '%language' => $langcode))); } /** @@ -522,64 +258,7 @@ function testUpdateImportSourceLocal() { } /** -<<<<<<< HEAD - * Tests translation import without a translations directory. - * - * Test conditions: - * - Source: remote and local files - * - Import overwrite: all existing translations - * - Translation directory: not available - */ - function testUpdateImportWithoutDirectory() { - $config = config('locale.settings'); - - // Build the test environment. - $this->setTranslationFiles(); - $this-> setCurrentTranslations(); - $config->set('translation.default_filename', '%project-%version.%language._po'); - - // Set the update conditions for this test. - $this->setTranslationsDirectory(''); - $edit = array( - 'use_source' => LOCALE_TRANSLATION_USE_SOURCE_REMOTE_AND_LOCAL, - 'overwrite' => LOCALE_TRANSLATION_OVERWRITE_ALL, - ); - $this->drupalPost('admin/config/regional/translate/settings', $edit, t('Save configuration')); - - // Execute the translation update. - $this->drupalGet('admin/reports/translations/check'); - $this->drupalPost('admin/reports/translations', array(), t('Update translations')); - - // Check if the translation has been updated, using the status cache. - $status = \Drupal::state()->get('locale.translation_status'); - $this->assertEqual($status['contrib_module_one']['de']->type, LOCALE_TRANSLATION_CURRENT, 'Translation of contrib_module_one found'); - $this->assertEqual($status['contrib_module_two']['de']->type, LOCALE_TRANSLATION_CURRENT, 'Translation of contrib_module_two found'); - $this->assertEqual($status['contrib_module_three']['de']->type, LOCALE_TRANSLATION_CURRENT, 'Translation of contrib_module_three found'); - - // Check the new translation status. - // The static cache needs to be flushed first to get the most recent data - // from the database. The function was called earlier during this test. - drupal_static_reset('locale_translation_get_file_history'); - $history = locale_translation_get_file_history(); - $this->assertTrue($history['contrib_module_one']['de']->timestamp >= $this->timestamp_now, 'Translation of contrib_module_one is imported'); - $this->assertTrue($history['contrib_module_one']['de']->last_checked >= $this->timestamp_now, 'Translation of contrib_module_one is updated'); - $this->assertEqual($history['contrib_module_two']['de']->timestamp, $this->timestamp_medium, 'Translation of contrib_module_two is imported'); - $this->assertEqual($history['contrib_module_two']['de']->last_checked, $this->timestamp_medium, 'Translation of contrib_module_two is updated'); - $this->assertEqual($history['contrib_module_three']['de']->timestamp, $this->timestamp_medium, 'Translation of contrib_module_three is not imported'); - $this->assertEqual($history['contrib_module_three']['de']->last_checked, $this->timestamp_medium, 'Translation of contrib_module_three is not updated'); - - // Check whether existing translations have (not) been overwritten. - $this->assertEqual(t('January', array(), array('langcode' => 'de')), 'Januar_1', 'Translation of January'); - $this->assertEqual(t('February', array(), array('langcode' => 'de')), 'Februar_1', 'Translation of February'); - $this->assertEqual(t('March', array(), array('langcode' => 'de')), 'Marz_1', 'Translation of March'); - $this->assertEqual(t('May', array(), array('langcode' => 'de')), 'Mai_customized', 'Translation of May'); - $this->assertEqual(t('June', array(), array('langcode' => 'de')), 'Juni', 'Translation of June'); - $this->assertEqual(t('Monday', array(), array('langcode' => 'de')), 'Montag', 'Translation of Monday'); - } - - /** - * Tests translation import with a translations directory and only overwrite - * non-customized translations. + * Tests translation import and only overwrite non-customized translations. * * Test conditions: * - Source: remote and local files @@ -615,8 +294,7 @@ function testUpdateImportModeNonCustomized() { } /** - * Tests translation import with a translations directory and don't overwrite - * any translation. + * Tests translation import and don't overwrite any translation. * * Test conditions: * - Source: remote and local files diff --git a/core/modules/locale/locale.batch.inc b/core/modules/locale/locale.batch.inc index e177437..8e73466 100644 --- a/core/modules/locale/locale.batch.inc +++ b/core/modules/locale/locale.batch.inc @@ -114,7 +114,7 @@ function locale_translation_batch_status_finished($success, $results) { if (!isset($results['failed_files']) && !isset($results['files'])) { drupal_set_message(t('Nothing to check.')); } - state()->set('locale.translation_last_checked', REQUEST_TIME); + Drupal::state()->set('locale.translation_last_checked', REQUEST_TIME); } else { drupal_set_message($t('An error occurred trying to check available interface translation updates.'), 'error'); @@ -214,7 +214,7 @@ function locale_translation_batch_fetch_import($project, $langcode, $options, &$ function locale_translation_batch_fetch_finished($success, $results) { module_load_include('bulk.inc', 'locale'); if ($success) { - state()->set('locale.translation_last_checked', REQUEST_TIME); + Drupal::state()->set('locale.translation_last_checked', REQUEST_TIME); } return locale_translate_batch_finished($success, $results); } diff --git a/core/modules/locale/locale.compare.inc b/core/modules/locale/locale.compare.inc index 7139f68..be7c480 100644 --- a/core/modules/locale/locale.compare.inc +++ b/core/modules/locale/locale.compare.inc @@ -232,7 +232,7 @@ function locale_translation_check_projects($projects = array(), $langcodes = arr else { // Retrieve and save the status of local translations only. locale_translation_check_projects_local($projects, $langcodes); - state()->set('locale.translation_last_checked', REQUEST_TIME); + Drupal::state()->set('locale.translation_last_checked', REQUEST_TIME); } } diff --git a/core/modules/locale/locale.module b/core/modules/locale/locale.module index 94daf49..60434c8 100644 --- a/core/modules/locale/locale.module +++ b/core/modules/locale/locale.module @@ -505,9 +505,7 @@ function locale_themes_disabled($themes) { function locale_cron() { // Update translations only when an update frequency was set by the admin // and a translatable language was set. - //if ($frequency = config('locale.settings')->get('translation.update_interval_days') && locale_translatable_language_list()) { - // @todo Remove next line after testing - if (TRUE) { + if ($frequency = config('locale.settings')->get('translation.update_interval_days') && locale_translatable_language_list()) { module_load_include('translation.inc', 'locale'); locale_cron_fill_queue(); } @@ -1039,7 +1037,7 @@ function locale_translation_file_history_delete($projects = array(), $langcodes */ function locale_translation_get_status($projects = NULL, $langcodes = NULL) { $result = array(); - $status = state()->get('locale.translation_status'); + $status = Drupal::state()->get('locale.translation_status'); module_load_include('translation.inc', 'locale'); $projects = $projects ? $projects : array_keys(locale_translation_get_projects()); $langcodes = $langcodes ? $langcodes : array_keys(locale_translatable_language_list()); diff --git a/core/modules/locale/locale.translation.inc b/core/modules/locale/locale.translation.inc index 6dc1829..5070cb5 100644 --- a/core/modules/locale/locale.translation.inc +++ b/core/modules/locale/locale.translation.inc @@ -328,7 +328,7 @@ function locale_cron_fill_queue() { $last = REQUEST_TIME - $config->get('translation.update_interval_days') * 3600 * 24; $query = db_select('locale_file', 'f'); $query->join('locale_project', 'p', 'p.name = f.project'); - $query->condition('f.last_checked', $last, '>='); + $query->condition('f.last_checked', $last, '<'); $query->fields('f', array('project', 'langcode')); if (!$config->get('translation.check_disabled_modules')) { $query->condition('p.status', 1);