From 72ee3e0f9941debef15d2854187dacda52e1ce3d Mon Sep 17 00:00:00 2001 From: Kaspars Dambis Date: Wed, 18 Sep 2024 13:57:40 +0300 Subject: [PATCH] Test the uninstall --- tests/class-two-factor-core.php | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/tests/class-two-factor-core.php b/tests/class-two-factor-core.php index 29c1336b..5f6a15a2 100644 --- a/tests/class-two-factor-core.php +++ b/tests/class-two-factor-core.php @@ -1555,4 +1555,30 @@ public function test_all_sessions_destroyed_when_enabling_2fa_by_admin() { // Validate that the Admin still has a session. $this->assertCount( 1, $admin_session_manager->get_all(), 'No admin sessions are present first' ); } + + /** + * Plugin uninstall removes all user meta. + * + * @covers Two_Factor_Core::uninstall + */ + public function test_uninstall_removes_user_meta() { + $user = self::factory()->user->create_and_get(); + + // Enable a provider for the user. + Two_Factor_Core::enable_provider_for_user( $user->ID, 'Two_Factor_Totp' ); + + $this->assertContains( + 'Two_Factor_Totp', + Two_Factor_Core::get_enabled_providers_for_user( $user->ID ), + 'Sample provider was enabled' + ); + + Two_Factor_Core::uninstall(); + + $this->assertNotContains( + 'Two_Factor_Totp', + Two_Factor_Core::get_enabled_providers_for_user( $user->ID ), + 'Provider was disabled due to uninstall' + ); + } }