Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
jdamner committed Feb 27, 2025
1 parent 7e8fffc commit 5c2ba6a
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 16 deletions.
22 changes: 8 additions & 14 deletions packages/sso/src/SSO.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,20 +146,14 @@ public function map_user_group_to_wp_role( string|array $default_role, array $at
return $default_role;
}

switch ( $attributes[ $role_key ][0] ) {
case 'BoxUK-WP_Admin':
return 'administrator';
case 'BoxUK-WP_Editor':
return 'editor';
case 'BoxUK-WP_Author':
return 'author';
case 'BoxUK-WP_Contributor':
return 'contributor';
case 'BoxUK-WP_Subscriber':
return 'subscriber';
default:
return $default_role;
}
return match ( $attributes[ $role_key ][0] ) {
'BoxUKWP_Admin' => 'administrator',
'BoxUKWP_Editor' => 'editor',
'BoxUKWP_Author' => 'author',
'BoxUKWP_Contributor' => 'contributor',
'BoxUKWP_Subscriber' => 'subscriber',
default => $default_role
};
}

/**
Expand Down
43 changes: 41 additions & 2 deletions packages/sso/tests/TestSSO.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,11 @@ public function test_get_sso_url() {
);
}

/**
* Test Attribute Mapping
*
* @return void
*/
public function test_attribute_mapping() {
$class_in_test = new SSO();

Expand All @@ -127,6 +132,35 @@ public function test_attribute_mapping() {
);
}

/**
* Test Maybe Update User
*
* @return void
*/
public function test_maybe_update_role() {
$class_in_test = new SSO();
// @todo - write this test.
}

/**
* Test Mapping user Roles
*
* @return void
*/
public function test_map_user_group_to_wp_role() {
$class_in_test = new SSO();

$this->assertEquals(
'test',
$class_in_test->map_user_group_to_wp_role( 'test', [] )
);

$this->assertEquals(
'administrator',
$class_in_test->map_user_group_to_wp_role( 'test', [ 'user_role' => [ 0 => 'BoxUKWP_Admin' ] ] )
);
}

/**
* Test Saml Config
*
Expand All @@ -153,10 +187,15 @@ public function test_saml_config( bool $is_error ) {
}
}

/**
* Test Hide SSO Settings
*
* @return void
*/
public function test_hide_sso_settings() {
global $wp_settings_sections;
$wp_settings_sections['general'] = [
'sso_settings' => true
$wp_settings_sections['general'] = [ // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited -- override during test
'sso_settings' => true,
];

$class_in_test = new SSO();
Expand Down

0 comments on commit 5c2ba6a

Please sign in to comment.