Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test coverage for user preference checkbox handling #8084

Open
wants to merge 2 commits into
base: trunk
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions src/wp-admin/includes/user.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ function edit_user( $user_id = 0 ) {
}

if ( $update ) {
$user->rich_editing = isset( $_POST['rich_editing'] ) && 'false' === $_POST['rich_editing'] ? 'false' : 'true';
$user->syntax_highlighting = isset( $_POST['syntax_highlighting'] ) && 'false' === $_POST['syntax_highlighting'] ? 'false' : 'true';
$user->rich_editing = isset( $_POST['rich_editing'] ) ? 'true' : 'false';
$user->syntax_highlighting = isset( $_POST['syntax_highlighting'] ) ? 'true' : 'false';
$user->admin_color = isset( $_POST['admin_color'] ) ? sanitize_text_field( $_POST['admin_color'] ) : 'fresh';
$user->show_admin_bar_front = isset( $_POST['admin_bar_front'] ) ? 'true' : 'false';
}
Expand Down
10 changes: 5 additions & 5 deletions src/wp-admin/user-edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -300,8 +300,8 @@
<tr class="user-rich-editing-wrap">
<th scope="row"><?php _e( 'Visual Editor' ); ?></th>
<td>
<label for="rich_editing"><input name="rich_editing" type="checkbox" id="rich_editing" value="false" <?php checked( 'false', $profile_user->rich_editing ); ?> />
<?php _e( 'Disable the visual editor when writing' ); ?>
<label for="rich_editing"><input name="rich_editing" type="checkbox" id="rich_editing" value="true"<?php checked( 'true', $profile_user->rich_editing ); ?> />
<?php _e( 'Enable the visual editor when writing' ); ?>
</label>
</td>
</tr>
Expand All @@ -324,8 +324,8 @@
<tr class="user-syntax-highlighting-wrap">
<th scope="row"><?php _e( 'Syntax Highlighting' ); ?></th>
<td>
<label for="syntax_highlighting"><input name="syntax_highlighting" type="checkbox" id="syntax_highlighting" value="false" <?php checked( 'false', $profile_user->syntax_highlighting ); ?> />
<?php _e( 'Disable syntax highlighting when editing code' ); ?>
<label for="syntax_highlighting"><input name="syntax_highlighting" type="checkbox" id="syntax_highlighting" value="true"<?php checked( 'true', $profile_user->syntax_highlighting ); ?> />
<?php _e( 'Enable syntax highlighting when editing code' ); ?>
</label>
</td>
</tr>
Expand Down Expand Up @@ -370,7 +370,7 @@
<th scope="row"><?php _e( 'Toolbar' ); ?></th>
<td>
<label for="admin_bar_front">
<input name="admin_bar_front" type="checkbox" id="admin_bar_front" value="1"<?php checked( _get_admin_bar_pref( 'front', $profile_user->ID ) ); ?> />
<input name="admin_bar_front" type="checkbox" id="admin_bar_front" value="true"<?php checked( _get_admin_bar_pref( 'front', $profile_user->ID ) ); ?> />
<?php _e( 'Show Toolbar when viewing site' ); ?>
</label><br />
</td>
Expand Down
42 changes: 42 additions & 0 deletions tests/phpunit/tests/user.php
Original file line number Diff line number Diff line change
Expand Up @@ -2289,4 +2289,46 @@ function ( $meta_id, $object_id, $meta_key ) use ( &$db_update_count ) {
// Verify there are no updates to 'use_ssl' user meta.
$this->assertSame( 1, $db_update_count );
}

/**
* Test user preference checkbox handling.
*
* @ticket 57393
*
* @covers ::edit_user
*/
public function test_user_preferences_checkbox_handling() {
wp_set_current_user( self::$admin_id );

// Test when preferences are enabled.
$_POST = array(
'nickname' => 'Test User',
'email' => '[email protected]',
'rich_editing' => 'true',
'syntax_highlighting' => 'true',
'admin_bar_front' => 'true',
);

$result = edit_user( self::$author_id );
$this->assertNotWPError( $result );

$user = get_user_by( 'id', self::$author_id );
$this->assertSame( 'true', $user->rich_editing );
$this->assertSame( 'true', $user->syntax_highlighting );
$this->assertSame( 'true', $user->show_admin_bar_front );

// Test when preferences are disabled.
$_POST = array(
'nickname' => 'Test User',
'email' => '[email protected]',
);

$result = edit_user( self::$author_id );
$this->assertNotWPError( $result );

$user = get_user_by( 'id', self::$author_id );
$this->assertSame( 'false', $user->rich_editing );
$this->assertSame( 'false', $user->syntax_highlighting );
$this->assertSame( 'false', $user->show_admin_bar_front );
}
}
Loading