diff --git a/core/modules/locale/tests/modules/locale_test/lib/Drupal/locale_test/LocaleTestBundle.php b/core/modules/locale/tests/modules/locale_test/lib/Drupal/locale_test/LocaleTestBundle.php index c1035ec..75819f4 100644 --- a/core/modules/locale/tests/modules/locale_test/lib/Drupal/locale_test/LocaleTestBundle.php +++ b/core/modules/locale/tests/modules/locale_test/lib/Drupal/locale_test/LocaleTestBundle.php @@ -4,10 +4,10 @@ * @file * Contains Drupal\locale_test\LocaleTestBundle. * - * This is a workaround for not letting FinishResponseSubscriber to neglect and - * override the already configured 'Last-Modified' HTTP header which is set and - * needed when a remote translation file is served via a menu callback. So a new - * event subscriber is registered here to save the value and set it back. + * This is a workaround to make sure the 'Last-Modified' HTTP header is not + * overridden by FinishResponseSubscriber. 'Last-Modified' is set when a remote + * translation file is served via a menu callback. So a new event subscriber is + * registered here to save the value and set it back. */ namespace Drupal\locale_test; diff --git a/core/modules/locale/tests/modules/locale_test/lib/Drupal/locale_test/LocaleTestFinishResponseSubscriber.php b/core/modules/locale/tests/modules/locale_test/lib/Drupal/locale_test/LocaleTestFinishResponseSubscriber.php index d93ac89..b9b4a7e 100644 --- a/core/modules/locale/tests/modules/locale_test/lib/Drupal/locale_test/LocaleTestFinishResponseSubscriber.php +++ b/core/modules/locale/tests/modules/locale_test/lib/Drupal/locale_test/LocaleTestFinishResponseSubscriber.php @@ -4,10 +4,10 @@ * @file * Definition of Drupal\locale_test\LocaleTestFinishResponseSubscriber. * - * This is a workaround for not letting FinishResponseSubscriber to neglect and - * override the already configured 'Last-Modified' HTTP header which is set and - * needed when a remote translation file is served via a menu callback. So this - * is a new event subscriber which saves the value and sets it back. + * This is a workaround to make sure the 'Last-Modified' HTTP header is not + * overridden by FinishResponseSubscriber. 'Last-Modified' is set when a remote + * translation file is served via a menu callback. So this is a new event + * subscriber which saves the value and sets it back. * It does so with the saveLastModified() method which has a very high priority, * so it can save the defined header really early in a class property. Then * later on the setLastModified() method can set the header again using the diff --git a/core/modules/locale/tests/modules/locale_test/locale_test.module b/core/modules/locale/tests/modules/locale_test/locale_test.module index b3bb53b..1faa0aa 100644 --- a/core/modules/locale/tests/modules/locale_test/locale_test.module +++ b/core/modules/locale/tests/modules/locale_test/locale_test.module @@ -5,6 +5,9 @@ * Simulate a custom module with a local po file. */ +define('LOCALE_TEST_TIMESTAMP_NEW', REQUEST_TIME - 100); +define('LOCALE_TEST_TIMESTAMP_OLD', REQUEST_TIME - 300); + /** * Implements hook_system_info_alter(). * @@ -14,7 +17,7 @@ function locale_test_system_info_alter(&$info, $file, $type) { // Only modify the system info if required. // By default the locale_test modules are hidden and have a project specified. - // To test the module detection proces by locale_project_list() the + // To test the module detection process by locale_project_list() the // test modules should mimic a custom module. I.e. be non-hidden. if (state()->get('locale.test_system_info_alter')) { if ($file->name == 'locale_test' || $file->name == 'locale_test_translate') { @@ -25,7 +28,7 @@ function locale_test_system_info_alter(&$info, $file, $type) { } /** - * Helper function to copy a translation file to the translations folder. + * Copies a translation file to the translations folder. * * Mock modules use this method to copy their po files to the translations * folder. They can also specify a timestamp which will be set for the copied @@ -39,8 +42,8 @@ function locale_test_system_info_alter(&$info, $file, $type) { * @param string $translation_file * Name of the translation file that will be copied. * @param int $timestamp - * Optional. Timestamp will be set as the creation date for the copy of - * the translation file. + * (optional) Timestamp will be set as the creation date for the copy of + * the translation file. By default the timestamp is the current time. */ function locale_test_copy_translation_file($module, $translation_file, $timestamp = NULL) { $translation_file_path = drupal_get_path('module', $module) . '/' . $translation_file; @@ -49,33 +52,28 @@ function locale_test_copy_translation_file($module, $translation_file, $timestam file_unmanaged_copy($translation_file_path, $destination, FILE_EXISTS_REPLACE); if (!empty($timestamp)) { - // Set desired timestamp as creation date for the copied translation file. + // Set the timestamp of the newly copied file. touch($destination, $timestamp); } } /** - * Helper function to serve a translation file as a result of a page callback. + * Serves a translation file as a result of a page callback. * * @param string $module * Name of the module providing the translation file that will be served. - * @param string $langcode - * Language code of the translation file. + * @param string $translation_file + * Name of the translation file that will be served. * @param int $timestamp * Timestamp of date that will be set in the 'Last-Modified' HTTP header. */ -function locale_test_serve_translation_file($module, $langcode, $timestamp) { - module_load_include('translation.inc', 'locale'); - module_load_include('compare.inc', 'locale'); - - $projects = locale_translation_get_projects(array($module)); - $source = locale_translation_source_build($projects[$module], $langcode); - $file = locale_translation_source_check_file($source); +function locale_test_serve_translation_file($module, $translation_file, $timestamp) { + $translation_file_path = drupal_get_path('module', $module) . '/' . $translation_file; $headers = array( 'Content-Type' => 'text/x-po; charset=utf-8', 'Last-Modified' => gmdate(DATE_RFC1123, $timestamp), ); - return file_transfer($file->uri, $headers); + return file_transfer(drupal_realpath($translation_file_path), $headers); } /** diff --git a/core/modules/locale/tests/modules/locale_test_contrib_one/locale_test_contrib_one.install b/core/modules/locale/tests/modules/locale_test_contrib_one/locale_test_contrib_one.install index a24ef2d..15e18fa 100644 --- a/core/modules/locale/tests/modules/locale_test_contrib_one/locale_test_contrib_one.install +++ b/core/modules/locale/tests/modules/locale_test_contrib_one/locale_test_contrib_one.install @@ -7,8 +7,10 @@ /** * Implements hook_install(). + * + * Copies the translation file provided by the module to the standard + * translations folder and sets timestamp of the new copy. */ function locale_test_contrib_one_install() { - $timestamp = REQUEST_TIME - 100; - locale_test_copy_translation_file('locale_test_contrib_one', 'locale_test_contrib_one-8.x-1.1.de.po', $timestamp); + locale_test_copy_translation_file(LOCALE_TEST_CONTRIB_ONE_MODULE_NAME, LOCALE_TEST_CONTRIB_ONE_PO_FILE, LOCALE_TEST_CONTRIB_ONE_PO_TIMESTAMP_LOCAL); } diff --git a/core/modules/locale/tests/modules/locale_test_contrib_one/locale_test_contrib_one.module b/core/modules/locale/tests/modules/locale_test_contrib_one/locale_test_contrib_one.module index ab99af1..6b2ee3b 100644 --- a/core/modules/locale/tests/modules/locale_test_contrib_one/locale_test_contrib_one.module +++ b/core/modules/locale/tests/modules/locale_test_contrib_one/locale_test_contrib_one.module @@ -6,6 +6,17 @@ */ /** + * Constants to control how the module will provide translation sources. Locale + * test mockup modules are almost identical with each other, these constants + * mean the differences between them. They also give us an overview what + * scenarios can be tested using these mockup modules. + */ +define('LOCALE_TEST_CONTRIB_ONE_MODULE_NAME', 'locale_test_contrib_one'); +define('LOCALE_TEST_CONTRIB_ONE_PO_FILE', 'locale_test_contrib_one-8.x-1.1.de.po'); +define('LOCALE_TEST_CONTRIB_ONE_PO_TIMESTAMP_LOCAL', LOCALE_TEST_TIMESTAMP_OLD); +define('LOCALE_TEST_CONTRIB_ONE_PO_TIMESTAMP_REMOTE', LOCALE_TEST_TIMESTAMP_NEW); + +/** * Implements hook_locale_translation_projects_alter(). * * The po file supplied with the module is used as mock remote translation file @@ -18,8 +29,8 @@ function locale_test_contrib_one_locale_translation_projects_alter(&$projects) { // Set the server URL and pattern to where the remote po file for this module // can be found. - if (isset($projects['locale_test_contrib_one'])) { - $projects['locale_test_contrib_one']['info']['interface translation server pattern'] = $url . '/%core/%project/%project-%version.%language.po'; + if (isset($projects[LOCALE_TEST_CONTRIB_ONE_MODULE_NAME])) { + $projects[LOCALE_TEST_CONTRIB_ONE_MODULE_NAME]['info']['interface translation server pattern'] = $url . '/%core/%project/%project-%version.%language.po'; } } @@ -30,11 +41,12 @@ function locale_test_contrib_one_locale_translation_projects_alter(&$projects) { */ function locale_test_contrib_one_menu() { $items = array(); - $items['locale-test-remote-translations/8.x/locale_test_contrib_one-8.x-1.1.de.po'] = array( - 'title' => 'Testing: locale_test_contrib_one-8.x-1.1.de.po', + $items['locale-test-remote-translations/8.x/' . LOCALE_TEST_CONTRIB_ONE_PO_FILE] = array( + 'title' => 'Testing: !po_file', + 'title arguments' => array('!po_file' => LOCALE_TEST_CONTRIB_ONE_PO_FILE), 'page callback' => 'locale_test_contrib_one_remote_translation', 'access callback' => TRUE, - 'type' => MENU_CALLBACK, + 'type' => MENU_NORMAL_ITEM, ); return $items; } @@ -45,5 +57,5 @@ function locale_test_contrib_one_menu() { function locale_test_contrib_one_remote_translation() { // This is essentially the exact same translation file as the one used for // locale po file testing, but we serve its content through this callback. - return locale_test_serve_translation_file('locale_test_contrib_one', 'de', REQUEST_TIME - 100); + return locale_test_serve_translation_file(LOCALE_TEST_CONTRIB_ONE_MODULE_NAME, LOCALE_TEST_CONTRIB_ONE_PO_FILE, LOCALE_TEST_CONTRIB_ONE_PO_TIMESTAMP_REMOTE); }