- <?php
- * @file
- * Tests for locale.module.
- */
-
- * Functional tests for language configuration's effect on negotiation setup.
- */
- class LocaleConfigurationTest extends BackdropWebTestCase {
- function setUp() {
- parent::setUp('locale');
- }
-
-
- * Functional tests for adding, editing and deleting languages.
- */
- function testLanguageConfiguration() {
- global $base_url;
-
-
- $admin_user = $this->backdropCreateUser(array('administer languages', 'access administration pages'));
- $this->backdropLogin($admin_user);
-
-
- $this->backdropGet('admin/config/regional/language/detection/url');
- $this->assertFieldByXPath('//input[@name="prefix[en]"]', '', 'Default English has no path prefix.');
-
-
- $edit = array(
- 'predefined_langcode' => 'fr',
- );
- $this->backdropPost('admin/config/regional/language/add', $edit, t('Add language'));
- $this->assertText('French', 'Language added successfully.');
- $this->assertEqual($this->getUrl(), url('admin/config/regional/language', array('absolute' => TRUE)), 'Correct page redirection.');
-
-
- $this->backdropGet('admin/config/regional/language/detection/url');
- $this->assertFieldByXPath('//input[@name="prefix[en]"]', '', 'Default English has no path prefix.');
-
- $this->backdropGet('admin/config/regional/language/detection/url');
- $this->assertFieldByXPath('//input[@name="prefix[fr]"]', 'fr', 'French has a path prefix.');
-
-
- $this->backdropGet('admin/config/regional/language');
- $this->assertFieldChecked('edit-site-default-en', 'English is the default language.');
-
- $edit = array(
- 'site_default' => 'fr',
- );
- $this->backdropPost(NULL, $edit, t('Save configuration'));
- $this->assertNoFieldChecked('edit-site-default-en', 'Default language updated.');
- $this->assertEqual($this->getUrl(), url('admin/config/regional/language', array('absolute' => TRUE)), 'Correct page redirection.');
-
-
-
- $this->backdropGet('admin/config/regional/language/detection/url');
- $this->assertFieldByXPath('//input[@name="prefix[en]"]', 'en', 'A valid path prefix has been added to the previous default language.');
-
- $this->backdropGet('admin/config/regional/language/detection/url');
- $this->assertFieldByXPath('//input[@name="prefix[fr]"]', 'fr', 'French still has a path prefix.');
- }
- }
-
- * Tests localization of the JavaScript libraries.
- *
- * Currently, only the jQuery datepicker is localized using Backdrop translations.
- */
- class LocaleLibraryInfoAlterTest extends BackdropWebTestCase {
- function setUp() {
- parent::setUp('locale', 'locale_test');
- }
-
-
- * Verifies that the datepicker can be localized.
- *
- * @see locale_library_info_alter()
- */
- public function testLibraryInfoAlter() {
- backdrop_add_library('system', 'ui.datepicker');
- $scripts = backdrop_get_js();
- $this->assertTrue(strpos($scripts, 'locale.datepicker.js'), 'locale.datepicker.js added to scripts.');
- }
- }
-
- * Functional tests for JavaScript parsing for translatable strings.
- */
- class LocaleJavascriptTranslationTest extends BackdropWebTestCase {
- function setUp() {
- parent::setUp('locale', 'locale_test');
- }
-
- function testFileParsing() {
-
- $filename = backdrop_get_path('module', 'locale_test') . '/locale_test.js';
-
-
- _locale_parse_js_file($filename);
-
-
- $source_strings = db_select('locales_source', 's')
- ->fields('s', array('source', 'context'))
- ->condition('s.location', $filename)
- ->execute()
- ->fetchAllKeyed();
-
-
- $test_strings = array(
- "Standard Call t" => '',
- "Whitespace Call t" => '',
-
- "Single Quote t" => '',
- "Single Quote \\'Escaped\\' t" => '',
- "Single Quote Concat strings t" => '',
-
- "Double Quote t" => '',
- "Double Quote \\\"Escaped\\\" t" => '',
- "Double Quote Concat strings t" => '',
-
- "Context !key Args t" => "Context string",
-
- "Context Unquoted t" => "Context string unquoted",
- "Context Single Quoted t" => "Context string single quoted",
- "Context Double Quoted t" => "Context string double quoted",
-
- "Standard Call plural" => '',
- "Standard Call @count plural" => '',
- "Whitespace Call plural" => '',
- "Whitespace Call @count plural" => '',
-
- "Single Quote plural" => '',
- "Single Quote @count plural" => '',
- "Single Quote \\'Escaped\\' plural" => '',
- "Single Quote \\'Escaped\\' @count plural" => '',
-
- "Double Quote plural" => '',
- "Double Quote @count plural" => '',
- "Double Quote \\\"Escaped\\\" plural" => '',
- "Double Quote \\\"Escaped\\\" @count plural" => '',
-
- "Context !key Args plural" => "Context string",
- "Context !key Args @count plural" => "Context string",
-
- "Context Unquoted plural" => "Context string unquoted",
- "Context Unquoted @count plural" => "Context string unquoted",
- "Context Single Quoted plural" => "Context string single quoted",
- "Context Single Quoted @count plural" => "Context string single quoted",
- "Context Double Quoted plural" => "Context string double quoted",
- "Context Double Quoted @count plural" => "Context string double quoted",
-
- "No count argument plural - singular" => '',
- "No count argument plural - plural" => '',
- );
-
-
- foreach ($test_strings as $str => $context) {
- $args = array('%source' => $str, '%context' => $context);
-
-
- $this->assertTrue(isset($source_strings[$str]), format_string('Found source string: %source', $args));
-
-
- $this->assertTrue(isset($source_strings[$str]) && $source_strings[$str] === $context, strlen($context) > 0 ? format_string('Context for %source is %context', $args) : format_string('Context for %source is blank', $args));
- }
-
- $this->assertEqual(count($source_strings), count($test_strings), 'Found correct number of source strings.');
- }
- }
-
- * Functional test for string translation and validation.
- */
- class LocaleTranslationFunctionalTest extends BackdropWebTestCase {
- function setUp() {
- parent::setUp('locale');
- }
-
-
- * Adds a language and tests string translation by users with the appropriate permissions.
- */
- function testStringTranslation() {
- global $base_url;
-
-
- $admin_user = $this->backdropCreateUser(array('administer languages', 'access administration pages'));
-
- $translate_user = $this->backdropCreateUser(array('translate interface', 'access administration pages'));
-
- $langcode = 'xx';
-
- $name = $this->randomName(16);
-
- $native = $this->randomName(16);
-
-
- $language_indicator = "<em class=\"locale-untranslated\">$langcode</em> ";
-
- $translation = $this->randomName(16);
- $translation_to_en = $this->randomName(16);
-
-
- $this->backdropLogin($admin_user);
- $edit = array(
- 'predefined_langcode' => 'custom',
- 'langcode' => $langcode,
- 'name' => $name,
- 'native' => $native,
- 'direction' => '0',
- );
- $this->backdropPost('admin/config/regional/language/add', $edit, t('Add custom language'));
-
- t($name, array(), array('langcode' => $langcode));
-
- locale_reset();
- $this->assertRaw('"edit-site-default-' . $langcode .'"', 'Language code found.');
- $this->assertText(t($name), 'Test language added.');
- $this->backdropLogout();
-
-
- $this->backdropLogin($translate_user);
- $search = array(
- 'string' => $name,
- 'language' => 'all',
- 'translation' => 'all',
- );
- $this->backdropPost('admin/config/regional/translate/translate', $search, t('Filter'));
-
-
-
- $this->assertText($name, 'Search found the name.');
- $this->assertRaw($language_indicator, 'Name is untranslated.');
-
- $this->clickLink(t('Edit'));
-
- $matches = array();
- preg_match('!admin/config/regional/translate/edit/(\d+)!', $this->getUrl(), $matches);
- $lid = $matches[1];
-
- $this->assertText($name, 'name found on edit screen.');
- $this->assertNoText('English', 'No way to translate the string to English.');
- $this->backdropLogout();
- $this->backdropLogin($admin_user);
- $this->backdropPost('admin/config/regional/language/edit/en', array('locale_translate_english' => TRUE), t('Save language'));
- $this->backdropLogout();
- $this->backdropLogin($translate_user);
- $this->backdropPost('admin/config/regional/translate/translate', $search, t('Filter'));
-
-
-
- $this->assertText($name, 'Search found the name.');
- $this->assertRaw($language_indicator, 'Name is untranslated.');
-
- $this->clickLink(t('Edit'));
- $string_edit_url = $this->getUrl();
- $edit = array(
- "translations[$langcode]" => $translation,
- 'translations[en]' => $translation_to_en,
- );
- $this->backdropPost(NULL, $edit, t('Save translations'));
- $this->assertText(t('The string has been saved.'), 'The string has been saved.');
- $this->assertEqual($this->getUrl(), url('admin/config/regional/translate/translate', array('absolute' => TRUE)), 'Correct page redirection.');
- $this->backdropGet($string_edit_url);
- $this->assertRaw($translation, 'Non-English translation properly saved.');
- $this->assertRaw($translation_to_en, 'English translation properly saved.');
- $this->assertTrue($name != $translation && t($name, array(), array('langcode' => $langcode)) == $translation, 't() works for non-English.');
-
-
-
- locale_reset();
-
- $this->assertTrue($name != $translation_to_en && t($name, array(), array('langcode' => 'en')) == $translation_to_en, 't() works for English.');
- $this->assertTrue(t($name, array(), array('langcode' => LANGUAGE_SYSTEM)) == $name, 't() works for LANGUAGE_SYSTEM.');
- $this->backdropPost('admin/config/regional/translate/translate', $search, t('Filter'));
-
- $this->assertNoRaw($language_indicator, 'String is translated.');
-
-
-
- db_update('locales_target')
- ->fields(array('translation' => ''))
- ->condition('language', $langcode, '=')
- ->condition('lid', $lid, '=')
- ->execute();
- $this->backdropPost('admin/config/regional/translate/edit/' . $lid, $edit, t('Save translations'));
- $this->assertText(t('The string has been saved.'), 'The string has been saved.');
-
-
-
- $random_lid = 999999;
- $this->backdropGet('admin/config/regional/translate/edit/' . $random_lid);
- $this->assertText(t('String not found'), 'String not found.');
- $this->assertEqual($this->getUrl(), url('admin/config/regional/translate/translate', array('absolute' => TRUE)), 'Correct page redirection.');
- $this->backdropLogout();
-
-
- $this->backdropLogin($admin_user);
- $path = 'admin/config/regional/language/delete/' . $langcode;
-
- $this->backdropPost($path, array(), t('Delete'));
-
- $t_args = array('%language' => $name, '%langcode' => $langcode);
- $this->assertRaw(t('The %language (%langcode) language has been removed.', $t_args), 'The test language has been removed.');
-
- $this->backdropGet($path);
-
- $this->assertResponse(404, 'Language no longer found.');
- $this->backdropLogout();
-
-
- $this->backdropLogin($translate_user);
- $search = array(
- 'string' => $name,
- 'language' => 'all',
- 'translation' => 'all',
- );
- $this->backdropPost('admin/config/regional/translate/translate', $search, t('Filter'));
-
- $this->clickLink(t('Delete'));
- $this->assertText(t('Are you sure you want to delete the string'), '"delete" link is correct.');
-
- $path = 'admin/config/regional/translate/delete/' . $lid;
- $this->backdropGet($path);
-
- $this->clickLink(t('Cancel'));
- $this->assertEqual($this->getUrl(), url('admin/config/regional/translate/translate', array('absolute' => TRUE)), 'Correct page redirection.');
- $this->assertRaw($name, 'The string was not deleted.');
-
- $this->backdropPost('admin/config/regional/translate/delete/' . $lid, array(), t('Delete'));
- $this->assertText(t('The string has been removed.'), 'The string has been removed message.');
- $this->assertEqual($this->getUrl(), url('admin/config/regional/translate/translate', array('absolute' => TRUE)), 'Correct page redirection.');
- $this->backdropPost('admin/config/regional/translate/translate', $search, t('Filter'));
- $this->assertNoText($name, 'Search now can not find the name.');
- }
-
-
- * Adds a language and checks that the JavaScript translation files are
- * properly created and rebuilt on deletion.
- */
- function testJavaScriptTranslation() {
- $user = $this->backdropCreateUser(array('translate interface', 'administer languages', 'access administration pages'));
- $this->backdropLogin($user);
-
- $langcode = 'xx';
-
- $name = $this->randomName(16);
-
- $native = $this->randomName(16);
-
-
- $edit = array(
- 'predefined_langcode' => 'custom',
- 'langcode' => $langcode,
- 'name' => $name,
- 'native' => $native,
- 'direction' => '0',
- );
- $this->backdropPost('admin/config/regional/language/add', $edit, t('Add custom language'));
- backdrop_static_reset('language_list');
-
-
- $this->backdropGet('admin/config/regional/translate/translate');
-
-
-
- $query = db_select('locales_source', 'l');
- $query->addExpression('min(l.lid)', 'lid');
- $result = $query->condition('l.location', '%.js%', 'LIKE')->execute();
- $url = 'admin/config/regional/translate/edit/' . $result->fetchObject()->lid;
- $edit = array('translations['. $langcode .']' => $this->randomName());
- $this->backdropPost($url, $edit, t('Save translations'));
-
-
- require_once BACKDROP_ROOT . '/core/includes/locale.inc';
- _locale_rebuild_js($langcode);
-
- $locale_javascripts = state_get('locale_translation_javascript', array());
- $js_file = 'public://' . settings_get('locale_js_directory', 'languages') . '/' . $langcode . '_' . $locale_javascripts[$langcode] . '.js';
- $this->assertTrue($result = file_exists($js_file), format_string('JavaScript file created: %file', array('%file' => $result ? $js_file : 'not found')));
-
-
- file_unmanaged_delete($js_file);
- $this->assertTrue($result = !file_exists($js_file), format_string('JavaScript file deleted: %file', array('%file' => $result ? $js_file : 'found')));
- cache_clear_all();
- _locale_rebuild_js($langcode);
- $this->assertTrue($result = file_exists($js_file), format_string('JavaScript file rebuilt: %file', array('%file' => $result ? $js_file : 'not found')));
- }
-
-
- * Tests the validation of the translation input.
- */
- function testStringValidation() {
- global $base_url;
-
-
- $admin_user = $this->backdropCreateUser(array('administer languages', 'access administration pages', 'translate interface'));
- $this->backdropLogin($admin_user);
- $langcode = 'xx';
-
- $name = $this->randomName(16);
-
- $native = $this->randomName(16);
-
-
- $language_indicator = "<em class=\"locale-untranslated\">$langcode</em> ";
-
- $key = $this->randomName(16);
- $bad_translations[$key] = "<script>alert('xss');</script>" . $key;
- $key = $this->randomName(16);
- $bad_translations[$key] = '<img SRC="javascript:alert(\'xss\');">' . $key;
- $key = $this->randomName(16);
- $bad_translations[$key] = '<<SCRIPT>alert("xss");//<</SCRIPT>' . $key;
- $key = $this->randomName(16);
- $bad_translations[$key] ="<BODY ONLOAD=alert('xss')>" . $key;
-
-
- $edit = array(
- 'predefined_langcode' => 'custom',
- 'langcode' => $langcode,
- 'name' => $name,
- 'native' => $native,
- 'direction' => '0',
- );
- $this->backdropPost('admin/config/regional/language/add', $edit, t('Add custom language'));
-
- t($name, array(), array('langcode' => $langcode));
-
- $search = array(
- 'string' => $name,
- 'language' => 'all',
- 'translation' => 'all',
- );
- $this->backdropPost('admin/config/regional/translate/translate', $search, t('Filter'));
-
- $content = $this->backdropGetContent();
- $this->assertTrue(preg_match('@(admin/config/regional/translate/edit/[0-9]+)@', $content, $matches), 'Found the edit path.');
- $path = $matches[0];
- foreach ($bad_translations as $key => $translation) {
- $edit = array(
- "translations[$langcode]" => $translation,
- );
- $this->backdropPost($path, $edit, t('Save translations'));
-
- $form_class = $this->xpath('//form[@id="locale-translate-edit-form"]//textarea/@class');
- $this->assertNotIdentical(FALSE, strpos($form_class[0], 'error'), 'The string was rejected as unsafe.');
- $this->assertNoText(t('The string has been saved.'), 'The string was not saved.');
- }
- }
-
-
- * Tests translation search form.
- */
- function testStringSearch() {
- global $base_url;
-
-
- $admin_user = $this->backdropCreateUser(array('administer languages', 'access administration pages'));
-
- $translate_user = $this->backdropCreateUser(array('translate interface', 'access administration pages'));
-
-
- $langcode = 'xx';
-
- $name = $this->randomName(16);
-
- $native = $this->randomName(16);
-
-
- $language_indicator = "<em class=\"locale-untranslated\">$langcode</em> ";
-
- $translation = $this->randomName(16);
-
-
- $this->backdropLogin($admin_user);
- $edit = array(
- 'predefined_langcode' => 'custom',
- 'langcode' => $langcode,
- 'name' => $name,
- 'native' => $native,
- 'direction' => '0',
- );
- $this->backdropPost('admin/config/regional/language/add', $edit, t('Add custom language'));
-
- t($name, array(), array('langcode' => $langcode));
-
- locale_reset();
- $this->backdropLogout();
-
-
- $this->backdropLogin($translate_user);
- $search = array(
- 'string' => $name,
- 'language' => 'all',
- 'translation' => 'all',
- );
- $this->backdropPost('admin/config/regional/translate/translate', $search, t('Filter'));
-
-
-
- $this->assertText($name, 'Search found the string.');
-
-
-
- $search = array(
- 'string' => $name,
- 'language' => 'all',
- 'translation' => 'translated',
- );
- $this->backdropPost('admin/config/regional/translate/translate', $search, t('Filter'));
- $this->assertText(t('No strings available.'), "Search didn't find the string.");
-
-
-
- $search = array(
- 'string' => $name,
- 'language' => 'all',
- 'translation' => 'untranslated',
- );
- $this->backdropPost('admin/config/regional/translate/translate', $search, t('Filter'));
- $this->assertNoText(t('No strings available.'), 'Search found the string.');
-
-
-
- $search = array(
- 'string' => $name,
- 'language' => $langcode,
- 'translation' => 'untranslated',
- );
- $this->backdropPost('admin/config/regional/translate/translate', $search, t('Filter'));
- $this->assertNoText(t('No strings available.'), 'Search found the string.');
-
-
-
- $this->clickLink(t('Edit'));
-
- $matches = array();
- preg_match('!admin/config/regional/translate/edit/(\d)+!', $this->getUrl(), $matches);
- $lid = $matches[1];
- $edit = array(
- "translations[$langcode]" => $translation,
- );
- $this->backdropPost(NULL, $edit, t('Save translations'));
-
-
-
- $search = array(
- 'string' => $translation,
- 'language' => 'all',
- 'translation' => 'translated',
- );
- $this->backdropPost('admin/config/regional/translate/translate', $search, t('Filter'));
- $this->assertNoText(t('No strings available.'), 'Search found the translation.');
-
-
-
- $search = array(
- 'string' => $name,
- 'language' => 'all',
- 'translation' => 'untranslated',
- );
- $this->backdropPost('admin/config/regional/translate/translate', $search, t('Filter'));
- $this->assertText(t('No strings available.'), "Search didn't find the source string.");
-
-
-
- $search = array(
- 'string' => $translation,
- 'language' => 'all',
- 'translation' => 'untranslated',
- );
- $this->backdropPost('admin/config/regional/translate/translate', $search, t('Filter'));
- $this->assertText(t('No strings available.'), "Search didn't find the translation.");
-
-
- $search = array(
- 'string' => $translation,
- 'language' => $langcode,
- 'translation' => 'all',
- );
- $this->backdropPost('admin/config/regional/translate/translate', $search, t('Filter'));
- $this->assertNoText(t('No strings available.'), 'Search found the translation.');
-
-
- $search = array(
- 'string' => $translation,
- 'language' => LANGUAGE_SYSTEM,
- 'translation' => 'all',
- );
- $this->backdropPost('admin/config/regional/translate/translate', $search, t('Filter'));
- $this->assertText(t('No strings available.'), "Search didn't find the translation.");
-
-
- $unavailable_string = $this->randomName(16);
- $search = array(
- 'string' => $unavailable_string,
- 'language' => 'all',
- 'translation' => 'all',
- );
- $this->backdropPost('admin/config/regional/translate/translate', $search, t('Filter'));
- $this->assertText(t('No strings available.'), "Search didn't find the invalid string.");
- }
- }
-
- * Tests plural index computation functionality.
- */
- class LocalePluralFormatTest extends BackdropWebTestCase {
- function setUp() {
- parent::setUp('locale', 'locale_test');
-
- $admin_user = $this->backdropCreateUser(array('administer languages', 'translate interface', 'access administration pages'));
- $this->backdropLogin($admin_user);
- }
-
-
- * Tests locale_get_plural() functionality.
- */
- function testGetPluralFormat() {
-
-
- $this->importPoFile($this->getPoFileWithSimplePlural(), array(
- 'langcode' => 'fr',
- ));
- $this->importPoFile($this->getPoFileWithComplexPlural(), array(
- 'langcode' => 'hr',
- ));
-
-
-
- $this->importPoFile($this->getPoFileWithMissingPlural(), array(
- 'langcode' => 'fr',
- ));
- $this->importPoFile($this->getPoFileWithBrokenPlural(), array(
- 'langcode' => 'hr',
- ));
-
-
- backdrop_static_reset('locale_get_plural');
- backdrop_static_reset('locale_get_plural:plurals');
-
-
- $this->assertIdentical(locale_get_plural(1, 'en'), 0, "Computed plural index for 'en' with count 1 is 0.");
- $this->assertIdentical(locale_get_plural(0, 'en'), 1, "Computed plural index for 'en' with count 0 is 1.");
- $this->assertIdentical(locale_get_plural(5, 'en'), 1, "Computed plural index for 'en' with count 5 is 1.");
-
-
- $this->assertIdentical(locale_get_plural(1, 'fr'), 0, "Computed plural index for 'fr' with count 1 is 0.");
- $this->assertIdentical(locale_get_plural(0, 'fr'), 0, "Computed plural index for 'fr' with count 0 is 0.");
- $this->assertIdentical(locale_get_plural(5, 'fr'), 1, "Computed plural index for 'fr' with count 5 is 1.");
-
-
- $this->assertIdentical(locale_get_plural( 1, 'hr'), 0, "Computed plural index for 'hr' with count 1 is 0.");
- $this->assertIdentical(locale_get_plural(21, 'hr'), 0, "Computed plural index for 'hr' with count 21 is 0.");
- $this->assertIdentical(locale_get_plural( 0, 'hr'), 2, "Computed plural index for 'hr' with count 0 is 2.");
- $this->assertIdentical(locale_get_plural( 2, 'hr'), 1, "Computed plural index for 'hr' with count 2 is 1.");
- $this->assertIdentical(locale_get_plural( 8, 'hr'), 2, "Computed plural index for 'hr' with count 8 is 2.");
-
-
- $this->assertIdentical(locale_get_plural( 1, 'hu'), -1, "Computed plural index for 'hu' with count 1 is -1.");
- $this->assertIdentical(locale_get_plural(21, 'hu'), -1, "Computed plural index for 'hu' with count 21 is -1.");
- $this->assertIdentical(locale_get_plural( 0, 'hu'), -1, "Computed plural index for 'hu' with count 0 is -1.");
- }
-
-
- * Imports a standalone .po file in a given language.
- *
- * @param $contents
- * Contents of the .po file to import.
- * @param $options
- * Additional options to pass to the translation import form.
- */
- function importPoFile($contents, array $options = array()) {
- $name = backdrop_tempnam('temporary://', "po_") . '.po';
- file_put_contents($name, $contents);
- $options['files[file]'] = $name;
- $options['mode'] = LOCALE_IMPORT_OVERWRITE;
- $this->backdropPost('admin/config/regional/translate/import', $options, t('Import'));
- backdrop_unlink($name);
- }
-
-
- * Returns a .po file with a simple plural formula.
- */
- function getPoFileWithSimplePlural() {
- return <<< EOF
- msgid ""
- msgstr ""
- "Project-Id-Version: Backdrop 1\\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 "1 hour"
- msgid_plural "@count hours"
- msgstr[0] "1 heure"
- msgstr[1] "@count heures"
-
- msgid "Monday"
- msgstr "lundi"
- EOF;
- }
-
-
- * Returns a .po file with a complex plural formula.
- */
- function getPoFileWithComplexPlural() {
- return <<< EOF
- msgid ""
- msgstr ""
- "Project-Id-Version: Backdrop 1\\n"
- "MIME-Version: 1.0\\n"
- "Content-Type: text/plain; charset=UTF-8\\n"
- "Content-Transfer-Encoding: 8bit\\n"
- "Plural-Forms: nplurals=3; plural=n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2;\\n"
-
- msgid "1 hour"
- msgid_plural "@count hours"
- msgstr[0] "@count sat"
- msgstr[1] "@count sata"
- msgstr[2] "@count sati"
-
- msgid "Monday"
- msgstr "Ponedjeljak"
- EOF;
- }
-
-
- * Returns a .po file with a missing plural formula.
- */
- function getPoFileWithMissingPlural() {
- return <<< EOF
- msgid ""
- msgstr ""
- "Project-Id-Version: Backdrop 1\\n"
- "MIME-Version: 1.0\\n"
- "Content-Type: text/plain; charset=UTF-8\\n"
- "Content-Transfer-Encoding: 8bit\\n"
-
- msgid "Monday"
- msgstr "lundi"
- EOF;
- }
-
-
- * Returns a .po file with a broken plural formula.
- */
- function getPoFileWithBrokenPlural() {
- return <<< EOF
- msgid ""
- msgstr ""
- "Project-Id-Version: Backdrop 1\\n"
- "MIME-Version: 1.0\\n"
- "Content-Type: text/plain; charset=UTF-8\\n"
- "Content-Transfer-Encoding: 8bit\\n"
- "Plural-Forms: broken, will not parse\\n"
-
- msgid "Monday"
- msgstr "Ponedjeljak"
- EOF;
- }
- }
-
- * Functional tests for the import of translation files.
- */
- class LocaleImportFunctionalTest extends BackdropWebTestCase {
-
- * A user able to create languages and import translations.
- */
- protected $admin_user = NULL;
-
- function setUp() {
- parent::setUp('locale', 'locale_test');
-
-
- $source = backdrop_get_path('module', 'locale_test');
- $destination = settings_get('locale_translate_file_directory', conf_path() . '/files/translations');
- file_prepare_directory($destination, FILE_CREATE_DIRECTORY);
- foreach (file_scan_directory($source, '/.*\.po/') as $file) {
- file_unmanaged_copy($file->uri, $destination . '/' . $file->filename, FILE_EXISTS_REPLACE);
- }
-
- $this->admin_user = $this->backdropCreateUser(array('administer languages', 'translate interface', 'access administration pages'));
- $this->backdropLogin($this->admin_user);
- }
-
-
- * Test import of standalone .po files.
- */
- function testStandalonePoFile() {
-
- $this->importPoFile($this->getPoFile(), array(
- 'langcode' => 'fr',
- ));
-
-
- $this->assertRaw(t('The language %language has been created.', array('%language' => 'French')), 'The language has been automatically created.');
-
-
- $this->assertRaw(t('The translation was successfully imported. There are %number newly created translated strings, %update strings were updated and %delete strings were removed.', array('%number' => 9, '%update' => 0, '%delete' => 0)), 'The translation file was successfully imported.');
-
-
- $locale_plurals = state_get('locale_translation_plurals', array());
- $this->assert($locale_plurals['fr']['plurals'] == 2, 'Plural number initialized.');
-
-
- $this->assertEqual($this->getUrl(), url('admin/config/regional/translate', array('absolute' => TRUE)), 'Correct page redirection.');
-
-
-
- $this->importPoFile($this->getBadPoFile(), array(
- 'langcode' => 'fr',
- ));
-
-
- $this->assertRaw(t('The translation was successfully imported. There are %number newly created translated strings, %update strings were updated and %delete strings were removed.', array('%number' => 1, '%update' => 0, '%delete' => 0)), 'The translation file was successfully imported.');
- $skip_message = format_plural(2, 'A translation string was skipped because of disallowed or malformed HTML. <a href="@url">See the log</a> for details.', '@count translation strings were skipped because of disallowed or malformed HTML. <a href="@url">See the log</a> for details.', array('@url' => url('admin/reports/dblog')));
- $this->assertRaw($skip_message, 'Unsafe strings were skipped.');
-
-
-
- $name = $this->randomName(16);
- $this->backdropPost('admin/config/regional/translate/import', array(
- 'langcode' => 'fr',
- 'files[file]' => $name,
- ), t('Import'));
- $this->assertEqual($this->getUrl(), url('admin/config/regional/translate/import', array('absolute' => TRUE)), 'Correct page redirection.');
- $this->assertText(t('File to import not found.'), 'File to import not found message.');
-
-
-
-
- $this->importPoFile($this->getOverwritePoFile(), array(
- 'langcode' => 'fr',
- 'mode' => 1,
- ));
-
-
- $this->assertRaw(t('The translation was successfully imported. There are %number newly created translated strings, %update strings were updated and %delete strings were removed.', array('%number' => 1, '%update' => 0, '%delete' => 0)), 'The translation file was successfully imported.');
-
- $search = array(
- 'string' => 'Montag',
- 'language' => 'fr',
- 'translation' => 'translated',
- );
- $this->backdropPost('admin/config/regional/translate/translate', $search, t('Filter'));
- $this->assertText(t('No strings available.'), 'String not overwritten by imported string.');
-
-
- $locale_plurals = state_get('locale_translation_plurals', array());
- $this->assert($locale_plurals['fr']['plurals'] == 2, 'Plural numbers untouched.');
-
-
-
- $this->importPoFile($this->getOverwritePoFile(), array(
- 'langcode' => 'fr',
- 'mode' => 0,
- ));
-
-
- $this->assertRaw(t('The translation was successfully imported. There are %number newly created translated strings, %update strings were updated and %delete strings were removed.', array('%number' => 0, '%update' => 2, '%delete' => 0)), 'The translation file was successfully imported.');
-
- $search = array(
- 'string' => 'Montag',
- 'language' => 'fr',
- 'translation' => 'translated',
- );
- $this->backdropPost('admin/config/regional/translate/translate', $search, t('Filter'));
- $this->assertNoText(t('No strings available.'), 'String overwritten by imported string.');
-
- $locale_plurals = state_get('locale_translation_plurals', array());
- $this->assert($locale_plurals['fr']['plurals'] == 3, 'Plural numbers changed.');
- }
-
-
- * Test automatic import of a module's translation files.
- */
- function testAutomaticModuleTranslationImportLanguageEnable() {
-
- $langcode = 'xx';
-
- $name = $this->randomName(16);
-
-
- $edit = array(
- 'predefined_langcode' => 'custom',
- 'langcode' => $langcode,
- 'name' => $name,
- 'native' => $name,
- 'direction' => '0',
- );
- $this->backdropPost('admin/config/regional/language/add', $edit, t('Add custom language'));
-
-
-
- $this->assertText(t('One translation file imported.'), 'Language file automatically imported.');
-
-
- $search = array(
- 'string' => 'lundi',
- 'language' => $langcode,
- 'translation' => 'translated',
- );
- $this->backdropPost('admin/config/regional/translate/translate', $search, t('Filter'));
- $this->assertNoText(t('No strings available.'), 'String successfully imported.');
- }
-
-
- * Test msgctxt context support.
- */
- function testLanguageContext() {
-
- $this->importPoFile($this->getPoFileWithContext(), array(
- 'langcode' => 'hr',
- ));
-
- $this->assertIdentical(t('May', array(), array('langcode' => 'hr', 'context' => 'Long month name')), 'Svibanj', 'Long month name context is working.');
- $this->assertIdentical(t('May', array(), array('langcode' => 'hr')), 'Svi.', 'Default context is working.');
- }
-
-
- * Test empty msgstr at end of .po file see #611786.
- */
- function testEmptyMsgstr() {
- $langcode = 'hu';
-
-
- $this->importPoFile($this->getPoFileWithMsgstr(), array(
- 'langcode' => $langcode,
- ));
-
- $this->assertRaw(t('The translation was successfully imported. There are %number newly created translated strings, %update strings were updated and %delete strings were removed.', array('%number' => 1, '%update' => 0, '%delete' => 0)), 'The translation file was successfully imported.');
- $this->assertIdentical(t('Operations', array(), array('langcode' => $langcode)), 'Műveletek', 'String imported and translated.');
-
-
- $this->importPoFile($this->getPoFileWithEmptyMsgstr(), array(
- 'langcode' => $langcode,
- 'mode' => 0,
- ));
- $this->assertRaw(t('The translation was successfully imported. There are %number newly created translated strings, %update strings were updated and %delete strings were removed.', array('%number' => 0, '%update' => 0, '%delete' => 1)), 'The translation file was successfully imported.');
-
-
- $language_indicator = "<em class=\"locale-untranslated\">$langcode</em> ";
- $str = "Operations";
- $search = array(
- 'string' => $str,
- 'language' => 'all',
- 'translation' => 'all',
- );
- $this->backdropPost('admin/config/regional/translate/translate', $search, t('Filter'));
-
-
- $this->assertText($str, 'Search found the string.');
- $this->assertRaw($language_indicator, 'String is untranslated again.');
- }
-
-
- * Helper function: import a standalone .po file in a given language.
- *
- * @param $contents
- * Contents of the .po file to import.
- * @param $options
- * Additional options to pass to the translation import form.
- */
- function importPoFile($contents, array $options = array()) {
- $name = backdrop_tempnam('temporary://', "po_") . '.po';
- file_put_contents($name, $contents);
- $options['files[file]'] = $name;
- $this->backdropPost('admin/config/regional/translate/import', $options, t('Import'));
- backdrop_unlink($name);
- }
-
-
- * Helper function that returns a proper .po file.
- */
- function getPoFile() {
- return <<< EOF
- msgid ""
- msgstr ""
- "Project-Id-Version: Backdrop 1\\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 "One sheep"
- msgid_plural "@count sheep"
- msgstr[0] "un mouton"
- msgstr[1] "@count moutons"
-
- msgid "Monday"
- msgstr "lundi"
-
- msgid "Tuesday"
- msgstr "mardi"
-
- msgid "Wednesday"
- msgstr "mercredi"
-
- msgid "Thursday"
- msgstr "jeudi"
-
- msgid "Friday"
- msgstr "vendredi"
-
- msgid "Saturday"
- msgstr "samedi"
-
- msgid "Sunday"
- msgstr "dimanche"
- EOF;
- }
-
-
- * Helper function that returns a bad .po file.
- */
- function getBadPoFile() {
- return <<< EOF
- msgid ""
- msgstr ""
- "Project-Id-Version: Backdrop 1\\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 "Save configuration"
- msgstr "Enregistrer la configuration"
-
- msgid "edit"
- msgstr "modifier<img SRC="javascript:alert(\'xss\');">"
-
- msgid "delete"
- msgstr "supprimer<script>alert('xss');</script>"
-
- EOF;
- }
-
-
- * Helper function that returns a proper .po file for testing.
- */
- function getOverwritePoFile() {
- return <<< EOF
- msgid ""
- msgstr ""
- "Project-Id-Version: Backdrop 1\\n"
- "MIME-Version: 1.0\\n"
- "Content-Type: text/plain; charset=UTF-8\\n"
- "Content-Transfer-Encoding: 8bit\\n"
- "Plural-Forms: nplurals=3; plural=n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2;\\n"
-
- msgid "Monday"
- msgstr "Montag"
-
- msgid "Day"
- msgstr "Jour"
- EOF;
- }
-
-
- * Helper function that returns a .po file with context.
- */
- function getPoFileWithContext() {
-
-
- return <<< EOF
- msgid ""
- msgstr ""
- "Project-Id-Version: Backdrop 1\\n"
- "MIME-Version: 1.0\\n"
- "Content-Type: text/plain; charset=UTF-8\\n"
- "Content-Transfer-Encoding: 8bit\\n"
- "Plural-Forms: nplurals=3; plural=n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2;\\n"
-
- msgctxt "Long month name"
- msgid "May"
- msgstr "Svibanj"
-
- msgid "May"
- msgstr "Svi."
- EOF;
- }
-
-
- * Helper function that returns a .po file with an empty last item.
- */
- function getPoFileWithEmptyMsgstr() {
- return <<< EOF
- msgid ""
- msgstr ""
- "Project-Id-Version: Backdrop 1\\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 "Operations"
- msgstr ""
-
- EOF;
- }
-
- * Helper function that returns a .po file with an empty last item.
- */
- function getPoFileWithMsgstr() {
- return <<< EOF
- msgid ""
- msgstr ""
- "Project-Id-Version: Backdrop 1\\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 "Operations"
- msgstr "Műveletek"
-
- msgid "Will not appear in Backdrop core, so we can ensure the test passes"
- msgstr ""
-
- EOF;
- }
-
- }
-
- * Functional tests for the export of translation files.
- */
- class LocaleExportFunctionalTest extends BackdropWebTestCase {
-
- * A user able to create languages and export translations.
- */
- protected $admin_user = NULL;
-
- function setUp() {
- parent::setUp('locale', 'locale_test');
-
- $this->admin_user = $this->backdropCreateUser(array('administer languages', 'translate interface', 'access administration pages'));
- $this->backdropLogin($this->admin_user);
- }
-
-
- * Test exportation of translations.
- */
- function testExportTranslation() {
-
-
- $name = backdrop_tempnam('temporary://', "po_") . '.po';
- file_put_contents($name, $this->getPoFile());
- $this->backdropPost('admin/config/regional/translate/import', array(
- 'langcode' => 'fr',
- 'files[file]' => $name,
- ), t('Import'));
- backdrop_unlink($name);
-
-
- $this->backdropPost('admin/config/regional/translate/export', array(
- 'langcode' => 'fr',
- ), t('Export'));
-
-
- $this->assertRaw('# French translation of Backdrop', 'Exported French translation file.');
-
- $this->assertRaw('msgstr "lundi"', 'French translations present in exported file.');
- }
-
-
- * Test exportation of translation template file.
- */
- function testExportTranslationTemplateFile() {
-
-
-
-
- $this->backdropPost('admin/config/regional/translate/export', array(), t('Export'));
-
- $this->assertRaw('# LANGUAGE translation of PROJECT', 'Exported translation template file.');
- }
-
-
- * Helper function that returns a proper .po file.
- */
- function getPoFile() {
- return <<< EOF
- msgid ""
- msgstr ""
- "Project-Id-Version: Backdrop 0\\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 "Monday"
- msgstr "lundi"
- EOF;
- }
-
- }
-
- * Tests for the st() function.
- */
- class LocaleInstallTest extends BackdropWebTestCase {
- function setUp() {
- parent::setUp('locale');
-
-
- require_once BACKDROP_ROOT . '/core/includes/install.inc';
- }
-
-
- * Verify that function signatures of t() and st() are equal.
- */
- function testFunctionSignatures() {
- $reflector_t = new ReflectionFunction('t');
- $reflector_st = new ReflectionFunction('st');
- $this->assertEqual($reflector_t->getParameters(), $reflector_st->getParameters(), 'Function signatures of t() and st() are equal.');
- }
- }
-
- * Locale uninstall with English UI functional test.
- */
- class LocaleUninstallFunctionalTest extends BackdropWebTestCase {
-
-
- * @var string
- */
- protected $langcode;
-
- function setUp() {
- parent::setUp('locale');
- $this->langcode = 'en';
- }
-
-
- * Check if the values of the Locale variables are correct after uninstall.
- */
- function testUninstallProcess() {
- $locale_module = array('locale', 'language');
-
-
- require_once BACKDROP_ROOT . '/core/includes/locale.inc';
-
- $language = (object) array(
- 'langcode' => 'fr',
- 'name' => 'French',
- 'default' => $this->langcode == 'fr',
- );
- language_save($language);
-
-
- backdrop_language_initialize();
- $this->assertEqual($GLOBALS['language']->langcode, $this->langcode, format_string('Current language: %lang', array('%lang' => $GLOBALS['language']->langcode)));
-
-
- $node_type = node_type_load('post');
- $node_type->settings['language'] = 1;
- node_type_save($node_type);
-
-
- settings_get('locale_js_directory', 'js_translations');
-
-
- $user = $this->backdropCreateUser(array('translate interface', 'access administration pages'));
- $this->backdropLogin($user);
- $this->backdropGet('admin/config/regional/translate/translate');
- $string = db_query('SELECT min(lid) AS lid FROM {locales_source} WHERE location LIKE :location', array(
- ':location' => '%.js%',
- ))->fetchObject();
- $edit = array('translations[fr]' => 'french translation');
- $this->backdropPost('admin/config/regional/translate/edit/' . $string->lid, $edit, t('Save translations'));
- _locale_rebuild_js('fr');
- $locale_javascripts = state_get('locale_translation_javascript', array());
- $js_file = 'public://' . settings_get('locale_js_directory', 'languages') . '/fr_' . $locale_javascripts['fr'] . '.js';
- $this->assertTrue($result = file_exists($js_file), format_string('JavaScript file created: %file', array('%file' => $result ? $js_file : t('none'))));
-
-
- backdrop_load('module', 'locale');
- config('language.settings')
- ->set('language_negotiation.' . LANGUAGE_TYPE_INTERFACE, array_keys(locale_language_negotiation_info()))
- ->set('language_negotiation.' . LANGUAGE_TYPE_CONTENT, array_keys(locale_language_negotiation_info()))
- ->set('language_negotiation.' . LANGUAGE_TYPE_URL, array_keys(locale_language_negotiation_info()))
- ->save();
-
-
- config('locale.settings')
- ->set('language_negotiation_url_part', FALSE)
- ->set('language_negotiation_session_parameter', FALSE)
- ->save();
-
-
- module_disable($locale_module);
- backdrop_uninstall_modules($locale_module);
-
-
- $this->backdropGet('');
-
-
- backdrop_language_initialize();
- $this->assertEqual($GLOBALS['language']->langcode, 'en', format_string('Language after uninstall: %lang', array('%lang' => $GLOBALS['language']->langcode)));
-
-
- $this->assertTrue($result = !file_exists($js_file), format_string('JavaScript file deleted: %file', array('%file' => $result ? $js_file : 'found')));
-
-
- $language_count = config_get('system.core', 'language_count');
- $this->assertEqual($language_count, 1, format_string('Language count: %count', array('%count' => $language_count)));
-
- backdrop_static_reset('language_types_info');
- backdrop_static_reset('language_negotiation_info');
-
-
- require_once BACKDROP_ROOT . '/core/includes/language.inc';
- $this->assertTrue(count(language_types_info()) == 0, 'Language types reset');
- $language_negotiation = language_negotiation_get(LANGUAGE_TYPE_INTERFACE) == LANGUAGE_NEGOTIATION_DEFAULT;
- $this->assertTrue($language_negotiation, format_string('Interface language negotiation: %setting', array('%setting' => $language_negotiation ? 'none' : 'set')));
- $language_negotiation = language_negotiation_get(LANGUAGE_TYPE_CONTENT) == LANGUAGE_NEGOTIATION_DEFAULT;
- $this->assertTrue($language_negotiation, format_string('Content language negotiation: %setting', array('%setting' => $language_negotiation ? 'none' : 'set')));
- $language_negotiation = language_negotiation_get(LANGUAGE_TYPE_URL) == LANGUAGE_NEGOTIATION_DEFAULT;
- $this->assertTrue($language_negotiation, format_string('URL language negotiation: %setting', array('%setting' => $language_negotiation ? 'none' : 'set')));
-
-
- $this->assertFalse(config_get('locale.settings', 'language_negotiation_url_part'), format_string('URL language negotiation method indicator settings cleared.'));
- $this->assertFalse(config_get('locale.settings', 'language_negotiation_session_parameter'), format_string('Visit language negotiation method settings cleared.'));
-
-
- $javascript_parsed_count = count(state_get('locale_javascript_parsed', array()));
- $this->assertEqual($javascript_parsed_count, 0, format_string('JavaScript parsed count: %count', array('%count' => $javascript_parsed_count)));
-
-
- $locale_js_directory = settings_get('locale_js_directory', 'languages');
- $this->assertEqual($locale_js_directory, 'languages', format_string('JavaScript translations directory: %dir', array('%dir' => $locale_js_directory)));
- }
- }
-
- * Locale uninstall with French UI functional test.
- *
- * Because this class extends LocaleUninstallFunctionalTest, it doesn't require a new
- * test of its own. Rather, it switches the default UI language in setUp and then
- * runs the testUninstallProcess (which it inherits from LocaleUninstallFunctionalTest)
- * to test with this new language.
- */
- class LocaleUninstallFrenchFunctionalTest extends LocaleUninstallFunctionalTest {
- function setUp() {
- parent::setUp();
- $this->langcode = 'fr';
- }
- }
-
- * Functional tests for the language switching feature.
- */
- class LocaleLanguageSwitchingFunctionalTest extends BackdropWebTestCase {
- function setUp() {
- parent::setUp('locale');
-
-
- $admin_user = $this->backdropCreateUser(array('administer blocks', 'administer languages', 'translate interface', 'access administration pages'));
- $this->backdropLogin($admin_user);
- }
-
-
- * Functional tests for the language switcher block.
- */
- function testLanguageBlock() {
-
- $language_type = LANGUAGE_TYPE_INTERFACE;
- $layout = layout_load('default');
- $layout->addBlock('locale', $language_type, 'sidebar');
- $layout->save();
-
-
- $edit = array(
- 'predefined_langcode' => 'fr',
- );
- $this->backdropPost('admin/config/regional/language/add', $edit, t('Add language'));
-
-
- $edit = array('language[locale-url][enabled]' => '1');
- $this->backdropPost('admin/config/regional/language/detection', $edit, t('Save settings'));
-
-
- $this->backdropGet('user');
- $this->assertText(t('Languages'), 'Language switcher block found.');
-
-
- list($language_switcher) = $this->xpath('//*[contains(@class,:class)]/div[@class="block-content"]', array(':class' => 'block-locale-' . str_replace('_', '-', $language_type)));
- $links = array(
- 'active' => array(),
- 'inactive' => array(),
- );
- $anchors = array(
- 'active' => array(),
- 'inactive' => array(),
- );
- foreach ($language_switcher->ul->li as $link) {
- $classes = explode(" ", (string) $link['class']);
- list($langcode) = array_intersect($classes, array('en', 'fr'));
- if (in_array('active', $classes)) {
- $links['active'][] = $langcode;
- }
- else {
- $links['inactive'][] = $langcode;
- }
- $anchor_classes = explode(" ", (string) $link->a['class']);
- if (in_array('active', $anchor_classes)) {
- $anchors['active'][] = $langcode;
- }
- else {
- $anchors['inactive'][] = $langcode;
- }
- }
- $this->assertIdentical($links, array('active' => array('en'), 'inactive' => array('fr')), 'Only the current language list item is marked as active on the language switcher block.');
- $this->assertIdentical($anchors, array('active' => array('en'), 'inactive' => array('fr')), 'Only the current language anchor is marked as active on the language switcher block.');
- }
- }
-
- * Test browser language detection.
- */
- class LocaleBrowserDetectionTest extends BackdropUnitTestCase {
-
- * Unit tests for the locale_language_from_browser() function.
- */
- function testLanguageFromBrowser() {
-
- require_once BACKDROP_ROOT . '/core/includes/locale.inc';
-
- $languages = array(
-
- 'en' => (object) array(
- 'langcode' => 'en',
- ),
- 'en-US' => (object) array(
- 'langcode' => 'en-US',
- ),
-
- 'fr-CA' => (object) array(
- 'langcode' => 'fr-CA',
- ),
- 'fr' => (object) array(
- 'langcode' => 'fr',
- ),
-
- 'es-MX' => (object) array(
- 'langcode' => 'es-MX',
- ),
-
- 'pt' => (object) array(
- 'langcode' => 'pt',
- ),
-
-
- 'eh-oh-laa-laa' => (object) array(
- 'langcode' => 'eh-oh-laa-laa',
- ),
- );
-
- $test_cases = array(
-
- 'en,en-US,fr-CA,fr,es-MX' => 'en',
- 'en-US,en,fr-CA,fr,es-MX' => 'en',
- 'fr,en' => 'en',
- 'en,fr' => 'en',
- 'en-US,fr' => 'en',
- 'fr,en-US' => 'en',
- 'fr,fr-CA' => 'fr-CA',
- 'fr-CA,fr' => 'fr-CA',
- 'fr' => 'fr-CA',
- 'fr;q=1' => 'fr-CA',
- 'fr,es-MX' => 'fr-CA',
- 'fr,es' => 'fr-CA',
- 'es,fr' => 'fr-CA',
- 'es-MX,de' => 'es-MX',
- 'de,es-MX' => 'es-MX',
-
-
- 'en' => 'en',
- 'En' => 'en',
- 'EN' => 'en',
- ' en' => 'en',
- 'en ' => 'en',
- 'en, fr' => 'en',
-
-
-
-
- 'es' => 'es-MX',
- 'es-MX' => 'es-MX',
- 'pt' => 'pt',
- 'pt-PT' => 'pt',
- 'pt-PT;q=0.5,pt-BR;q=1,en;q=0.7' => 'en',
- 'pt-PT;q=1,pt-BR;q=0.5,en;q=0.7' => 'en',
- 'pt-PT;q=0.4,pt-BR;q=0.1,en;q=0.7' => 'en',
- 'pt-PT;q=0.1,pt-BR;q=0.4,en;q=0.7' => 'en',
-
-
-
- 'eh-oh-laa-laa' => 'eh-oh-laa-laa',
- 'eh-oh-laa' => 'eh-oh-laa-laa',
- 'eh-oh' => 'eh-oh-laa-laa',
- 'eh' => 'eh-oh-laa-laa',
-
-
- 'fr,en;q=0.5' => 'fr-CA',
- 'fr,en;q=0.5,fr-CA;q=0.25' => 'fr',
-
-
- '*,fr-CA;q=0.5' => 'en',
- '*,en;q=0.25' => 'fr-CA',
- 'en,en-US;q=0.5,fr;q=0.25' => 'en',
- 'en-US,en;q=0.5,fr;q=0.25' => 'en-US',
-
-
- '' => FALSE,
- 'de,pl' => FALSE,
- 'iecRswK4eh' => FALSE,
- $this->randomName(10) => FALSE,
- );
-
- foreach ($test_cases as $accept_language => $expected_result) {
- $_SERVER['HTTP_ACCEPT_LANGUAGE'] = $accept_language;
- $result = locale_language_from_browser($languages);
- $this->assertIdentical($result, $expected_result, format_string("Language selection '@accept-language' selects '@result', result = '@actual'", array('@accept-language' => $accept_language, '@result' => $expected_result, '@actual' => isset($result) ? $result : 'none')));
- }
- }
- }
-
- * Functional tests for a user's ability to change their default language.
- */
- class LocaleUserLanguageFunctionalTest extends BackdropWebTestCase {
- function setUp() {
- parent::setUp('locale');
- }
-
-
- * Test if user can change their default language.
- */
- function testUserLanguageConfiguration() {
- global $base_url;
-
-
- $admin_user = $this->backdropCreateUser(array('administer languages', 'access administration pages'));
-
- $web_user = $this->backdropCreateUser();
-
-
- $this->backdropLogin($admin_user);
-
- $langcode = 'xx';
-
- $name = $this->randomName(16);
- $edit = array(
- 'predefined_langcode' => 'custom',
- 'langcode' => $langcode,
- 'name' => $name,
- 'native' => $name,
- 'direction' => '0',
- );
- $this->backdropPost('admin/config/regional/language/add', $edit, t('Add custom language'));
-
-
-
- $langcode_disabled = 'xx-yy';
-
- $name_disabled = $this->randomName(16);
- $edit = array(
- 'predefined_langcode' => 'custom',
- 'langcode' => $langcode_disabled,
- 'name' => $name_disabled,
- 'native' => $name_disabled,
- 'direction' => '0',
- );
- $this->backdropPost('admin/config/regional/language/add', $edit, t('Add custom language'));
-
- $edit = array(
- 'languages[' . $langcode_disabled . '][enabled]' => FALSE,
- );
- $this->backdropPost('admin/config/regional/language', $edit, t('Save configuration'));
- $this->backdropLogout();
-
-
- $this->backdropLogin($web_user);
- $path = 'user/' . $web_user->uid . '/edit';
- $this->backdropGet($path);
-
- $this->assertText(t('Language'), 'Language selector available.');
-
- $this->assertText($name, 'Language present on form.');
-
- $this->assertNoText($name_disabled, 'Disabled language not present on form.');
-
- $edit = array(
- 'language' => $langcode,
- );
- $this->backdropPost($path, $edit, t('Save'));
-
- $this->assertText(t('The changes have been saved.'), 'Changes were saved.');
-
-
- $this->backdropGet($path);
- $elements = $this->xpath('//input[@id=:id]', array(':id' => 'edit-language-' . $langcode));
- $this->assertTrue(isset($elements[0]) && !empty($elements[0]['checked']), 'Default language successfully updated.');
-
- $this->backdropLogout();
- }
- }
-
- * Functional test for language handling during user creation.
- */
- class LocaleUserCreationTest extends BackdropWebTestCase {
- function setUp() {
- parent::setUp('locale');
- config_set('system.core', 'user_register', USER_REGISTER_VISITORS);
- }
-
-
- * Functional test for language handling during user creation.
- */
- function testLocalUserCreation() {
-
- $admin_user = $this->backdropCreateUser(array('administer languages', 'access administration pages', 'administer users'));
- $this->backdropLogin($admin_user);
-
-
- $langcode = 'fr';
- $edit = array(
- 'predefined_langcode' => 'fr',
- );
- $this->backdropPost('admin/config/regional/language/add', $edit, t('Add language'));
- $this->assertText('French', 'Language added successfully.');
- $this->assertEqual($this->getUrl(), url('admin/config/regional/language', array('absolute' => TRUE)), 'Correct page redirection.');
-
-
- $edit = array(
- 'language[locale-url][enabled]' => TRUE,
- );
- $this->backdropPost('admin/config/regional/language/detection', $edit, t('Save settings'));
- $this->assertText(t('Language negotiation configuration saved.'), 'Set language negotiation.');
-
-
-
- $this->backdropGet($langcode . '/admin/people/create');
- $this->assertFieldChecked("edit-language-$langcode", 'Global language set in the language selector.');
-
-
-
- $username = $this->randomName(10);
- $password = $this->randomName(10);
- $edit = array(
- 'name' => $username,
- 'mail' => $this->randomName(4) . '@example.com',
- 'pass' => $password,
- );
-
- $this->backdropPost($langcode . '/admin/people/create', $edit, t('Create new account'));
-
- $user = user_load_by_name($username);
- $this->assertEqual($user->language, $langcode, 'New user has correct language set.');
-
-
- $this->backdropLogout();
-
- $this->backdropGet($langcode . '/user/register');
- $this->assertNoFieldByName('language[fr]', 'Language selector is not accessible.');
-
- $username = $this->randomName(10);
- $edit = array(
- 'name' => $username,
- 'mail' => $this->randomName(4) . '@example.com',
- );
-
- $this->backdropPost($langcode . '/user/register', $edit, t('Create new account'));
-
- $user = user_load_by_name($username);
- $this->assertEqual($user->language, $langcode, 'New user has correct language set.');
-
-
-
- $user_edit = $langcode . '/user/' . $user->uid . '/edit';
-
- $this->backdropLogin($admin_user);
- $this->backdropGet($user_edit);
- $this->assertFieldChecked("edit-language-$langcode", 'Language selector is accessible and correct language is selected.');
-
-
- $user->pass_raw = $this->randomName(10);
- $edit = array(
- 'pass' => $user->pass_raw,
- );
-
- $this->backdropPost($user_edit, $edit, t('Save'));
-
- $this->backdropLogin($user);
- $this->backdropGet($user_edit);
- $this->assertFieldChecked("edit-language-$langcode", 'Language selector is accessible and correct language is selected.');
- }
- }
-
- * Functional tests for configuring a different URL alias per language.
- */
- class LocalePathFunctionalTest extends BackdropWebTestCase {
- function setUp() {
- parent::setUp('locale', 'path');
- }
-
-
- * Test if a language can be associated with a URL alias.
- */
- function testPathLanguageConfiguration() {
- global $base_url;
-
-
- $admin_user = $this->backdropCreateUser(array('administer languages', 'create page content', 'administer url aliases', 'create url aliases', 'access administration pages'));
-
-
- $this->backdropLogin($admin_user);
-
- $langcode = 'xx';
-
- $name = $this->randomName(16);
-
- $prefix = $langcode;
- $edit = array(
- 'predefined_langcode' => 'custom',
- 'langcode' => $langcode,
- 'name' => $name,
- 'native' => $name,
- 'direction' => '0',
- );
- $this->backdropPost('admin/config/regional/language/add', $edit, t('Add custom language'));
-
-
- $edit = array( "prefix[$langcode]" => $prefix );
- $this->backdropPost('admin/config/regional/language/detection/url', $edit, t('Save configuration'));
-
-
-
- $this->backdropGet($prefix);
- $this->assertText(t('Welcome to Backdrop'), 'The "xx" home page is readily available.');
-
-
- $node = $this->backdropCreateNode(array('type' => 'page'));
-
-
- $path = 'admin/config/urls/path/add';
- $english_path = $this->randomName(8);
- $edit = array(
- 'source' => 'node/' . $node->nid,
- 'alias' => $english_path,
- 'langcode' => 'en',
- );
- $this->backdropPost($path, $edit, t('Save URL alias'));
-
-
- $custom_language_path = $this->randomName(8);
- $edit = array(
- 'source' => 'node/' . $node->nid,
- 'alias' => $custom_language_path,
- 'langcode' => $langcode,
- );
- $this->backdropPost($path, $edit, t('Save URL alias'));
-
-
- $this->backdropGet($english_path);
- $this->assertText($node->title, 'English alias works.');
-
-
- $this->backdropGet($prefix . '/' . $custom_language_path);
- $this->assertText($node->title, 'Custom language alias works.');
-
-
- $custom_path = $this->randomName(8);
-
-
- $edit = array(
- 'source' => 'node/' . $node->nid,
- 'alias' => $custom_path,
- 'langcode' => LANGUAGE_NONE,
- );
- path_save($edit);
- $lookup_path = backdrop_lookup_path('alias', 'node/' . $node->nid, 'en');
- $this->assertEqual($english_path, $lookup_path, 'English language alias has priority.');
-
- $lookup_path = backdrop_lookup_path('alias', 'node/' . $node->nid, $prefix);
- $this->assertEqual($custom_language_path, $lookup_path, 'Custom language alias has priority.');
- path_delete($edit);
-
-
- $first_node = $this->backdropCreateNode(array('type' => 'post', 'promote' => 1));
- $second_node = $this->backdropCreateNode(array('type' => 'post', 'promote' => 1));
-
-
- $edit = array(
- 'source' => 'node/' . $first_node->nid,
- 'alias' => $custom_path,
- 'langcode' => 'en',
- );
- path_save($edit);
-
-
- $edit = array(
- 'source' => 'node/' . $second_node->nid,
- 'alias' => $custom_path,
- 'langcode' => LANGUAGE_NONE,
- );
- path_save($edit);
-
-
- $this->backdropGet('<front>');
- $custom_path_url = base_path() . (config_get('system.core', 'clean_url') ? $custom_path : '?q=' . $custom_path);
- $elements = $this->xpath('//a[@href=:href and .=:title]', array(':href' => $custom_path_url, ':title' => $first_node->title));
- $this->assertTrue(!empty($elements), 'First node links to the URL alias.');
- $elements = $this->xpath('//a[@href=:href and .=:title]', array(':href' => $custom_path_url, ':title' => $second_node->title));
- $this->assertTrue(!empty($elements), 'Second node links to the URL alias.');
-
-
- $this->backdropGet($custom_path);
- $this->assertText($first_node->title, 'Custom alias returns first node.');
-
-
- $this->backdropGet($prefix . '/' . $custom_path);
- $this->assertText($second_node->title, 'Custom alias with prefix returns second node.');
-
- }
- }
-
- * Functional tests for multilingual support on nodes.
- */
- class LocaleContentFunctionalTest extends BackdropWebTestCase {
- function setUp() {
- parent::setUp('locale');
- }
-
-
- * Verifies that machine name fields are always LTR.
- */
- function testMachineNameLTR() {
-
- $admin_user = $this->backdropCreateUser(array('administer languages', 'administer content types', 'access administration pages'));
-
-
- $this->backdropLogin($admin_user);
-
-
- $this->backdropGet('admin/structure/types/add');
- $this->assertFieldByXpath('//input[@name="type" and @dir="ltr"]', NULL, 'The machine name field is LTR when no additional language is configured.');
-
-
- $edit = array();
- $edit['predefined_langcode'] = 'ar';
- $this->backdropPost('admin/config/regional/language/add', $edit, t('Add language'));
-
- $edit = array();
- $edit['site_default'] = 'ar';
- $this->backdropPost(NULL, $edit, t('Save configuration'));
-
-
- $this->backdropGet('admin/structure/types/add');
- $this->assertFieldByXpath('//input[@name="type" and @dir="ltr"]', NULL, 'The machine name field is LTR when the default language is RTL.');
- }
-
-
- * Test if a content type can be set to multilingual and language is present.
- */
- function testContentTypeLanguageConfiguration() {
- global $base_url;
-
-
- $admin_user = $this->backdropCreateUser(array('administer languages', 'administer content types', 'access administration pages'));
-
- $web_user = $this->backdropCreateUser(array('create post content', 'create page content', 'edit any page content'));
-
-
- $this->backdropLogin($admin_user);
-
- $langcode = 'xx';
-
- $name = $this->randomName(16);
- $edit = array(
- 'predefined_langcode' => 'custom',
- 'langcode' => $langcode,
- 'name' => $name,
- 'native' => $name,
- 'direction' => '0',
- );
- $this->backdropPost('admin/config/regional/language/add', $edit, t('Add custom language'));
-
-
-
- $langcode_disabled = 'xx-yy';
-
- $name_disabled = $this->randomName(16);
- $edit = array(
- 'predefined_langcode' => 'custom',
- 'langcode' => $langcode_disabled,
- 'name' => $name_disabled,
- 'native' => $name_disabled,
- 'direction' => '0',
- );
- $this->backdropPost('admin/config/regional/language/add', $edit, t('Add custom language'));
-
- $path = 'admin/config/regional/language';
- $edit = array(
- 'languages[' . $langcode_disabled . '][enabled]' => FALSE,
- );
- $this->backdropPost($path, $edit, t('Save configuration'));
-
-
- $this->backdropGet('admin/structure/types/manage/page');
- $this->assertText(t('Multilingual support'), 'Multilingual support fieldset present on content type configuration form.');
- $edit = array(
- 'language' => 1,
- );
- $this->backdropPost('admin/structure/types/manage/page', $edit, t('Save content type'));
- $this->assertRaw(t('The content type %type has been updated.', array('%type' => 'Page')), 'Page content type has been updated.');
- $this->backdropLogout();
-
-
- $this->backdropLogin($web_user);
- $this->backdropGet('node/add/post');
-
- $this->assertNoFieldByName('language', NULL, 'Language select not present on add post form.');
-
-
- $this->backdropGet('node/add/page');
-
- $this->assertFieldByName('langcode', NULL, 'Language select present on add Page form.');
-
- $this->assertText($name, 'Enabled language present.');
-
- $this->assertNoText($name_disabled, 'Disabled language not present.');
-
-
- $node_title = $this->randomName();
- $node_body = $this->randomName();
- $edit = array(
- 'type' => 'page',
- 'title' => $node_title,
- 'body' => array($langcode => array(array('value' => $node_body))),
- 'langcode' => $langcode,
- );
- $node = $this->backdropCreateNode($edit);
-
- $path = 'node/' . $node->nid . '/edit';
- $this->backdropGet($path);
- $label = $name . ' (' . $name . ')';
- $this->assertRaw('<option value="' . $langcode . '" selected="selected">' . $label . '</option>', 'Correct language selected.');
-
- $edit = array(
- 'langcode' => 'en',
- );
- $this->backdropPost($path, $edit, t('Save'));
- $this->assertRaw(t('%title has been updated.', array('%title' => $node_title)), 'Page content updated.');
-
- $this->backdropLogout();
- }
-
-
- * Test if a dir and lang tags exist in node's attributes.
- */
- function testContentTypeDirLang() {
-
- $admin_user = $this->backdropCreateUser(array('administer languages', 'administer content types', 'access administration pages'));
-
- $web_user = $this->backdropCreateUser(array('create post content', 'edit own post content'));
-
-
- $this->backdropLogin($admin_user);
-
-
- $edit = array();
- $edit['predefined_langcode'] = 'ar';
- $this->backdropPost('admin/config/regional/language/add', $edit, t('Add language'));
-
-
- $edit = array();
- $edit['predefined_langcode'] = 'es';
- $this->backdropPost('admin/config/regional/language/add', $edit, t('Add language'));
-
-
- $this->backdropGet('admin/structure/types/manage/post');
- $edit = array(
- 'language' => 1,
- );
- $this->backdropPost('admin/structure/types/manage/post', $edit, t('Save content type'));
- $this->assertRaw(t('The content type %type has been updated.', array('%type' => 'Post')), 'Post content type has been updated.');
- $this->backdropLogout();
-
-
- $this->backdropLogin($web_user);
-
-
- $node_en = $this->createNodePost('en');
- $node_ar = $this->createNodePost('ar');
- $node_es = $this->createNodePost('es');
-
- $this->backdropGet('node');
-
-
- $pattern = '|id="node-' . $node_en->nid . '"[^<>]*lang="en"|';
- $this->assertNoPattern($pattern, 'The lang tag has not been assigned to the English node.');
-
-
- $pattern = '|id="node-' . $node_en->nid . '"[^<>]*dir="ltr"|';
- $this->assertNoPattern($pattern, 'The dir tag has not been assigned to the English node.');
-
-
- $pattern = '|id="node-' . $node_ar->nid . '"[^<>]*lang="ar" dir="rtl"|';
- $this->assertPattern($pattern, 'The lang and dir tags have been assigned correctly to the Arabic node.');
-
-
- $pattern = '|id="node-' . $node_es->nid . '"[^<>]*lang="es"|';
- $this->assertPattern($pattern, 'The lang tag has been assigned correctly to the Spanish node.');
-
-
- $pattern = '|id="node-' . $node_es->nid . '"[^<>]*lang="es" dir="ltr"|';
- $this->assertNoPattern($pattern, 'The dir tag has not been assigned to the Spanish node.');
-
- $this->backdropLogout();
- }
-
-
- * Create node in a specific language.
- */
- protected function createNodePost($langcode) {
- $this->backdropGet('node/add/post');
- $node_title = $this->randomName();
- $node_body = $this->randomName();
- $edit = array(
- 'type' => 'post',
- 'title' => $node_title,
- 'body' => array($langcode => array(array('value' => $node_body))),
- 'langcode' => $langcode,
- 'promote' => 1,
- );
- return $this->backdropCreateNode($edit);
- }
- }
-
- * Test UI language negotiation
- *
- * 1. URL (PATH) > DEFAULT
- * UI Language base on URL prefix, browser language preference has no
- * influence:
- * admin/config
- * UI in site default language
- * zh-hans/admin/config
- * UI in Chinese
- * blah-blah/admin/config
- * 404
- * 2. URL (PATH) > BROWSER > DEFAULT
- * admin/config
- * UI in user's browser language preference if the site has that
- * language enabled, if not, the default language
- * zh-hans/admin/config
- * UI in Chinese
- * blah-blah/admin/config
- * 404
- * 3. URL (DOMAIN) > DEFAULT
- * http://example.com/admin/config
- * UI language in site default
- * http://example.cn/admin/config
- * UI language in Chinese
- */
- class LocaleUILanguageNegotiationTest extends BackdropWebTestCase {
- function setUp() {
- parent::setUp('locale', 'locale_test');
- require_once BACKDROP_ROOT . '/core/includes/language.inc';
- backdrop_load('module', 'locale');
- $admin_user = $this->backdropCreateUser(array('administer languages', 'translate interface', 'access administration pages', 'administer blocks'));
- $this->backdropLogin($admin_user);
- }
-
-
- * Tests for language switching by URL path.
- */
- function testUILanguageNegotiation() {
-
-
- $langcode_unknown = 'blah-blah';
-
- $langcode_browser_fallback = 'vi';
-
- $langcode = 'zh-hans';
-
- $http_header_browser_fallback = array("Accept-Language: $langcode_browser_fallback;q=1");
-
- $http_header_blah = array("Accept-Language: blah;q=1");
-
-
- $language_domain = 'example.cn';
-
-
- require_once BACKDROP_ROOT . '/core/includes/locale.inc';
- $language = (object) array(
- 'langcode' => $langcode_browser_fallback,
- );
- language_save($language);
- $language = (object) array(
- 'langcode' => $langcode,
- );
- language_save($language);
-
-
-
- $default_string = 'Configure languages for content and the user interface';
-
-
-
-
-
- backdrop_static_reset('language_list');
- $core_config = config('system.core');
- $languages = language_list(TRUE);
- $default_langcode = $core_config->get('language_default');
- $core_config->set('language_default', $languages['vi']->langcode);
- $core_config->save();
-
- $this->backdropGet('admin/config');
-
- $core_config->set('language_default', $default_langcode);
- $core_config->save();
-
-
- $language_browser_fallback_string = "In $langcode_browser_fallback In $langcode_browser_fallback In $langcode_browser_fallback";
- $language_string = "In $langcode In $langcode In $langcode";
-
- $edit = array('string' => $default_string);
- $this->backdropPost('admin/config/regional/translate/translate', $edit, t('Filter'));
-
- $this->clickLink('Edit');
- $edit = array(
- "translations[$langcode_browser_fallback]" => $language_browser_fallback_string,
- "translations[$langcode]" => $language_string,
- );
- $this->backdropPost(NULL, $edit, t('Save translations'));
-
-
- config_get('locale.settings', 'language_negotiation_url_type', LANGUAGE_TYPE_INTERFACE);
-
- $tests = array(
-
- array(
- 'language_negotiation' => array(LANGUAGE_NEGOTIATION_URL, LANGUAGE_NEGOTIATION_DEFAULT),
- 'path' => 'admin/config',
- 'expect' => $default_string,
- 'expected_provider' => LANGUAGE_NEGOTIATION_DEFAULT,
- 'http_header' => $http_header_browser_fallback,
- 'message' => 'URL (PATH) > DEFAULT: no language prefix, UI language is default and the browser language preference setting is not used.',
- ),
-
- array(
- 'language_negotiation' => array(LANGUAGE_NEGOTIATION_URL, LANGUAGE_NEGOTIATION_DEFAULT),
- 'path' => "$langcode/admin/config",
- 'expect' => $language_string,
- 'expected_provider' => LANGUAGE_NEGOTIATION_URL,
- 'http_header' => $http_header_browser_fallback,
- 'message' => 'URL (PATH) > DEFAULT: with language prefix, UI language is switched based on path prefix',
- ),
-
- array(
- 'language_negotiation' => array(LANGUAGE_NEGOTIATION_URL, LANGUAGE_NEGOTIATION_BROWSER),
- 'path' => 'admin/config',
- 'expect' => $language_browser_fallback_string,
- 'expected_provider' => LANGUAGE_NEGOTIATION_BROWSER,
- 'http_header' => $http_header_browser_fallback,
- 'message' => 'URL (PATH) > BROWSER: no language prefix, UI language is determined by browser language preference',
- ),
-
- array(
- 'language_negotiation' => array(LANGUAGE_NEGOTIATION_URL, LANGUAGE_NEGOTIATION_BROWSER),
- 'path' => "$langcode/admin/config",
- 'expect' => $language_string,
- 'expected_provider' => LANGUAGE_NEGOTIATION_URL,
- 'http_header' => $http_header_browser_fallback,
- 'message' => 'URL (PATH) > BROWSER: with language prefix, UI language is based on path prefix',
- ),
-
- array(
- 'language_negotiation' => array(LANGUAGE_NEGOTIATION_URL, LANGUAGE_NEGOTIATION_BROWSER, LANGUAGE_NEGOTIATION_DEFAULT),
- 'path' => 'admin/config',
- 'expect' => $default_string,
- 'expected_provider' => LANGUAGE_NEGOTIATION_DEFAULT,
- 'http_header' => $http_header_blah,
- 'message' => 'URL (PATH) > BROWSER > DEFAULT: no language prefix and browser language preference set to unknown language should use default language',
- ),
- );
-
- foreach ($tests as $test) {
- $this->runTest($test);
- }
-
-
- config_set('language.settings', 'language_negotiation.' . LANGUAGE_TYPE_INTERFACE, array_keys(locale_language_negotiation_info()));
- $this->backdropGet("$langcode_unknown/admin/config", array(), $http_header_browser_fallback);
- $this->assertResponse(404, "Unknown language path prefix should return 404");
-
-
-
- $edit = array("domain[$langcode]" => "https://$language_domain:99");
- $this->backdropPost("admin/config/regional/language/detection/url", $edit, t('Save configuration'));
-
-
- $tests = array(
-
- array(
- 'language_negotiation' => array(LANGUAGE_NEGOTIATION_URL, LANGUAGE_NEGOTIATION_DEFAULT),
- 'language_negotiation_url_part' => LANGUAGE_NEGOTIATION_URL_DOMAIN,
- 'path' => 'admin/config',
- 'expect' => $default_string,
- 'expected_provider' => LANGUAGE_NEGOTIATION_DEFAULT,
- 'http_header' => $http_header_browser_fallback,
- 'message' => 'URL (DOMAIN) > DEFAULT: default domain should get default language',
- ),
-
-
- array(
- 'language_negotiation' => array(LANGUAGE_NEGOTIATION_URL, LANGUAGE_NEGOTIATION_DEFAULT),
- 'language_negotiation_url_part' => LANGUAGE_NEGOTIATION_URL_DOMAIN,
- 'locale_test_domain' => $language_domain . ':88',
- 'path' => 'admin/config',
- 'expect' => $language_string,
- 'expected_provider' => LANGUAGE_NEGOTIATION_URL,
- 'http_header' => $http_header_browser_fallback,
- 'message' => 'URL (DOMAIN) > DEFAULT: domain example.cn should switch to Chinese',
- ),
- );
-
- foreach ($tests as $test) {
- $this->runTest($test);
- }
- }
-
- protected function runTest($test) {
- if (!empty($test['language_negotiation'])) {
- language_negotiation_set(LANGUAGE_TYPE_INTERFACE, $test['language_negotiation']);
- }
- if (!empty($test['language_negotiation_url_part'])) {
- config_set('locale.settings', 'language_negotiation_url_part', $test['language_negotiation_url_part']);
- }
- if (!empty($test['locale_test_domain'])) {
- state_set('locale_test_domain', $test['locale_test_domain']);
- }
- $this->backdropGet($test['path'], array(), $test['http_header']);
- $this->assertText($test['expect'], $test['message']);
- $this->assertText(t('Language negotiation provider: @name', array('@name' => $test['expected_provider'])));
- }
-
-
- * Test URL language detection when the requested URL has no language.
- */
- function testUrlLanguageFallback() {
-
- $langcode_browser_fallback = 'it';
- $language = (object) array(
- 'langcode' => $langcode_browser_fallback,
- );
- language_save($language);
- $languages = language_list();
-
-
-
- $edit = array('prefix[en]' => 'en');
- $this->backdropPost('admin/config/regional/language/detection/url', $edit, t('Save configuration'));
-
-
- $edit = array(
- 'language[locale-browser][enabled]' => TRUE,
- 'language[locale-browser][weight]' => -8,
- 'language[locale-url][enabled]' => TRUE,
- 'language[locale-url][weight]' => -10,
- );
- $this->backdropPost('admin/config/regional/language/detection', $edit, t('Save settings'));
- $this->backdropGet('admin/config/regional/language/detection');
-
-
- $layout = layout_load('home');
- $layout->addBlock('locale', 'language', 'top');
- $layout->save();
-
-
- theme_enable(array('stark'));
- config_set('system.core', 'theme_default', 'stark');
-
-
-
- $http_header = array("Accept-Language: $langcode_browser_fallback;q=1");
- $language = (object) array('langcode' => '');
- $this->backdropGet('', array('language' => $language), $http_header);
-
-
-
- $args = array(':url' => base_path() . (config_get('system.core', 'clean_url') ? $langcode_browser_fallback : "?q=$langcode_browser_fallback"));
- $fields = $this->xpath('//*[contains(@class,"block-locale-language")]//a[@class="language-link active" and @href=:url]', $args);
- $this->assertTrue($fields[0] == $languages[$langcode_browser_fallback]->native, 'The browser language is the URL active language');
-
-
- $fields = $this->xpath('//*[contains(@class,"site-name")]//a[@rel="home" and @href=:url]//span', $args);
- $this->assertTrue($fields[0] == 'Backdrop CMS', 'URLs are rewritten using the browser language.');
- }
-
-
- * Tests url() when separate domains are used for multiple languages.
- */
- function testLanguageDomain() {
-
- $langcode = 'it';
- $language = (object) array(
- 'langcode' => $langcode,
- );
- language_save($language);
- $languages = language_list();
-
-
- $edit = array(
- 'language[locale-url][enabled]' => TRUE,
- 'language[locale-url][weight]' => -10,
- );
- $this->backdropPost('admin/config/regional/language/detection', $edit, t('Save settings'));
-
-
- $edit = array(
- 'language_negotiation_url_part' => LANGUAGE_NEGOTIATION_URL_DOMAIN,
- 'domain[it]' => 'it.example.com',
- );
- $this->backdropPost('admin/config/regional/language/detection/url', $edit, t('Save configuration'));
-
-
- $link = (config_get('system.core', 'clean_url')) ? 'it.example.com/admin' : 'it.example.com/?q=admin';
-
- global $is_https;
-
-
-
- $italian_url = url('admin', array('language' => $languages['it']));
- $url_scheme = ($is_https) ? 'https://' : 'http://';
- $correct_link = $url_scheme . $link;
- $this->assertTrue($italian_url == $correct_link, format_string('The url() function returns the right url (@url) in accordance with the chosen language', array('@url' => $italian_url . " == " . $correct_link)));
-
-
- $GLOBALS['settings']['https'] = TRUE;
- $italian_url = url('admin', array('https' => TRUE, 'language' => $languages['it']));
- $correct_link = 'https://' . $link;
- $this->assertTrue($italian_url == $correct_link, format_string('The url() function returns the right https url (via options) (@url) in accordance with the chosen language', array('@url' => $italian_url . " == " . $correct_link)));
- unset($GLOBALS['settings']['https']);
-
-
- $temp_https = $is_https;
- $is_https = TRUE;
- $italian_url = url('admin', array('language' => $languages['it']));
- $correct_link = 'https://' . $link;
- $this->assertTrue($italian_url == $correct_link, format_string('The url() function returns the right url (via current url scheme) (@url) in accordance with the chosen language', array('@url' => $italian_url . " == " . $correct_link)));
- $is_https = $temp_https;
- }
- }
-
- * Test that URL rewriting works as expected.
- */
- class LocaleUrlRewritingTest extends BackdropWebTestCase {
-
-
- * @var User
- */
- protected $web_user;
-
- function setUp() {
- parent::setUp('locale');
-
-
- $this->web_user = $this->backdropCreateUser(array('administer languages', 'access administration pages'));
- $this->backdropLogin($this->web_user);
-
-
- $edit = array();
- $edit['predefined_langcode'] = 'fr';
- $this->backdropPost('admin/config/regional/language/add', $edit, t('Add language'));
-
-
- $edit = array();
- $edit['predefined_langcode'] = 'it';
- $this->backdropPost('admin/config/regional/language/add', $edit, t('Add language'));
-
-
- $edit = array('languages[it][enabled]' => FALSE);
- $this->backdropPost('admin/config/regional/language', $edit, t('Save configuration'));
-
-
- $edit = array('language[locale-url][enabled]' => 1);
- $this->backdropPost('admin/config/regional/language/detection', $edit, t('Save settings'));
-
-
- backdrop_static_reset('language_list');
- backdrop_static_reset('locale_url_outbound_alter');
- backdrop_static_reset('locale_language_url_rewrite_url');
- }
-
-
- * Check that disabled or non-installed languages are not considered.
- */
- function testUrlRewritingEdgeCases() {
-
- $languages = language_list();
- $this->checkUrl($languages['it'], 'Path language is ignored if language is disabled.', 'URL language negotiation does not work with disabled languages');
-
-
- $non_existing = language_default();
- $non_existing->langcode = $this->randomName();
- $this->checkUrl($non_existing, 'Path language is ignored if language is not installed.', 'URL language negotiation does not work with non-installed languages');
- }
-
-
- * Check URL rewriting for the given language.
- *
- * The test is performed with a fixed URL (the default home page) to check
- * that language prefixes are not added to it, and that the prefixed URL is
- * actually not working.
- *
- * @param string $language
- * The language prefix, e.g. 'es'.
- * @param string $message1
- * Message to display in assertion that language prefixes are not added.
- * @param string $message2
- * The message to display confirming prefixed URL is not working.
- */
- private function checkUrl($language, $message1, $message2) {
- $options = array('language' => $language);
- $base_path = trim(base_path(), '/');
- $rewritten_path = trim(str_replace(array('?q=', $base_path), '', url('node', $options)), '/');
- $segments = explode('/', $rewritten_path, 2);
- $prefix = $segments[0];
- $path = isset($segments[1]) ? $segments[1] : $prefix;
-
-
-
- $prefixes = locale_language_negotiation_url_prefixes();
- $stored_prefix = isset($prefixes[$language->langcode]) ? $prefixes[$language->langcode] : $this->randomName();
- if ($this->assertNotEqual($stored_prefix, $prefix, $message1)) {
- $prefix = $stored_prefix;
- }
-
- $this->backdropGet("$prefix/$path");
- $this->assertResponse(404, $message2);
- }
-
-
- * Check URL rewriting when using a domain name and a non-standard port.
- */
- function testDomainNameNegotiationPort() {
- $edit = array(
-
- 'language_negotiation_url_part' => LANGUAGE_NEGOTIATION_URL_DOMAIN,
- 'prefix[fr]' => '',
- 'domain[fr]' => 'example.fr',
- );
- $this->backdropPost('admin/config/regional/language/detection/url', $edit, t('Save configuration'));
-
-
- backdrop_static_reset('language_list');
- backdrop_static_reset('language_url_outbound_alter');
- backdrop_static_reset('language_url_rewrite_url');
-
-
-
- $index_php = strpos(url('', array('absolute' => TRUE)), 'index.php') !== FALSE;
-
-
- $http_host = $_SERVER['HTTP_HOST'];
-
-
- $_SERVER['HTTP_HOST'] .= ':88';
-
-
- $languages = language_list();
- $language = $languages['fr'];
- $url = url('', array(
- 'absolute' => TRUE,
- 'language' => $language
- ));
-
- $expected = 'http://example.fr:88/';
- $expected .= $index_php ? 'index.php/' : '';
-
- $this->assertEqual($url, $expected, 'The right port is used.');
-
-
- $url = url('', array(
- 'absolute' => TRUE,
- 'language' => $language,
- 'base_url' => $GLOBALS['base_url'] . ':90',
- ));
-
- $expected = 'http://example.fr:90/';
- $expected .= $index_php ? 'index.php/' : '';
-
- $this->assertEqual($url, $expected, 'A given port is not overridden.');
-
-
- $_SERVER['HTTP_HOST'] = $http_host;
- }
- }
-
- * Functional test for multilingual fields.
- */
- class LocaleMultilingualFieldsFunctionalTest extends BackdropWebTestCase {
- function setUp() {
- parent::setUp('locale');
-
- $admin_user = $this->backdropCreateUser(array('administer languages', 'administer content types', 'access administration pages', 'create page content', 'edit own page content'));
- $this->backdropLogin($admin_user);
-
-
- require_once BACKDROP_ROOT . '/core/includes/locale.inc';
- $language = (object) array(
- 'langcode' => 'it',
- 'name' => 'Italian',
- );
- language_save($language);
-
-
- $edit = array('language[locale-url][enabled]' => '1');
- $this->backdropPost('admin/config/regional/language/detection', $edit, t('Save settings'));
-
-
- $edit = array(
- 'language' => 1,
- );
- $this->backdropPost('admin/structure/types/manage/page', $edit, t('Save content type'));
- $this->assertRaw(t('The content type %type has been updated.', array('%type' => 'Page')), 'Page content type has been updated.');
-
-
- $field = field_info_field('body');
- $field['translatable'] = TRUE;
- field_update_field($field);
- }
-
-
- * Test if field languages are correctly set through the node form.
- */
- function testMultilingualNodeForm() {
-
- $langcode = LANGUAGE_NONE;
- $title_key = "title";
- $title_value = $this->randomName(8);
- $body_key = "body[$langcode][0][value]";
- $body_value = $this->randomName(16);
-
-
- $edit = array();
- $edit[$title_key] = $title_value;
- $edit[$body_key] = $body_value;
- $edit['langcode'] = 'en';
- $this->backdropPost('node/add/page', $edit, t('Save'));
-
-
- $node = $this->backdropGetNodeByTitle($edit[$title_key]);
- $this->assertTrue($node, 'Node found in database.');
-
- $assert = isset($node->body['en']) && !isset($node->body[LANGUAGE_NONE]) && $node->body['en'][0]['value'] == $body_value;
- $this->assertTrue($assert, 'Field language correctly set.');
-
-
- $this->backdropGet("node/$node->nid/edit");
- $edit = array(
- $title_key => $this->randomName(8),
- 'langcode' => 'it',
- );
- $this->backdropPost(NULL, $edit, t('Save'));
- $node = $this->backdropGetNodeByTitle($edit[$title_key], TRUE);
- $this->assertTrue($node, 'Node found in database.');
-
- $assert = isset($node->body['it']) && !isset($node->body['en']) && $node->body['it'][0]['value'] == $body_value;
- $this->assertTrue($assert, 'Field language correctly changed.');
-
-
- language_negotiation_set(LANGUAGE_TYPE_CONTENT, array(LANGUAGE_NEGOTIATION_URL => 0));
-
-
- $this->backdropGet("it/node/$node->nid");
- $this->assertRaw($body_value, 'Body correctly displayed using Italian as requested language');
-
- $this->backdropGet("node/$node->nid");
- $this->assertRaw($body_value, 'Body correctly displayed using English as requested language');
- }
-
-
- * Test multilingual field display settings.
- */
- function testMultilingualDisplaySettings() {
-
- $langcode = LANGUAGE_NONE;
- $title_key = "title";
- $title_value = $this->randomName(8);
- $body_key = "body[$langcode][0][value]";
- $body_value = $this->randomName(16);
-
-
- $edit = array();
- $edit[$title_key] = $title_value;
- $edit[$body_key] = $body_value;
- $edit['langcode'] = 'en';
- $this->backdropPost('node/add/page', $edit, t('Save'));
-
-
- $node = $this->backdropGetNodeByTitle($edit[$title_key]);
- $this->assertTrue($node, 'Node found in database.');
-
-
- $this->backdropGet("node/$node->nid");
- $body = $this->xpath('//article[@id=:id]//p', array(':id' => 'node-' . $node->nid));
- $this->assertEqual(current($body), $node->body['en'][0]['value'], 'Node body is correctly shown.');
- }
- }
-
- * Functional tests for comment language.
- */
- class LocaleCommentLanguageFunctionalTest extends BackdropWebTestCase {
- function setUp() {
- parent::setUp('locale', 'locale_test');
-
-
- $admin_user = $this->backdropCreateUser(array('administer site configuration', 'administer languages', 'access administration pages', 'administer content types', 'create post content'));
- $this->backdropLogin($admin_user);
-
-
- $edit = array('predefined_langcode' => 'fr');
- $this->backdropPost('admin/config/regional/language/add', $edit, t('Add language'));
-
-
- $edit = array('language' => 1);
- $this->backdropPost('admin/structure/types/manage/post', $edit, t('Save content type'));
-
-
- state_set('locale_test_content_language_type', TRUE);
-
-
-
-
-
- $edit = array(
- 'language[locale-user][enabled]' => TRUE,
- 'language_content[locale-url][enabled]' => TRUE,
- 'language_content[locale-interface][enabled]' => FALSE,
- );
- $this->backdropPost('admin/config/regional/language/detection', $edit, t('Save settings'));
-
-
-
- $edit = array('language' => 'fr');
- $this->backdropPost("user/{$admin_user->uid}/edit", $edit, t('Save'));
- }
-
-
- * Test that comment language is properly set.
- */
- function testCommentLanguage() {
- backdrop_static_reset('language_list');
-
-
-
-
-
-
-
- foreach (language_list() as $node_langcode => $node_language) {
- $langcode_none = LANGUAGE_NONE;
-
-
- $title = $this->randomName();
- $edit = array(
- "title" => $title,
- "body[$langcode_none][0][value]" => $this->randomName(),
- "langcode" => $node_langcode,
- );
- $this->backdropPost("node/add/post", $edit, t('Save'));
- $node = $this->backdropGetNodeByTitle($title);
-
- $prefixes = locale_language_negotiation_url_prefixes();
- foreach (language_list() as $langcode => $language) {
-
- $prefix = empty($prefixes[$langcode]) ? '' : $prefixes[$langcode] . '/';
- $edit = array("comment_body[$langcode_none][0][value]" => $this->randomName());
- $this->backdropPost("{$prefix}node/{$node->nid}", $edit, t('Save'));
-
-
- $comment = db_select('comment', 'c')
- ->fields('c')
- ->condition('nid', $node->nid)
- ->orderBy('cid', 'DESC')
- ->execute()
- ->fetchObject();
- $args = array('%node_language' => $node_langcode, '%comment_language' => $comment->langcode, '%langcode' => $langcode);
- $this->assertEqual($comment->langcode, $langcode, format_string('The comment posted with content language %langcode and belonging to the node with language %node_language has language %comment_language', $args));
- }
- }
- }
- }
-
- * Functional tests for localizing date formats.
- */
- class LocaleDateFormatsFunctionalTest extends BackdropWebTestCase {
- function setUp() {
- parent::setUp('locale');
-
-
- date_default_timezone_set('UTC');
-
-
- $admin_user = $this->backdropCreateUser(array('administer site configuration', 'administer languages', 'access administration pages', 'create post content'));
- $this->backdropLogin($admin_user);
- }
-
- protected function checkRequirements() {
- $errors = parent::checkRequirements();
-
- if (!extension_loaded('intl')) {
- $errors[] = 'PHP intl extension is not present.';
- }
-
- return $errors;
- }
-
-
- * Functional tests for localizing date formats.
- */
- function testLocalizeDateFormats() {
-
- $edit = array(
- 'predefined_langcode' => 'fr',
- );
- $this->backdropPost('admin/config/regional/language/add', $edit, t('Add language'));
-
-
- $language_type = LANGUAGE_TYPE_INTERFACE;
- $edit = array(
- "{$language_type}[locale-url][enabled]" => TRUE,
- );
- $this->backdropPost('admin/config/regional/language/detection', $edit, t('Save settings'));
-
-
- $GLOBALS['language_url'] = language_default();
-
-
- $edit = array(
- 'label' => 'Example Style',
- 'name' => 'example_style',
- 'pattern' => 'd.m.Y - H:i',
- );
- $this->backdropPost('admin/config/regional/date-time/formats/add', $edit, t('Add format'));
-
-
- $edit = array(
- 'locales[en]' => 'm.d.Y - H:i',
- 'locales[fr]' => 'Y.m.d - H:i',
- );
- $this->backdropPost('admin/config/regional/date-time/formats/example_style/localize', $edit, t('Save configuration'));
- $this->assertText(t('Date localizations saved.'), 'Localized date formats saved.');
-
-
-
-
- $this->backdropGet('admin/config/regional/date-time/formats');
- $this->assertText(format_date(REQUEST_TIME, 'custom', 'd.m.Y'));
-
-
- $edit = array(
- 'locales[en]' => 'D, m/d/Y - g:ia',
- 'locales[fr]' => 'D, Y/m/Y - H:i',
- );
- $this->backdropPost('admin/config/regional/date-time/formats/medium/localize', $edit, t('Save configuration'));
- $this->assertText(t('Date localizations saved.'), 'Medium date formats updated.');
-
-
- $node = $this->backdropCreateNode(array('type' => 'post'));
-
-
- $this->backdropGet('node/' . $node->nid);
- $english_date = format_date($node->created, 'custom', 'D, m/d/Y - g:ia');
- $this->assertText($english_date, 'English date format appears');
- $this->backdropGet('fr/node/' . $node->nid);
- $french_date = format_date($node->created, 'custom', 'D, Y/m/Y - H:i');
- $this->assertText($french_date, 'French date format appears');
- }
- }
-
- * Functional test for language types/negotiation info.
- */
- class LocaleLanguageNegotiationInfoFunctionalTest extends BackdropWebTestCase {
- function setUp() {
- parent::setUp('locale');
- require_once BACKDROP_ROOT .'/core/includes/language.inc';
- $admin_user = $this->backdropCreateUser(array('administer languages', 'access administration pages', 'view the administration theme'));
- $this->backdropLogin($admin_user);
- $this->backdropPost('admin/config/regional/language/add', array('predefined_langcode' => 'it'), t('Add language'));
- }
-
-
- * Tests alterations to language types/negotiation info.
- */
- function testInfoAlterations() {
-
- state_set('locale_test_language_types', TRUE);
- state_set('locale_test_language_negotiation_info', TRUE);
- $this->languageNegotiationUpdate();
-
-
-
- state_set('locale_test_content_language_type', TRUE);
- $this->languageNegotiationUpdate();
- $type = LANGUAGE_TYPE_CONTENT;
-
- $language_types = language_types_get_configurable();
- $this->assertTrue(in_array($type, $language_types), 'Content language type is configurable.');
-
-
-
- $test_type = 'test_language_type';
- $provider = LANGUAGE_NEGOTIATION_INTERFACE;
- $test_provider = 'test_language_provider';
- $form_field = $type . '['. $provider .'][enabled]';
- $edit = array(
- $form_field => TRUE,
- $type . '[' . $test_provider . '][enabled]' => TRUE,
- $test_type . '[' . $test_provider . '][enabled]' => TRUE,
- );
- $this->backdropPost('admin/config/regional/language/detection', $edit, t('Save settings'));
-
-
-
- state_set('locale_test_language_negotiation_info_alter', TRUE);
- $this->languageNegotiationUpdate();
- $negotiation = (array) config_get('language.settings', "language_negotiation.$type");
- $this->assertFalse(isset($negotiation[$provider]), 'Interface language provider removed from the stored settings.');
- $this->assertNoFieldByXPath("//input[@name=\"$form_field\"]", NULL, 'Interface language provider unavailable.');
-
-
-
- foreach (language_types_get_configurable() as $type) {
- $form_field = $type . '[test_language_provider_ts][enabled]';
- if ($type == $test_type) {
- $this->assertFieldByXPath("//input[@name=\"$form_field\"]", NULL, format_string('Type-specific test language provider available for %type.', array('%type' => $type)));
- }
- else {
- $this->assertNoFieldByXPath("//input[@name=\"$form_field\"]", NULL, format_string('Type-specific test language provider unavailable for %type.', array('%type' => $type)));
- }
- }
-
-
- $this->backdropGet('');
- $last = state_get('locale_test_language_negotiation_last', array());
- foreach (language_types_info() as $type_name => $type_info) {
- $langcode = $last[$type_name];
- $value = ($type_name == LANGUAGE_TYPE_CONTENT || strpos($type_name, 'test') !== FALSE) ? 'it' : 'en';
- $this->assertEqual($langcode, $value, format_string('The negotiated language for %type is %language', array('%type' => $type_name, '%language' => $langcode)));
- }
-
-
-
- $this->languageNegotiationUpdate('disable');
-
-
- foreach (language_types_info() as $type_name => $type_info) {
- $this->assertTrue(strpos($type_name, 'test') === FALSE, format_string('The %type language is still available', array('%type' => $type_name)));
- }
-
-
-
- $negotiation = (array) config_get('language.settings', "language_negotiation.$type");
- $this->assertFalse(isset($negotiation[$test_provider]), 'The disabled test language provider is not part of the content language negotiation settings.');
-
-
- $this->assertNoRaw(t('Test language detection'), 'No test language type configuration available.');
- $this->assertNoRaw(t('This is a test language provider'), 'No test language provider available.');
- }
-
-
- * Update language types/negotiation information.
- *
- * Manually invoke locale_modules_enabled()/locale_modules_disabled() since
- * they would not be invoked after enabling/disabling locale_test the first
- * time.
- */
- protected function languageNegotiationUpdate($op = 'enable') {
- static $last_op = NULL;
- $modules = array('locale_test');
-
-
- if ($last_op != $op) {
- $function = "module_{$op}";
- $function($modules);
-
- module_implements_reset();
- }
-
- backdrop_static_reset('language_types_info');
- backdrop_static_reset('language_negotiation_info');
- backdrop_static_reset('language_types_get_configurable');
-
- $function = "language_modules_{$op}d";
- if (function_exists($function)) {
- $function($modules);
- }
-
- $this->backdropGet('admin/config/regional/language/detection');
- }
- }
-
- * Tests locale translation safe string handling.
- */
- class LocaleStringIsSafeTest extends BackdropWebTestCase {
- function setUp() {
- parent::setUp('locale');
- }
-
-
- * Tests for locale_string_is_safe().
- */
- public function testLocaleStringIsSafe() {
-
- $string = 'Hello world!';
- $result = locale_string_is_safe($string);
- $this->assertTrue($result);
-
-
- $string = 'Hello <strong>world</strong>!';
- $result = locale_string_is_safe($string);
- $this->assertTrue($result);
-
-
-
- $string = 'Hello <img src="world.png" alt="world" />!';
- $result = locale_string_is_safe($string);
- $this->assertFalse($result);
-
-
- $string = 'Hi <a href="[current-user:url]">user</a>';
- $result = locale_string_is_safe($string);
- $this->assertTrue($result);
- }
- }