Skip to content

Commit

Permalink
Add a unit test that disabled providers are still deleted during unin…
Browse files Browse the repository at this point in the history
…stall
  • Loading branch information
kasparsd committed Dec 2, 2024
1 parent 656772a commit f275d7c
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions tests/class-two-factor-core.php
Original file line number Diff line number Diff line change
Expand Up @@ -1581,4 +1581,41 @@ public function test_uninstall_removes_user_meta() {
'Provider was disabled due to uninstall'
);
}

/**
* Plugin uninstall removes all user meta even for disabled providers.
*
* @covers Two_Factor_Core::uninstall
*/
public function test_uninstall_removes_disabled_provider_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' );

$totp_provider = Two_Factor_Totp::get_instance();

$totp_provider->set_user_totp_key( $user->ID, 'some_key' );

$this->assertEquals( 'some_key', $totp_provider->get_user_totp_key( $user->ID ), 'TOTP secret was set for user' );

add_filter(
'two_factor_providers',
function( $providers ) {
return array_diff_key( $providers, array( 'Two_Factor_Totp' => null ) );
}
);

$this->assertNotContains(
'Two_Factor_Totp',
Two_Factor_Core::get_enabled_providers_for_user( $user->ID ),
'TOTP provider is disabled for everyone via filter'
);

Two_Factor_Core::uninstall();

$this->assertEmpty( $totp_provider->get_user_totp_key( $user->ID ), 'TOTP secret was deleted during uninstall' );

remove_all_filters( 'two_factor_providers' );
}
}

0 comments on commit f275d7c

Please sign in to comment.