From 112c4908ad7294cae23a300e8e25dc82116e34be Mon Sep 17 00:00:00 2001 From: John Bintz Date: Sat, 15 Aug 2009 15:53:55 -0400 Subject: [PATCH] more cleanup of capabilities --- classes/WhatDidTheySayAdmin.php | 39 ++++++++++++++++---------------- test/WhatDidTheySayAdminTest.php | 32 +++++++++++++++++--------- 2 files changed, 40 insertions(+), 31 deletions(-) diff --git a/classes/WhatDidTheySayAdmin.php b/classes/WhatDidTheySayAdmin.php index f5bda31..59c1f11 100644 --- a/classes/WhatDidTheySayAdmin.php +++ b/classes/WhatDidTheySayAdmin.php @@ -73,9 +73,11 @@ class WhatDidTheySayAdmin { } function handle_update($info) { - $result = $this->handle_update_languages($info); - if (!empty($result)) { - $this->notices[] = $result; + foreach (array( + 'languages', 'capabilities' + ) as $method) { + $result = $this->{"handle_update_${method}"}($info); + if (!empty($result)) { $this->notices[] = $result; } } } @@ -120,26 +122,23 @@ class WhatDidTheySayAdmin { return $updated; } - function handle_update_allowed_users($users) { - $allowed_users = array(); - foreach ($users as $user) { - if (is_numeric($user)) { - $user_info = get_userdata($user); - if (!empty($user_info)) { - $allowed_users[] = $user; - } - } - } - - $this->_update_options('allowed_users', $allowed_users); - } - - function handle_update_capabilities($capabilities) { + function handle_update_capabilities($capabilities_info) { $options = get_option('what-did-they-say-options'); $updated = false; - switch ($language_info['action']) { + switch ($capabilities_info['action']) { case "capabilities": - } + if (isset($capabilities_info['capabilities'])) { + foreach (array_keys($this->default_options['capabilities']) as $capability) { + if (isset($capabilities_info['capabilities'][$capability])) { + $options['capabilities'][$capability] = $capabilities_info['capabilities'][$capability]; + } + } + $updated = __('User capabilities updated', 'what-did-they-say'); + } + break; + } + update_option('what-did-they-say-options', $options); + return $updated; } function handle_update_options($requested_options) { diff --git a/test/WhatDidTheySayAdminTest.php b/test/WhatDidTheySayAdminTest.php index 3f8889e..b9d655f 100644 --- a/test/WhatDidTheySayAdminTest.php +++ b/test/WhatDidTheySayAdminTest.php @@ -59,17 +59,6 @@ class WhatDidTheySayAdminTest extends PHPUnit_Framework_TestCase { $this->assertEquals($expected_results, $options['languages']); } - function testHandleUpdateAllowedUsers() { - $admin = new WhatDidTheySayAdmin(); - - wp_insert_user((object)array('ID' => 1)); - - $admin->handle_update_allowed_users(array(1, 2)); - - $options = get_option('what-did-they-say-options'); - $this->assertEquals(array(1), $options['allowed_users']); - } - function testHandleUpdateOptions() { $admin = new WhatDidTheySayAdmin(); @@ -106,6 +95,27 @@ class WhatDidTheySayAdminTest extends PHPUnit_Framework_TestCase { ), $admin->build_default_languages() ); } + + function testHandleUpdateCapabilities() { + $admin = new WhatDidTheySayAdmin(); + update_option('what-did-they-say-options', $admin->default_options); + + $admin->handle_update_capabilities(array( + 'action' => 'capabilities', + 'capabilities' => array( + 'submit_transcription' => 'contributor', + 'approve_transcription' => 'subscriber', + 'change_languages' => 'reader' + ) + )); + + $result = get_option('what-did-they-say-options'); + $this->assertEquals(array( + 'submit_transcription' => 'contributor', + 'approve_transcription' => 'subscriber', + 'change_languages' => 'reader' + ), $result['capabilities']); + } } ?> \ No newline at end of file