From c4f7d2c5ce5ac844f05841c9897ba7f7b7fa9aae Mon Sep 17 00:00:00 2001 From: John Bintz Date: Wed, 9 Sep 2009 08:20:07 -0400 Subject: [PATCH] some cleanup --- classes/WDTSLanguageOptions.php | 2 +- classes/WhatDidTheySayAdmin.php | 14 +++++++------- test/WDTSLanguageOptionsTest.php | 10 ++++------ 3 files changed, 12 insertions(+), 14 deletions(-) diff --git a/classes/WDTSLanguageOptions.php b/classes/WDTSLanguageOptions.php index 8621af0..641820c 100644 --- a/classes/WDTSLanguageOptions.php +++ b/classes/WDTSLanguageOptions.php @@ -47,7 +47,7 @@ class WDTSLanguageOptions { $did_delete = false; if (isset($options['languages'][$code_to_delete])) { - $did_delete = true; + $did_delete = $options['languages'][$code_to_delete]; unset($options['languages'][$code_to_delete]); } diff --git a/classes/WhatDidTheySayAdmin.php b/classes/WhatDidTheySayAdmin.php index b38e419..0c121c5 100644 --- a/classes/WhatDidTheySayAdmin.php +++ b/classes/WhatDidTheySayAdmin.php @@ -240,15 +240,19 @@ class WhatDidTheySayAdmin { function handle_update_languages($info) { $updated = false; if (current_user_can('change_languages')) { - $options = get_option('what-did-they-say-options'); + $language_options = new WDTSLanguageOptions(); + switch ($info['action']) { case "delete": - $updated = sprintf(__('%s deleted.', 'what-did-they-say'), $options['languages'][$info['code']]['name']); - unset($options['languages'][$info['code']]); + if ($result = $language_options->delete_language($info['code'])) { + $updated = sprintf(__('%s deleted.', 'what-did-they-say'), $result['name']); + } break; case "add": $this->read_language_file(); if (isset($this->all_languages[$info['code']])) { + + $options['languages'][$info['code']] = array('name' => $this->all_languages[$info['code']]); $updated = sprintf(__('%s added.', 'what-did-they-say'), $this->all_languages[$info['code']]); } @@ -274,10 +278,6 @@ class WhatDidTheySayAdmin { } break; } - if ($updated !== false) { - ksort($options['languages']); - update_option('what-did-they-say-options', $options); - } } return $updated; } diff --git a/test/WDTSLanguageOptionsTest.php b/test/WDTSLanguageOptionsTest.php index 42a1048..c8675c5 100644 --- a/test/WDTSLanguageOptionsTest.php +++ b/test/WDTSLanguageOptionsTest.php @@ -48,7 +48,7 @@ class WDTSLanguageOptionsTest extends PHPUnit_Framework_TestCase { function providerTestDeleteLanguage() { return array( - array('de', true), + array('de', array('name' => 'German')), array('fr', false) ); } @@ -71,12 +71,10 @@ class WDTSLanguageOptionsTest extends PHPUnit_Framework_TestCase { $this->l->delete_language($code) ); - if ($expected_result) { - unset($check[$code]); - } + if ($expected_result) { unset($check[$code]); } - $this->assertEquals(array( - 'languages' => $check ), + $this->assertEquals( + array('languages' => $check), get_option($this->l->key) ); }