Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions tests/class-two-factor-core.php
Original file line number Diff line number Diff line change
Expand Up @@ -2544,9 +2544,15 @@ public function test_wp_login_non_two_factor_user() {
* @covers Two_Factor_Core::add_settings_action_link
*/
public function test_add_settings_action_link() {
$old_user_id = get_current_user_id();
$admin = self::factory()->user->create_and_get( array( 'role' => 'administrator' ) );
wp_set_current_user( $admin->ID );

$links = array( 'deactivate' => '<a href="#">Deactivate</a>' );
$result = Two_Factor_Core::add_settings_action_link( $links );

wp_set_current_user( $old_user_id );

// Settings link should be first.
$this->assertCount( 3, $result );
$first = reset( $result );
Expand Down
8 changes: 7 additions & 1 deletion tests/providers/class-two-factor-backup-codes.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,13 +159,19 @@ public function test_generate_code_and_validate_code_false_different_users() {
public function test_user_options() {
$user = new WP_User( self::factory()->user->create() );

// Register the script so wp_localize_script() can attach data to it.
$this->provider->enqueue_assets();

ob_start();
$this->provider->user_options( $user );
$buffer = ob_get_clean();

$this->assertStringContainsString( '<div id="two-factor-backup-codes">', $buffer );
$this->assertStringContainsString( '<div class="two-factor-backup-codes-wrapper" style="display:none;">', $buffer );
$this->assertStringContainsString( "user_id: {$user->ID}", $buffer );

// User ID is passed via wp_localize_script; check the registered script data rather than the HTML buffer.
$script_data = wp_scripts()->get_data( 'two-factor-backup-codes-admin', 'data' );
$this->assertStringContainsString( '"userId":"' . $user->ID . '"', $script_data );
}

/**
Expand Down
Loading