diff --git a/packages/sso/src/SSO.php b/packages/sso/src/SSO.php index 6f5e1e4..779ea46 100644 --- a/packages/sso/src/SSO.php +++ b/packages/sso/src/SSO.php @@ -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 + }; } /** diff --git a/packages/sso/tests/TestSSO.php b/packages/sso/tests/TestSSO.php index 199434c..c68f60c 100644 --- a/packages/sso/tests/TestSSO.php +++ b/packages/sso/tests/TestSSO.php @@ -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(); @@ -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 * @@ -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();