From 27cfc58b343ce3dd49498cd6d91cafb5d7db77f6 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Thu, 14 Jul 2022 14:26:37 +0000 Subject: [PATCH] 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. git-svn-id: https://develop.svn.wordpress.org/trunk@53701 602fd350-edb4-49c9-b593-d223f7449a82 --- tests/phpunit/tests/ajax/Attachments.php | 22 ++-------------------- 1 file changed, 2 insertions(+), 20 deletions(-) diff --git a/tests/phpunit/tests/ajax/Attachments.php b/tests/phpunit/tests/ajax/Attachments.php index baf7c7f4fc..91d6943c99 100644 --- a/tests/phpunit/tests/ajax/Attachments.php +++ b/tests/phpunit/tests/ajax/Attachments.php @@ -18,16 +18,7 @@ class Tests_Ajax_Attachments extends WP_Ajax_UnitTestCase { */ public function test_wp_ajax_send_attachment_to_editor_should_return_an_image() { // Become an administrator. - $post = $_POST; - $user_id = self::factory()->user->create( - array( - 'role' => 'administrator', - 'user_login' => 'user_36578_administrator', - 'user_email' => 'user_36578_administrator@example.com', - ) - ); - wp_set_current_user( $user_id ); - $_POST = array_merge( $_POST, $post ); + $this->_setRole( 'administrator' ); $filename = DIR_TESTDATA . '/images/canola.jpg'; $contents = file_get_contents( $filename ); @@ -74,16 +65,7 @@ class Tests_Ajax_Attachments extends WP_Ajax_UnitTestCase { $this->skipWithMultisite(); // Become an administrator. - $post = $_POST; - $user_id = self::factory()->user->create( - array( - 'role' => 'administrator', - 'user_login' => 'user_36578_administrator', - 'user_email' => 'user_36578_administrator@example.com', - ) - ); - wp_set_current_user( $user_id ); - $_POST = array_merge( $_POST, $post ); + $this->_setRole( 'administrator' ); $filename = DIR_TESTDATA . '/formatting/entities.txt'; $contents = file_get_contents( $filename );