Skip to content

Commit 27cfc58

Browse files
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
1 parent 0c41143 commit 27cfc58

File tree

1 file changed

+2
-20
lines changed

1 file changed

+2
-20
lines changed

tests/phpunit/tests/ajax/Attachments.php

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,7 @@ class Tests_Ajax_Attachments extends WP_Ajax_UnitTestCase {
1818
*/
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' => '[email protected]',
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';
3324
$contents = file_get_contents( $filename );
@@ -74,16 +65,7 @@ public function test_wp_ajax_send_attachment_to_editor_should_return_a_link() {
7465
$this->skipWithMultisite();
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' => '[email protected]',
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';
8971
$contents = file_get_contents( $filename );

0 commit comments

Comments
 (0)