1 locale.test | LocaleUninstallFunctionalTest::testUninstallProcess() |
Check if the values of the Locale variables are correct after uninstall.
File
- core/
modules/ locale/ tests/ locale.test, line 1241 - Tests for locale.module.
Class
- LocaleUninstallFunctionalTest
- Locale uninstall with English UI functional test.
Code
function testUninstallProcess() {
$locale_module = array('locale', 'language');
// Add a new language and optionally set it as default.
require_once BACKDROP_ROOT . '/core/includes/locale.inc';
$language = (object) array(
'langcode' => 'fr',
'name' => 'French',
'default' => $this->langcode == 'fr',
);
language_save($language);
// Check the UI language.
backdrop_language_initialize();
$this->assertEqual($GLOBALS['language']->langcode, $this->langcode, format_string('Current language: %lang', array('%lang' => $GLOBALS['language']->langcode)));
// Enable multilingual workflow option for posts.
$node_type = node_type_load('post');
$node_type->settings['language'] = 1;
node_type_save($node_type);
// Change JavaScript translations directory.
settings_get('locale_js_directory', 'js_translations');
// Build the JavaScript translation file for French.
$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'))));
// Change language negotiation options.
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();
// Change language providers settings.
config('locale.settings')
->set('language_negotiation_url_part', FALSE)
->set('language_negotiation_session_parameter', FALSE)
->save();
// Uninstall Locale.
module_disable($locale_module);
backdrop_uninstall_modules($locale_module);
// Visit the home page.
$this->backdropGet('');
// Check the init language logic.
backdrop_language_initialize();
$this->assertEqual($GLOBALS['language']->langcode, 'en', format_string('Language after uninstall: %lang', array('%lang' => $GLOBALS['language']->langcode)));
// Check JavaScript files deletion.
$this->assertTrue($result = !file_exists($js_file), format_string('JavaScript file deleted: %file', array('%file' => $result ? $js_file : 'found')));
// Check language count.
$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');
// Check language negotiation.
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')));
// Check language providers settings.
$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.'));
// Check JavaScript parsed.
$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)));
// Check JavaScript translations directory.
$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)));
}