change language updating

This commit is contained in:
John Bintz 2009-08-14 06:54:25 -04:00
parent 852c00f16f
commit ce753acf20
2 changed files with 37 additions and 17 deletions

View File

@ -44,17 +44,29 @@ class WhatDidTheySayAdmin {
}
function handle_update_languages($language_info) {
$languages = array();
foreach ($language_info as $code => $info) {
if (isset($this->all_languages[$code])) {
$language = $code;
if (isset($info['default'])) { $language = array('code' => $code, 'default' => true); }
$languages[] = $language;
}
$options = get_option('what-did-they-say-options');
switch ($language_info['action']) {
case "delete":
unset($options['languages'][$language_info['code']]);
break;
case "add":
if (isset($this->all_languages[$language_info['code']])) {
$options['languages'][$language_info['code']] = array('name' => $this->all_languages[$language_info['code']]);
}
break;
case "default":
if (isset($options['languages'][$language_info['code']])) {
foreach ($options['languages'] as $code => $info) {
if ($code == $language_info['code']) {
$options['languages'][$code]['default'] = true;
} else {
unset($options['languages'][$code]['default']);
}
}
}
break;
}
$this->_update_options('languages', $languages);
update_option('what-did-they-say-options', $options);
}
function handle_update_allowed_users($users) {

View File

@ -18,12 +18,20 @@ class WhatDidTheySayAdminTest extends PHPUnit_Framework_TestCase {
function providerTestHandleUpdateLanguages() {
return array(
array(
array(
array('en' => array('name' => 'English'), 'de' => array('name' => 'German')),
array('code' => 'en', 'action' => 'delete'),
array('de' => array('name' => 'German'))
)
)
array('en' => array('name' => 'English'), 'de' => array('name' => 'German')),
array('code' => 'en', 'action' => 'delete'),
array('de' => array('name' => 'German'))
),
array(
array('de' => array('name' => 'German')),
array('code' => 'en', 'action' => 'add'),
array('en' => array('name' => 'English'), 'de' => array('name' => 'German')),
),
array(
array('en' => array('name' => 'English', 'default' => true), 'de' => array('name' => 'German')),
array('code' => 'de', 'action' => 'default'),
array('en' => array('name' => 'English'), 'de' => array('name' => 'German', 'default' => true)),
),
);
}
@ -38,7 +46,7 @@ class WhatDidTheySayAdminTest extends PHPUnit_Framework_TestCase {
'fr' => 'French'
);
update_option('what-did-they-say-options', array('languages', $original_options));
update_option('what-did-they-say-options', array('languages' => $original_options));
$admin->handle_update_languages($form_submission);