Make WordPress Core


Ignore:
Timestamp:
05/26/2025 02:34:12 PM (10 months ago)
Author:
johnbillion
Message:

Build/Test Tools: Increase shared user fixtures following switch to bcrypt hashing.

User creation is somewhat more expensive since switching the default password hashing algorithm to bcrypt in 6.8. This speeds up the tests by making more use of shared user fixtures, thus reducing the number of users that are created during tests.

Props peterwilsoncc.

See #63026

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/comment/wpHandleCommentSubmission.php

    r59319 r60253  
    1010    protected static $post;
    1111    protected static $author_id;
     12    protected static $author_id2;
    1213    protected static $editor_id;
    1314
     
    2021            array(
    2122                'role' => 'author',
     23            )
     24        );
     25
     26        self::$author_id2 = $factory->user->create(
     27            array(
     28                'role'     => 'author',
     29                'user_url' => 'http://user.example.org',
    2230            )
    2331        );
     
    224232    public function test_submitting_valid_comment_as_logged_in_user_succeeds() {
    225233
    226         $user = self::factory()->user->create_and_get(
    227             array(
    228                 'user_url' => 'http://user.example.org',
    229             )
    230         );
     234        $user = get_user_by( 'id', self::$author_id2 );
    231235
    232236        wp_set_current_user( $user->ID );
     
    315319        $error = 'comment_id_not_found';
    316320
    317         $user = self::factory()->user->create_and_get(
    318             array(
    319                 'role' => 'author',
    320             )
    321         );
     321        $user = get_user_by( 'id', self::$author_id2 );
    322322
    323323        wp_set_current_user( $user->ID );
     
    344344        $error = 'comment_id_not_found';
    345345
    346         $user = self::factory()->user->create_and_get(
    347             array(
    348                 'role' => 'author',
    349             )
    350         );
     346        $user = get_user_by( 'id', self::$author_id2 );
    351347
    352348        wp_set_current_user( $user->ID );
     
    835831     * @ticket 36901
    836832     */
    837     public function test_comments_flood_user_is_admin() {
    838         $user = self::factory()->user->create_and_get(
    839             array(
    840                 'role' => 'administrator',
    841             )
    842         );
     833    public function test_comments_flood_user_can_moderate_comments() {
     834        $user = get_user_by( 'id', self::$editor_id );
    843835        wp_set_current_user( $user->ID );
    844836
     
    854846        $second_comment  = wp_handle_comment_submission( $data );
    855847
    856         $this->assertNotWPError( $second_comment );
    857         $this->assertSame( (string) self::$post->ID, $second_comment->comment_post_ID );
     848        $this->assertTrue( current_user_can( 'moderate_comments' ), 'Test user should have the moderate_comments capability' );
     849        $this->assertNotWPError( $second_comment, 'Second comment should not trigger comment flooding error.' );
     850        $this->assertSame( (string) self::$post->ID, $second_comment->comment_post_ID, 'Second comment should be made against initial post.' );
    858851    }
    859852
Note: See TracChangeset for help on using the changeset viewer.