Skip to content

Commit

Permalink
Add a unit test for the new filter
Browse files Browse the repository at this point in the history
  • Loading branch information
kasparsd committed Feb 14, 2025
1 parent 927408c commit 80d7f98
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions tests/class-two-factor-core.php
Original file line number Diff line number Diff line change
Expand Up @@ -1556,6 +1556,38 @@ public function test_all_sessions_destroyed_when_enabling_2fa_by_admin() {
$this->assertCount( 1, $admin_session_manager->get_all(), 'No admin sessions are present first' );
}

public function test_can_filter_registered_providers_for_user() {
$user = self::factory()->user->create_and_get();

$this->assertEquals(
Two_Factor_Core::get_providers(),
Two_Factor_Core::get_supported_providers_for_user( $user ),
'All providers are available by default'
);

add_filter(
'two_factor_providers_for_user',
function( $providers, $user ) {
$this->assertInstanceOf( WP_User::class, $user );

return array_diff_key( $providers, array( 'Two_Factor_Email' => null ) );
},
10,
2
);

$providers = Two_Factor_Core::get_providers();
unset( $providers['Two_Factor_Email'] );

$this->assertEquals(
$providers,
Two_Factor_Core::get_supported_providers_for_user( $user ),
'Email provider can be disabled for a user'
);

remove_all_filters( 'two_factor_providers_for_user' );
}

/**
* Plugin uninstall removes all user meta.
*
Expand Down

0 comments on commit 80d7f98

Please sign in to comment.