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) { function handle_update_languages($language_info) {
$options = get_option('what-did-they-say-options');
switch ($language_info['action']) {
$languages = array(); case "delete":
foreach ($language_info as $code => $info) { unset($options['languages'][$language_info['code']]);
if (isset($this->all_languages[$code])) { break;
$language = $code; case "add":
if (isset($info['default'])) { $language = array('code' => $code, 'default' => true); } if (isset($this->all_languages[$language_info['code']])) {
$languages[] = $language; $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']);
} }
} }
$this->_update_options('languages', $languages); }
break;
}
update_option('what-did-they-say-options', $options);
} }
function handle_update_allowed_users($users) { function handle_update_allowed_users($users) {

View File

@ -17,13 +17,21 @@ class WhatDidTheySayAdminTest extends PHPUnit_Framework_TestCase {
function providerTestHandleUpdateLanguages() { function providerTestHandleUpdateLanguages() {
return array( return array(
array(
array( array(
array('en' => array('name' => 'English'), 'de' => array('name' => 'German')), array('en' => array('name' => 'English'), 'de' => array('name' => 'German')),
array('code' => 'en', 'action' => 'delete'), array('code' => 'en', 'action' => 'delete'),
array('de' => array('name' => 'German')) 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' '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); $admin->handle_update_languages($form_submission);