Make WordPress Core


Ignore:
Timestamp:
10/14/2024 09:14:49 PM (16 months ago)
Author:
SergeyBiryukov
Message:

Users: Further adjust the check for use_ssl meta in wp_insert_user().

This removes a redundant check for a falsey value, which is equivalent to the empty() check directly before.

Includes minor adjustments in the unit test:

  • Adding a @covers tag.
  • Correcting the description for clarity.
  • Using assertSame() for strict type checking.

Follow-up to [59216].

See #60299.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/user.php

    r59216 r59232  
    22482248
    22492249    /**
    2250      * Test that update_user_meta for 'use_ssl' doesn't write to DB unnecessarily.
     2250     * Tests that wp_insert_user() does not unnecessarily update the 'use_ssl' meta.
    22512251     *
    22522252     * @ticket 60299
    2253      */
    2254     public function test_unnecessary_assignment_of_use_ssl_in_meta() {
     2253     *
     2254     * @covers ::wp_insert_user
     2255     */
     2256    public function test_wp_insert_user_should_not_unnecessary_update_use_ssl_meta() {
    22552257        $user_id = self::$contrib_id;
    2256         // Keep track of db writing calls.
    2257         $set_db_counts = 0;
    2258 
    2259         // Track db updates with calls to do_action( "update_user_meta", ... with 'use_ssl' meta key.
     2258        // Keep track of database writing calls.
     2259        $db_update_count = 0;
     2260
     2261        // Track database updates via update_user_meta() with 'use_ssl' meta key.
    22602262        add_action(
    22612263            'update_user_meta',
    2262             function ( $meta_id, $object_id, $meta_key ) use ( &$set_db_counts ) {
     2264            function ( $meta_id, $object_id, $meta_key ) use ( &$db_update_count ) {
    22632265                if ( 'use_ssl' !== $meta_key ) {
    22642266                    return;
    22652267                }
    2266                 $set_db_counts++;
     2268                $db_update_count++;
    22672269            },
    22682270            10,
     
    22792281
    22802282        $this->assertIsInt( $user_id );
    2281         $this->assertEquals( 1, $set_db_counts );
     2283        $this->assertSame( 1, $db_update_count );
    22822284
    22832285        // Update the user without changing the 'use_ssl' meta.
     
    22852287        $user_id        = edit_user( $user_id );
    22862288
    2287         // Verify there are no updates to use_ssl user meta.
    2288         $this->assertEquals( 1, $set_db_counts );
     2289        // Verify there are no updates to 'use_ssl' user meta.
     2290        $this->assertSame( 1, $db_update_count );
    22892291    }
    22902292}
Note: See TracChangeset for help on using the changeset viewer.