Commit 17d17254 authored by Dries's avatar Dries

- Patch #1099396 by Désiré, droplet, plach: language_count() is never...

- Patch #1099396 by Désiré, droplet, plach: language_count() is never decremented when removing a language.
parent 5e142ee2
......@@ -2292,6 +2292,9 @@ function drupal_language_types() {
* Return true if there is more than one language enabled.
*/
function drupal_multilingual() {
// The "language_count" variable stores the number of enabled languages to
// avoid unnecessarily querying the database when building the list of
// enabled languages on monolingual sites.
return variable_get('language_count', 1) > 1;
}
......
......@@ -467,6 +467,9 @@ function locale_languages_delete_form_submit($form, &$form_state) {
->fields(array('language' => ''))
->condition('language', $form_state['values']['langcode'])
->execute();
if ($languages[$form_state['values']['langcode']]->enabled) {
variable_set('language_count', variable_get('language_count', 1) - 1);
}
module_invoke_all('multilingual_settings_changed');
$variables = array('%locale' => $languages[$form_state['values']['langcode']]->name);
drupal_set_message(t('The language %locale has been removed.', $variables));
......
......@@ -129,7 +129,7 @@ class LocaleConfigurationTest extends DrupalWebTestCase {
$this->drupalGet('admin/config/regional/language');
$this->clickLink(t('delete'));
$this->assertText(t('Are you sure you want to delete the language'), t('"delete" link is correct.'));
// Delete the language.
// Delete an enabled language.
$this->drupalGet('admin/config/regional/language/delete/' . $langcode);
// First test the 'cancel' link.
$this->clickLink(t('Cancel'));
......@@ -144,6 +144,31 @@ class LocaleConfigurationTest extends DrupalWebTestCase {
// Verify that language is no longer found.
$this->drupalGet('admin/config/regional/language/delete/' . $langcode);
$this->assertResponse(404, t('Language no longer found.'));
// Make sure the "language_count" variable has been updated correctly.
drupal_static_reset('language_list');
$enabled = language_list('enabled');
$this->assertEqual(variable_get('language_count', 1), count($enabled[1]), t('Language count is correct.'));
// Delete a disabled language.
// Disable an enabled language.
$edit = array(
'enabled[fr]' => FALSE,
);
$this->drupalPost($path, $edit, t('Save configuration'));
$this->assertNoFieldChecked('edit-enabled-fr', t('French language disabled.'));
// Get the count of enabled languages.
drupal_static_reset('language_list');
$enabled = language_list('enabled');
// Delete the disabled language.
$this->drupalPost('admin/config/regional/language/delete/fr', array(), t('Delete'));
// We need raw here because %locale will add HTML.
$this->assertRaw(t('The language %locale has been removed.', array('%locale' => 'French')), t('Disabled language has been removed.'));
$this->assertEqual($this->getUrl(), url('admin/config/regional/language', array('absolute' => TRUE)), t('Correct page redirection.'));
// Verify that language is no longer found.
$this->drupalGet('admin/config/regional/language/delete/fr');
$this->assertResponse(404, t('Language no longer found.'));
// Make sure the "language_count" variable has not changed.
$this->assertEqual(variable_get('language_count', 1), count($enabled[1]), t('Language count is correct.'));
// Ensure we can't delete the English language.
$this->drupalGet('admin/config/regional/language/delete/en');
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment