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 new file mode 100644 index 0000000..2f9db4a --- /dev/null +++ b/core/modules/locale/tests/modules/locale_test/lib/Drupal/locale_test/LocaleTestBundle.php @@ -0,0 +1,34 @@ +register('finish_response_subscriber', 'Drupal\locale_test\LocaleTestFinishResponseSubscriber') + ->addArgument(new Reference('language_manager')) + ->setScope('request') + ->addTag('event_subscriber'); + } +} 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 new file mode 100644 index 0000000..e62705e --- /dev/null +++ b/core/modules/locale/tests/modules/locale_test/lib/Drupal/locale_test/LocaleTestFinishResponseSubscriber.php @@ -0,0 +1,41 @@ +getResponse(); + $last_modified = $response->headers->get('Last-Modified'); + // Parent method will change it to REQUEST_TIME. + parent::onRespond($event); + if (!empty($last_modified)) { + // But here it's the desired one again. + $response->headers->set('Last-Modified', $last_modified); + } + } +} diff --git a/core/modules/locale/tests/modules/locale_test/locale_test.info b/core/modules/locale/tests/modules/locale_test/locale_test.info index f17a400..5277751 100644 --- a/core/modules/locale/tests/modules/locale_test/locale_test.info +++ b/core/modules/locale/tests/modules/locale_test/locale_test.info @@ -4,6 +4,7 @@ package = Testing version = 1.2 core = 8.x hidden = TRUE +dependencies[] = locale ; Definitions for interface translations. interface translation project = locale_test 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 8f87ddc..b3bb53b 100644 --- a/core/modules/locale/tests/modules/locale_test/locale_test.module +++ b/core/modules/locale/tests/modules/locale_test/locale_test.module @@ -25,6 +25,60 @@ function locale_test_system_info_alter(&$info, $file, $type) { } /** + * Helper function to copy 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 + * file in order to be able to test different scenarios with these translation + * files. + * + * @param string $module + * Name of the module providing the translation file that will be copied by + * this method. Will be used for constructing the path for this translation + * file. + * @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. + */ +function locale_test_copy_translation_file($module, $translation_file, $timestamp = NULL) { + $translation_file_path = drupal_get_path('module', $module) . '/' . $translation_file; + $translate_directory = variable_get('locale_translate_file_directory', conf_path() . '/files/translations'); + $destination = $translate_directory . '/' . $translation_file; + file_unmanaged_copy($translation_file_path, $destination, FILE_EXISTS_REPLACE); + + if (!empty($timestamp)) { + // Set desired timestamp as creation date for the copied translation file. + touch($destination, $timestamp); + } +} + +/** + * Helper function to serve 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 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); + $headers = array( + 'Content-Type' => 'text/x-po; charset=utf-8', + 'Last-Modified' => gmdate(DATE_RFC1123, $timestamp), + ); + return file_transfer($file->uri, $headers); +} + +/** * Implements hook_locale_translation_projects_alter(). * * The translation status process by default checks the status of the installed diff --git a/core/modules/locale/tests/modules/locale_test_contrib_one/locale_test_contrib_one-8.x-1.1.de.po b/core/modules/locale/tests/modules/locale_test_contrib_one/locale_test_contrib_one-8.x-1.1.de.po new file mode 100644 index 0000000..adf6f55 --- /dev/null +++ b/core/modules/locale/tests/modules/locale_test_contrib_one/locale_test_contrib_one-8.x-1.1.de.po @@ -0,0 +1,16 @@ +msgid "" +msgstr "" +"Project-Id-Version: Drupal 8\\n" +"MIME-Version: 1.0\\n" +"Content-Type: text/plain; charset=UTF-8\\n" +"Content-Transfer-Encoding: 8bit\\n" +"Plural-Forms: nplurals=2; plural=(n > 1);\\n" + +msgid "January" +msgstr "Januar_1" + +msgid "February" +msgstr "Februar_1" + +msgid "March" +msgstr "Marz_1" diff --git a/core/modules/locale/tests/modules/locale_test_contrib_one/locale_test_contrib_one.info b/core/modules/locale/tests/modules/locale_test_contrib_one/locale_test_contrib_one.info new file mode 100644 index 0000000..6db4613 --- /dev/null +++ b/core/modules/locale/tests/modules/locale_test_contrib_one/locale_test_contrib_one.info @@ -0,0 +1,8 @@ +name = Locale test contributed module one +project = locale_test_contrib_one +description = Translation test module mocking a contributed module with translation files on remote and local file locations. +package = Testing +version = 8.x-1.1 +core = 8.x +;;hidden = TRUE +dependencies[] = locale_test 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 new file mode 100644 index 0000000..a24ef2d --- /dev/null +++ b/core/modules/locale/tests/modules/locale_test_contrib_one/locale_test_contrib_one.install @@ -0,0 +1,14 @@ + TRUE)) . 'locale-test-remote-translations'; + + // 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'; + } +} + +/** + * Implements hook_menu(). + * + * Provides a callback for the remote translation file. + */ +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', + 'page callback' => 'locale_test_contrib_one_remote_translation', + 'access callback' => TRUE, + 'type' => MENU_CALLBACK, + ); + return $items; +} + +/** + * Page callback; serves remote translation file. + */ +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); +}