Skip to content

Commit 80d7f98

Browse files
committed
Add a unit test for the new filter
1 parent 927408c commit 80d7f98

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

tests/class-two-factor-core.php

+32
Original file line numberDiff line numberDiff line change
@@ -1556,6 +1556,38 @@ public function test_all_sessions_destroyed_when_enabling_2fa_by_admin() {
15561556
$this->assertCount( 1, $admin_session_manager->get_all(), 'No admin sessions are present first' );
15571557
}
15581558

1559+
public function test_can_filter_registered_providers_for_user() {
1560+
$user = self::factory()->user->create_and_get();
1561+
1562+
$this->assertEquals(
1563+
Two_Factor_Core::get_providers(),
1564+
Two_Factor_Core::get_supported_providers_for_user( $user ),
1565+
'All providers are available by default'
1566+
);
1567+
1568+
add_filter(
1569+
'two_factor_providers_for_user',
1570+
function( $providers, $user ) {
1571+
$this->assertInstanceOf( WP_User::class, $user );
1572+
1573+
return array_diff_key( $providers, array( 'Two_Factor_Email' => null ) );
1574+
},
1575+
10,
1576+
2
1577+
);
1578+
1579+
$providers = Two_Factor_Core::get_providers();
1580+
unset( $providers['Two_Factor_Email'] );
1581+
1582+
$this->assertEquals(
1583+
$providers,
1584+
Two_Factor_Core::get_supported_providers_for_user( $user ),
1585+
'Email provider can be disabled for a user'
1586+
);
1587+
1588+
remove_all_filters( 'two_factor_providers_for_user' );
1589+
}
1590+
15591591
/**
15601592
* Plugin uninstall removes all user meta.
15611593
*

0 commit comments

Comments
 (0)