Tests: Use the factory method instead of the property.

This replaces all references to the `WP_UnitTestCase_Base::$factory` property with static function calls to the `WP_UnitTestCase_Base::factory()` method.

This is a consistency improvement for the test suite.

Follow up to [35225], [35242], [49603], [54087], [54088].

Props jrf.
See #55652.

git-svn-id: https://develop.svn.wordpress.org/trunk@54090 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Sergey Biryukov
2022-09-06 22:09:49 +00:00
parent 563e24ced1
commit ff56396bf3
52 changed files with 598 additions and 598 deletions

View File

@@ -185,7 +185,7 @@ class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control
$this->assertSame( 'view', $data['endpoints'][0]['args']['context']['default'] );
$this->assertSame( array( 'view', 'embed', 'edit' ), $data['endpoints'][0]['args']['context']['enum'] );
// Single.
$attachment_id = $this->factory->attachment->create_object(
$attachment_id = self::factory()->attachment->create_object(
$this->test_file,
0,
array(
@@ -246,7 +246,7 @@ class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control
}
public function test_registered_get_item_params() {
$id1 = $this->factory->attachment->create_object(
$id1 = self::factory()->attachment->create_object(
$this->test_file,
0,
array(
@@ -266,7 +266,7 @@ class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control
* @ticket 43701
*/
public function test_allow_header_sent_on_options_request() {
$id1 = $this->factory->attachment->create_object(
$id1 = self::factory()->attachment->create_object(
$this->test_file,
0,
array(
@@ -294,7 +294,7 @@ class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control
public function test_get_items() {
wp_set_current_user( 0 );
$id1 = $this->factory->attachment->create_object(
$id1 = self::factory()->attachment->create_object(
$this->test_file,
0,
array(
@@ -302,8 +302,8 @@ class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control
'post_excerpt' => 'A sample caption',
)
);
$draft_post = $this->factory->post->create( array( 'post_status' => 'draft' ) );
$id2 = $this->factory->attachment->create_object(
$draft_post = self::factory()->post->create( array( 'post_status' => 'draft' ) );
$id2 = self::factory()->attachment->create_object(
$this->test_file,
$draft_post,
array(
@@ -311,8 +311,8 @@ class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control
'post_excerpt' => 'A sample caption',
)
);
$published_post = $this->factory->post->create( array( 'post_status' => 'publish' ) );
$id3 = $this->factory->attachment->create_object(
$published_post = self::factory()->post->create( array( 'post_status' => 'publish' ) );
$id3 = self::factory()->attachment->create_object(
$this->test_file,
$published_post,
array(
@@ -334,7 +334,7 @@ class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control
public function test_get_items_logged_in_editor() {
wp_set_current_user( self::$editor_id );
$id1 = $this->factory->attachment->create_object(
$id1 = self::factory()->attachment->create_object(
$this->test_file,
0,
array(
@@ -342,8 +342,8 @@ class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control
'post_excerpt' => 'A sample caption',
)
);
$draft_post = $this->factory->post->create( array( 'post_status' => 'draft' ) );
$id2 = $this->factory->attachment->create_object(
$draft_post = self::factory()->post->create( array( 'post_status' => 'draft' ) );
$id2 = self::factory()->attachment->create_object(
$this->test_file,
$draft_post,
array(
@@ -351,8 +351,8 @@ class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control
'post_excerpt' => 'A sample caption',
)
);
$published_post = $this->factory->post->create( array( 'post_status' => 'publish' ) );
$id3 = $this->factory->attachment->create_object(
$published_post = self::factory()->post->create( array( 'post_status' => 'publish' ) );
$id3 = self::factory()->attachment->create_object(
$this->test_file,
$published_post,
array(
@@ -372,7 +372,7 @@ class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control
}
public function test_get_items_media_type() {
$id1 = $this->factory->attachment->create_object(
$id1 = self::factory()->attachment->create_object(
$this->test_file,
0,
array(
@@ -395,7 +395,7 @@ class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control
}
public function test_get_items_mime_type() {
$id1 = $this->factory->attachment->create_object(
$id1 = self::factory()->attachment->create_object(
$this->test_file,
0,
array(
@@ -418,8 +418,8 @@ class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control
}
public function test_get_items_parent() {
$post_id = $this->factory->post->create( array( 'post_title' => 'Test Post' ) );
$attachment_id = $this->factory->attachment->create_object(
$post_id = self::factory()->post->create( array( 'post_title' => 'Test Post' ) );
$attachment_id = self::factory()->attachment->create_object(
$this->test_file,
$post_id,
array(
@@ -427,7 +427,7 @@ class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control
'post_excerpt' => 'A sample caption',
)
);
$attachment_id2 = $this->factory->attachment->create_object(
$attachment_id2 = self::factory()->attachment->create_object(
$this->test_file,
0,
array(
@@ -463,7 +463,7 @@ class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control
public function test_get_items_invalid_status_param_is_error_response() {
wp_set_current_user( self::$editor_id );
$this->factory->attachment->create_object(
self::factory()->attachment->create_object(
$this->test_file,
0,
array(
@@ -481,7 +481,7 @@ class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control
public function test_get_items_private_status() {
// Logged out users can't make the request.
wp_set_current_user( 0 );
$attachment_id1 = $this->factory->attachment->create_object(
$attachment_id1 = self::factory()->attachment->create_object(
$this->test_file,
0,
array(
@@ -505,7 +505,7 @@ class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control
public function test_get_items_multiple_statuses() {
// Logged out users can't make the request.
wp_set_current_user( 0 );
$attachment_id1 = $this->factory->attachment->create_object(
$attachment_id1 = self::factory()->attachment->create_object(
$this->test_file,
0,
array(
@@ -514,7 +514,7 @@ class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control
'post_status' => 'private',
)
);
$attachment_id2 = $this->factory->attachment->create_object(
$attachment_id2 = self::factory()->attachment->create_object(
$this->test_file,
0,
array(
@@ -550,7 +550,7 @@ class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control
}
public function test_get_items_valid_date() {
$id1 = $this->factory->attachment->create_object(
$id1 = self::factory()->attachment->create_object(
$this->test_file,
0,
array(
@@ -559,7 +559,7 @@ class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control
'post_excerpt' => 'A sample caption',
)
);
$id2 = $this->factory->attachment->create_object(
$id2 = self::factory()->attachment->create_object(
$this->test_file,
0,
array(
@@ -568,7 +568,7 @@ class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control
'post_excerpt' => 'A sample caption',
)
);
$id3 = $this->factory->attachment->create_object(
$id3 = self::factory()->attachment->create_object(
$this->test_file,
0,
array(
@@ -601,7 +601,7 @@ class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control
* @ticket 50617
*/
public function test_get_items_valid_modified_date() {
$id1 = $this->factory->attachment->create_object(
$id1 = self::factory()->attachment->create_object(
$this->test_file,
0,
array(
@@ -610,7 +610,7 @@ class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control
'post_excerpt' => 'A sample caption',
)
);
$id2 = $this->factory->attachment->create_object(
$id2 = self::factory()->attachment->create_object(
$this->test_file,
0,
array(
@@ -619,7 +619,7 @@ class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control
'post_excerpt' => 'A sample caption',
)
);
$id3 = $this->factory->attachment->create_object(
$id3 = self::factory()->attachment->create_object(
$this->test_file,
0,
array(
@@ -661,7 +661,7 @@ class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control
* @ticket 55677
*/
public function test_get_items_with_empty_page_runs_count_query_after() {
$this->factory->attachment->create_object(
self::factory()->attachment->create_object(
$this->test_file,
0,
array(
@@ -683,7 +683,7 @@ class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control
}
public function test_get_item() {
$attachment_id = $this->factory->attachment->create_object(
$attachment_id = self::factory()->attachment->create_object(
$this->test_file,
0,
array(
@@ -703,7 +703,7 @@ class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control
* @requires function imagejpeg
*/
public function test_get_item_sizes() {
$attachment_id = $this->factory->attachment->create_object(
$attachment_id = self::factory()->attachment->create_object(
$this->test_file,
0,
array(
@@ -734,7 +734,7 @@ class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control
* @requires function imagejpeg
*/
public function test_get_item_sizes_with_no_url() {
$attachment_id = $this->factory->attachment->create_object(
$attachment_id = self::factory()->attachment->create_object(
$this->test_file,
0,
array(
@@ -761,8 +761,8 @@ class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control
public function test_get_item_private_post_not_authenticated() {
wp_set_current_user( 0 );
$draft_post = $this->factory->post->create( array( 'post_status' => 'draft' ) );
$id1 = $this->factory->attachment->create_object(
$draft_post = self::factory()->post->create( array( 'post_status' => 'draft' ) );
$id1 = self::factory()->attachment->create_object(
$this->test_file,
$draft_post,
array(
@@ -776,7 +776,7 @@ class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control
}
public function test_get_item_inherit_status_with_invalid_parent() {
$attachment_id = $this->factory->attachment->create_object(
$attachment_id = self::factory()->attachment->create_object(
$this->test_file,
REST_TESTS_IMPOSSIBLY_HIGH_NUMBER,
array(
@@ -793,7 +793,7 @@ class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control
}
public function test_get_item_auto_status_with_invalid_parent_not_authenticated_returns_error() {
$attachment_id = $this->factory->attachment->create_object(
$attachment_id = self::factory()->attachment->create_object(
$this->test_file,
REST_TESTS_IMPOSSIBLY_HIGH_NUMBER,
array(
@@ -963,7 +963,7 @@ class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control
}
public function test_create_item_invalid_edit_permissions() {
$post_id = $this->factory->post->create( array( 'post_author' => self::$editor_id ) );
$post_id = self::factory()->post->create( array( 'post_author' => self::$editor_id ) );
wp_set_current_user( self::$author_id );
$request = new WP_REST_Request( 'POST', '/wp/v2/media' );
$request->set_param( 'post', $post_id );
@@ -972,7 +972,7 @@ class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control
}
public function test_create_item_invalid_upload_permissions() {
$post_id = $this->factory->post->create( array( 'post_author' => self::$editor_id ) );
$post_id = self::factory()->post->create( array( 'post_author' => self::$editor_id ) );
wp_set_current_user( self::$uploader_id );
$request = new WP_REST_Request( 'POST', '/wp/v2/media' );
$request->set_param( 'post', $post_id );
@@ -981,7 +981,7 @@ class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control
}
public function test_create_item_invalid_post_type() {
$attachment_id = $this->factory->post->create(
$attachment_id = self::factory()->post->create(
array(
'post_type' => 'attachment',
'post_status' => 'inherit',
@@ -1046,7 +1046,7 @@ class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control
public function test_update_item() {
wp_set_current_user( self::$editor_id );
$attachment_id = $this->factory->attachment->create_object(
$attachment_id = self::factory()->attachment->create_object(
$this->test_file,
0,
array(
@@ -1075,8 +1075,8 @@ class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control
public function test_update_item_parent() {
wp_set_current_user( self::$editor_id );
$original_parent = $this->factory->post->create( array() );
$attachment_id = $this->factory->attachment->create_object(
$original_parent = self::factory()->post->create( array() );
$attachment_id = self::factory()->attachment->create_object(
$this->test_file,
$original_parent,
array(
@@ -1089,7 +1089,7 @@ class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control
$attachment = get_post( $attachment_id );
$this->assertSame( $original_parent, $attachment->post_parent );
$new_parent = $this->factory->post->create( array() );
$new_parent = self::factory()->post->create( array() );
$request = new WP_REST_Request( 'POST', '/wp/v2/media/' . $attachment_id );
$request->set_param( 'post', $new_parent );
rest_get_server()->dispatch( $request );
@@ -1100,7 +1100,7 @@ class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control
public function test_update_item_invalid_permissions() {
wp_set_current_user( self::$author_id );
$attachment_id = $this->factory->attachment->create_object(
$attachment_id = self::factory()->attachment->create_object(
$this->test_file,
0,
array(
@@ -1116,7 +1116,7 @@ class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control
}
public function test_update_item_invalid_post_type() {
$attachment_id = $this->factory->post->create(
$attachment_id = self::factory()->post->create(
array(
'post_type' => 'attachment',
'post_status' => 'inherit',
@@ -1124,7 +1124,7 @@ class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control
)
);
wp_set_current_user( self::$editor_id );
$attachment_id = $this->factory->attachment->create_object(
$attachment_id = self::factory()->attachment->create_object(
$this->test_file,
0,
array(
@@ -1448,7 +1448,7 @@ class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control
public function test_delete_item() {
wp_set_current_user( self::$editor_id );
$attachment_id = $this->factory->attachment->create_object(
$attachment_id = self::factory()->attachment->create_object(
$this->test_file,
0,
array(
@@ -1464,7 +1464,7 @@ class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control
public function test_delete_item_no_trash() {
wp_set_current_user( self::$editor_id );
$attachment_id = $this->factory->attachment->create_object(
$attachment_id = self::factory()->attachment->create_object(
$this->test_file,
0,
array(
@@ -1489,7 +1489,7 @@ class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control
public function test_delete_item_invalid_delete_permissions() {
wp_set_current_user( self::$author_id );
$attachment_id = $this->factory->attachment->create_object(
$attachment_id = self::factory()->attachment->create_object(
$this->test_file,
0,
array(
@@ -1504,7 +1504,7 @@ class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control
}
public function test_prepare_item() {
$attachment_id = $this->factory->attachment->create_object(
$attachment_id = self::factory()->attachment->create_object(
$this->test_file,
0,
array(
@@ -1523,7 +1523,7 @@ class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control
}
public function test_prepare_item_limit_fields() {
$attachment_id = $this->factory->attachment->create_object(
$attachment_id = self::factory()->attachment->create_object(
$this->test_file,
0,
array(
@@ -1614,7 +1614,7 @@ class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control
$this->assertArrayHasKey( 'my_custom_int', $data['schema']['properties'] );
$this->assertSame( $schema, $data['schema']['properties']['my_custom_int'] );
$attachment_id = $this->factory->attachment->create_object(
$attachment_id = self::factory()->attachment->create_object(
$this->test_file,
0,
array(
@@ -1651,7 +1651,7 @@ class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control
);
wp_set_current_user( self::$editor_id );
$attachment_id = $this->factory->attachment->create_object(
$attachment_id = self::factory()->attachment->create_object(
$this->test_file,
0,
array(
@@ -1677,14 +1677,14 @@ class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control
}
public function test_search_item_by_filename() {
$id1 = $this->factory->attachment->create_object(
$id1 = self::factory()->attachment->create_object(
$this->test_file,
0,
array(
'post_mime_type' => 'image/jpeg',
)
);
$id2 = $this->factory->attachment->create_object(
$id2 = self::factory()->attachment->create_object(
$this->test_file2,
0,
array(
@@ -1935,7 +1935,7 @@ class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control
add_action( 'rest_after_insert_attachment', array( $this, 'filter_rest_after_insert_attachment' ) );
wp_set_current_user( self::$editor_id );
$attachment_id = $this->factory->attachment->create_object(
$attachment_id = self::factory()->attachment->create_object(
$this->test_file,
0,
array(