summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAngie Byron <webchick@24967.no-reply.drupal.org>2009-02-13 00:45:18 +0000
committerAngie Byron <webchick@24967.no-reply.drupal.org>2009-02-13 00:45:18 +0000
commit2da17d8010a41fd96dbb6e1785b4a7b56a9cbee0 (patch)
tree5ab901437cfbbad0335646a0f20680afcfb634e3
parent52c17c6d3ec99a872436ad09377401c25ff0bb55 (diff)
downloadbrdo-2da17d8010a41fd96dbb6e1785b4a7b56a9cbee0.tar.gz
brdo-2da17d8010a41fd96dbb6e1785b4a7b56a9cbee0.tar.bz2
#347288 by plach: Fix Locale uninstall (with tests).
-rw-r--r--includes/locale.inc2
-rw-r--r--modules/locale/locale.install32
-rw-r--r--modules/locale/locale.test153
3 files changed, 177 insertions, 10 deletions
diff --git a/includes/locale.inc b/includes/locale.inc
index 1c272841b..46f268ed6 100644
--- a/includes/locale.inc
+++ b/includes/locale.inc
@@ -2283,7 +2283,7 @@ function _locale_rebuild_js($langcode = NULL) {
// Delete old file, if we have no translations anymore, or a different file to be saved.
if (!empty($language->javascript) && (!$data || $language->javascript != $data_hash)) {
- file_delete(file_create_path($dir . '/' . $language->language . '_' . $language->javascript . '.js'));
+ file_unmanaged_delete(file_create_path($dir . '/' . $language->language . '_' . $language->javascript . '.js'));
$language->javascript = '';
$status = 'deleted';
}
diff --git a/modules/locale/locale.install b/modules/locale/locale.install
index 044ab62d3..d9ef10afb 100644
--- a/modules/locale/locale.install
+++ b/modules/locale/locale.install
@@ -209,14 +209,36 @@ function locale_update_6005() {
* Implementation of hook_uninstall().
*/
function locale_uninstall() {
- // Delete all JavaScript translation files
- $files = db_query('SELECT javascript FROM {languages}');
+ // Delete all JavaScript translation files.
+ $locale_js_directory = file_create_path(variable_get('locale_js_directory', 'languages'));
+ $files = db_query('SELECT language, javascript FROM {languages}');
while ($file = db_fetch_object($files)) {
- if (!empty($file)) {
- file_delete(file_create_path($file->javascript));
+ if (!empty($file->javascript)) {
+ file_unmanaged_delete(file_create_path($locale_js_directory . '/' . $file->language . '_' . $file->javascript . '.js'));
}
}
-
+ // Delete the JavaScript translations directory if empty.
+ @rmdir($locale_js_directory);
+
+ // Clear variables.
+ variable_del('language_default');
+ variable_del('language_count');
+ variable_del('language_negotiation');
+ variable_del('javascript_parsed');
+ variable_del('language_content_type_default');
+ variable_del('language_content_type_negotiation');
+ variable_del('locale_cache_strings');
+ variable_del('locale_js_directory');
+
+ foreach (node_get_types() as $type => $content_type) {
+ $setting = variable_del('language_content_type_' . $type);
+ }
+
+ // Switch back to English: with a $language->language value different from 'en'
+ // successive calls of t() might result in calling locale(), which in turn might
+ // try to query the unexisting {locales_source} and {locales_target} tables.
+ drupal_init_language();
+
// Remove tables.
drupal_uninstall_schema('locale');
}
diff --git a/modules/locale/locale.test b/modules/locale/locale.test
index ebd7febbc..c5d1ee533 100644
--- a/modules/locale/locale.test
+++ b/modules/locale/locale.test
@@ -1,11 +1,25 @@
<?php
// $Id$
-class LocaleTestCase extends DrupalWebTestCase {
+/**
+ * @file
+ * Tests for Locale module.
+ *
+ * The test file includes:
+ * - a functional test for the translation functionalities;
+ * - a functional test for the PO files import feature;
+ * - a functional test for the language switching feature
+ * - a couple of functional tests for the uninstall process.
+ */
+
+/**
+ * Functional test for string translation and validation.
+ */
+class LocaleTranslationFunctionalTest extends DrupalWebTestCase {
function getInfo() {
return array(
'name' => t('String translate and validate'),
- 'description' => 'Adds a new locale and translates its name. Checks the validation of translation strings.',
+ 'description' => t('Adds a new locale and translates its name. Checks the validation of translation strings.'),
'group' => 'Locale',
);
}
@@ -14,7 +28,10 @@ class LocaleTestCase extends DrupalWebTestCase {
parent::setUp('locale');
}
- function testlocaleModuleTest() {
+ /**
+ * Adds a language and tests string translation by users with the appropriate permissions.
+ */
+ function testStringTranslation() {
global $base_url;
// User to add and remove language.
@@ -113,7 +130,10 @@ class LocaleTestCase extends DrupalWebTestCase {
$this->assertNoText($name, 'Search now can not find the name');
}
- function testLocaleStringTest() {
+ /**
+ * Tests the validation of the translation input.
+ */
+ function testStringValidation() {
global $base_url;
// User to add language and strings
@@ -307,6 +327,131 @@ EOF;
}
/**
+ * Locale uninstall with English UI functional test.
+ */
+class LocaleUninstallFunctionalTest extends DrupalWebTestCase {
+ function getInfo() {
+ return array(
+ 'name' => t('Locale uninstall (EN)'),
+ 'description' => t('Tests the uninstall process using the built-in UI language.'),
+ 'group' => t('Locale'),
+ );
+ }
+
+ /**
+ * The default language set for the UI before uninstall.
+ */
+ protected $ui_language;
+
+ function setUp() {
+ parent::setUp('locale');
+ $this->ui_language = 'en';
+ }
+
+ /**
+ * Check if the values of the Locale variables are correct after uninstall.
+ */
+ function testUninstallProcess() {
+ $locale_module = array('locale');
+
+ // Add a new language and optionally set it as default.
+ require_once DRUPAL_ROOT . '/includes/locale.inc';
+ locale_add_language('fr', 'French', 'Français', LANGUAGE_LTR, '', '', TRUE, $this->ui_language == 'fr');
+
+ // Check the UI language.
+ drupal_init_language();
+ global $language;
+ $this->assertEqual($language->language, $this->ui_language, t('Current language: %lang', array('%lang' => $language->language)));
+
+ // Change language negotiation options.
+ variable_set('language_negotiation', LANGUAGE_NEGOTIATION_PATH_DEFAULT);
+
+ // Enable multilingual workflow option for articles.
+ variable_set('language_content_type_article', 1);
+
+ // Change JavaScript translations directory.
+ variable_set('locale_js_directory', 'js_translations');
+
+ // Build the JavaScript translation file for French.
+ $user = $this->drupalCreateUser(array('translate interface', 'access administration pages'));
+ $this->drupalLogin($user);
+ $this->drupalGet('admin/build/translate/translate');
+ $string = db_fetch_object(db_query('SELECT min(lid) AS lid FROM {locales_source} WHERE location LIKE \'%.js%\' AND textgroup = \'default\''));
+ $edit = array('translations[fr]' => 'french translation');
+ $this->drupalPost('admin/build/translate/edit/'. $string->lid, $edit, t('Save translations'));
+ _locale_rebuild_js('fr');
+ $file = db_fetch_object(db_query('SELECT javascript FROM {languages} WHERE language = \'fr\''));
+ $js_file = file_create_path(variable_get('locale_js_directory', 'languages')) .'/fr_'. $file->javascript .'.js';
+ $this->assertTrue($result = file_exists($js_file), t('JavaScript file created: %file', array('%file' => $result ? $js_file : t('none'))));
+
+ // Disable string caching.
+ variable_set('locale_cache_strings', 0);
+
+ // Uninstall Locale.
+ module_disable($locale_module);
+ drupal_uninstall_modules($locale_module);
+
+ // Visit the front page.
+ $this->drupalGet('');
+
+ // Check the init language logic.
+ drupal_init_language();
+ $this->assertEqual($language->language, 'en', t('Language after uninstall: %lang', array('%lang' => $language->language)));
+
+ // Check JavaScript files deletion.
+ $this->assertTrue($result = !file_exists($js_file), t('JavaScript file deleted: %file', array('%file' => $result ? $js_file : t('found'))));
+
+ // Check language count.
+ $language_count = variable_get('language_count', 1);
+ $this->assertEqual($language_count, 1, t('Language count: %count', array('%count' => $language_count)));
+
+ // Check language negotiation.
+ $language_negotiation = variable_get('language_negotiation', LANGUAGE_NEGOTIATION_NONE) == LANGUAGE_NEGOTIATION_NONE;
+ $this->assertTrue($language_negotiation, t('Language negotiation: %setting', array('%setting' => t($language_negotiation ? 'none' : 'set'))));
+
+ // Check JavaScript parsed.
+ $javascript_parsed_count = count(variable_get('javascript_parsed', array()));
+ $this->assertEqual($javascript_parsed_count, 0, t('JavaScript parsed count: %count', array('%count' => $javascript_parsed_count)));
+
+ // Check multilingual workflow option for articles.
+ $multilingual = variable_get('language_content_type_article', 0);
+ $this->assertEqual($multilingual, 0, t('Multilingual workflow option: %status', array('%status' => t($multilingual ? 'enabled': 'disabled'))));
+
+ // Check JavaScript translations directory.
+ $locale_js_directory = variable_get('locale_js_directory', 'languages');
+ $this->assertEqual($locale_js_directory, 'languages', t('JavaScript translations directory: %dir', array('%dir' => $locale_js_directory)));
+
+ // Check string caching.
+ $locale_cache_strings = variable_get('locale_cache_strings', 1);
+ $this->assertEqual($locale_cache_strings, 1, t('String caching: %status', array('%status' => t($locale_cache_strings ? 'enabled': 'disabled'))));
+ }
+}
+
+/**
+ * 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 getInfo() {
+ return array(
+ 'name' => t('Locale uninstall (FR)'),
+ 'description' => t('Tests the uninstall process using French as UI language.'),
+ 'group' => t('Locale'),
+ );
+ }
+
+ function setUp() {
+ parent::setUp();
+ $this->ui_language = 'fr';
+ }
+}
+
+
+/**
* Functional tests for the language switching feature.
*/
class LanguageSwitchingFunctionalTest extends DrupalWebTestCase {