more cleanup of capabilities

This commit is contained in:
John Bintz 2009-08-15 15:53:55 -04:00
parent 8e3601cda5
commit 112c4908ad
2 changed files with 40 additions and 31 deletions

View File

@ -73,9 +73,11 @@ class WhatDidTheySayAdmin {
} }
function handle_update($info) { function handle_update($info) {
$result = $this->handle_update_languages($info); foreach (array(
if (!empty($result)) { 'languages', 'capabilities'
$this->notices[] = $result; ) as $method) {
$result = $this->{"handle_update_${method}"}($info);
if (!empty($result)) { $this->notices[] = $result; }
} }
} }
@ -120,26 +122,23 @@ class WhatDidTheySayAdmin {
return $updated; return $updated;
} }
function handle_update_allowed_users($users) { function handle_update_capabilities($capabilities_info) {
$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) {
$options = get_option('what-did-they-say-options'); $options = get_option('what-did-they-say-options');
$updated = false; $updated = false;
switch ($language_info['action']) { switch ($capabilities_info['action']) {
case "capabilities": 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) { function handle_update_options($requested_options) {

View File

@ -59,17 +59,6 @@ class WhatDidTheySayAdminTest extends PHPUnit_Framework_TestCase {
$this->assertEquals($expected_results, $options['languages']); $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() { function testHandleUpdateOptions() {
$admin = new WhatDidTheySayAdmin(); $admin = new WhatDidTheySayAdmin();
@ -106,6 +95,27 @@ class WhatDidTheySayAdminTest extends PHPUnit_Framework_TestCase {
), $admin->build_default_languages() ), $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']);
}
} }
?> ?>