Make WordPress Core

Changeset 53701


Ignore:
Timestamp:
07/14/2022 02:26:37 PM (11 months ago)
Author:
SergeyBiryukov
Message:

Tests: Use a consistent way of setting the Administrator role in Ajax tests.

This removes some duplicate code in favor of calling the WP_Ajax_UnitTestCase::_setRole() method created specifically for this purpose and used in other tests.

Follow-up to [500/tests], [37288].

Props martin.krcho.
See #56203.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/ajax/Attachments.php

    r53561 r53701  
    1919    public function test_wp_ajax_send_attachment_to_editor_should_return_an_image() {
    2020        // Become an administrator.
    21         $post    = $_POST;
    22         $user_id = self::factory()->user->create(
    23             array(
    24                 'role'       => 'administrator',
    25                 'user_login' => 'user_36578_administrator',
    26                 'user_email' => 'user_36578_administrator@example.com',
    27             )
    28         );
    29         wp_set_current_user( $user_id );
    30         $_POST = array_merge( $_POST, $post );
     21        $this->_setRole( 'administrator' );
    3122
    3223        $filename = DIR_TESTDATA . '/images/canola.jpg';
     
    7566
    7667        // Become an administrator.
    77         $post    = $_POST;
    78         $user_id = self::factory()->user->create(
    79             array(
    80                 'role'       => 'administrator',
    81                 'user_login' => 'user_36578_administrator',
    82                 'user_email' => 'user_36578_administrator@example.com',
    83             )
    84         );
    85         wp_set_current_user( $user_id );
    86         $_POST = array_merge( $_POST, $post );
     68        $this->_setRole( 'administrator' );
    8769
    8870        $filename = DIR_TESTDATA . '/formatting/entities.txt';
Note: See TracChangeset for help on using the changeset viewer.