diff --git a/tests/phpunit/tests/admin/includesScreen.php b/tests/phpunit/tests/admin/includesScreen.php index a5750fd5bd9cd..4b4ba86c5c7d6 100644 --- a/tests/phpunit/tests/admin/includesScreen.php +++ b/tests/phpunit/tests/admin/includesScreen.php @@ -495,7 +495,7 @@ public function setup_block_editor_test( $hook = 'post.php' ) { $GLOBALS['hook_suffix'] = $hook; if ( 'post.php' === $hook ) { - $post_id = $this->factory->post->create( + $post_id = self::factory()->post->create( array( 'post_type' => 'type_shows_in_rest', ) diff --git a/tests/phpunit/tests/admin/includesTheme.php b/tests/phpunit/tests/admin/includesTheme.php index 00b9501dcdb0f..9f2fdbc085386 100644 --- a/tests/phpunit/tests/admin/includesTheme.php +++ b/tests/phpunit/tests/admin/includesTheme.php @@ -230,7 +230,7 @@ public function test_get_post_templates_child_theme() { * @ticket 28121 */ public function test_get_theme_featured_list_api() { - wp_set_current_user( $this->factory->user->create( array( 'role' => 'administrator' ) ) ); + wp_set_current_user( self::factory()->user->create( array( 'role' => 'administrator' ) ) ); $featured_list_api = get_theme_feature_list( true ); $this->assertNonEmptyMultidimensionalArray( $featured_list_api ); } diff --git a/tests/phpunit/tests/auth.php b/tests/phpunit/tests/auth.php index 25813124159b6..2198fadcd0ddb 100644 --- a/tests/phpunit/tests/auth.php +++ b/tests/phpunit/tests/auth.php @@ -407,7 +407,7 @@ public function test_log_in_using_email() { 'user_email' => 'mail@example.com', 'user_pass' => 'password', ); - $this->factory->user->create( $user_args ); + self::factory()->user->create( $user_args ); $this->assertInstanceOf( 'WP_User', wp_authenticate( $user_args['user_email'], $user_args['user_pass'] ) ); $this->assertInstanceOf( 'WP_User', wp_authenticate( $user_args['user_login'], $user_args['user_pass'] ) ); diff --git a/tests/phpunit/tests/category/walkerCategory.php b/tests/phpunit/tests/category/walkerCategory.php index 4e711c4f23c6f..2728b11131168 100644 --- a/tests/phpunit/tests/category/walkerCategory.php +++ b/tests/phpunit/tests/category/walkerCategory.php @@ -30,7 +30,7 @@ public function set_up() { */ public function test_start_el_with_empty_attributes( $value, $expected ) { $output = ''; - $category = $this->factory->category->create_and_get(); + $category = self::factory()->category->create_and_get(); $link = get_term_link( $category ); $args = array( diff --git a/tests/phpunit/tests/comment.php b/tests/phpunit/tests/comment.php index a847784d87917..9683110030418 100644 --- a/tests/phpunit/tests/comment.php +++ b/tests/phpunit/tests/comment.php @@ -720,13 +720,13 @@ public function setup_notify_comment() { /** * Set up a comment for testing. */ - $post = $this->factory->post->create( + $post = self::factory()->post->create( array( 'post_author' => self::$user_id, ) ); - $comment = $this->factory->comment->create( + $comment = self::factory()->comment->create( array( 'comment_post_ID' => $post, ) diff --git a/tests/phpunit/tests/comment/checkComment.php b/tests/phpunit/tests/comment/checkComment.php index 0f02b63dbfe93..5efcf9acceedb 100644 --- a/tests/phpunit/tests/comment/checkComment.php +++ b/tests/phpunit/tests/comment/checkComment.php @@ -146,7 +146,7 @@ public function test_should_return_true_when_comment_previously_approved_is_enab ); // Make sure comment author has an approved comment. - $this->factory->comment->create( + self::factory()->comment->create( array( 'user_id' => $subscriber_id, 'comment_approved' => '1', diff --git a/tests/phpunit/tests/comment/commentsOpen.php b/tests/phpunit/tests/comment/commentsOpen.php index 54e08ea8ed1d5..7549498e900f6 100644 --- a/tests/phpunit/tests/comment/commentsOpen.php +++ b/tests/phpunit/tests/comment/commentsOpen.php @@ -17,7 +17,7 @@ public function test_post_does_not_exist() { * @ticket 54159 */ public function test_post_exist_status_open() { - $post = $this->factory->post->create_and_get(); + $post = self::factory()->post->create_and_get(); $this->assertTrue( comments_open( $post ) ); } @@ -25,7 +25,7 @@ public function test_post_exist_status_open() { * @ticket 54159 */ public function test_post_exist_status_closed() { - $post = $this->factory->post->create_and_get(); + $post = self::factory()->post->create_and_get(); $post->comment_status = 'closed'; $this->assertFalse( comments_open( $post ) ); diff --git a/tests/phpunit/tests/comment/pingsOpen.php b/tests/phpunit/tests/comment/pingsOpen.php index 2ef7029804c8e..93a25d5a73e9d 100644 --- a/tests/phpunit/tests/comment/pingsOpen.php +++ b/tests/phpunit/tests/comment/pingsOpen.php @@ -17,7 +17,7 @@ public function test_post_does_not_exist() { * @ticket 54159 */ public function test_post_exist_status_open() { - $post = $this->factory->post->create_and_get(); + $post = self::factory()->post->create_and_get(); $this->assertTrue( pings_open( $post ) ); } @@ -25,7 +25,7 @@ public function test_post_exist_status_open() { * @ticket 54159 */ public function test_post_exist_status_closed() { - $post = $this->factory->post->create_and_get(); + $post = self::factory()->post->create_and_get(); $post->ping_status = 'closed'; $this->assertFalse( pings_open( $post ) ); diff --git a/tests/phpunit/tests/comment/template.php b/tests/phpunit/tests/comment/template.php index 7cb089d54a971..0632a22863279 100644 --- a/tests/phpunit/tests/comment/template.php +++ b/tests/phpunit/tests/comment/template.php @@ -58,7 +58,7 @@ public function test_get_comments_number_without_arg() { */ public function test_get_comments_number_text_with_post_id() { $post_id = self::$post_id; - $this->factory->comment->create_post_comments( $post_id, 6 ); + self::factory()->comment->create_post_comments( $post_id, 6 ); $comments_number_text = get_comments_number_text( false, false, false, $post_id ); @@ -84,12 +84,12 @@ public function test_get_comments_number_text_declension_with_default_args() { $this->assertSame( __( 'No Comments' ), get_comments_number_text() ); - $this->factory->comment->create_post_comments( $post_id, 1 ); + self::factory()->comment->create_post_comments( $post_id, 1 ); $this->go_to( $permalink ); $this->assertSame( __( '1 Comment' ), get_comments_number_text() ); - $this->factory->comment->create_post_comments( $post_id, 1 ); + self::factory()->comment->create_post_comments( $post_id, 1 ); $this->go_to( $permalink ); $this->assertSame( sprintf( _n( '%s Comment', '%s Comments', 2 ), '2' ), get_comments_number_text() ); @@ -106,7 +106,7 @@ public function test_get_comments_number_text_declension_with_custom_args( $numb $post_id = self::$post_id; $permalink = get_permalink( $post_id ); - $this->factory->comment->create_post_comments( $post_id, $number ); + self::factory()->comment->create_post_comments( $post_id, $number ); $this->go_to( $permalink ); add_filter( 'gettext_with_context', array( $this, 'enable_comment_number_declension' ), 10, 4 ); diff --git a/tests/phpunit/tests/customize/nav-menus.php b/tests/phpunit/tests/customize/nav-menus.php index 429afed1f7943..5785558103c95 100644 --- a/tests/phpunit/tests/customize/nav-menus.php +++ b/tests/phpunit/tests/customize/nav-menus.php @@ -417,7 +417,7 @@ public function test_search_available_items_query_should_return_unassigned_term_ ) ); - $term_id = $this->factory->term->create( + $term_id = self::factory()->term->create( array( 'taxonomy' => 'wptests_tax', 'name' => 'foobar', diff --git a/tests/phpunit/tests/date/getFeedBuildDate.php b/tests/phpunit/tests/date/getFeedBuildDate.php index 23d97aa4730a5..c1d9edb66cb98 100644 --- a/tests/phpunit/tests/date/getFeedBuildDate.php +++ b/tests/phpunit/tests/date/getFeedBuildDate.php @@ -55,7 +55,7 @@ public function test_should_fall_back_to_last_post_modified() { $this->assertFalse( get_feed_build_date( DATE_RFC3339 ), 'False when unable to determine valid time' ); - $this->factory->post->create( + self::factory()->post->create( array( 'post_date' => $datetime->format( 'Y-m-d H:i:s' ), ) @@ -68,7 +68,7 @@ public function test_should_fall_back_to_last_post_modified() { 'Fall back to time of last post modified with no posts' ); - $post_id_broken = $this->factory->post->create(); + $post_id_broken = self::factory()->post->create(); $post_broken = get_post( $post_id_broken ); $post_broken->post_modified_gmt = 0; diff --git a/tests/phpunit/tests/date/getTheModifiedDate.php b/tests/phpunit/tests/date/getTheModifiedDate.php index 9b0dad77cf29d..7189a7282c669 100644 --- a/tests/phpunit/tests/date/getTheModifiedDate.php +++ b/tests/phpunit/tests/date/getTheModifiedDate.php @@ -20,7 +20,7 @@ public function test_get_the_modified_date_with_post_id() { 'post_date' => '2016-01-21 15:34:36', 'post_date_gmt' => '2016-01-21 15:34:36', ); - $post_id = $this->factory->post->create( $details ); + $post_id = self::factory()->post->create( $details ); $format = 'Y-m-d'; $expected = '2016-01-21'; $actual = get_the_modified_date( $format, $post_id ); @@ -39,7 +39,7 @@ public function test_get_the_modified_date_default() { 'post_date' => '2016-01-21 15:34:36', 'post_date_gmt' => '2016-01-21 15:34:36', ); - $post_id = $this->factory->post->create( $details ); + $post_id = self::factory()->post->create( $details ); $post = get_post( $post_id ); $GLOBALS['post'] = $post; @@ -111,7 +111,7 @@ public function test_get_the_modified_time_with_post_id() { 'post_date' => '2016-01-21 15:34:36', 'post_date_gmt' => '2016-01-21 15:34:36', ); - $post_id = $this->factory->post->create( $details ); + $post_id = self::factory()->post->create( $details ); $format = 'G'; $expected = 1453390476; $actual = get_the_modified_time( $format, $post_id ); @@ -130,7 +130,7 @@ public function test_get_the_modified_time_default() { 'post_date' => '2016-01-21 15:34:36', 'post_date_gmt' => '2016-01-21 15:34:36', ); - $post_id = $this->factory->post->create( $details ); + $post_id = self::factory()->post->create( $details ); $post = get_post( $post_id ); $GLOBALS['post'] = $post; diff --git a/tests/phpunit/tests/date/xmlrpc.php b/tests/phpunit/tests/date/xmlrpc.php index 8a4efaf46d2b6..6344265e1f98c 100644 --- a/tests/phpunit/tests/date/xmlrpc.php +++ b/tests/phpunit/tests/date/xmlrpc.php @@ -221,7 +221,7 @@ public function test_date_edit_comment() { $datetimeutc = $datetime->setTimezone( new DateTimeZone( 'UTC' ) ); $this->make_user_by_role( 'administrator' ); - $post_id = $this->factory->post->create(); + $post_id = self::factory()->post->create(); $comment_data = array( 'comment_post_ID' => $post_id, diff --git a/tests/phpunit/tests/general/template.php b/tests/phpunit/tests/general/template.php index 88c1092e0c6d3..8a29853526960 100644 --- a/tests/phpunit/tests/general/template.php +++ b/tests/phpunit/tests/general/template.php @@ -104,7 +104,7 @@ public function test_has_site_icon() { * @covers ::has_site_icon */ public function test_has_site_icon_returns_true_when_called_for_other_site_with_site_icon_set() { - $blog_id = $this->factory->blog->create(); + $blog_id = self::factory()->blog->create(); switch_to_blog( $blog_id ); $this->set_site_icon(); restore_current_blog(); @@ -119,7 +119,7 @@ public function test_has_site_icon_returns_true_when_called_for_other_site_with_ * @covers ::has_site_icon */ public function test_has_site_icon_returns_false_when_called_for_other_site_without_site_icon_set() { - $blog_id = $this->factory->blog->create(); + $blog_id = self::factory()->blog->create(); $this->assertFalse( has_site_icon( $blog_id ) ); } @@ -298,7 +298,7 @@ public function test_has_custom_logo() { * @covers ::has_custom_logo */ public function test_has_custom_logo_returns_true_when_called_for_other_site_with_custom_logo_set() { - $blog_id = $this->factory->blog->create(); + $blog_id = self::factory()->blog->create(); switch_to_blog( $blog_id ); $this->set_custom_logo(); restore_current_blog(); @@ -313,7 +313,7 @@ public function test_has_custom_logo_returns_true_when_called_for_other_site_wit * @covers ::has_custom_logo */ public function test_has_custom_logo_returns_false_when_called_for_other_site_without_custom_logo_set() { - $blog_id = $this->factory->blog->create(); + $blog_id = self::factory()->blog->create(); $this->assertFalse( has_custom_logo( $blog_id ) ); } @@ -343,7 +343,7 @@ public function test_get_custom_logo() { * @covers ::get_custom_logo */ public function test_get_custom_logo_returns_logo_when_called_for_other_site_with_custom_logo_set() { - $blog_id = $this->factory->blog->create(); + $blog_id = self::factory()->blog->create(); switch_to_blog( $blog_id ); $this->set_custom_logo(); @@ -466,7 +466,7 @@ private function insert_custom_logo() { * @covers ::get_site_icon_url */ public function test_get_site_icon_url_preserves_switched_state() { - $blog_id = $this->factory->blog->create(); + $blog_id = self::factory()->blog->create(); switch_to_blog( $blog_id ); $expected = $GLOBALS['_wp_switched_stack']; @@ -486,7 +486,7 @@ public function test_get_site_icon_url_preserves_switched_state() { * @covers ::has_custom_logo */ public function test_has_custom_logo_preserves_switched_state() { - $blog_id = $this->factory->blog->create(); + $blog_id = self::factory()->blog->create(); switch_to_blog( $blog_id ); $expected = $GLOBALS['_wp_switched_stack']; @@ -506,7 +506,7 @@ public function test_has_custom_logo_preserves_switched_state() { * @covers ::get_custom_logo */ public function test_get_custom_logo_preserves_switched_state() { - $blog_id = $this->factory->blog->create(); + $blog_id = self::factory()->blog->create(); switch_to_blog( $blog_id ); $expected = $GLOBALS['_wp_switched_stack']; diff --git a/tests/phpunit/tests/general/wpGetDocumentTitle.php b/tests/phpunit/tests/general/wpGetDocumentTitle.php index b7b82c7093416..b12990fd5c665 100644 --- a/tests/phpunit/tests/general/wpGetDocumentTitle.php +++ b/tests/phpunit/tests/general/wpGetDocumentTitle.php @@ -101,7 +101,7 @@ public function test_front_page_title() { update_option( 'show_on_front', 'page' ); update_option( 'page_on_front', - $this->factory->post->create( + self::factory()->post->create( array( 'post_title' => 'front-page', 'post_type' => 'page', @@ -128,7 +128,7 @@ public function front_page_title_parts( $parts ) { } public function test_home_title() { - $blog_page_id = $this->factory->post->create( + $blog_page_id = self::factory()->post->create( array( 'post_title' => 'blog-page', 'post_type' => 'page', @@ -205,7 +205,7 @@ public function test_post_type_archive_title() { ) ); - $this->factory->post->create( + self::factory()->post->create( array( 'post_type' => 'cpt', ) diff --git a/tests/phpunit/tests/image/functions.php b/tests/phpunit/tests/image/functions.php index 75e5514c8baef..98b2608c87abf 100644 --- a/tests/phpunit/tests/image/functions.php +++ b/tests/phpunit/tests/image/functions.php @@ -658,7 +658,7 @@ public function test_wp_generate_attachment_metadata_pdf() { $this->markTestSkipped( $editor->get_error_message() ); } - $attachment_id = $this->factory->attachment->create_object( + $attachment_id = self::factory()->attachment->create_object( $test_file, 0, array( @@ -735,7 +735,7 @@ public function test_crop_setting_for_pdf() { $this->markTestSkipped( $editor->get_error_message() ); } - $attachment_id = $this->factory->attachment->create_object( + $attachment_id = self::factory()->attachment->create_object( $test_file, 0, array( @@ -808,7 +808,7 @@ public function test_fallback_intermediate_image_sizes() { $this->markTestSkipped( $editor->get_error_message() ); } - $attachment_id = $this->factory->attachment->create_object( + $attachment_id = self::factory()->attachment->create_object( $test_file, 0, array( @@ -882,7 +882,7 @@ public function test_pdf_preview_doesnt_overwrite_existing_jpeg() { $this->markTestSkipped( $editor->get_error_message() ); } - $attachment_id = $this->factory->attachment->create_object( + $attachment_id = self::factory()->attachment->create_object( $pdf_path, 0, array( diff --git a/tests/phpunit/tests/link/getPostTypeArchiveLink.php b/tests/phpunit/tests/link/getPostTypeArchiveLink.php index e658b78725f67..7f3da3f30f66f 100644 --- a/tests/phpunit/tests/link/getPostTypeArchiveLink.php +++ b/tests/phpunit/tests/link/getPostTypeArchiveLink.php @@ -19,7 +19,7 @@ public function test_get_post_archive_link_with_post_archive_on_front_page() { * @ticket 19902 */ public function test_get_post_archive_link_with_post_archive_on_a_blog_page() { - $page_for_posts = $this->factory->post->create( + $page_for_posts = self::factory()->post->create( array( 'post_title' => 'blog-page', 'post_type' => 'page', diff --git a/tests/phpunit/tests/link/getThePrivacyPolicyLink.php b/tests/phpunit/tests/link/getThePrivacyPolicyLink.php index 97d321b805b9c..942ae20c41c89 100644 --- a/tests/phpunit/tests/link/getThePrivacyPolicyLink.php +++ b/tests/phpunit/tests/link/getThePrivacyPolicyLink.php @@ -115,7 +115,7 @@ public function test_get_the_privacy_policy_link_should_not_prepend_and_append_s * @ticket 44192 */ public function test_function_should_return_empty_string_when_privacy_page_title_empty() { - $nameless_page_id = $this->factory->post->create( + $nameless_page_id = self::factory()->post->create( array( 'post_type' => 'page', 'post_title' => '', diff --git a/tests/phpunit/tests/media/getPostGalleries.php b/tests/phpunit/tests/media/getPostGalleries.php index bc34ef02d0ec1..363fea8149603 100644 --- a/tests/phpunit/tests/media/getPostGalleries.php +++ b/tests/phpunit/tests/media/getPostGalleries.php @@ -28,7 +28,7 @@ public function test_returns_empty_array_with_non_existent_post() { * @ticket 43826 */ public function test_returns_empty_array_with_post_with_no_gallery() { - $post_id = $this->factory->post->create( + $post_id = self::factory()->post->create( array( 'post_content' => '

A post with no gallery

', ) @@ -49,7 +49,7 @@ public function test_returns_empty_array_with_post_with_no_gallery() { * @param string $needle The content of a non-gallery block. */ public function test_returns_only_galleries( $content, $needle ) { - $image_id = $this->factory->attachment->create_object( + $image_id = self::factory()->attachment->create_object( array( 'file' => 'test.jpg', 'post_parent' => 0, @@ -66,7 +66,7 @@ public function test_returns_only_galleries( $content, $needle ) { $content ); - $post_id = $this->factory->post->create( + $post_id = self::factory()->post->create( array( 'post_content' => $content, ) @@ -124,7 +124,7 @@ class="wp-image-IMAGE_ID" */ public function test_returns_no_srcs_with_shortcode_in_post_with_no_attached_images() { // Set up an unattached image. - $this->factory->attachment->create_object( + self::factory()->attachment->create_object( array( 'file' => 'test.jpg', 'post_parent' => 0, @@ -133,7 +133,7 @@ public function test_returns_no_srcs_with_shortcode_in_post_with_no_attached_ima ) ); - $post_id = $this->factory->post->create( + $post_id = self::factory()->post->create( array( 'post_content' => '[gallery]', ) @@ -173,7 +173,7 @@ public function test_returns_no_srcs_with_shortcode_in_post_with_no_attached_ima */ public function test_returns_no_srcs_with_block_in_post_with_no_attached_images() { // Set up an unattached image. - $this->factory->attachment->create_object( + self::factory()->attachment->create_object( array( 'file' => 'test.jpg', 'post_parent' => 0, @@ -182,7 +182,7 @@ public function test_returns_no_srcs_with_block_in_post_with_no_attached_images( ) ); - $post_id = $this->factory->post->create( + $post_id = self::factory()->post->create( array( 'post_content' => '', ) @@ -231,7 +231,7 @@ public function test_returns_no_srcs_with_block_in_post_with_no_attached_images( */ public function test_returns_no_srcs_with_block_v2_in_post_with_no_attached_images() { // Set up an unattached image. - $image_id = $this->factory->attachment->create_object( + $image_id = self::factory()->attachment->create_object( array( 'file' => 'test.jpg', 'post_parent' => 0, @@ -260,7 +260,7 @@ class="wp-image-$image_id" BLOB; - $post_id = $this->factory->post->create( + $post_id = self::factory()->post->create( array( 'post_content' => $blob, ) @@ -309,19 +309,19 @@ class="wp-image-$image_id" * @group shortcode */ public function test_returns_html_with_shortcode_gallery() { - $post_id = $this->factory->post->create( + $post_id = self::factory()->post->create( array( 'post_content' => 'I have no gallery', ) ); - $post_id_two = $this->factory->post->create( + $post_id_two = self::factory()->post->create( array( 'post_content' => "[gallery id='$post_id']", ) ); - $this->factory->attachment->create_object( + self::factory()->attachment->create_object( array( 'file' => 'test.jpg', 'post_parent' => $post_id, @@ -363,14 +363,14 @@ public function test_returns_html_with_shortcode_gallery() { * @group blocks */ public function test_returns_html_with_block_gallery() { - $post_id = $this->factory->post->create( + $post_id = self::factory()->post->create( array( 'post_content' => 'I have no gallery.', ) ); // Set up an unattached image. - $image_id = $this->factory->attachment->create( + $image_id = self::factory()->attachment->create( array( 'file' => 'test.jpg', 'post_parent' => $post_id, @@ -387,7 +387,7 @@ public function test_returns_html_with_block_gallery() { BLOB; - $post_id_two = $this->factory->post->create( + $post_id_two = self::factory()->post->create( array( 'post_content' => $blob, ) @@ -426,7 +426,7 @@ public function test_returns_html_with_block_gallery() { * @group blocks */ public function test_returns_html_with_block_gallery_v2() { - $image_id = $this->factory->attachment->create_object( + $image_id = self::factory()->attachment->create_object( array( 'file' => 'test.jpg', 'post_parent' => 0, @@ -455,7 +455,7 @@ class="wp-image-$image_id" BLOB; - $post_id = $this->factory->post->create( + $post_id = self::factory()->post->create( array( 'post_content' => $blob, ) @@ -495,17 +495,17 @@ class="wp-image-$image_id" * @group shortcode */ public function test_respects_post_id_with_shortcode_gallery() { - $global_post_id = $this->factory->post->create( + $global_post_id = self::factory()->post->create( array( 'post_content' => 'Global Post', ) ); - $post_id = $this->factory->post->create( + $post_id = self::factory()->post->create( array( 'post_content' => '[gallery]', ) ); - $this->factory->attachment->create_object( + self::factory()->attachment->create_object( array( 'file' => 'test.jpg', 'post_parent' => $post_id, @@ -577,7 +577,7 @@ public function test_respects_post_id_with_block_gallery() { $ids_joined = join( ',', $ids ); - $global_post_id = $this->factory->post->create( + $global_post_id = self::factory()->post->create( array( 'post_content' => 'Global Post', ) @@ -588,12 +588,12 @@ public function test_respects_post_id_with_block_gallery() { BLOB; - $post_id = $this->factory->post->create( + $post_id = self::factory()->post->create( array( 'post_content' => $blob, ) ); - $this->factory->attachment->create_object( + self::factory()->attachment->create_object( array( 'file' => 'test.jpg', 'post_parent' => $post_id, @@ -657,7 +657,7 @@ public function test_respects_post_id_with_block_gallery_v2() { ); $metadata = array_merge( array( 'file' => 'image1.jpg' ), self::IMG_META ); $url = 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/' . 'image1.jpg'; - $global_post_id = $this->factory->post->create( + $global_post_id = self::factory()->post->create( array( 'post_content' => 'Global Post', ) @@ -683,12 +683,12 @@ class="wp-image-$attachment_id" BLOB; - $post_id = $this->factory->post->create( + $post_id = self::factory()->post->create( array( 'post_content' => $blob, ) ); - $this->factory->attachment->create_object( + self::factory()->attachment->create_object( array( 'file' => 'test.jpg', 'post_parent' => $post_id, @@ -742,17 +742,17 @@ class="wp-image-$attachment_id" * @group shortcode */ public function test_respects_shortcode_id_attribute() { - $post_id = $this->factory->post->create( + $post_id = self::factory()->post->create( array( 'post_content' => 'No gallery defined', ) ); - $post_id_two = $this->factory->post->create( + $post_id_two = self::factory()->post->create( array( 'post_content' => "[gallery id='$post_id']", ) ); - $this->factory->attachment->create_object( + self::factory()->attachment->create_object( array( 'file' => 'test.jpg', 'post_parent' => $post_id, @@ -950,7 +950,7 @@ public function test_respects_additional_shortcode_and_block_attributes() { */ public function test_returns_srcs_from_html_with_block_with_no_json_blob() { // Set up an unattached image. - $image_id = $this->factory->attachment->create_object( + $image_id = self::factory()->attachment->create_object( array( 'file' => 'test.jpg', 'post_parent' => 0, @@ -972,7 +972,7 @@ public function test_returns_srcs_from_html_with_block_with_no_json_blob() { BLOB; - $post_id = $this->factory->post->create( + $post_id = self::factory()->post->create( array( 'post_content' => $blob, ) @@ -1022,12 +1022,12 @@ public function test_returns_srcs_from_html_with_block_with_no_json_blob() { * @group blocks */ public function test_returns_srcs_with_nested_block_gallery() { - $post_id = $this->factory->post->create( + $post_id = self::factory()->post->create( array( 'post_content' => 'I have no gallery.', ) ); - $image_id = $this->factory->attachment->create_object( + $image_id = self::factory()->attachment->create_object( array( 'file' => 'test.jpg', 'post_parent' => $post_id, @@ -1045,7 +1045,7 @@ public function test_returns_srcs_with_nested_block_gallery() { BLOB; - $post_id_two = $this->factory->post->create( array( 'post_content' => $blob ) ); + $post_id_two = self::factory()->post->create( array( 'post_content' => $blob ) ); $galleries = get_post_galleries( $post_id_two, false ); diff --git a/tests/phpunit/tests/menu/walker-nav-menu-edit.php b/tests/phpunit/tests/menu/walker-nav-menu-edit.php index 30ae8f81b0a31..0df5531975652 100644 --- a/tests/phpunit/tests/menu/walker-nav-menu-edit.php +++ b/tests/phpunit/tests/menu/walker-nav-menu-edit.php @@ -40,7 +40,7 @@ public function tear_down() { public function test_original_title_prefix_should_not_be_shown_if_empty() { $expected = ''; - $post_id = $this->factory->post->create(); + $post_id = self::factory()->post->create(); $item = array( 'classes' => array(), diff --git a/tests/phpunit/tests/menu/walker-nav-menu.php b/tests/phpunit/tests/menu/walker-nav-menu.php index f530d43e1056f..1dda827c1e0cc 100644 --- a/tests/phpunit/tests/menu/walker-nav-menu.php +++ b/tests/phpunit/tests/menu/walker-nav-menu.php @@ -49,7 +49,7 @@ public function tear_down() { */ public function test_noopener_no_referrer_for_target_blank() { $actual = ''; - $post_id = $this->factory->post->create(); + $post_id = self::factory()->post->create(); $post_title = get_the_title( $post_id ); $item = array( @@ -80,7 +80,7 @@ public function test_noopener_no_referrer_for_target_blank() { */ public function test_start_el_with_empty_attributes( $value, $expected ) { $output = ''; - $post_id = $this->factory->post->create(); + $post_id = self::factory()->post->create(); $post_title = get_the_title( $post_id ); $item = array( diff --git a/tests/phpunit/tests/menu/wpAjaxMenuQuickSearch.php b/tests/phpunit/tests/menu/wpAjaxMenuQuickSearch.php index 232b729c231d2..9fceb5fc955b2 100644 --- a/tests/phpunit/tests/menu/wpAjaxMenuQuickSearch.php +++ b/tests/phpunit/tests/menu/wpAjaxMenuQuickSearch.php @@ -104,7 +104,7 @@ public function test_search_returns_results_for_published_posts() { public function test_search_should_return_unassigned_term_items() { register_taxonomy( 'wptests_tax', 'post' ); - $this->factory->term->create( + self::factory()->term->create( array( 'taxonomy' => 'wptests_tax', 'name' => 'foobar', diff --git a/tests/phpunit/tests/multisite/wpInstallDefaults.php b/tests/phpunit/tests/multisite/wpInstallDefaults.php index c48a832a05cdc..cb05566a37d60 100644 --- a/tests/phpunit/tests/multisite/wpInstallDefaults.php +++ b/tests/phpunit/tests/multisite/wpInstallDefaults.php @@ -13,7 +13,7 @@ class Tests_Multisite_wpInstallDefaults extends WP_UnitTestCase { * @ticket 40036 */ public function test_option_should_not_be_empty_by_default() { - $blog_id = $this->factory->blog->create(); + $blog_id = self::factory()->blog->create(); switch_to_blog( $blog_id ); @@ -39,7 +39,7 @@ public function test_empty_option_should_fall_back_to_default() { update_site_option( 'first_page', '' ); update_site_option( 'first_comment', '' ); - $blog_id = $this->factory->blog->create(); + $blog_id = self::factory()->blog->create(); switch_to_blog( $blog_id ); @@ -65,7 +65,7 @@ public function test_non_default_option_values() { update_site_option( 'first_page', 'Some page content' ); update_site_option( 'first_comment', 'Some comment content' ); - $blog_id = $this->factory->blog->create(); + $blog_id = self::factory()->blog->create(); switch_to_blog( $blog_id ); diff --git a/tests/phpunit/tests/post.php b/tests/phpunit/tests/post.php index 9e204804e6873..6f07ca859364c 100644 --- a/tests/phpunit/tests/post.php +++ b/tests/phpunit/tests/post.php @@ -454,7 +454,7 @@ public function test_wp_delete_post_reassign_hierarchical_post_type() { public function test_pre_wp_unique_post_slug_filter() { add_filter( 'pre_wp_unique_post_slug', array( $this, 'filter_pre_wp_unique_post_slug' ), 10, 6 ); - $post_id = $this->factory->post->create( + $post_id = self::factory()->post->create( array( 'title' => 'An example', 'post_status' => 'publish', diff --git a/tests/phpunit/tests/post/walkerPage.php b/tests/phpunit/tests/post/walkerPage.php index 6b71bb021667b..a5a632dcdaa85 100644 --- a/tests/phpunit/tests/post/walkerPage.php +++ b/tests/phpunit/tests/post/walkerPage.php @@ -28,7 +28,7 @@ public function set_up() { */ public function test_start_el_with_empty_attributes( $value, $expected ) { $output = ''; - $page = $this->factory->post->create_and_get( array( 'post_type' => 'page' ) ); + $page = self::factory()->post->create_and_get( array( 'post_type' => 'page' ) ); $link = get_permalink( $page ); add_filter( diff --git a/tests/phpunit/tests/post/wpPublishPost.php b/tests/phpunit/tests/post/wpPublishPost.php index a8c0227b0ced2..25fa87a71c91d 100644 --- a/tests/phpunit/tests/post/wpPublishPost.php +++ b/tests/phpunit/tests/post/wpPublishPost.php @@ -142,7 +142,7 @@ public function test_wp_publish_post_and_avoid_content_filtering() { */ public function test_wp_publish_post_respects_current_categories() { $post_id = self::$auto_draft_id; - $category_id = $this->factory->term->create( array( 'taxonomy' => 'category' ) ); + $category_id = self::factory()->term->create( array( 'taxonomy' => 'category' ) ); wp_set_post_categories( $post_id, $category_id ); wp_publish_post( $post_id ); @@ -183,7 +183,7 @@ public function test_wp_publish_post_adds_default_category() { */ public function test_wp_publish_post_adds_default_category_when_tagged() { $post_id = self::$auto_draft_id; - $tag_id = $this->factory->term->create( array( 'taxonomy' => 'post_tag' ) ); + $tag_id = self::factory()->term->create( array( 'taxonomy' => 'post_tag' ) ); wp_set_post_tags( $post_id, array( $tag_id ) ); wp_publish_post( $post_id ); @@ -218,7 +218,7 @@ public function test_wp_publish_post_respects_current_terms() { ); $post_id = self::$auto_draft_id; - $term_id = $this->factory->term->create( array( 'taxonomy' => 'tax_51292' ) ); + $term_id = self::factory()->term->create( array( 'taxonomy' => 'tax_51292' ) ); wp_set_object_terms( $post_id, array( $term_id ), 'tax_51292' ); wp_publish_post( $post_id ); diff --git a/tests/phpunit/tests/privacy/wpPrivacySendErasureFulfillmentNotification.php b/tests/phpunit/tests/privacy/wpPrivacySendErasureFulfillmentNotification.php index 96b4e0ecd9651..ef71a5f85de39 100644 --- a/tests/phpunit/tests/privacy/wpPrivacySendErasureFulfillmentNotification.php +++ b/tests/phpunit/tests/privacy/wpPrivacySendErasureFulfillmentNotification.php @@ -131,7 +131,7 @@ public function test_should_send_email_no_privacy_policy() { * @ticket 44234 */ public function test_should_send_email_with_privacy_policy() { - $privacy_policy = $this->factory->post->create( + $privacy_policy = self::factory()->post->create( array( 'post_type' => 'page', 'title' => 'Site Privacy Policy', @@ -307,7 +307,7 @@ public function test_should_not_send_email_when_passed_invalid_request_id() { * @ticket 44234 */ public function test_should_not_send_email_when_not_user_request() { - $post_id = $this->factory->post->create( + $post_id = self::factory()->post->create( array( 'post_type' => 'post', // Should be 'user_request'. ) diff --git a/tests/phpunit/tests/privacy/wpPrivacySendRequestConfirmationNotification.php b/tests/phpunit/tests/privacy/wpPrivacySendRequestConfirmationNotification.php index f2933bdda0cfe..ee083b30c6bad 100644 --- a/tests/phpunit/tests/privacy/wpPrivacySendRequestConfirmationNotification.php +++ b/tests/phpunit/tests/privacy/wpPrivacySendRequestConfirmationNotification.php @@ -55,7 +55,7 @@ public function test_function_should_not_send_email_when_not_a_valid_request_id( * @ticket 43967 */ public function test_function_should_not_send_email_when_not_a_wp_user_request() { - $post_id = $this->factory->post->create( + $post_id = self::factory()->post->create( array( 'post_type' => 'post', ) diff --git a/tests/phpunit/tests/query.php b/tests/phpunit/tests/query.php index 9a8a9b3ffd4db..fef3e197482b2 100644 --- a/tests/phpunit/tests/query.php +++ b/tests/phpunit/tests/query.php @@ -644,19 +644,19 @@ public function test_get_queried_object_should_return_first_of_multiple_terms() register_taxonomy( 'tax1', 'post' ); register_taxonomy( 'tax2', 'post' ); - $term1 = $this->factory->term->create( + $term1 = self::factory()->term->create( array( 'taxonomy' => 'tax1', 'name' => 'term1', ) ); - $term2 = $this->factory->term->create( + $term2 = self::factory()->term->create( array( 'taxonomy' => 'tax2', 'name' => 'term2', ) ); - $post_id = $this->factory->post->create(); + $post_id = self::factory()->post->create(); wp_set_object_terms( $post_id, 'term1', 'tax1' ); wp_set_object_terms( $post_id, 'term2', 'tax2' ); @@ -674,19 +674,19 @@ public function test_query_vars_should_match_first_of_multiple_terms() { register_taxonomy( 'tax1', 'post' ); register_taxonomy( 'tax2', 'post' ); - $term1 = $this->factory->term->create( + $term1 = self::factory()->term->create( array( 'taxonomy' => 'tax1', 'name' => 'term1', ) ); - $term2 = $this->factory->term->create( + $term2 = self::factory()->term->create( array( 'taxonomy' => 'tax2', 'name' => 'term2', ) ); - $post_id = $this->factory->post->create(); + $post_id = self::factory()->post->create(); wp_set_object_terms( $post_id, 'term1', 'tax1' ); wp_set_object_terms( $post_id, 'term2', 'tax2' ); diff --git a/tests/phpunit/tests/query/conditionals.php b/tests/phpunit/tests/query/conditionals.php index 95621882b0384..c447c638d6986 100644 --- a/tests/phpunit/tests/query/conditionals.php +++ b/tests/phpunit/tests/query/conditionals.php @@ -978,13 +978,13 @@ public function test_is_single_with_slug_that_begins_with_a_number_that_clashes_ public function test_is_single_with_slug_that_clashes_with_attachment() { $this->set_permalink_structure( '/%postname%/' ); - $attachment_id = $this->factory->post->create( + $attachment_id = self::factory()->post->create( array( 'post_type' => 'attachment', ) ); - $post_id = $this->factory->post->create( + $post_id = self::factory()->post->create( array( 'post_title' => get_post( $attachment_id )->post_title, ) diff --git a/tests/phpunit/tests/query/noFoundRows.php b/tests/phpunit/tests/query/noFoundRows.php index 457da449942a4..7b4f66a416030 100644 --- a/tests/phpunit/tests/query/noFoundRows.php +++ b/tests/phpunit/tests/query/noFoundRows.php @@ -73,7 +73,7 @@ public function test_no_found_rows_non_bool_cast_to_true() { * @ticket 29552 */ public function test_no_found_rows_default_with_nopaging_true() { - $p = $this->factory->post->create(); + $p = self::factory()->post->create(); $q = new WP_Query( array( @@ -90,7 +90,7 @@ public function test_no_found_rows_default_with_nopaging_true() { * @ticket 29552 */ public function test_no_found_rows_default_with_postsperpage_minus1() { - $p = $this->factory->post->create(); + $p = self::factory()->post->create(); $q = new WP_Query( array( diff --git a/tests/phpunit/tests/query/search.php b/tests/phpunit/tests/query/search.php index 418acbfc8520b..954bd5f748db4 100644 --- a/tests/phpunit/tests/query/search.php +++ b/tests/phpunit/tests/query/search.php @@ -266,7 +266,7 @@ public function test_search_orderby_should_be_empty_when_search_string_is_longer * @ticket 31025 */ public function test_s_zero() { - $p1 = $this->factory->post->create( + $p1 = self::factory()->post->create( array( 'post_status' => 'publish', 'post_title' => '1', @@ -275,7 +275,7 @@ public function test_s_zero() { ) ); - $p2 = $this->factory->post->create( + $p2 = self::factory()->post->create( array( 'post_status' => 'publish', 'post_title' => '0', diff --git a/tests/phpunit/tests/rest-api/rest-attachments-controller.php b/tests/phpunit/tests/rest-api/rest-attachments-controller.php index 2c97f81c05c14..05f6aab921347 100644 --- a/tests/phpunit/tests/rest-api/rest-attachments-controller.php +++ b/tests/phpunit/tests/rest-api/rest-attachments-controller.php @@ -185,7 +185,7 @@ public function test_context_param() { $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 @@ public function test_registered_query_params() { } 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 @@ public function test_registered_get_item_params() { * @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 @@ public function test_allow_header_sent_on_options_request() { 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 @@ public function test_get_items() { '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 @@ public function test_get_items() { '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 @@ public function test_get_items() { 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 @@ public function test_get_items_logged_in_editor() { '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 @@ public function test_get_items_logged_in_editor() { '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 @@ public function test_get_items_logged_in_editor() { } 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 @@ public function test_get_items_media_type() { } 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 @@ public function test_get_items_mime_type() { } 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 @@ public function test_get_items_parent() { '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 @@ public function test_get_items_parent() { 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 @@ public function test_get_items_invalid_status_param_is_error_response() { 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 @@ public function test_get_items_private_status() { 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 @@ public function test_get_items_multiple_statuses() { '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 @@ public function test_get_items_invalid_date() { } 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 @@ public function test_get_items_valid_date() { '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 @@ public function test_get_items_valid_date() { '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 @@ public function test_get_items_invalid_modified_date() { * @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 @@ public function test_get_items_valid_modified_date() { '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 @@ public function test_get_items_valid_modified_date() { '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 @@ public function test_get_items_avoid_duplicated_count_query_if_no_items() { * @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 @@ public function test_get_items_with_empty_page_runs_count_query_after() { } 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 @@ public function test_get_item() { * @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 @@ public function test_get_item_sizes() { * @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 @@ public function test_get_item_sizes_with_no_url() { 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 @@ public function test_get_item_private_post_not_authenticated() { } 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 @@ public function test_get_item_inherit_status_with_invalid_parent() { } 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 @@ public function test_create_item_invalid_upload_files_capability() { } 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 @@ public function test_create_item_invalid_edit_permissions() { } 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 @@ public function test_create_item_invalid_upload_permissions() { } 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 @@ public function test_create_item_ensure_relative_path() { 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 @@ public function test_update_item() { 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 @@ public function test_update_item_parent() { $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 @@ public function test_update_item_parent() { 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 @@ public function test_update_item_invalid_permissions() { } 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 @@ public function test_update_item_invalid_post_type() { ) ); 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 @@ public function test_attachment_roundtrip_as_superadmin_unfiltered_html() { 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 @@ public function test_delete_item() { 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 @@ public function test_delete_item_no_trash() { 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 @@ public function test_delete_item_invalid_delete_permissions() { } 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 @@ public function test_prepare_item() { } 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 @@ public function test_get_additional_field_registration() { $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 @@ public function test_additional_field_update_errors() { ); 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 @@ public function test_additional_field_update_errors() { } 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 @@ public function test_rest_insert_attachment_hooks_fire_once_on_update() { 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( diff --git a/tests/phpunit/tests/rest-api/rest-categories-controller.php b/tests/phpunit/tests/rest-api/rest-categories-controller.php index ef72b6f8faded..805472487f021 100644 --- a/tests/phpunit/tests/rest-api/rest-categories-controller.php +++ b/tests/phpunit/tests/rest-api/rest-categories-controller.php @@ -121,7 +121,7 @@ public function test_context_param() { $this->assertSame( 'view', $data['endpoints'][0]['args']['context']['default'] ); $this->assertSameSets( array( 'view', 'embed', 'edit' ), $data['endpoints'][0]['args']['context']['enum'] ); // Single. - $category1 = $this->factory->category->create( array( 'name' => 'Season 5' ) ); + $category1 = self::factory()->category->create( array( 'name' => 'Season 5' ) ); $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/categories/' . $category1 ); $response = rest_get_server()->dispatch( $request ); $data = $response->get_data(); @@ -172,9 +172,9 @@ public function test_get_items_invalid_permission_for_context() { } public function test_get_items_hide_empty_arg() { - $post_id = $this->factory->post->create(); - $category1 = $this->factory->category->create( array( 'name' => 'Season 5' ) ); - $category2 = $this->factory->category->create( array( 'name' => 'The Be Sharps' ) ); + $post_id = self::factory()->post->create(); + $category1 = self::factory()->category->create( array( 'name' => 'Season 5' ) ); + $category2 = self::factory()->category->create( array( 'name' => 'The Be Sharps' ) ); $total_categories = self::$total_categories + 2; @@ -197,15 +197,15 @@ public function test_get_items_hide_empty_arg() { } public function test_get_items_parent_zero_arg() { - $parent1 = $this->factory->category->create( array( 'name' => 'Homer' ) ); - $parent2 = $this->factory->category->create( array( 'name' => 'Marge' ) ); - $this->factory->category->create( + $parent1 = self::factory()->category->create( array( 'name' => 'Homer' ) ); + $parent2 = self::factory()->category->create( array( 'name' => 'Marge' ) ); + self::factory()->category->create( array( 'name' => 'Bart', 'parent' => $parent1, ) ); - $this->factory->category->create( + self::factory()->category->create( array( 'name' => 'Lisa', 'parent' => $parent2, @@ -229,15 +229,15 @@ public function test_get_items_parent_zero_arg() { } public function test_get_items_parent_zero_arg_string() { - $parent1 = $this->factory->category->create( array( 'name' => 'Homer' ) ); - $parent2 = $this->factory->category->create( array( 'name' => 'Marge' ) ); - $this->factory->category->create( + $parent1 = self::factory()->category->create( array( 'name' => 'Homer' ) ); + $parent2 = self::factory()->category->create( array( 'name' => 'Marge' ) ); + self::factory()->category->create( array( 'name' => 'Bart', 'parent' => $parent1, ) ); - $this->factory->category->create( + self::factory()->category->create( array( 'name' => 'Lisa', 'parent' => $parent2, @@ -261,7 +261,7 @@ public function test_get_items_parent_zero_arg_string() { } public function test_get_items_by_parent_non_found() { - $parent1 = $this->factory->category->create( array( 'name' => 'Homer' ) ); + $parent1 = self::factory()->category->create( array( 'name' => 'Homer' ) ); $request = new WP_REST_Request( 'GET', '/wp/v2/categories' ); $request->set_param( 'parent', $parent1 ); @@ -284,8 +284,8 @@ public function test_get_items_invalid_page() { } public function test_get_items_include_query() { - $id1 = $this->factory->category->create(); - $id2 = $this->factory->category->create(); + $id1 = self::factory()->category->create(); + $id2 = self::factory()->category->create(); $request = new WP_REST_Request( 'GET', '/wp/v2/categories' ); @@ -305,8 +305,8 @@ public function test_get_items_include_query() { } public function test_get_items_exclude_query() { - $id1 = $this->factory->category->create(); - $id2 = $this->factory->category->create(); + $id1 = self::factory()->category->create(); + $id2 = self::factory()->category->create(); $request = new WP_REST_Request( 'GET', '/wp/v2/categories' ); $request->set_param( 'per_page', self::$per_page ); @@ -325,8 +325,8 @@ public function test_get_items_exclude_query() { } public function test_get_items_orderby_args() { - $this->factory->category->create( array( 'name' => 'Apple' ) ); - $this->factory->category->create( array( 'name' => 'Banana' ) ); + self::factory()->category->create( array( 'name' => 'Apple' ) ); + self::factory()->category->create( array( 'name' => 'Banana' ) ); /* * Tests: @@ -356,9 +356,9 @@ public function test_get_items_orderby_args() { } public function test_get_items_orderby_id() { - $this->factory->category->create( array( 'name' => 'Cantaloupe' ) ); - $this->factory->category->create( array( 'name' => 'Apple' ) ); - $this->factory->category->create( array( 'name' => 'Banana' ) ); + self::factory()->category->create( array( 'name' => 'Cantaloupe' ) ); + self::factory()->category->create( array( 'name' => 'Apple' ) ); + self::factory()->category->create( array( 'name' => 'Banana' ) ); // Defaults to 'orderby' => 'name', 'order' => 'asc'. $request = new WP_REST_Request( 'GET', '/wp/v2/categories' ); @@ -392,9 +392,9 @@ public function test_get_items_orderby_id() { } public function test_get_items_orderby_slugs() { - $this->factory->category->create( array( 'name' => 'Burrito' ) ); - $this->factory->category->create( array( 'name' => 'Taco' ) ); - $this->factory->category->create( array( 'name' => 'Chalupa' ) ); + self::factory()->category->create( array( 'name' => 'Burrito' ) ); + self::factory()->category->create( array( 'name' => 'Taco' ) ); + self::factory()->category->create( array( 'name' => 'Chalupa' ) ); $request = new WP_REST_Request( 'GET', '/wp/v2/categories' ); $request->set_param( 'orderby', 'include_slugs' ); @@ -408,20 +408,20 @@ public function test_get_items_orderby_slugs() { } protected function post_with_categories() { - $post_id = $this->factory->post->create(); - $category1 = $this->factory->category->create( + $post_id = self::factory()->post->create(); + $category1 = self::factory()->category->create( array( 'name' => 'DC', 'description' => 'Purveyor of fine detective comics', ) ); - $category2 = $this->factory->category->create( + $category2 = self::factory()->category->create( array( 'name' => 'Marvel', 'description' => 'Home of the Marvel Universe', ) ); - $category3 = $this->factory->category->create( + $category3 = self::factory()->category->create( array( 'name' => 'Image', 'description' => 'American independent comic publisher', @@ -493,25 +493,25 @@ public function test_get_items_custom_tax_post_args() { register_taxonomy( 'batman', 'post', array( 'show_in_rest' => true ) ); $controller = new WP_REST_Terms_Controller( 'batman' ); $controller->register_routes(); - $term1 = $this->factory->term->create( + $term1 = self::factory()->term->create( array( 'name' => 'Cape', 'taxonomy' => 'batman', ) ); - $term2 = $this->factory->term->create( + $term2 = self::factory()->term->create( array( 'name' => 'Mask', 'taxonomy' => 'batman', ) ); - $this->factory->term->create( + self::factory()->term->create( array( 'name' => 'Car', 'taxonomy' => 'batman', ) ); - $post_id = $this->factory->post->create(); + $post_id = self::factory()->post->create(); wp_set_object_terms( $post_id, array( $term1, $term2 ), 'batman' ); $request = new WP_REST_Request( 'GET', '/wp/v2/batman' ); @@ -525,8 +525,8 @@ public function test_get_items_custom_tax_post_args() { } public function test_get_items_search_args() { - $this->factory->category->create( array( 'name' => 'Apple' ) ); - $this->factory->category->create( array( 'name' => 'Banana' ) ); + self::factory()->category->create( array( 'name' => 'Apple' ) ); + self::factory()->category->create( array( 'name' => 'Banana' ) ); /* * Tests: @@ -549,8 +549,8 @@ public function test_get_items_search_args() { } public function test_get_items_slug_arg() { - $this->factory->category->create( array( 'name' => 'Apple' ) ); - $this->factory->category->create( array( 'name' => 'Banana' ) ); + self::factory()->category->create( array( 'name' => 'Apple' ) ); + self::factory()->category->create( array( 'name' => 'Banana' ) ); $request = new WP_REST_Request( 'GET', '/wp/v2/categories' ); $request->set_param( 'slug', 'apple' ); @@ -562,8 +562,8 @@ public function test_get_items_slug_arg() { } public function test_get_terms_parent_arg() { - $category1 = $this->factory->category->create( array( 'name' => 'Parent' ) ); - $this->factory->category->create( + $category1 = self::factory()->category->create( array( 'name' => 'Parent' ) ); + self::factory()->category->create( array( 'name' => 'Child', 'parent' => $category1, @@ -587,13 +587,13 @@ public function test_get_terms_invalid_parent_arg() { public function test_get_terms_private_taxonomy() { register_taxonomy( 'robin', 'post', array( 'public' => false ) ); - $this->factory->term->create( + self::factory()->term->create( array( 'name' => 'Cape', 'taxonomy' => 'robin', ) ); - $this->factory->term->create( + self::factory()->term->create( array( 'name' => 'Mask', 'taxonomy' => 'robin', @@ -632,7 +632,7 @@ public function test_get_terms_pagination_headers() { $this->assertStringContainsString( '<' . $next_link . '>; rel="next"', $headers['Link'] ); // 3rd page. - $this->factory->category->create(); + self::factory()->category->create(); $total_categories++; $total_pages++; $request = new WP_REST_Request( 'GET', '/wp/v2/categories' ); @@ -775,7 +775,7 @@ public function test_get_item_invalid_permission_for_context() { public function test_get_term_private_taxonomy() { register_taxonomy( 'robin', 'post', array( 'public' => false ) ); - $term1 = $this->factory->term->create( + $term1 = self::factory()->term->create( array( 'name' => 'Cape', 'taxonomy' => 'robin', @@ -789,7 +789,7 @@ public function test_get_term_private_taxonomy() { public function test_get_item_incorrect_taxonomy() { register_taxonomy( 'robin', 'post' ); - $term1 = $this->factory->term->create( + $term1 = self::factory()->term->create( array( 'name' => 'Cape', 'taxonomy' => 'robin', @@ -824,7 +824,7 @@ public function test_create_item() { public function test_create_item_term_already_exists() { wp_set_current_user( self::$administrator ); - $existing_id = $this->factory->category->create( array( 'name' => 'Existing' ) ); + $existing_id = self::factory()->category->create( array( 'name' => 'Existing' ) ); $request = new WP_REST_Request( 'POST', '/wp/v2/categories' ); $request->set_param( 'name', 'Existing' ); @@ -890,7 +890,7 @@ public function test_create_item_with_parent() { public function test_create_item_invalid_parent() { wp_set_current_user( self::$administrator ); - $term = get_term_by( 'id', $this->factory->category->create(), 'category' ); + $term = get_term_by( 'id', self::factory()->category->create(), 'category' ); $request = new WP_REST_Request( 'POST', '/wp/v2/categories/' . $term->term_id ); $request->set_param( 'name', 'My Awesome Term' ); @@ -922,7 +922,7 @@ public function test_update_item() { 'slug' => 'original-slug', ); - $term = get_term_by( 'id', $this->factory->category->create( $orig_args ), 'category' ); + $term = get_term_by( 'id', self::factory()->category->create( $orig_args ), 'category' ); $request = new WP_REST_Request( 'POST', '/wp/v2/categories/' . $term->term_id ); $request->set_param( 'name', 'New Name' ); @@ -968,7 +968,7 @@ public function test_update_item_invalid_term() { public function test_update_item_incorrect_permissions() { wp_set_current_user( self::$subscriber ); - $term = get_term_by( 'id', $this->factory->category->create(), 'category' ); + $term = get_term_by( 'id', self::factory()->category->create(), 'category' ); $request = new WP_REST_Request( 'POST', '/wp/v2/categories/' . $term->term_id ); $request->set_param( 'name', 'Incorrect permissions' ); @@ -979,8 +979,8 @@ public function test_update_item_incorrect_permissions() { public function test_update_item_parent() { wp_set_current_user( self::$administrator ); - $parent = get_term_by( 'id', $this->factory->category->create(), 'category' ); - $term = get_term_by( 'id', $this->factory->category->create(), 'category' ); + $parent = get_term_by( 'id', self::factory()->category->create(), 'category' ); + $term = get_term_by( 'id', self::factory()->category->create(), 'category' ); $request = new WP_REST_Request( 'POST', '/wp/v2/categories/' . $term->term_id ); $request->set_param( 'parent', $parent->term_id ); @@ -994,12 +994,12 @@ public function test_update_item_parent() { public function test_update_item_remove_parent() { wp_set_current_user( self::$administrator ); - $old_parent_term = get_term_by( 'id', $this->factory->category->create(), 'category' ); + $old_parent_term = get_term_by( 'id', self::factory()->category->create(), 'category' ); $new_parent_id = 0; $term = get_term_by( 'id', - $this->factory->category->create( + self::factory()->category->create( array( 'parent' => $old_parent_term->term_id, ) @@ -1021,7 +1021,7 @@ public function test_update_item_remove_parent() { public function test_update_item_invalid_parent() { wp_set_current_user( self::$administrator ); - $term = get_term_by( 'id', $this->factory->category->create(), 'category' ); + $term = get_term_by( 'id', self::factory()->category->create(), 'category' ); $request = new WP_REST_Request( 'POST', '/wp/v2/categories/' . $term->term_id ); $request->set_param( 'parent', REST_TESTS_IMPOSSIBLY_HIGH_NUMBER ); @@ -1032,7 +1032,7 @@ public function test_update_item_invalid_parent() { public function test_delete_item() { wp_set_current_user( self::$administrator ); - $term = get_term_by( 'id', $this->factory->category->create( array( 'name' => 'Deleted Category' ) ), 'category' ); + $term = get_term_by( 'id', self::factory()->category->create( array( 'name' => 'Deleted Category' ) ), 'category' ); $request = new WP_REST_Request( 'DELETE', '/wp/v2/categories/' . $term->term_id ); $request->set_param( 'force', true ); @@ -1046,7 +1046,7 @@ public function test_delete_item() { public function test_delete_item_no_trash() { wp_set_current_user( self::$administrator ); - $term = get_term_by( 'id', $this->factory->category->create( array( 'name' => 'Deleted Category' ) ), 'category' ); + $term = get_term_by( 'id', self::factory()->category->create( array( 'name' => 'Deleted Category' ) ), 'category' ); $request = new WP_REST_Request( 'DELETE', '/wp/v2/categories/' . $term->term_id ); $response = rest_get_server()->dispatch( $request ); @@ -1076,7 +1076,7 @@ public function test_delete_item_invalid_term() { public function test_delete_item_incorrect_permissions() { wp_set_current_user( self::$subscriber ); - $term = get_term_by( 'id', $this->factory->category->create(), 'category' ); + $term = get_term_by( 'id', self::factory()->category->create(), 'category' ); $request = new WP_REST_Request( 'DELETE', '/wp/v2/categories/' . $term->term_id ); $response = rest_get_server()->dispatch( $request ); $this->assertErrorResponse( 'rest_cannot_delete', $response, 403 ); @@ -1108,7 +1108,7 @@ public function test_prepare_item_limit_fields() { } public function test_prepare_taxonomy_term_child() { - $child = $this->factory->category->create( + $child = self::factory()->category->create( array( 'parent' => 1, ) @@ -1170,7 +1170,7 @@ public function test_get_additional_field_registration() { $this->assertArrayHasKey( 'my_custom_int', $data['schema']['properties'] ); $this->assertSame( $schema, $data['schema']['properties']['my_custom_int'] ); - $category_id = $this->factory->category->create(); + $category_id = self::factory()->category->create(); $request = new WP_REST_Request( 'GET', '/wp/v2/categories/' . $category_id ); $response = rest_get_server()->dispatch( $request ); diff --git a/tests/phpunit/tests/rest-api/rest-comments-controller.php b/tests/phpunit/tests/rest-api/rest-comments-controller.php index bf5d112d4e7d1..eb66ee5d418f7 100644 --- a/tests/phpunit/tests/rest-api/rest-comments-controller.php +++ b/tests/phpunit/tests/rest-api/rest-comments-controller.php @@ -237,7 +237,7 @@ public function test_get_items_with_password() { 'comment_post_ID' => self::$password_id, ); - $password_comment = $this->factory->comment->create( $args ); + $password_comment = self::factory()->comment->create( $args ); $request = new WP_REST_Request( 'GET', '/wp/v2/comments' ); $request->set_param( 'password', 'toomanysecrets' ); @@ -261,7 +261,7 @@ public function test_get_items_with_password_without_post() { 'comment_post_ID' => self::$password_id, ); - $password_comment = $this->factory->comment->create( $args ); + $password_comment = self::factory()->comment->create( $args ); $request = new WP_REST_Request( 'GET', '/wp/v2/comments' ); $request->set_param( 'password', 'toomanysecrets' ); @@ -284,7 +284,7 @@ public function test_get_items_with_password_with_multiple_post() { 'comment_post_ID' => self::$password_id, ); - $password_comment = $this->factory->comment->create( $args ); + $password_comment = self::factory()->comment->create( $args ); $request = new WP_REST_Request( 'GET', '/wp/v2/comments' ); $request->set_param( 'password', 'toomanysecrets' ); @@ -302,7 +302,7 @@ public function test_get_password_items_without_edit_post_permission() { 'comment_post_ID' => self::$password_id, ); - $password_comment = $this->factory->comment->create( $args ); + $password_comment = self::factory()->comment->create( $args ); $request = new WP_REST_Request( 'GET', '/wp/v2/comments' ); @@ -321,7 +321,7 @@ public function test_get_password_items_with_edit_post_permission() { 'comment_post_ID' => self::$password_id, ); - $password_comment = $this->factory->comment->create( $args ); + $password_comment = self::factory()->comment->create( $args ); $request = new WP_REST_Request( 'GET', '/wp/v2/comments' ); @@ -340,7 +340,7 @@ public function test_get_items_without_private_post_permission() { 'comment_post_ID' => self::$private_id, ); - $private_comment = $this->factory->comment->create( $args ); + $private_comment = self::factory()->comment->create( $args ); $request = new WP_REST_Request( 'GET', '/wp/v2/comments' ); @@ -359,7 +359,7 @@ public function test_get_items_with_private_post_permission() { 'comment_post_ID' => self::$private_id, ); - $private_comment = $this->factory->comment->create( $args ); + $private_comment = self::factory()->comment->create( $args ); $request = new WP_REST_Request( 'GET', '/wp/v2/comments' ); @@ -373,7 +373,7 @@ public function test_get_items_with_private_post_permission() { public function test_get_items_with_invalid_post() { wp_set_current_user( 0 ); - $comment_id = $this->factory->comment->create( + $comment_id = self::factory()->comment->create( array( 'comment_approved' => 1, 'comment_post_ID' => REST_TESTS_IMPOSSIBLY_HIGH_NUMBER, @@ -394,7 +394,7 @@ public function test_get_items_with_invalid_post() { public function test_get_items_with_invalid_post_permission() { wp_set_current_user( self::$admin_id ); - $comment_id = $this->factory->comment->create( + $comment_id = self::factory()->comment->create( array( 'comment_approved' => 1, 'comment_post_ID' => REST_TESTS_IMPOSSIBLY_HIGH_NUMBER, @@ -424,7 +424,7 @@ public function test_get_items_no_permission_for_context() { public function test_get_items_no_post() { wp_set_current_user( self::$admin_id ); - $this->factory->comment->create_post_comments( 0, 2 ); + self::factory()->comment->create_post_comments( 0, 2 ); $request = new WP_REST_Request( 'GET', '/wp/v2/comments' ); $request->set_param( 'post', 0 ); @@ -453,8 +453,8 @@ public function test_get_items_edit_context() { } public function test_get_items_for_post() { - $second_post_id = $this->factory->post->create(); - $this->factory->comment->create_post_comments( $second_post_id, 2 ); + $second_post_id = self::factory()->post->create(); + self::factory()->comment->create_post_comments( $second_post_id, 2 ); $request = new WP_REST_Request( 'GET', '/wp/v2/comments' ); $request->set_query_params( @@ -478,8 +478,8 @@ public function test_get_items_include_query() { 'comment_post_ID' => self::$post_id, ); - $id1 = $this->factory->comment->create( $args ); - $id2 = $this->factory->comment->create( $args ); + $id1 = self::factory()->comment->create( $args ); + $id2 = self::factory()->comment->create( $args ); $request = new WP_REST_Request( 'GET', '/wp/v2/comments' ); @@ -518,8 +518,8 @@ public function test_get_items_exclude_query() { 'comment_post_ID' => self::$post_id, ); - $id1 = $this->factory->comment->create( $args ); - $id2 = $this->factory->comment->create( $args ); + $id1 = self::factory()->comment->create( $args ); + $id2 = self::factory()->comment->create( $args ); $request = new WP_REST_Request( 'GET', '/wp/v2/comments' ); $response = rest_get_server()->dispatch( $request ); @@ -574,7 +574,7 @@ public function test_get_items_order_query() { 'comment_post_ID' => self::$post_id, ); - $id = $this->factory->comment->create( $args ); + $id = self::factory()->comment->create( $args ); $request = new WP_REST_Request( 'GET', '/wp/v2/comments' ); @@ -598,7 +598,7 @@ public function test_get_items_order_query() { public function test_get_items_private_post_no_permissions() { wp_set_current_user( 0 ); - $post_id = $this->factory->post->create( array( 'post_status' => 'private' ) ); + $post_id = self::factory()->post->create( array( 'post_status' => 'private' ) ); $request = new WP_REST_Request( 'GET', '/wp/v2/comments' ); $request->set_param( 'post', $post_id ); @@ -616,11 +616,11 @@ public function test_get_items_author_arg() { 'user_id' => self::$author_id, ); - $this->factory->comment->create( $args ); + self::factory()->comment->create( $args ); $args['user_id'] = self::$subscriber_id; - $this->factory->comment->create( $args ); + self::factory()->comment->create( $args ); unset( $args['user_id'] ); - $this->factory->comment->create( $args ); + self::factory()->comment->create( $args ); // Limit to comment author. $request = new WP_REST_Request( 'GET', '/wp/v2/comments' ); @@ -659,11 +659,11 @@ public function test_get_items_author_exclude_arg() { 'user_id' => self::$author_id, ); - $this->factory->comment->create( $args ); + self::factory()->comment->create( $args ); $args['user_id'] = self::$subscriber_id; - $this->factory->comment->create( $args ); + self::factory()->comment->create( $args ); unset( $args['user_id'] ); - $this->factory->comment->create( $args ); + self::factory()->comment->create( $args ); $total_comments = self::$total_comments + 3; @@ -709,12 +709,12 @@ public function test_get_items_parent_arg() { 'comment_approved' => 1, 'comment_post_ID' => self::$post_id, ); - $parent_id = $this->factory->comment->create( $args ); - $parent_id2 = $this->factory->comment->create( $args ); + $parent_id = self::factory()->comment->create( $args ); + $parent_id2 = self::factory()->comment->create( $args ); $args['comment_parent'] = $parent_id; - $this->factory->comment->create( $args ); + self::factory()->comment->create( $args ); $args['comment_parent'] = $parent_id2; - $this->factory->comment->create( $args ); + self::factory()->comment->create( $args ); $total_comments = self::$total_comments + 4; @@ -745,12 +745,12 @@ public function test_get_items_parent_exclude_arg() { 'comment_approved' => 1, 'comment_post_ID' => self::$post_id, ); - $parent_id = $this->factory->comment->create( $args ); - $parent_id2 = $this->factory->comment->create( $args ); + $parent_id = self::factory()->comment->create( $args ); + $parent_id2 = self::factory()->comment->create( $args ); $args['comment_parent'] = $parent_id; - $this->factory->comment->create( $args ); + self::factory()->comment->create( $args ); $args['comment_parent'] = $parent_id2; - $this->factory->comment->create( $args ); + self::factory()->comment->create( $args ); $total_comments = self::$total_comments + 4; @@ -786,7 +786,7 @@ public function test_get_items_search_query() { 'comment_author' => 'Homer J Simpson', ); - $id = $this->factory->comment->create( $args ); + $id = self::factory()->comment->create( $args ); $total_comments = self::$total_comments + 1; @@ -825,7 +825,7 @@ public function test_get_comments_pagination_headers() { $this->assertStringContainsString( '<' . $next_link . '>; rel="next"', $headers['Link'] ); // 3rd page. - $this->factory->comment->create( + self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, ) @@ -895,19 +895,19 @@ public function test_get_comments_invalid_date() { } public function test_get_comments_valid_date() { - $comment1 = $this->factory->comment->create( + $comment1 = self::factory()->comment->create( array( 'comment_date' => '2016-01-15T00:00:00Z', 'comment_post_ID' => self::$post_id, ) ); - $comment2 = $this->factory->comment->create( + $comment2 = self::factory()->comment->create( array( 'comment_date' => '2016-01-16T00:00:00Z', 'comment_post_ID' => self::$post_id, ) ); - $comment3 = $this->factory->comment->create( + $comment3 = self::factory()->comment->create( array( 'comment_date' => '2016-01-17T00:00:00Z', 'comment_post_ID' => self::$post_id, @@ -1003,7 +1003,7 @@ public function test_get_comment_invalid_context() { public function test_get_comment_invalid_post_id() { wp_set_current_user( 0 ); - $comment_id = $this->factory->comment->create( + $comment_id = self::factory()->comment->create( array( 'comment_approved' => 1, 'comment_post_ID' => REST_TESTS_IMPOSSIBLY_HIGH_NUMBER, @@ -1018,7 +1018,7 @@ public function test_get_comment_invalid_post_id() { public function test_get_comment_invalid_post_id_as_admin() { wp_set_current_user( self::$admin_id ); - $comment_id = $this->factory->comment->create( + $comment_id = self::factory()->comment->create( array( 'comment_approved' => 1, 'comment_post_ID' => REST_TESTS_IMPOSSIBLY_HIGH_NUMBER, @@ -1047,7 +1047,7 @@ public function test_get_comment_not_approved_same_user() { } public function test_get_comment_with_children_link() { - $comment_id_1 = $this->factory->comment->create( + $comment_id_1 = self::factory()->comment->create( array( 'comment_approved' => 1, 'comment_post_ID' => self::$post_id, @@ -1055,7 +1055,7 @@ public function test_get_comment_with_children_link() { ) ); - $child_comment = $this->factory->comment->create( + $child_comment = self::factory()->comment->create( array( 'comment_approved' => 1, 'comment_parent' => $comment_id_1, @@ -1071,7 +1071,7 @@ public function test_get_comment_with_children_link() { } public function test_get_comment_without_children_link() { - $comment_id_1 = $this->factory->comment->create( + $comment_id_1 = self::factory()->comment->create( array( 'comment_approved' => 1, 'comment_post_ID' => self::$post_id, @@ -1093,7 +1093,7 @@ public function test_get_comment_with_password_without_edit_post_permission() { 'comment_post_ID' => self::$password_id, ); - $password_comment = $this->factory->comment->create( $args ); + $password_comment = self::factory()->comment->create( $args ); $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/comments/%s', $password_comment ) ); $response = rest_get_server()->dispatch( $request ); @@ -1111,7 +1111,7 @@ public function test_get_comment_with_password_with_valid_password() { 'comment_post_ID' => self::$password_id, ); - $password_comment = $this->factory->comment->create( $args ); + $password_comment = self::factory()->comment->create( $args ); $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/comments/%s', $password_comment ) ); $request->set_param( 'password', 'toomanysecrets' ); @@ -1490,7 +1490,7 @@ public function test_create_item_invalid_date() { public function test_create_item_assign_different_user() { - $subscriber_id = $this->factory->user->create( + $subscriber_id = self::factory()->user->create( array( 'role' => 'subscriber', 'user_email' => 'cbg@androidsdungeon.com', @@ -1521,7 +1521,7 @@ public function test_create_item_assign_different_user() { } public function test_create_comment_without_type() { - $post_id = $this->factory->post->create(); + $post_id = self::factory()->post->create(); wp_set_current_user( self::$admin_id ); @@ -1559,7 +1559,7 @@ public function test_create_comment_without_type() { * @ticket 38820 */ public function test_create_comment_with_invalid_type() { - $post_id = $this->factory->post->create(); + $post_id = self::factory()->post->create(); wp_set_current_user( self::$admin_id ); @@ -1583,7 +1583,7 @@ public function test_create_comment_with_invalid_type() { } public function test_create_comment_invalid_email() { - $post_id = $this->factory->post->create(); + $post_id = self::factory()->post->create(); wp_set_current_user( self::$admin_id ); @@ -1606,7 +1606,7 @@ public function test_create_comment_invalid_email() { } public function test_create_item_current_user() { - $user_id = $this->factory->user->create( + $user_id = self::factory()->user->create( array( 'role' => 'subscriber', 'user_email' => 'lylelanley@example.com', @@ -1728,7 +1728,7 @@ public function test_create_comment_status_without_permission() { } public function test_create_comment_with_status_IP_and_user_agent() { - $post_id = $this->factory->post->create(); + $post_id = self::factory()->post->create(); wp_set_current_user( self::$admin_id ); @@ -2006,7 +2006,7 @@ public function test_create_comment_password_post_invalid_permission() { public function test_create_item_duplicate() { wp_set_current_user( self::$subscriber_id ); - $this->factory->comment->create( + self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_author' => 'Guy N. Cognito', @@ -2031,7 +2031,7 @@ public function test_create_item_duplicate() { } public function test_create_comment_closed() { - $post_id = $this->factory->post->create( + $post_id = self::factory()->post->create( array( 'comment_status' => 'closed', ) @@ -2303,7 +2303,7 @@ public function test_create_comment_with_password() { } public function test_update_item() { - $post_id = $this->factory->post->create(); + $post_id = self::factory()->post->create(); wp_set_current_user( self::$admin_id ); @@ -2347,7 +2347,7 @@ public function test_update_comment_date( $params, $results ) { update_option( 'timezone_string', $params['timezone_string'] ); - $comment_id = $this->factory->comment->create(); + $comment_id = self::factory()->comment->create(); $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/comments/%d', $comment_id ) ); if ( isset( $params['date'] ) ) { @@ -2374,7 +2374,7 @@ public function test_update_comment_date( $params, $results ) { } public function test_update_item_no_content() { - $post_id = $this->factory->post->create(); + $post_id = self::factory()->post->create(); wp_set_current_user( self::$admin_id ); @@ -2412,7 +2412,7 @@ public function test_update_item_no_change() { public function test_update_comment_status() { wp_set_current_user( self::$admin_id ); - $comment_id = $this->factory->comment->create( + $comment_id = self::factory()->comment->create( array( 'comment_approved' => 0, 'comment_post_ID' => self::$post_id, @@ -2439,7 +2439,7 @@ public function test_update_comment_status() { public function test_update_comment_field_does_not_use_default_values() { wp_set_current_user( self::$admin_id ); - $comment_id = $this->factory->comment->create( + $comment_id = self::factory()->comment->create( array( 'comment_approved' => 0, 'comment_post_ID' => self::$post_id, @@ -2720,7 +2720,7 @@ public function test_update_comment_when_can_moderate_comments() { } public function test_update_comment_private_post_invalid_permission() { - $private_comment_id = $this->factory->comment->create( + $private_comment_id = self::factory()->comment->create( array( 'comment_approved' => 1, 'comment_post_ID' => self::$private_id, @@ -2745,7 +2745,7 @@ public function test_update_comment_private_post_invalid_permission() { public function test_update_comment_with_children_link() { wp_set_current_user( self::$admin_id ); - $comment_id_1 = $this->factory->comment->create( + $comment_id_1 = self::factory()->comment->create( array( 'comment_approved' => 1, 'comment_post_ID' => self::$post_id, @@ -2753,7 +2753,7 @@ public function test_update_comment_with_children_link() { ) ); - $child_comment = $this->factory->comment->create( + $child_comment = self::factory()->comment->create( array( 'comment_approved' => 1, 'comment_post_ID' => self::$post_id, @@ -3047,7 +3047,7 @@ public function test_comment_roundtrip_as_superadmin_unfiltered_html() { public function test_delete_item() { wp_set_current_user( self::$admin_id ); - $comment_id = $this->factory->comment->create( + $comment_id = self::factory()->comment->create( array( 'comment_approved' => 1, 'comment_post_ID' => self::$post_id, @@ -3067,7 +3067,7 @@ public function test_delete_item() { public function test_delete_item_skip_trash() { wp_set_current_user( self::$admin_id ); - $comment_id = $this->factory->comment->create( + $comment_id = self::factory()->comment->create( array( 'comment_approved' => 1, 'comment_post_ID' => self::$post_id, @@ -3088,7 +3088,7 @@ public function test_delete_item_skip_trash() { public function test_delete_item_already_trashed() { wp_set_current_user( self::$admin_id ); - $comment_id = $this->factory->comment->create( + $comment_id = self::factory()->comment->create( array( 'comment_approved' => 1, 'comment_post_ID' => self::$post_id, @@ -3123,7 +3123,7 @@ public function test_delete_comment_without_permission() { public function test_delete_child_comment_link() { wp_set_current_user( self::$admin_id ); - $comment_id_1 = $this->factory->comment->create( + $comment_id_1 = self::factory()->comment->create( array( 'comment_approved' => 1, 'comment_post_ID' => self::$post_id, @@ -3131,7 +3131,7 @@ public function test_delete_child_comment_link() { ) ); - $child_comment = $this->factory->comment->create( + $child_comment = self::factory()->comment->create( array( 'comment_approved' => 1, 'comment_parent' => $comment_id_1, diff --git a/tests/phpunit/tests/rest-api/rest-pages-controller.php b/tests/phpunit/tests/rest-api/rest-pages-controller.php index 40b3dc714e107..a6a9cfa3f46d5 100644 --- a/tests/phpunit/tests/rest-api/rest-pages-controller.php +++ b/tests/phpunit/tests/rest-api/rest-pages-controller.php @@ -51,7 +51,7 @@ public function test_context_param() { $this->assertSame( 'view', $data['endpoints'][0]['args']['context']['default'] ); $this->assertSame( array( 'view', 'embed', 'edit' ), $data['endpoints'][0]['args']['context']['enum'] ); // Single. - $page_id = $this->factory->post->create( array( 'post_type' => 'page' ) ); + $page_id = self::factory()->post->create( array( 'post_type' => 'page' ) ); $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/pages/' . $page_id ); $response = rest_get_server()->dispatch( $request ); $data = $response->get_data(); @@ -94,13 +94,13 @@ public function test_registered_query_params() { } public function test_get_items() { - $id1 = $this->factory->post->create( + $id1 = self::factory()->post->create( array( 'post_status' => 'publish', 'post_type' => 'page', ) ); - $id2 = $this->factory->post->create( + $id2 = self::factory()->post->create( array( 'post_status' => 'draft', 'post_type' => 'page', @@ -114,13 +114,13 @@ public function test_get_items() { } public function test_get_items_parent_query() { - $id1 = $this->factory->post->create( + $id1 = self::factory()->post->create( array( 'post_status' => 'publish', 'post_type' => 'page', ) ); - $id2 = $this->factory->post->create( + $id2 = self::factory()->post->create( array( 'post_status' => 'publish', 'post_type' => 'page', @@ -148,26 +148,26 @@ public function test_get_items_parent_query() { } public function test_get_items_parents_query() { - $id1 = $this->factory->post->create( + $id1 = self::factory()->post->create( array( 'post_status' => 'publish', 'post_type' => 'page', ) ); - $id2 = $this->factory->post->create( + $id2 = self::factory()->post->create( array( 'post_status' => 'publish', 'post_type' => 'page', 'post_parent' => $id1, ) ); - $id3 = $this->factory->post->create( + $id3 = self::factory()->post->create( array( 'post_status' => 'publish', 'post_type' => 'page', ) ); - $id4 = $this->factory->post->create( + $id4 = self::factory()->post->create( array( 'post_status' => 'publish', 'post_type' => 'page', @@ -190,13 +190,13 @@ public function test_get_items_parents_query() { } public function test_get_items_parent_exclude_query() { - $id1 = $this->factory->post->create( + $id1 = self::factory()->post->create( array( 'post_status' => 'publish', 'post_type' => 'page', ) ); - $this->factory->post->create( + self::factory()->post->create( array( 'post_status' => 'publish', 'post_type' => 'page', @@ -224,27 +224,27 @@ public function test_get_items_parent_exclude_query() { } public function test_get_items_menu_order_query() { - $id1 = $this->factory->post->create( + $id1 = self::factory()->post->create( array( 'post_status' => 'publish', 'post_type' => 'page', ) ); - $id2 = $this->factory->post->create( + $id2 = self::factory()->post->create( array( 'post_status' => 'publish', 'post_type' => 'page', 'menu_order' => 2, ) ); - $id3 = $this->factory->post->create( + $id3 = self::factory()->post->create( array( 'post_status' => 'publish', 'post_type' => 'page', 'menu_order' => 3, ) ); - $id4 = $this->factory->post->create( + $id4 = self::factory()->post->create( array( 'post_status' => 'publish', 'post_type' => 'page', @@ -302,13 +302,13 @@ public function test_get_items_min_max_pages_query() { public function test_get_items_private_filter_query_var() { // Private query vars inaccessible to unauthorized users. wp_set_current_user( 0 ); - $page_id = $this->factory->post->create( + $page_id = self::factory()->post->create( array( 'post_status' => 'publish', 'post_type' => 'page', ) ); - $draft_id = $this->factory->post->create( + $draft_id = self::factory()->post->create( array( 'post_status' => 'draft', 'post_type' => 'page', @@ -336,19 +336,19 @@ public function test_get_items_invalid_date() { } public function test_get_items_valid_date() { - $post1 = $this->factory->post->create( + $post1 = self::factory()->post->create( array( 'post_date' => '2016-01-15T00:00:00Z', 'post_type' => 'page', ) ); - $post2 = $this->factory->post->create( + $post2 = self::factory()->post->create( array( 'post_date' => '2016-01-16T00:00:00Z', 'post_type' => 'page', ) ); - $post3 = $this->factory->post->create( + $post3 = self::factory()->post->create( array( 'post_date' => '2016-01-17T00:00:00Z', 'post_type' => 'page', @@ -378,19 +378,19 @@ public function test_get_items_invalid_modified_date() { * @ticket 50617 */ public function test_get_items_valid_modified_date() { - $post1 = $this->factory->post->create( + $post1 = self::factory()->post->create( array( 'post_date' => '2016-01-01 00:00:00', 'post_type' => 'page', ) ); - $post2 = $this->factory->post->create( + $post2 = self::factory()->post->create( array( 'post_date' => '2016-01-02 00:00:00', 'post_type' => 'page', ) ); - $post3 = $this->factory->post->create( + $post3 = self::factory()->post->create( array( 'post_date' => '2016-01-03 00:00:00', 'post_type' => 'page', @@ -416,7 +416,7 @@ public function test_get_item() { } public function test_get_item_invalid_post_type() { - $post_id = $this->factory->post->create(); + $post_id = self::factory()->post->create(); $request = new WP_REST_Request( 'GET', '/wp/v2/pages/' . $post_id ); $response = rest_get_server()->dispatch( $request ); $this->assertSame( 404, $response->get_status() ); @@ -448,7 +448,7 @@ public function test_create_item_with_template() { } public function test_create_page_with_parent() { - $page_id = $this->factory->post->create( + $page_id = self::factory()->post->create( array( 'type' => 'page', ) @@ -498,7 +498,7 @@ public function test_update_item() { } public function test_delete_item() { - $page_id = $this->factory->post->create( + $page_id = self::factory()->post->create( array( 'post_type' => 'page', 'post_title' => 'Deleted page', @@ -525,7 +525,7 @@ public function test_prepare_item() { public function test_prepare_item_limit_fields() { wp_set_current_user( self::$editor_id ); - $page_id = $this->factory->post->create( + $page_id = self::factory()->post->create( array( 'post_status' => 'publish', 'post_type' => 'page', @@ -547,7 +547,7 @@ public function test_prepare_item_limit_fields() { } public function test_get_pages_params() { - $this->factory->post->create_many( + self::factory()->post->create_many( 8, array( 'post_type' => 'page', @@ -578,7 +578,7 @@ public function test_get_pages_params() { public function test_update_page_menu_order() { - $page_id = $this->factory->post->create( + $page_id = self::factory()->post->create( array( 'post_type' => 'page', ) @@ -601,7 +601,7 @@ public function test_update_page_menu_order() { public function test_update_page_menu_order_to_zero() { - $page_id = $this->factory->post->create( + $page_id = self::factory()->post->create( array( 'post_type' => 'page', 'menu_order' => 1, @@ -624,12 +624,12 @@ public function test_update_page_menu_order_to_zero() { } public function test_update_page_parent_non_zero() { - $page_id1 = $this->factory->post->create( + $page_id1 = self::factory()->post->create( array( 'post_type' => 'page', ) ); - $page_id2 = $this->factory->post->create( + $page_id2 = self::factory()->post->create( array( 'post_type' => 'page', ) @@ -647,12 +647,12 @@ public function test_update_page_parent_non_zero() { } public function test_update_page_parent_zero() { - $page_id1 = $this->factory->post->create( + $page_id1 = self::factory()->post->create( array( 'post_type' => 'page', ) ); - $page_id2 = $this->factory->post->create( + $page_id2 = self::factory()->post->create( array( 'post_type' => 'page', 'post_parent' => $page_id1, @@ -671,7 +671,7 @@ public function test_update_page_parent_zero() { } public function test_get_page_with_password() { - $page_id = $this->factory->post->create( + $page_id = self::factory()->post->create( array( 'post_type' => 'page', 'post_password' => '$inthebananastand', @@ -689,7 +689,7 @@ public function test_get_page_with_password() { } public function test_get_page_with_password_using_password() { - $page_id = $this->factory->post->create( + $page_id = self::factory()->post->create( array( 'post_type' => 'page', 'post_password' => '$inthebananastand', @@ -711,7 +711,7 @@ public function test_get_page_with_password_using_password() { } public function test_get_page_with_password_using_incorrect_password() { - $page_id = $this->factory->post->create( + $page_id = self::factory()->post->create( array( 'post_type' => 'page', 'post_password' => '$inthebananastand', @@ -727,7 +727,7 @@ public function test_get_page_with_password_using_incorrect_password() { } public function test_get_page_with_password_without_permission() { - $page_id = $this->factory->post->create( + $page_id = self::factory()->post->create( array( 'post_type' => 'page', 'post_password' => '$inthebananastand', diff --git a/tests/phpunit/tests/rest-api/rest-post-meta-fields.php b/tests/phpunit/tests/rest-api/rest-post-meta-fields.php index 85671eff54981..ebce49a7f355c 100644 --- a/tests/phpunit/tests/rest-api/rest-post-meta-fields.php +++ b/tests/phpunit/tests/rest-api/rest-post-meta-fields.php @@ -253,7 +253,7 @@ public function set_up() { protected function grant_write_permission() { // Ensure we have write permission. - $user = $this->factory->user->create( + $user = self::factory()->user->create( array( 'role' => 'editor', ) diff --git a/tests/phpunit/tests/rest-api/rest-post-statuses-controller.php b/tests/phpunit/tests/rest-api/rest-post-statuses-controller.php index 273c4e3916f48..901e8bb35783e 100644 --- a/tests/phpunit/tests/rest-api/rest-post-statuses-controller.php +++ b/tests/phpunit/tests/rest-api/rest-post-statuses-controller.php @@ -43,7 +43,7 @@ public function test_get_items() { } public function test_get_items_logged_in() { - $user_id = $this->factory->user->create( array( 'role' => 'author' ) ); + $user_id = self::factory()->user->create( array( 'role' => 'author' ) ); wp_set_current_user( $user_id ); $request = new WP_REST_Request( 'GET', '/wp/v2/statuses' ); @@ -72,7 +72,7 @@ public function test_get_items_unauthorized_context() { } public function test_get_item() { - $user_id = $this->factory->user->create( array( 'role' => 'author' ) ); + $user_id = self::factory()->user->create( array( 'role' => 'author' ) ); wp_set_current_user( $user_id ); $request = new WP_REST_Request( 'GET', '/wp/v2/statuses/publish' ); $request->set_param( 'context', 'edit' ); @@ -94,7 +94,7 @@ public function test_get_item_invalid_access() { } public function test_get_item_invalid_internal() { - $user_id = $this->factory->user->create(); + $user_id = self::factory()->user->create(); wp_set_current_user( $user_id ); $request = new WP_REST_Request( 'GET', '/wp/v2/statuses/inherit' ); diff --git a/tests/phpunit/tests/rest-api/rest-post-types-controller.php b/tests/phpunit/tests/rest-api/rest-post-types-controller.php index 22ff225a69a52..0ab2a7b937005 100644 --- a/tests/phpunit/tests/rest-api/rest-post-types-controller.php +++ b/tests/phpunit/tests/rest-api/rest-post-types-controller.php @@ -94,7 +94,7 @@ public function test_get_item_invalid_type() { } public function test_get_item_edit_context() { - $editor_id = $this->factory->user->create( array( 'role' => 'editor' ) ); + $editor_id = self::factory()->user->create( array( 'role' => 'editor' ) ); wp_set_current_user( $editor_id ); $request = new WP_REST_Request( 'GET', '/wp/v2/types/post' ); $request->set_param( 'context', 'edit' ); diff --git a/tests/phpunit/tests/rest-api/rest-posts-controller.php b/tests/phpunit/tests/rest-api/rest-posts-controller.php index 5ef229567b91f..5fa7e3cf98f02 100644 --- a/tests/phpunit/tests/rest-api/rest-posts-controller.php +++ b/tests/phpunit/tests/rest-api/rest-posts-controller.php @@ -273,8 +273,8 @@ public function test_get_items_empty_query() { } public function test_get_items_author_query() { - $this->factory->post->create( array( 'post_author' => self::$editor_id ) ); - $this->factory->post->create( array( 'post_author' => self::$author_id ) ); + self::factory()->post->create( array( 'post_author' => self::$editor_id ) ); + self::factory()->post->create( array( 'post_author' => self::$author_id ) ); $total_posts = self::$total_posts + 2; @@ -305,8 +305,8 @@ public function test_get_items_author_query() { } public function test_get_items_author_exclude_query() { - $this->factory->post->create( array( 'post_author' => self::$editor_id ) ); - $this->factory->post->create( array( 'post_author' => self::$author_id ) ); + self::factory()->post->create( array( 'post_author' => self::$editor_id ) ); + self::factory()->post->create( array( 'post_author' => self::$author_id ) ); $total_posts = self::$total_posts + 2; @@ -347,13 +347,13 @@ public function test_get_items_author_exclude_query() { } public function test_get_items_include_query() { - $id1 = $this->factory->post->create( + $id1 = self::factory()->post->create( array( 'post_status' => 'publish', 'post_date' => '2001-02-03 04:05:06', ) ); - $id2 = $this->factory->post->create( + $id2 = self::factory()->post->create( array( 'post_status' => 'publish', 'post_date' => '2001-02-03 04:05:07', @@ -386,19 +386,19 @@ public function test_get_items_include_query() { } public function test_get_items_orderby_author_query() { - $id2 = $this->factory->post->create( + $id2 = self::factory()->post->create( array( 'post_status' => 'publish', 'post_author' => self::$editor_id, ) ); - $id3 = $this->factory->post->create( + $id3 = self::factory()->post->create( array( 'post_status' => 'publish', 'post_author' => self::$editor_id, ) ); - $id1 = $this->factory->post->create( + $id1 = self::factory()->post->create( array( 'post_status' => 'publish', 'post_author' => self::$author_id, @@ -421,9 +421,9 @@ public function test_get_items_orderby_author_query() { } public function test_get_items_orderby_modified_query() { - $id1 = $this->factory->post->create( array( 'post_status' => 'publish' ) ); - $id2 = $this->factory->post->create( array( 'post_status' => 'publish' ) ); - $id3 = $this->factory->post->create( array( 'post_status' => 'publish' ) ); + $id1 = self::factory()->post->create( array( 'post_status' => 'publish' ) ); + $id2 = self::factory()->post->create( array( 'post_status' => 'publish' ) ); + $id3 = self::factory()->post->create( array( 'post_status' => 'publish' ) ); $this->update_post_modified( $id1, '2016-04-20 4:26:20' ); $this->update_post_modified( $id2, '2016-02-01 20:24:02' ); @@ -445,19 +445,19 @@ public function test_get_items_orderby_modified_query() { } public function test_get_items_orderby_parent_query() { - $id1 = $this->factory->post->create( + $id1 = self::factory()->post->create( array( 'post_status' => 'publish', 'post_type' => 'page', ) ); - $id2 = $this->factory->post->create( + $id2 = self::factory()->post->create( array( 'post_status' => 'publish', 'post_type' => 'page', ) ); - $id3 = $this->factory->post->create( + $id3 = self::factory()->post->create( array( 'post_status' => 'publish', 'post_type' => 'page', @@ -483,8 +483,8 @@ public function test_get_items_orderby_parent_query() { } public function test_get_items_exclude_query() { - $id1 = $this->factory->post->create( array( 'post_status' => 'publish' ) ); - $id2 = $this->factory->post->create( array( 'post_status' => 'publish' ) ); + $id1 = self::factory()->post->create( array( 'post_status' => 'publish' ) ); + $id2 = self::factory()->post->create( array( 'post_status' => 'publish' ) ); $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); $response = rest_get_server()->dispatch( $request ); @@ -513,7 +513,7 @@ public function test_get_items_exclude_query() { } public function test_get_items_search_query() { - $this->factory->post->create( + self::factory()->post->create( array( 'post_title' => 'Search Result', 'post_status' => 'publish', @@ -535,13 +535,13 @@ public function test_get_items_search_query() { } public function test_get_items_slug_query() { - $this->factory->post->create( + self::factory()->post->create( array( 'post_title' => 'Apple', 'post_status' => 'publish', ) ); - $this->factory->post->create( + self::factory()->post->create( array( 'post_title' => 'Banana', 'post_status' => 'publish', @@ -558,19 +558,19 @@ public function test_get_items_slug_query() { } public function test_get_items_multiple_slugs_array_query() { - $this->factory->post->create( + self::factory()->post->create( array( 'post_title' => 'Apple', 'post_status' => 'publish', ) ); - $this->factory->post->create( + self::factory()->post->create( array( 'post_title' => 'Banana', 'post_status' => 'publish', ) ); - $this->factory->post->create( + self::factory()->post->create( array( 'post_title' => 'Peach', 'post_status' => 'publish', @@ -592,19 +592,19 @@ public function test_get_items_multiple_slugs_array_query() { } public function test_get_items_multiple_slugs_string_query() { - $this->factory->post->create( + self::factory()->post->create( array( 'post_title' => 'Apple', 'post_status' => 'publish', ) ); - $this->factory->post->create( + self::factory()->post->create( array( 'post_title' => 'Banana', 'post_status' => 'publish', ) ); - $this->factory->post->create( + self::factory()->post->create( array( 'post_title' => 'Peach', 'post_status' => 'publish', @@ -628,7 +628,7 @@ public function test_get_items_multiple_slugs_string_query() { public function test_get_items_status_query() { wp_set_current_user( 0 ); - $this->factory->post->create( array( 'post_status' => 'draft' ) ); + self::factory()->post->create( array( 'post_status' => 'draft' ) ); $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); $request->set_param( 'per_page', self::$per_page ); @@ -654,9 +654,9 @@ public function test_get_items_status_query() { public function test_get_items_multiple_statuses_string_query() { wp_set_current_user( self::$editor_id ); - $this->factory->post->create( array( 'post_status' => 'draft' ) ); - $this->factory->post->create( array( 'post_status' => 'private' ) ); - $this->factory->post->create( array( 'post_status' => 'publish' ) ); + self::factory()->post->create( array( 'post_status' => 'draft' ) ); + self::factory()->post->create( array( 'post_status' => 'private' ) ); + self::factory()->post->create( array( 'post_status' => 'publish' ) ); $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); $request->set_param( 'context', 'edit' ); @@ -677,9 +677,9 @@ public function test_get_items_multiple_statuses_string_query() { public function test_get_items_multiple_statuses_array_query() { wp_set_current_user( self::$editor_id ); - $this->factory->post->create( array( 'post_status' => 'draft' ) ); - $this->factory->post->create( array( 'post_status' => 'pending' ) ); - $this->factory->post->create( array( 'post_status' => 'publish' ) ); + self::factory()->post->create( array( 'post_status' => 'draft' ) ); + self::factory()->post->create( array( 'post_status' => 'pending' ) ); + self::factory()->post->create( array( 'post_status' => 'publish' ) ); $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); $request->set_param( 'context', 'edit' ); @@ -709,7 +709,7 @@ public function test_get_items_multiple_statuses_one_invalid_query() { * @ticket 43701 */ public function test_get_items_multiple_statuses_custom_role_one_invalid_query() { - $private_post_id = $this->factory->post->create( array( 'post_status' => 'private' ) ); + $private_post_id = self::factory()->post->create( array( 'post_status' => 'private' ) ); wp_set_current_user( self::$private_reader_id ); @@ -730,7 +730,7 @@ public function test_get_items_invalid_status_query() { } public function test_get_items_status_without_permissions() { - $draft_id = $this->factory->post->create( + $draft_id = self::factory()->post->create( array( 'post_status' => 'draft', ) @@ -750,25 +750,25 @@ public function test_get_items_status_without_permissions() { } public function test_get_items_order_and_orderby() { - $this->factory->post->create( + self::factory()->post->create( array( 'post_title' => 'Apple Pie', 'post_status' => 'publish', ) ); - $this->factory->post->create( + self::factory()->post->create( array( 'post_title' => 'Apple Sauce', 'post_status' => 'publish', ) ); - $this->factory->post->create( + self::factory()->post->create( array( 'post_title' => 'Apple Cobbler', 'post_status' => 'publish', ) ); - $this->factory->post->create( + self::factory()->post->create( array( 'post_title' => 'Apple Coffee Cake', 'post_status' => 'publish', @@ -805,7 +805,7 @@ public function test_get_items_order_and_orderby() { } public function test_get_items_with_orderby_include_without_include_param() { - $this->factory->post->create( array( 'post_status' => 'publish' ) ); + self::factory()->post->create( array( 'post_status' => 'publish' ) ); $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); $request->set_param( 'orderby', 'include' ); @@ -816,19 +816,19 @@ public function test_get_items_with_orderby_include_without_include_param() { } public function test_get_items_with_orderby_id() { - $id1 = $this->factory->post->create( + $id1 = self::factory()->post->create( array( 'post_status' => 'publish', 'post_date' => '2016-01-13 02:26:48', ) ); - $id2 = $this->factory->post->create( + $id2 = self::factory()->post->create( array( 'post_status' => 'publish', 'post_date' => '2016-01-12 02:26:48', ) ); - $id3 = $this->factory->post->create( + $id3 = self::factory()->post->create( array( 'post_status' => 'publish', 'post_date' => '2016-01-11 02:26:48', @@ -850,14 +850,14 @@ public function test_get_items_with_orderby_id() { } public function test_get_items_with_orderby_slug() { - $id1 = $this->factory->post->create( + $id1 = self::factory()->post->create( array( 'post_title' => 'ABC', 'post_name' => 'xyz', 'post_status' => 'publish', ) ); - $id2 = $this->factory->post->create( + $id2 = self::factory()->post->create( array( 'post_title' => 'XYZ', 'post_name' => 'abc', @@ -881,7 +881,7 @@ public function test_get_items_with_orderby_slug() { public function test_get_items_with_orderby_slugs() { $slugs = array( 'burrito', 'taco', 'chalupa' ); foreach ( $slugs as $slug ) { - $this->factory->post->create( + self::factory()->post->create( array( 'post_title' => $slug, 'post_name' => $slug, @@ -903,14 +903,14 @@ public function test_get_items_with_orderby_slugs() { } public function test_get_items_with_orderby_relevance() { - $id1 = $this->factory->post->create( + $id1 = self::factory()->post->create( array( 'post_title' => 'Title is more relevant', 'post_content' => 'Content is', 'post_status' => 'publish', ) ); - $id2 = $this->factory->post->create( + $id2 = self::factory()->post->create( array( 'post_title' => 'Title is', 'post_content' => 'Content is less relevant', @@ -931,14 +931,14 @@ public function test_get_items_with_orderby_relevance() { } public function test_get_items_with_orderby_relevance_two_terms() { - $id1 = $this->factory->post->create( + $id1 = self::factory()->post->create( array( 'post_title' => 'Title is more relevant', 'post_content' => 'Content is', 'post_status' => 'publish', ) ); - $id2 = $this->factory->post->create( + $id2 = self::factory()->post->create( array( 'post_title' => 'Title is', 'post_content' => 'Content is less relevant', @@ -1005,9 +1005,9 @@ public function test_get_items_tags_query() { public function test_get_items_tags_exclude_query() { $id1 = self::$post_id; - $id2 = $this->factory->post->create( array( 'post_status' => 'publish' ) ); - $id3 = $this->factory->post->create( array( 'post_status' => 'publish' ) ); - $id4 = $this->factory->post->create( array( 'post_status' => 'publish' ) ); + $id2 = self::factory()->post->create( array( 'post_status' => 'publish' ) ); + $id3 = self::factory()->post->create( array( 'post_status' => 'publish' ) ); + $id4 = self::factory()->post->create( array( 'post_status' => 'publish' ) ); $tag = wp_insert_term( 'My Tag', 'post_tag' ); $total_posts = self::$total_posts + 3; @@ -1028,7 +1028,7 @@ public function test_get_items_tags_exclude_query() { public function test_get_items_tags_and_categories_query() { $id1 = self::$post_id; - $id2 = $this->factory->post->create( array( 'post_status' => 'publish' ) ); + $id2 = self::factory()->post->create( array( 'post_status' => 'publish' ) ); $tag = wp_insert_term( 'My Tag', 'post_tag' ); $category = wp_insert_term( 'My Category', 'category' ); @@ -1053,7 +1053,7 @@ public function test_get_items_tags_and_categories_query() { */ public function test_get_items_tags_or_categories_query() { $id1 = self::$post_id; - $id2 = $this->factory->post->create( array( 'post_status' => 'publish' ) ); + $id2 = self::factory()->post->create( array( 'post_status' => 'publish' ) ); $tag = wp_insert_term( 'My Tag', 'post_tag' ); $category = wp_insert_term( 'My Category', 'category' ); @@ -1075,7 +1075,7 @@ public function test_get_items_tags_or_categories_query() { public function test_get_items_tags_and_categories_exclude_query() { $id1 = self::$post_id; - $id2 = $this->factory->post->create( array( 'post_status' => 'publish' ) ); + $id2 = self::factory()->post->create( array( 'post_status' => 'publish' ) ); $tag = wp_insert_term( 'My Tag', 'post_tag' ); $category = wp_insert_term( 'My Category', 'category' ); @@ -1102,9 +1102,9 @@ public function test_get_items_tags_and_categories_exclude_query() { */ public function test_get_items_tags_or_categories_exclude_query() { $id1 = end( self::$post_ids ); - $id2 = $this->factory->post->create( array( 'post_status' => 'publish' ) ); - $id3 = $this->factory->post->create( array( 'post_status' => 'publish' ) ); - $id4 = $this->factory->post->create( array( 'post_status' => 'publish' ) ); + $id2 = self::factory()->post->create( array( 'post_status' => 'publish' ) ); + $id3 = self::factory()->post->create( array( 'post_status' => 'publish' ) ); + $id4 = self::factory()->post->create( array( 'post_status' => 'publish' ) ); $tag = wp_insert_term( 'My Tag', 'post_tag' ); $category = wp_insert_term( 'My Category', 'category' ); @@ -1366,7 +1366,7 @@ public function test_get_items_relation_with_no_tax_query() { public function test_get_items_sticky() { $id1 = self::$post_id; - $id2 = $this->factory->post->create( array( 'post_status' => 'publish' ) ); + $id2 = self::factory()->post->create( array( 'post_status' => 'publish' ) ); update_option( 'sticky_posts', array( $id2 ) ); @@ -1387,7 +1387,7 @@ public function test_get_items_sticky() { public function test_get_items_sticky_with_include() { $id1 = self::$post_id; - $id2 = $this->factory->post->create( array( 'post_status' => 'publish' ) ); + $id2 = self::factory()->post->create( array( 'post_status' => 'publish' ) ); update_option( 'sticky_posts', array( $id2 ) ); @@ -1455,7 +1455,7 @@ public function test_get_items_sticky_with_include_no_sticky_posts() { public function test_get_items_not_sticky() { $id1 = end( self::$post_ids ); - $id2 = $this->factory->post->create( array( 'post_status' => 'publish' ) ); + $id2 = self::factory()->post->create( array( 'post_status' => 'publish' ) ); $total_posts = self::$total_posts + 1; @@ -1477,8 +1477,8 @@ public function test_get_items_not_sticky() { public function test_get_items_not_sticky_with_exclude() { $id1 = end( self::$post_ids ); - $id2 = $this->factory->post->create( array( 'post_status' => 'publish' ) ); - $id3 = $this->factory->post->create( array( 'post_status' => 'publish' ) ); + $id2 = self::factory()->post->create( array( 'post_status' => 'publish' ) ); + $id3 = self::factory()->post->create( array( 'post_status' => 'publish' ) ); $total_posts = self::$total_posts + 2; @@ -1503,8 +1503,8 @@ public function test_get_items_not_sticky_with_exclude() { public function test_get_items_not_sticky_with_exclude_no_sticky_posts() { $id1 = self::$post_id; - $id2 = $this->factory->post->create( array( 'post_status' => 'publish' ) ); - $id3 = $this->factory->post->create( array( 'post_status' => 'publish' ) ); + $id2 = self::factory()->post->create( array( 'post_status' => 'publish' ) ); + $id3 = self::factory()->post->create( array( 'post_status' => 'publish' ) ); $total_posts = self::$total_posts + 2; @@ -1574,7 +1574,7 @@ public function test_get_items_primes_parent_post_caches() { $parent_id2 = self::$post_ids[1]; $parent_ids = array( $parent_id1, $parent_id2 ); $attachment_ids = array(); - $attachment_ids[] = $this->factory->attachment->create_object( + $attachment_ids[] = self::factory()->attachment->create_object( DIR_TESTDATA . '/images/canola.jpg', $parent_id1, array( @@ -1583,7 +1583,7 @@ public function test_get_items_primes_parent_post_caches() { ) ); - $attachment_ids[] = $this->factory->attachment->create_object( + $attachment_ids[] = self::factory()->attachment->create_object( DIR_TESTDATA . '/images/canola.jpg', $parent_id2, array( @@ -1628,7 +1628,7 @@ public function test_get_items_pagination_headers() { $this->assertStringContainsString( '<' . $next_link . '>; rel="next"', $headers['Link'] ); // 3rd page. - $this->factory->post->create(); + self::factory()->post->create(); $total_posts++; $total_pages++; $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); @@ -1707,7 +1707,7 @@ public function test_get_items_pagination_headers() { } public function test_get_items_status_draft_permissions() { - $draft_id = $this->factory->post->create( array( 'post_status' => 'draft' ) ); + $draft_id = self::factory()->post->create( array( 'post_status' => 'draft' ) ); // Drafts status query var inaccessible to unauthorized users. wp_set_current_user( 0 ); @@ -1737,7 +1737,7 @@ public function test_get_items_status_draft_permissions() { * @ticket 43701 */ public function test_get_items_status_private_permissions() { - $private_post_id = $this->factory->post->create( array( 'post_status' => 'private' ) ); + $private_post_id = self::factory()->post->create( array( 'post_status' => 'private' ) ); wp_set_current_user( 0 ); @@ -1792,9 +1792,9 @@ public function test_get_items_invalid_date() { } public function test_get_items_valid_date() { - $post1 = $this->factory->post->create( array( 'post_date' => '2016-01-15T00:00:00Z' ) ); - $post2 = $this->factory->post->create( array( 'post_date' => '2016-01-16T00:00:00Z' ) ); - $post3 = $this->factory->post->create( array( 'post_date' => '2016-01-17T00:00:00Z' ) ); + $post1 = self::factory()->post->create( array( 'post_date' => '2016-01-15T00:00:00Z' ) ); + $post2 = self::factory()->post->create( array( 'post_date' => '2016-01-16T00:00:00Z' ) ); + $post3 = self::factory()->post->create( array( 'post_date' => '2016-01-17T00:00:00Z' ) ); $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); $request->set_param( 'after', '2016-01-15T00:00:00Z' ); @@ -1820,9 +1820,9 @@ public function test_get_items_invalid_modified_date() { * @ticket 50617 */ public function test_get_items_valid_modified_date() { - $post1 = $this->factory->post->create( array( 'post_date' => '2016-01-01 00:00:00' ) ); - $post2 = $this->factory->post->create( array( 'post_date' => '2016-01-02 00:00:00' ) ); - $post3 = $this->factory->post->create( array( 'post_date' => '2016-01-03 00:00:00' ) ); + $post1 = self::factory()->post->create( array( 'post_date' => '2016-01-01 00:00:00' ) ); + $post2 = self::factory()->post->create( array( 'post_date' => '2016-01-02 00:00:00' ) ); + $post3 = self::factory()->post->create( array( 'post_date' => '2016-01-03 00:00:00' ) ); $this->update_post_modified( $post1, '2016-01-15 00:00:00' ); $this->update_post_modified( $post2, '2016-01-16 00:00:00' ); $this->update_post_modified( $post3, '2016-01-17 00:00:00' ); @@ -1940,7 +1940,7 @@ public function test_get_item_links_no_author() { } public function test_get_post_draft_status_not_authenticated() { - $draft_id = $this->factory->post->create( + $draft_id = self::factory()->post->create( array( 'post_status' => 'draft', ) @@ -1956,7 +1956,7 @@ public function test_get_post_draft_status_not_authenticated() { public function test_get_post_draft_edit_context() { $post_content = 'Hello World!'; - $this->factory->post->create( + self::factory()->post->create( array( 'post_title' => 'Hola', 'post_password' => 'password', @@ -1965,7 +1965,7 @@ public function test_get_post_draft_edit_context() { 'post_author' => self::$editor_id, ) ); - $draft_id = $this->factory->post->create( + $draft_id = self::factory()->post->create( array( 'post_status' => 'draft', 'post_author' => self::$contributor_id, @@ -2031,7 +2031,7 @@ public function test_get_post_context_without_permission() { } public function test_get_post_with_password() { - $post_id = $this->factory->post->create( + $post_id = self::factory()->post->create( array( 'post_password' => '$inthebananastand', ) @@ -2050,7 +2050,7 @@ public function test_get_post_with_password() { } public function test_get_post_with_password_using_password() { - $post_id = $this->factory->post->create( + $post_id = self::factory()->post->create( array( 'post_password' => '$inthebananastand', 'post_content' => 'Some secret content.', @@ -2074,7 +2074,7 @@ public function test_get_post_with_password_using_password() { } public function test_get_post_with_password_using_incorrect_password() { - $post_id = $this->factory->post->create( + $post_id = self::factory()->post->create( array( 'post_password' => '$inthebananastand', ) @@ -2090,7 +2090,7 @@ public function test_get_post_with_password_using_incorrect_password() { } public function test_get_post_with_password_without_permission() { - $post_id = $this->factory->post->create( + $post_id = self::factory()->post->create( array( 'post_password' => '$inthebananastand', 'post_content' => 'Some secret content.', @@ -2114,7 +2114,7 @@ public function test_get_post_with_password_without_permission() { * @ticket 43887 */ public function test_get_post_should_not_have_block_version_when_context_view() { - $post_id = $this->factory->post->create( + $post_id = self::factory()->post->create( array( 'post_content' => '', ) @@ -2134,7 +2134,7 @@ public function test_get_post_should_not_have_block_version_when_context_view() public function test_get_post_should_have_block_version_indicate_block_content_when_context_edit() { wp_set_current_user( self::$editor_id ); - $post_id = $this->factory->post->create( + $post_id = self::factory()->post->create( array( 'post_content' => '', ) @@ -2155,7 +2155,7 @@ public function test_get_post_should_have_block_version_indicate_block_content_w public function test_get_post_should_have_block_version_indicate_no_block_content_when_context_edit() { wp_set_current_user( self::$editor_id ); - $post_id = $this->factory->post->create( + $post_id = self::factory()->post->create( array( 'post_content' => '
', ) @@ -2783,7 +2783,7 @@ public function test_create_post_with_unsupported_format() { public function test_create_update_post_with_featured_media() { $file = DIR_TESTDATA . '/images/canola.jpg'; - $attachment_id = $this->factory->attachment->create_object( + $attachment_id = self::factory()->attachment->create_object( $file, 0, array( @@ -3187,7 +3187,7 @@ public function test_rest_update_post() { */ public function test_rest_update_post_with_empty_date() { // Create a new test post. - $post_id = $this->factory->post->create(); + $post_id = self::factory()->post->create(); wp_set_current_user( self::$editor_id ); @@ -3436,7 +3436,7 @@ public function test_update_post_date( $status, $params, $results ) { update_option( 'timezone_string', $params['timezone_string'] ); - $post_id = $this->factory->post->create( array( 'post_status' => $status ) ); + $post_id = self::factory()->post->create( array( 'post_status' => $status ) ); $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/posts/%d', $post_id ) ); if ( isset( $params['date'] ) ) { @@ -3501,7 +3501,7 @@ public function test_empty_post_date_gmt_shimmed_using_post_date() { // Need to set dates using wpdb directly because `wp_update_post` and // `wp_insert_post` have additional validation on dates. - $post_id = $this->factory->post->create(); + $post_id = self::factory()->post->create(); $wpdb->update( $wpdb->posts, array( @@ -4171,7 +4171,7 @@ public function test_post_roundtrip_as_superadmin_unfiltered_html() { } public function test_delete_item() { - $post_id = $this->factory->post->create( array( 'post_title' => 'Deleted post' ) ); + $post_id = self::factory()->post->create( array( 'post_title' => 'Deleted post' ) ); wp_set_current_user( self::$editor_id ); @@ -4186,7 +4186,7 @@ public function test_delete_item() { } public function test_delete_item_skip_trash() { - $post_id = $this->factory->post->create( array( 'post_title' => 'Deleted post' ) ); + $post_id = self::factory()->post->create( array( 'post_title' => 'Deleted post' ) ); wp_set_current_user( self::$editor_id ); @@ -4201,7 +4201,7 @@ public function test_delete_item_skip_trash() { } public function test_delete_item_already_trashed() { - $post_id = $this->factory->post->create( array( 'post_title' => 'Deleted post' ) ); + $post_id = self::factory()->post->create( array( 'post_title' => 'Deleted post' ) ); wp_set_current_user( self::$editor_id ); @@ -4222,7 +4222,7 @@ public function test_delete_post_invalid_id() { } public function test_delete_post_invalid_post_type() { - $page_id = $this->factory->post->create( array( 'post_type' => 'page' ) ); + $page_id = self::factory()->post->create( array( 'post_type' => 'page' ) ); wp_set_current_user( self::$editor_id ); @@ -4465,7 +4465,7 @@ public function test_get_additional_field_registration() { wp_set_current_user( 1 ); - $post_id = $this->factory->post->create(); + $post_id = self::factory()->post->create(); $request = new WP_REST_Request( 'GET', '/wp/v2/posts/' . $post_id ); $response = rest_get_server()->dispatch( $request ); @@ -4510,7 +4510,7 @@ public function test_get_additional_field_registration_null_schema() { 'update_callback' => null, ) ); - $post_id = $this->factory->post->create(); + $post_id = self::factory()->post->create(); // 'my_custom_int' should appear because ?_fields= isn't set. $request = new WP_REST_Request( 'GET', '/wp/v2/posts/' . $post_id ); @@ -4931,7 +4931,7 @@ public function test_generated_permalink_template_generated_slug_for_non_viewabl wp_set_current_user( self::$editor_id ); - $post_id = $this->factory->post->create( + $post_id = self::factory()->post->create( array( 'post_title' => 'Permalink Template', 'post_type' => 'private-post', @@ -4955,7 +4955,7 @@ public function test_generated_permalink_template_generated_slug_for_posts() { wp_set_current_user( self::$editor_id ); - $post_id = $this->factory->post->create( + $post_id = self::factory()->post->create( array( 'post_title' => 'Permalink Template', 'post_type' => 'post', diff --git a/tests/phpunit/tests/rest-api/rest-schema-setup.php b/tests/phpunit/tests/rest-api/rest-schema-setup.php index 65efbba7f4f96..a1e4330c0cc4a 100644 --- a/tests/phpunit/tests/rest-api/rest-schema-setup.php +++ b/tests/phpunit/tests/rest-api/rest-schema-setup.php @@ -205,7 +205,7 @@ public function test_build_wp_api_client_fixtures() { // fixture file will be different between runs of PHPUnit tests, which // is not desirable. - $administrator_id = $this->factory->user->create( + $administrator_id = self::factory()->user->create( array( 'role' => 'administrator', 'display_name' => 'REST API Client Fixture: User', @@ -215,7 +215,7 @@ public function test_build_wp_api_client_fixtures() { ); wp_set_current_user( $administrator_id ); - $post_id = $this->factory->post->create( + $post_id = self::factory()->post->create( array( 'post_name' => 'restapi-client-fixture-post', 'post_title' => 'REST API Client Fixture: Post', @@ -243,7 +243,7 @@ public function test_build_wp_api_client_fixtures() { ) ); - $page_id = $this->factory->post->create( + $page_id = self::factory()->post->create( array( 'post_type' => 'page', 'post_name' => 'restapi-client-fixture-page', @@ -273,7 +273,7 @@ public function test_build_wp_api_client_fixtures() { ) ); - $tag_id = $this->factory->tag->create( + $tag_id = self::factory()->tag->create( array( 'name' => 'REST API Client Fixture: Tag', 'slug' => 'restapi-client-fixture-tag', @@ -281,7 +281,7 @@ public function test_build_wp_api_client_fixtures() { ) ); - $media_id = $this->factory->attachment->create_object( + $media_id = self::factory()->attachment->create_object( get_temp_dir() . 'canola.jpg', 0, array( @@ -295,7 +295,7 @@ public function test_build_wp_api_client_fixtures() { ) ); - $comment_id = $this->factory->comment->create( + $comment_id = self::factory()->comment->create( array( 'comment_approved' => 1, 'comment_post_ID' => $post_id, diff --git a/tests/phpunit/tests/rest-api/rest-tags-controller.php b/tests/phpunit/tests/rest-api/rest-tags-controller.php index 788d6901f26b6..a4b566f7b2604 100644 --- a/tests/phpunit/tests/rest-api/rest-tags-controller.php +++ b/tests/phpunit/tests/rest-api/rest-tags-controller.php @@ -139,7 +139,7 @@ public function test_context_param() { $this->assertSame( 'view', $data['endpoints'][0]['args']['context']['default'] ); $this->assertSameSets( array( 'view', 'embed', 'edit' ), $data['endpoints'][0]['args']['context']['enum'] ); // Single. - $tag1 = $this->factory->tag->create( array( 'name' => 'Season 5' ) ); + $tag1 = self::factory()->tag->create( array( 'name' => 'Season 5' ) ); $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/tags/' . $tag1 ); $response = rest_get_server()->dispatch( $request ); $data = $response->get_data(); @@ -174,7 +174,7 @@ public function test_registered_query_params() { } public function test_get_items() { - $this->factory->tag->create(); + self::factory()->tag->create(); $request = new WP_REST_Request( 'GET', '/wp/v2/tags' ); $request->set_param( 'per_page', self::$per_page ); @@ -192,9 +192,9 @@ public function test_get_items_invalid_permission_for_context() { } public function test_get_items_hide_empty_arg() { - $post_id = $this->factory->post->create(); - $tag1 = $this->factory->tag->create( array( 'name' => 'Season 5' ) ); - $tag2 = $this->factory->tag->create( array( 'name' => 'The Be Sharps' ) ); + $post_id = self::factory()->post->create(); + $tag1 = self::factory()->tag->create( array( 'name' => 'Season 5' ) ); + $tag2 = self::factory()->tag->create( array( 'name' => 'The Be Sharps' ) ); wp_set_object_terms( $post_id, array( $tag1, $tag2 ), 'post_tag' ); @@ -213,8 +213,8 @@ public function test_get_items_hide_empty_arg() { } public function test_get_items_include_query() { - $id1 = $this->factory->tag->create(); - $id2 = $this->factory->tag->create(); + $id1 = self::factory()->tag->create(); + $id2 = self::factory()->tag->create(); $request = new WP_REST_Request( 'GET', '/wp/v2/tags' ); @@ -239,8 +239,8 @@ public function test_get_items_include_query() { } public function test_get_items_exclude_query() { - $id1 = $this->factory->tag->create(); - $id2 = $this->factory->tag->create(); + $id1 = self::factory()->tag->create(); + $id2 = self::factory()->tag->create(); $request = new WP_REST_Request( 'GET', '/wp/v2/tags' ); $request->set_param( 'per_page', self::$per_page ); @@ -288,8 +288,8 @@ public function test_get_items_offset_query() { public function test_get_items_orderby_args() { - $tag1 = $this->factory->tag->create( array( 'name' => 'Apple' ) ); - $tag2 = $this->factory->tag->create( array( 'name' => 'Zucchini' ) ); + $tag1 = self::factory()->tag->create( array( 'name' => 'Apple' ) ); + $tag2 = self::factory()->tag->create( array( 'name' => 'Zucchini' ) ); /* * Tests: @@ -324,9 +324,9 @@ public function test_get_items_orderby_args() { } public function test_get_items_orderby_id() { - $tag0 = $this->factory->tag->create( array( 'name' => 'Cantaloupe' ) ); - $tag1 = $this->factory->tag->create( array( 'name' => 'Apple' ) ); - $tag2 = $this->factory->tag->create( array( 'name' => 'Banana' ) ); + $tag0 = self::factory()->tag->create( array( 'name' => 'Cantaloupe' ) ); + $tag1 = self::factory()->tag->create( array( 'name' => 'Apple' ) ); + $tag2 = self::factory()->tag->create( array( 'name' => 'Banana' ) ); // Defaults to 'orderby' => 'name', 'order' => 'asc'. $request = new WP_REST_Request( 'GET', '/wp/v2/tags' ); @@ -360,9 +360,9 @@ public function test_get_items_orderby_id() { } public function test_get_items_orderby_slugs() { - $this->factory->tag->create( array( 'name' => 'Burrito' ) ); - $this->factory->tag->create( array( 'name' => 'Taco' ) ); - $this->factory->tag->create( array( 'name' => 'Chalupa' ) ); + self::factory()->tag->create( array( 'name' => 'Burrito' ) ); + self::factory()->tag->create( array( 'name' => 'Taco' ) ); + self::factory()->tag->create( array( 'name' => 'Chalupa' ) ); $request = new WP_REST_Request( 'GET', '/wp/v2/tags' ); $request->set_param( 'orderby', 'include_slugs' ); @@ -376,10 +376,10 @@ public function test_get_items_orderby_slugs() { } public function test_get_items_post_args() { - $post_id = $this->factory->post->create(); - $tag1 = $this->factory->tag->create( array( 'name' => 'DC' ) ); - $tag2 = $this->factory->tag->create( array( 'name' => 'Marvel' ) ); - $this->factory->tag->create( array( 'name' => 'Dark Horse' ) ); + $post_id = self::factory()->post->create(); + $tag1 = self::factory()->tag->create( array( 'name' => 'DC' ) ); + $tag2 = self::factory()->tag->create( array( 'name' => 'Marvel' ) ); + self::factory()->tag->create( array( 'name' => 'Dark Horse' ) ); wp_set_object_terms( $post_id, array( $tag1, $tag2 ), 'post_tag' ); @@ -400,7 +400,7 @@ public function test_get_items_post_args() { } public function test_get_terms_post_args_paging() { - $post_id = $this->factory->post->create(); + $post_id = self::factory()->post->create(); wp_set_object_terms( $post_id, self::$tag_ids, 'post_tag' ); @@ -437,7 +437,7 @@ public function test_get_terms_post_args_paging() { } public function test_get_items_post_empty() { - $post_id = $this->factory->post->create(); + $post_id = self::factory()->post->create(); $request = new WP_REST_Request( 'GET', '/wp/v2/tags' ); $request->set_param( 'post', $post_id ); @@ -452,25 +452,25 @@ public function test_get_items_custom_tax_post_args() { register_taxonomy( 'batman', 'post', array( 'show_in_rest' => true ) ); $controller = new WP_REST_Terms_Controller( 'batman' ); $controller->register_routes(); - $term1 = $this->factory->term->create( + $term1 = self::factory()->term->create( array( 'name' => 'Cape', 'taxonomy' => 'batman', ) ); - $term2 = $this->factory->term->create( + $term2 = self::factory()->term->create( array( 'name' => 'Mask', 'taxonomy' => 'batman', ) ); - $this->factory->term->create( + self::factory()->term->create( array( 'name' => 'Car', 'taxonomy' => 'batman', ) ); - $post_id = $this->factory->post->create(); + $post_id = self::factory()->post->create(); wp_set_object_terms( $post_id, array( $term1, $term2 ), 'batman' ); @@ -485,8 +485,8 @@ public function test_get_items_custom_tax_post_args() { } public function test_get_items_search_args() { - $tag1 = $this->factory->tag->create( array( 'name' => 'Apple' ) ); - $tag2 = $this->factory->tag->create( array( 'name' => 'Banana' ) ); + $tag1 = self::factory()->tag->create( array( 'name' => 'Apple' ) ); + $tag2 = self::factory()->tag->create( array( 'name' => 'Banana' ) ); /* * Tests: @@ -509,8 +509,8 @@ public function test_get_items_search_args() { } public function test_get_items_slug_arg() { - $tag1 = $this->factory->tag->create( array( 'name' => 'Apple' ) ); - $tag2 = $this->factory->tag->create( array( 'name' => 'Banana' ) ); + $tag1 = self::factory()->tag->create( array( 'name' => 'Apple' ) ); + $tag2 = self::factory()->tag->create( array( 'name' => 'Banana' ) ); $request = new WP_REST_Request( 'GET', '/wp/v2/tags' ); $request->set_param( 'slug', 'apple' ); @@ -522,10 +522,10 @@ public function test_get_items_slug_arg() { } public function test_get_items_slug_array_arg() { - $id1 = $this->factory->tag->create( array( 'name' => 'Taco' ) ); - $id2 = $this->factory->tag->create( array( 'name' => 'Enchilada' ) ); - $id3 = $this->factory->tag->create( array( 'name' => 'Burrito' ) ); - $this->factory->tag->create( array( 'name' => 'Pizza' ) ); + $id1 = self::factory()->tag->create( array( 'name' => 'Taco' ) ); + $id2 = self::factory()->tag->create( array( 'name' => 'Enchilada' ) ); + $id3 = self::factory()->tag->create( array( 'name' => 'Burrito' ) ); + self::factory()->tag->create( array( 'name' => 'Pizza' ) ); $request = new WP_REST_Request( 'GET', '/wp/v2/tags' ); $request->set_param( @@ -545,10 +545,10 @@ public function test_get_items_slug_array_arg() { } public function test_get_items_slug_csv_arg() { - $id1 = $this->factory->tag->create( array( 'name' => 'Taco' ) ); - $id2 = $this->factory->tag->create( array( 'name' => 'Enchilada' ) ); - $id3 = $this->factory->tag->create( array( 'name' => 'Burrito' ) ); - $this->factory->tag->create( array( 'name' => 'Pizza' ) ); + $id1 = self::factory()->tag->create( array( 'name' => 'Taco' ) ); + $id2 = self::factory()->tag->create( array( 'name' => 'Enchilada' ) ); + $id3 = self::factory()->tag->create( array( 'name' => 'Burrito' ) ); + self::factory()->tag->create( array( 'name' => 'Pizza' ) ); $request = new WP_REST_Request( 'GET', '/wp/v2/tags' ); $request->set_param( 'slug', 'taco,burrito, enchilada' ); @@ -562,13 +562,13 @@ public function test_get_items_slug_csv_arg() { public function test_get_terms_private_taxonomy() { register_taxonomy( 'robin', 'post', array( 'public' => false ) ); - $term1 = $this->factory->term->create( + $term1 = self::factory()->term->create( array( 'name' => 'Cape', 'taxonomy' => 'robin', ) ); - $term2 = $this->factory->term->create( + $term2 = self::factory()->term->create( array( 'name' => 'Mask', 'taxonomy' => 'robin', @@ -600,7 +600,7 @@ public function test_get_terms_pagination_headers() { $this->assertStringContainsString( '<' . $next_link . '>; rel="next"', $headers['Link'] ); // 3rd page. - $this->factory->tag->create(); + self::factory()->tag->create(); $total_tags++; $total_pages++; $request = new WP_REST_Request( 'GET', '/wp/v2/tags' ); @@ -665,7 +665,7 @@ public function test_get_items_invalid_context() { } public function test_get_item() { - $id = $this->factory->tag->create(); + $id = self::factory()->tag->create(); $request = new WP_REST_Request( 'GET', '/wp/v2/tags/' . $id ); $response = rest_get_server()->dispatch( $request ); @@ -676,7 +676,7 @@ public function test_get_item() { * @ticket 39122 */ public function test_get_item_meta() { - $id = $this->factory->tag->create(); + $id = self::factory()->tag->create(); $request = new WP_REST_Request( 'GET', '/wp/v2/tags/' . $id ); $response = rest_get_server()->dispatch( $request ); @@ -698,7 +698,7 @@ public function test_get_item_meta() { * @ticket 39122 */ public function test_get_item_meta_registered_for_different_taxonomy() { - $id = $this->factory->tag->create(); + $id = self::factory()->tag->create(); $request = new WP_REST_Request( 'GET', '/wp/v2/tags/' . $id ); $response = rest_get_server()->dispatch( $request ); @@ -716,7 +716,7 @@ public function test_get_term_invalid_term() { } public function test_get_item_invalid_permission_for_context() { - $id = $this->factory->tag->create(); + $id = self::factory()->tag->create(); wp_set_current_user( 0 ); @@ -728,7 +728,7 @@ public function test_get_item_invalid_permission_for_context() { public function test_get_term_private_taxonomy() { register_taxonomy( 'robin', 'post', array( 'public' => false ) ); - $term1 = $this->factory->term->create( + $term1 = self::factory()->term->create( array( 'name' => 'Cape', 'taxonomy' => 'robin', @@ -742,7 +742,7 @@ public function test_get_term_private_taxonomy() { public function test_get_item_incorrect_taxonomy() { register_taxonomy( 'robin', 'post' ); - $term1 = $this->factory->term->create( + $term1 = self::factory()->term->create( array( 'name' => 'Cape', 'taxonomy' => 'robin', @@ -833,7 +833,7 @@ public function test_create_item_with_meta() { public function test_create_item_with_meta_wrong_id() { wp_set_current_user( self::$administrator ); - $existing_tag_id = $this->factory->tag->create( array( 'name' => 'My Not So Awesome Term' ) ); + $existing_tag_id = self::factory()->tag->create( array( 'name' => 'My Not So Awesome Term' ) ); $request = new WP_REST_Request( 'POST', '/wp/v2/tags' ); $request->set_param( 'name', 'My Awesome Term' ); @@ -858,7 +858,7 @@ public function test_update_item() { 'slug' => 'original-slug', ); - $term = get_term_by( 'id', $this->factory->tag->create( $orig_args ), 'post_tag' ); + $term = get_term_by( 'id', self::factory()->tag->create( $orig_args ), 'post_tag' ); $request = new WP_REST_Request( 'POST', '/wp/v2/tags/' . $term->term_id ); $request->set_param( 'name', 'New Name' ); @@ -886,7 +886,7 @@ public function test_update_item() { public function test_update_item_no_change() { wp_set_current_user( self::$administrator ); - $term = get_term_by( 'id', $this->factory->tag->create(), 'post_tag' ); + $term = get_term_by( 'id', self::factory()->tag->create(), 'post_tag' ); $request = new WP_REST_Request( 'PUT', '/wp/v2/tags/' . $term->term_id ); $response = rest_get_server()->dispatch( $request ); @@ -914,7 +914,7 @@ public function test_update_item_invalid_term() { public function test_update_item_incorrect_permissions() { wp_set_current_user( self::$subscriber ); - $term = get_term_by( 'id', $this->factory->tag->create(), 'post_tag' ); + $term = get_term_by( 'id', self::factory()->tag->create(), 'post_tag' ); $request = new WP_REST_Request( 'POST', '/wp/v2/tags/' . $term->term_id ); $request->set_param( 'name', 'Incorrect permissions' ); @@ -928,7 +928,7 @@ public function test_update_item_incorrect_permissions() { public function test_update_item_with_edit_term_cap_granted() { wp_set_current_user( self::$subscriber ); - $term = $this->factory->tag->create_and_get(); + $term = self::factory()->tag->create_and_get(); $request = new WP_REST_Request( 'POST', '/wp/v2/tags/' . $term->term_id ); $request->set_param( 'name', 'New Name' ); @@ -955,7 +955,7 @@ public function grant_edit_term( $caps, $cap ) { public function test_update_item_with_edit_term_cap_revoked() { wp_set_current_user( self::$administrator ); - $term = $this->factory->tag->create_and_get(); + $term = self::factory()->tag->create_and_get(); $request = new WP_REST_Request( 'POST', '/wp/v2/tags/' . $term->term_id ); $request->set_param( 'name', 'New Name' ); @@ -977,7 +977,7 @@ public function revoke_edit_term( $caps, $cap ) { public function test_update_item_parent_non_hierarchical_taxonomy() { wp_set_current_user( self::$administrator ); - $term = get_term_by( 'id', $this->factory->tag->create(), 'post_tag' ); + $term = get_term_by( 'id', self::factory()->tag->create(), 'post_tag' ); $request = new WP_REST_Request( 'POST', '/wp/v2/tags/' . $term->term_id ); $request->set_param( 'parent', REST_TESTS_IMPOSSIBLY_HIGH_NUMBER ); @@ -1104,7 +1104,7 @@ public function test_tag_roundtrip_as_superadmin_html() { public function test_delete_item() { wp_set_current_user( self::$administrator ); - $term = get_term_by( 'id', $this->factory->tag->create( array( 'name' => 'Deleted Tag' ) ), 'post_tag' ); + $term = get_term_by( 'id', self::factory()->tag->create( array( 'name' => 'Deleted Tag' ) ), 'post_tag' ); $request = new WP_REST_Request( 'DELETE', '/wp/v2/tags/' . $term->term_id ); $request->set_param( 'force', true ); @@ -1118,7 +1118,7 @@ public function test_delete_item() { public function test_delete_item_no_trash() { wp_set_current_user( self::$administrator ); - $term = get_term_by( 'id', $this->factory->tag->create( array( 'name' => 'Deleted Tag' ) ), 'post_tag' ); + $term = get_term_by( 'id', self::factory()->tag->create( array( 'name' => 'Deleted Tag' ) ), 'post_tag' ); $request = new WP_REST_Request( 'DELETE', '/wp/v2/tags/' . $term->term_id ); $response = rest_get_server()->dispatch( $request ); @@ -1140,7 +1140,7 @@ public function test_delete_item_invalid_term() { public function test_delete_item_incorrect_permissions() { wp_set_current_user( self::$subscriber ); - $term = get_term_by( 'id', $this->factory->tag->create(), 'post_tag' ); + $term = get_term_by( 'id', self::factory()->tag->create(), 'post_tag' ); $request = new WP_REST_Request( 'DELETE', '/wp/v2/tags/' . $term->term_id ); $response = rest_get_server()->dispatch( $request ); @@ -1153,7 +1153,7 @@ public function test_delete_item_incorrect_permissions() { public function test_delete_item_with_delete_term_cap_granted() { wp_set_current_user( self::$subscriber ); - $term = get_term_by( 'id', $this->factory->tag->create( array( 'name' => 'Deleted Tag' ) ), 'post_tag' ); + $term = get_term_by( 'id', self::factory()->tag->create( array( 'name' => 'Deleted Tag' ) ), 'post_tag' ); $request = new WP_REST_Request( 'DELETE', '/wp/v2/tags/' . $term->term_id ); $request->set_param( 'force', true ); @@ -1181,7 +1181,7 @@ public function grant_delete_term( $caps, $cap ) { public function test_delete_item_with_delete_term_cap_revoked() { wp_set_current_user( self::$administrator ); - $term = get_term_by( 'id', $this->factory->tag->create( array( 'name' => 'Deleted Tag' ) ), 'post_tag' ); + $term = get_term_by( 'id', self::factory()->tag->create( array( 'name' => 'Deleted Tag' ) ), 'post_tag' ); $request = new WP_REST_Request( 'DELETE', '/wp/v2/tags/' . $term->term_id ); $request->set_param( 'force', true ); @@ -1201,7 +1201,7 @@ public function revoke_delete_term( $caps, $cap ) { } public function test_prepare_item() { - $term = get_term_by( 'id', $this->factory->tag->create(), 'post_tag' ); + $term = get_term_by( 'id', self::factory()->tag->create(), 'post_tag' ); $request = new WP_REST_Request( 'GET', '/wp/v2/tags/' . $term->term_id ); $response = rest_get_server()->dispatch( $request ); @@ -1214,7 +1214,7 @@ public function test_prepare_item_limit_fields() { $request = new WP_REST_Request; $endpoint = new WP_REST_Terms_Controller( 'post_tag' ); $request->set_param( '_fields', 'id,name' ); - $term = get_term_by( 'id', $this->factory->tag->create(), 'post_tag' ); + $term = get_term_by( 'id', self::factory()->tag->create(), 'post_tag' ); $response = $endpoint->prepare_item_for_response( $term, $request ); $this->assertSame( array( @@ -1276,7 +1276,7 @@ public function test_get_additional_field_registration() { $this->assertArrayHasKey( 'my_custom_int', $data['schema']['properties'] ); $this->assertSame( $schema, $data['schema']['properties']['my_custom_int'] ); - $tag_id = $this->factory->tag->create(); + $tag_id = self::factory()->tag->create(); $request = new WP_REST_Request( 'GET', '/wp/v2/tags/' . $tag_id ); $response = rest_get_server()->dispatch( $request ); @@ -1306,7 +1306,7 @@ public function test_additional_field_update_errors() { wp_set_current_user( self::$administrator ); - $tag_id = $this->factory->tag->create(); + $tag_id = self::factory()->tag->create(); // Check for error on update. $request = new WP_REST_Request( 'POST', sprintf( '/wp/v2/tags/%d', $tag_id ) ); @@ -1330,8 +1330,8 @@ public function test_additional_field_update_errors() { public function test_object_term_queries_are_cached() { global $wpdb; - $tags = $this->factory->tag->create_many( 2 ); - $p = $this->factory->post->create(); + $tags = self::factory()->tag->create_many( 2 ); + $p = self::factory()->post->create(); wp_set_object_terms( $p, $tags[0], 'post_tag' ); $request = new WP_REST_Request( 'GET', '/wp/v2/tags' ); diff --git a/tests/phpunit/tests/rest-api/rest-taxonomies-controller.php b/tests/phpunit/tests/rest-api/rest-taxonomies-controller.php index 38906f55137cb..78593e6bd86d5 100644 --- a/tests/phpunit/tests/rest-api/rest-taxonomies-controller.php +++ b/tests/phpunit/tests/rest-api/rest-taxonomies-controller.php @@ -112,7 +112,7 @@ public function test_get_item() { } public function test_get_item_edit_context() { - $editor_id = $this->factory->user->create( array( 'role' => 'editor' ) ); + $editor_id = self::factory()->user->create( array( 'role' => 'editor' ) ); wp_set_current_user( $editor_id ); $request = new WP_REST_Request( 'GET', '/wp/v2/taxonomies/category' ); $request->set_param( 'context', 'edit' ); diff --git a/tests/phpunit/tests/rest-api/rest-term-meta-fields.php b/tests/phpunit/tests/rest-api/rest-term-meta-fields.php index eb25ffc226715..5a61623387055 100644 --- a/tests/phpunit/tests/rest-api/rest-term-meta-fields.php +++ b/tests/phpunit/tests/rest-api/rest-term-meta-fields.php @@ -200,7 +200,7 @@ public function set_up() { protected function grant_write_permission() { // Ensure we have write permission. - $user = $this->factory->user->create( + $user = self::factory()->user->create( array( 'role' => 'editor', ) diff --git a/tests/phpunit/tests/rest-api/rest-users-controller.php b/tests/phpunit/tests/rest-api/rest-users-controller.php index d9885cf84fc8e..849b0e5464496 100644 --- a/tests/phpunit/tests/rest-api/rest-users-controller.php +++ b/tests/phpunit/tests/rest-api/rest-users-controller.php @@ -340,7 +340,7 @@ public function test_get_items_pagination_headers() { $this->assertStringContainsString( '<' . $next_link . '>; rel="next"', $headers['Link'] ); // 3rd page. - $this->factory->user->create(); + self::factory()->user->create(); $total_users++; $total_pages++; $request = new WP_REST_Request( 'GET', '/wp/v2/users' ); @@ -432,9 +432,9 @@ public function test_get_items_page() { public function test_get_items_orderby_name() { wp_set_current_user( self::$user ); - $low_id = $this->factory->user->create( array( 'display_name' => 'AAAAA' ) ); - $mid_id = $this->factory->user->create( array( 'display_name' => 'NNNNN' ) ); - $high_id = $this->factory->user->create( array( 'display_name' => 'ZZZZ' ) ); + $low_id = self::factory()->user->create( array( 'display_name' => 'AAAAA' ) ); + $mid_id = self::factory()->user->create( array( 'display_name' => 'NNNNN' ) ); + $high_id = self::factory()->user->create( array( 'display_name' => 'ZZZZ' ) ); $request = new WP_REST_Request( 'GET', '/wp/v2/users' ); $request->set_param( 'orderby', 'name' ); @@ -456,8 +456,8 @@ public function test_get_items_orderby_name() { public function test_get_items_orderby_url() { wp_set_current_user( self::$user ); - $low_id = $this->factory->user->create( array( 'user_url' => 'http://a.com' ) ); - $high_id = $this->factory->user->create( array( 'user_url' => 'http://b.com' ) ); + $low_id = self::factory()->user->create( array( 'user_url' => 'http://a.com' ) ); + $high_id = self::factory()->user->create( array( 'user_url' => 'http://b.com' ) ); $request = new WP_REST_Request( 'GET', '/wp/v2/users' ); $request->set_param( 'orderby', 'url' ); @@ -481,8 +481,8 @@ public function test_get_items_orderby_url() { public function test_get_items_orderby_slug() { wp_set_current_user( self::$user ); - $high_id = $this->factory->user->create( array( 'user_nicename' => 'blogin' ) ); - $low_id = $this->factory->user->create( array( 'user_nicename' => 'alogin' ) ); + $high_id = self::factory()->user->create( array( 'user_nicename' => 'blogin' ) ); + $low_id = self::factory()->user->create( array( 'user_nicename' => 'alogin' ) ); $request = new WP_REST_Request( 'GET', '/wp/v2/users' ); $request->set_param( 'orderby', 'slug' ); @@ -506,9 +506,9 @@ public function test_get_items_orderby_slug() { public function test_get_items_orderby_slugs() { wp_set_current_user( self::$user ); - $this->factory->user->create( array( 'user_nicename' => 'burrito' ) ); - $this->factory->user->create( array( 'user_nicename' => 'taco' ) ); - $this->factory->user->create( array( 'user_nicename' => 'chalupa' ) ); + self::factory()->user->create( array( 'user_nicename' => 'burrito' ) ); + self::factory()->user->create( array( 'user_nicename' => 'taco' ) ); + self::factory()->user->create( array( 'user_nicename' => 'chalupa' ) ); $request = new WP_REST_Request( 'GET', '/wp/v2/users' ); $request->set_param( 'orderby', 'include_slugs' ); @@ -524,8 +524,8 @@ public function test_get_items_orderby_slugs() { public function test_get_items_orderby_email() { wp_set_current_user( self::$user ); - $high_id = $this->factory->user->create( array( 'user_email' => 'bemail@gmail.com' ) ); - $low_id = $this->factory->user->create( array( 'user_email' => 'aemail@gmail.com' ) ); + $high_id = self::factory()->user->create( array( 'user_email' => 'bemail@gmail.com' ) ); + $low_id = self::factory()->user->create( array( 'user_email' => 'aemail@gmail.com' ) ); $request = new WP_REST_Request( 'GET', '/wp/v2/users' ); $request->set_param( 'orderby', 'email' ); @@ -604,8 +604,8 @@ public function test_get_items_offset() { public function test_get_items_include_query() { wp_set_current_user( self::$user ); - $id1 = $this->factory->user->create(); - $id2 = $this->factory->user->create(); + $id1 = self::factory()->user->create(); + $id2 = self::factory()->user->create(); $request = new WP_REST_Request( 'GET', '/wp/v2/users' ); @@ -640,8 +640,8 @@ public function test_get_items_include_query() { public function test_get_items_exclude_query() { wp_set_current_user( self::$user ); - $id1 = $this->factory->user->create(); - $id2 = $this->factory->user->create(); + $id1 = self::factory()->user->create(); + $id2 = self::factory()->user->create(); $request = new WP_REST_Request( 'GET', '/wp/v2/users' ); $request->set_param( 'per_page', self::$per_page ); // There are >10 users at this point. @@ -672,14 +672,14 @@ public function test_get_items_search() { $response = rest_get_server()->dispatch( $request ); $this->assertCount( 0, $response->get_data() ); - $yolo_id = $this->factory->user->create( array( 'display_name' => 'yololololo' ) ); + $yolo_id = self::factory()->user->create( array( 'display_name' => 'yololololo' ) ); $request = new WP_REST_Request( 'GET', '/wp/v2/users' ); $request->set_param( 'search', 'yololololo' ); $response = rest_get_server()->dispatch( $request ); $this->assertCount( 1, $response->get_data() ); // Default to wildcard search. - $adam_id = $this->factory->user->create( + $adam_id = self::factory()->user->create( array( 'role' => 'author', 'user_nicename' => 'adam', @@ -697,13 +697,13 @@ public function test_get_items_search() { public function test_get_items_slug_query() { wp_set_current_user( self::$user ); - $this->factory->user->create( + self::factory()->user->create( array( 'display_name' => 'foo', 'user_login' => 'bar', ) ); - $id2 = $this->factory->user->create( + $id2 = self::factory()->user->create( array( 'display_name' => 'Moo', 'user_login' => 'foo', @@ -721,25 +721,25 @@ public function test_get_items_slug_query() { public function test_get_items_slug_array_query() { wp_set_current_user( self::$user ); - $id1 = $this->factory->user->create( + $id1 = self::factory()->user->create( array( 'display_name' => 'Taco', 'user_login' => 'taco', ) ); - $id2 = $this->factory->user->create( + $id2 = self::factory()->user->create( array( 'display_name' => 'Enchilada', 'user_login' => 'enchilada', ) ); - $id3 = $this->factory->user->create( + $id3 = self::factory()->user->create( array( 'display_name' => 'Burrito', 'user_login' => 'burrito', ) ); - $this->factory->user->create( + self::factory()->user->create( array( 'display_name' => 'Hon Pizza', 'user_login' => 'pizza', @@ -767,25 +767,25 @@ public function test_get_items_slug_array_query() { public function test_get_items_slug_csv_query() { wp_set_current_user( self::$user ); - $id1 = $this->factory->user->create( + $id1 = self::factory()->user->create( array( 'display_name' => 'Taco', 'user_login' => 'taco', ) ); - $id2 = $this->factory->user->create( + $id2 = self::factory()->user->create( array( 'display_name' => 'Enchilada', 'user_login' => 'enchilada', ) ); - $id3 = $this->factory->user->create( + $id3 = self::factory()->user->create( array( 'display_name' => 'Burrito', 'user_login' => 'burrito', ) ); - $this->factory->user->create( + self::factory()->user->create( array( 'display_name' => 'Hon Pizza', 'user_login' => 'pizza', @@ -962,7 +962,7 @@ public function test_get_items_who_unauthorized_query() { } public function test_get_item() { - $user_id = $this->factory->user->create(); + $user_id = self::factory()->user->create(); wp_set_current_user( self::$user ); @@ -1029,7 +1029,7 @@ public function test_get_user_empty_capabilities() { $this->allow_user_to_manage_multisite(); - $lolz = $this->factory->user->create( + $lolz = self::factory()->user->create( array( 'display_name' => 'lolz', 'roles' => '', @@ -1114,13 +1114,13 @@ public function test_cannot_get_item_author_of_draft() { } public function test_get_item_published_author_post() { - $author_id = $this->factory->user->create( + $author_id = self::factory()->user->create( array( 'role' => 'author', ) ); - $post_id = $this->factory->post->create( + $post_id = self::factory()->post->create( array( 'post_author' => $author_id, ) @@ -1134,7 +1134,7 @@ public function test_get_item_published_author_post() { } public function test_get_item_published_author_pages() { - $author_id = $this->factory->user->create( + $author_id = self::factory()->user->create( array( 'role' => 'author', ) @@ -1146,7 +1146,7 @@ public function test_get_item_published_author_pages() { $response = rest_get_server()->dispatch( $request ); $this->assertSame( 401, $response->get_status() ); - $post_id = $this->factory->post->create( + $post_id = self::factory()->post->create( array( 'post_author' => $author_id, 'post_type' => 'page', @@ -1158,7 +1158,7 @@ public function test_get_item_published_author_pages() { } public function test_get_user_with_edit_context() { - $user_id = $this->factory->user->create(); + $user_id = self::factory()->user->create(); $this->allow_user_to_manage_multisite(); @@ -1169,13 +1169,13 @@ public function test_get_user_with_edit_context() { } public function test_get_item_published_author_wrong_context() { - $author_id = $this->factory->user->create( + $author_id = self::factory()->user->create( array( 'role' => 'author', ) ); - $post_id = $this->factory->post->create( + $post_id = self::factory()->post->create( array( 'post_author' => $author_id, ) @@ -1554,7 +1554,7 @@ public function test_create_user_invalid_role() { } public function test_update_item() { - $user_id = $this->factory->user->create( + $user_id = self::factory()->user->create( array( 'user_email' => 'test@example.com', 'user_pass' => 'sjflsfls', @@ -1620,13 +1620,13 @@ public function test_update_item_no_change() { } public function test_update_item_existing_email() { - $user1 = $this->factory->user->create( + $user1 = self::factory()->user->create( array( 'user_login' => 'test_json_user', 'user_email' => 'testjson@example.com', ) ); - $user2 = $this->factory->user->create( + $user2 = self::factory()->user->create( array( 'user_login' => 'test_json_user2', 'user_email' => 'testjson2@example.com', @@ -1684,7 +1684,7 @@ public function test_update_item_existing_email_case_not_own() { } public function test_update_item_invalid_locale() { - $user1 = $this->factory->user->create( + $user1 = self::factory()->user->create( array( 'user_login' => 'test_json_user', 'user_email' => 'testjson@example.com', @@ -1703,7 +1703,7 @@ public function test_update_item_invalid_locale() { } public function test_update_item_en_US_locale() { - $user_id = $this->factory->user->create( + $user_id = self::factory()->user->create( array( 'user_login' => 'test_json_user', 'user_email' => 'testjson@example.com', @@ -1727,7 +1727,7 @@ public function test_update_item_en_US_locale() { * @ticket 38632 */ public function test_update_item_empty_locale() { - $user_id = $this->factory->user->create( + $user_id = self::factory()->user->create( array( 'user_login' => 'test_json_user', 'user_email' => 'testjson@example.com', @@ -1751,13 +1751,13 @@ public function test_update_item_empty_locale() { } public function test_update_item_username_attempt() { - $user1 = $this->factory->user->create( + $user1 = self::factory()->user->create( array( 'user_login' => 'test_json_user', 'user_email' => 'testjson@example.com', ) ); - $user2 = $this->factory->user->create( + $user2 = self::factory()->user->create( array( 'user_login' => 'test_json_user2', 'user_email' => 'testjson2@example.com', @@ -1776,13 +1776,13 @@ public function test_update_item_username_attempt() { } public function test_update_item_existing_nicename() { - $user1 = $this->factory->user->create( + $user1 = self::factory()->user->create( array( 'user_login' => 'test_json_user', 'user_email' => 'testjson@example.com', ) ); - $user2 = $this->factory->user->create( + $user2 = self::factory()->user->create( array( 'user_login' => 'test_json_user2', 'user_email' => 'testjson2@example.com', @@ -1801,7 +1801,7 @@ public function test_update_item_existing_nicename() { } public function test_json_update_user() { - $user_id = $this->factory->user->create( + $user_id = self::factory()->user->create( array( 'user_email' => 'testjson2@example.com', 'user_pass' => 'sjflsfl3sdjls', @@ -1846,7 +1846,7 @@ public function test_json_update_user() { } public function test_update_user_role() { - $user_id = $this->factory->user->create( array( 'role' => 'administrator' ) ); + $user_id = self::factory()->user->create( array( 'role' => 'administrator' ) ); wp_set_current_user( self::$user ); @@ -1867,7 +1867,7 @@ public function test_update_user_role() { } public function test_update_user_multiple_roles() { - $user_id = $this->factory->user->create( array( 'role' => 'administrator' ) ); + $user_id = self::factory()->user->create( array( 'role' => 'administrator' ) ); wp_set_current_user( self::$user ); @@ -1913,7 +1913,7 @@ public function test_update_user_role_invalid_privilege_escalation() { * @group ms-excluded */ public function test_update_user_role_invalid_privilege_deescalation() { - $user_id = $this->factory->user->create( array( 'role' => 'administrator' ) ); + $user_id = self::factory()->user->create( array( 'role' => 'administrator' ) ); wp_set_current_user( $user_id ); @@ -1942,7 +1942,7 @@ public function test_update_user_role_invalid_privilege_deescalation() { * @group ms-required */ public function test_update_user_role_privilege_deescalation_multisite() { - $user_id = $this->factory->user->create( array( 'role' => 'administrator' ) ); + $user_id = self::factory()->user->create( array( 'role' => 'administrator' ) ); wp_set_current_user( $user_id ); $user = wp_get_current_user(); @@ -1956,7 +1956,7 @@ public function test_update_user_role_privilege_deescalation_multisite() { $this->assertSame( 'editor', $new_data['roles'][0] ); $this->assertNotEquals( 'administrator', $new_data['roles'][0] ); - $user_id = $this->factory->user->create( array( 'role' => 'administrator' ) ); + $user_id = self::factory()->user->create( array( 'role' => 'administrator' ) ); wp_set_current_user( $user_id ); $user = wp_get_current_user(); @@ -2046,7 +2046,7 @@ public function test_update_user_invalid_id() { * @ticket 40263 */ public function test_update_item_only_roles_as_editor() { - $user_id = $this->factory->user->create( + $user_id = self::factory()->user->create( array( 'role' => 'author', ) @@ -2064,7 +2064,7 @@ public function test_update_item_only_roles_as_editor() { * @ticket 40263 */ public function test_update_item_only_roles_as_site_administrator() { - $user_id = $this->factory->user->create( + $user_id = self::factory()->user->create( array( 'role' => 'author', ) @@ -2085,7 +2085,7 @@ public function test_update_item_only_roles_as_site_administrator() { * @ticket 40263 */ public function test_update_item_including_roles_and_other_params() { - $user_id = $this->factory->user->create( + $user_id = self::factory()->user->create( array( 'role' => 'author', ) @@ -2341,7 +2341,7 @@ public function test_user_roundtrip_as_superadmin_html() { } public function test_delete_item() { - $user_id = $this->factory->user->create( array( 'display_name' => 'Deleted User' ) ); + $user_id = self::factory()->user->create( array( 'display_name' => 'Deleted User' ) ); $this->allow_user_to_manage_multisite(); @@ -2366,7 +2366,7 @@ public function test_delete_item() { } public function test_delete_item_no_trash() { - $user_id = $this->factory->user->create( array( 'display_name' => 'Deleted User' ) ); + $user_id = self::factory()->user->create( array( 'display_name' => 'Deleted User' ) ); $this->allow_user_to_manage_multisite(); @@ -2396,7 +2396,7 @@ public function test_delete_item_no_trash() { } public function test_delete_current_item() { - $user_id = $this->factory->user->create( + $user_id = self::factory()->user->create( array( 'role' => 'administrator', 'display_name' => 'Deleted User', @@ -2425,7 +2425,7 @@ public function test_delete_current_item() { } public function test_delete_current_item_no_trash() { - $user_id = $this->factory->user->create( + $user_id = self::factory()->user->create( array( 'role' => 'administrator', 'display_name' => 'Deleted User', @@ -2458,7 +2458,7 @@ public function test_delete_current_item_no_trash() { } public function test_delete_user_without_permission() { - $user_id = $this->factory->user->create(); + $user_id = self::factory()->user->create(); $this->allow_user_to_manage_multisite(); @@ -2496,9 +2496,9 @@ public function test_delete_user_reassign() { $this->allow_user_to_manage_multisite(); // Test with a new user, to avoid any complications. - $user_id = $this->factory->user->create(); - $reassign_id = $this->factory->user->create(); - $test_post = $this->factory->post->create( + $user_id = self::factory()->user->create(); + $reassign_id = self::factory()->user->create(); + $test_post = self::factory()->post->create( array( 'post_author' => $user_id, ) @@ -2530,7 +2530,7 @@ public function test_delete_user_reassign() { } public function test_delete_user_invalid_reassign_id() { - $user_id = $this->factory->user->create(); + $user_id = self::factory()->user->create(); $this->allow_user_to_manage_multisite(); @@ -2551,7 +2551,7 @@ public function test_delete_user_invalid_reassign_id() { } public function test_delete_user_invalid_reassign_passed_as_string() { - $user_id = $this->factory->user->create(); + $user_id = self::factory()->user->create(); $this->allow_user_to_manage_multisite(); @@ -2566,13 +2566,13 @@ public function test_delete_user_invalid_reassign_passed_as_string() { } public function test_delete_user_reassign_passed_as_boolean_false_trashes_post() { - $user_id = $this->factory->user->create(); + $user_id = self::factory()->user->create(); $this->allow_user_to_manage_multisite(); wp_set_current_user( self::$user ); - $test_post = $this->factory->post->create( + $test_post = self::factory()->post->create( array( 'post_author' => $user_id, ) @@ -2594,13 +2594,13 @@ public function test_delete_user_reassign_passed_as_boolean_false_trashes_post() } public function test_delete_user_reassign_passed_as_string_false_trashes_post() { - $user_id = $this->factory->user->create(); + $user_id = self::factory()->user->create(); $this->allow_user_to_manage_multisite(); wp_set_current_user( self::$user ); - $test_post = $this->factory->post->create( + $test_post = self::factory()->post->create( array( 'post_author' => $user_id, ) @@ -2622,13 +2622,13 @@ public function test_delete_user_reassign_passed_as_string_false_trashes_post() } public function test_delete_user_reassign_passed_as_empty_string_trashes_post() { - $user_id = $this->factory->user->create(); + $user_id = self::factory()->user->create(); $this->allow_user_to_manage_multisite(); wp_set_current_user( self::$user ); - $test_post = $this->factory->post->create( + $test_post = self::factory()->post->create( array( 'post_author' => $user_id, ) @@ -2650,13 +2650,13 @@ public function test_delete_user_reassign_passed_as_empty_string_trashes_post() } public function test_delete_user_reassign_passed_as_0_reassigns_author() { - $user_id = $this->factory->user->create(); + $user_id = self::factory()->user->create(); $this->allow_user_to_manage_multisite(); wp_set_current_user( self::$user ); - $test_post = $this->factory->post->create( + $test_post = self::factory()->post->create( array( 'post_author' => $user_id, ) @@ -2831,7 +2831,7 @@ public function test_additional_field_update_errors() { */ public function test_get_item_from_different_site_as_site_administrator() { switch_to_blog( self::$site ); - $user_id = $this->factory->user->create( + $user_id = self::factory()->user->create( array( 'role' => 'author', ) @@ -2851,7 +2851,7 @@ public function test_get_item_from_different_site_as_site_administrator() { */ public function test_get_item_from_different_site_as_network_administrator() { switch_to_blog( self::$site ); - $user_id = $this->factory->user->create( + $user_id = self::factory()->user->create( array( 'role' => 'author', ) @@ -2871,7 +2871,7 @@ public function test_get_item_from_different_site_as_network_administrator() { */ public function test_update_item_from_different_site_as_site_administrator() { switch_to_blog( self::$site ); - $user_id = $this->factory->user->create( + $user_id = self::factory()->user->create( array( 'role' => 'author', ) @@ -2893,7 +2893,7 @@ public function test_update_item_from_different_site_as_site_administrator() { */ public function test_update_item_from_different_site_as_network_administrator() { switch_to_blog( self::$site ); - $user_id = $this->factory->user->create( + $user_id = self::factory()->user->create( array( 'role' => 'author', ) @@ -2915,7 +2915,7 @@ public function test_update_item_from_different_site_as_network_administrator() */ public function test_delete_item_from_different_site_as_site_administrator() { switch_to_blog( self::$site ); - $user_id = $this->factory->user->create( + $user_id = self::factory()->user->create( array( 'role' => 'author', ) @@ -2937,7 +2937,7 @@ public function test_delete_item_from_different_site_as_site_administrator() { */ public function test_delete_item_from_different_site_as_network_administrator() { switch_to_blog( self::$site ); - $user_id = $this->factory->user->create( + $user_id = self::factory()->user->create( array( 'role' => 'author', ) diff --git a/tests/phpunit/tests/rest-api/wpRestMenusController.php b/tests/phpunit/tests/rest-api/wpRestMenusController.php index 4b2384c1a7dd1..3db23f2d450a6 100644 --- a/tests/phpunit/tests/rest-api/wpRestMenusController.php +++ b/tests/phpunit/tests/rest-api/wpRestMenusController.php @@ -85,7 +85,7 @@ public function set_up() { 'taxonomy' => 'nav_menu', ); - $this->menu_id = $this->factory->term->create( $orig_args ); + $this->menu_id = self::factory()->term->create( $orig_args ); register_meta( 'term', @@ -133,7 +133,7 @@ public function test_context_param() { $this->assertSameSets( array( 'view', 'embed', 'edit' ), $data['endpoints'][0]['args']['context']['enum'] ); $this->assertSame( array( 'v1' => true ), $data['endpoints'][0]['allow_batch'] ); // Single. - $tag1 = $this->factory->tag->create( array( 'name' => 'Season 5' ) ); + $tag1 = self::factory()->tag->create( array( 'name' => 'Season 5' ) ); $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/menus/' . $tag1 ); $response = rest_get_server()->dispatch( $request ); $data = $response->get_data(); diff --git a/tests/phpunit/tests/taxonomy.php b/tests/phpunit/tests/taxonomy.php index a0914dcade255..9b31b573a2a73 100644 --- a/tests/phpunit/tests/taxonomy.php +++ b/tests/phpunit/tests/taxonomy.php @@ -681,13 +681,13 @@ public function test_it_should_be_possible_to_register_a_query_var_that_matches_ 'publicly_queryable' => false, ) ); - $t = $this->factory->term->create_and_get( + $t = self::factory()->term->create_and_get( array( 'taxonomy' => 'wptests_tax', ) ); - $p = $this->factory->post->create(); + $p = self::factory()->post->create(); wp_set_object_terms( $p, $t->slug, 'wptests_tax' ); add_filter( 'do_parse_request', array( $this, 'register_query_var' ) ); diff --git a/tests/phpunit/tests/term/cache.php b/tests/phpunit/tests/term/cache.php index d60e03074a8f2..3a12bc1b04073 100644 --- a/tests/phpunit/tests/term/cache.php +++ b/tests/phpunit/tests/term/cache.php @@ -244,7 +244,7 @@ public function test_term_objects_should_not_be_modified_by_update_term_cache() public function test_get_term_by_slug_cache() { global $wpdb; - $term_id = $this->factory->term->create( + $term_id = self::factory()->term->create( array( 'slug' => 'burrito', 'name' => 'Taco', @@ -275,7 +275,7 @@ public function test_get_term_by_slug_cache() { public function test_get_term_by_slug_cache_update() { global $wpdb; - $term_id = $this->factory->term->create( + $term_id = self::factory()->term->create( array( 'slug' => 'burrito', 'name' => 'Taco', @@ -313,7 +313,7 @@ public function test_get_term_by_slug_cache_update() { public function test_get_term_by_name_cache() { global $wpdb; - $term_id = $this->factory->term->create( + $term_id = self::factory()->term->create( array( 'name' => 'Burrito', 'slug' => 'noburrito', @@ -342,7 +342,7 @@ public function test_get_term_by_name_cache() { public function test_get_term_by_name_cache_update() { global $wpdb; - $term_id = $this->factory->term->create( + $term_id = self::factory()->term->create( array( 'name' => 'Burrito', 'slug' => 'noburrito', @@ -377,7 +377,7 @@ public function test_get_term_by_name_cache_update() { public function test_invalidating_term_caches_should_fail_when_invalidation_is_suspended() { global $wpdb; - $term_id = $this->factory->term->create( + $term_id = self::factory()->term->create( array( 'name' => 'Burrito', 'taxonomy' => 'post_tag', @@ -420,7 +420,7 @@ public function test_invalidating_term_caches_should_fail_when_invalidation_is_s public function test_get_term_by_does_not_prime_term_meta_cache() { global $wpdb; - $term_id = $this->factory->term->create( + $term_id = self::factory()->term->create( array( 'name' => 'Burrito', 'taxonomy' => 'post_tag', diff --git a/tests/phpunit/tests/term/getTermBy.php b/tests/phpunit/tests/term/getTermBy.php index cdc484e90a47d..6422e44f0a515 100644 --- a/tests/phpunit/tests/term/getTermBy.php +++ b/tests/phpunit/tests/term/getTermBy.php @@ -196,7 +196,7 @@ public function test_should_sanitize_slug() { public function test_query_should_not_contain_order_by_clause() { global $wpdb; - $term_id = $this->factory->term->create( + $term_id = self::factory()->term->create( array( 'name' => 'burrito', 'taxonomy' => 'post_tag', @@ -211,7 +211,7 @@ public function test_query_should_not_contain_order_by_clause() { * @ticket 21760 */ public function test_query_should_contain_limit_clause() { - $term_id = $this->factory->term->create( + $term_id = self::factory()->term->create( array( 'name' => 'burrito', 'taxonomy' => 'post_tag', @@ -242,7 +242,7 @@ public function test_prevent_recursion_by_get_terms_filter() { public function test_get_term_by_name_with_string_0() { register_taxonomy( 'wptests_tax', 'post', array( 'hierarchical' => true ) ); - $term_id = $this->factory->term->create( + $term_id = self::factory()->term->create( array( 'name' => '0', 'taxonomy' => 'wptests_tax', @@ -259,7 +259,7 @@ public function test_get_term_by_name_with_string_0() { public function test_get_term_by_slug_with_string_0() { register_taxonomy( 'wptests_tax', 'post', array( 'hierarchical' => true ) ); - $term_id = $this->factory->term->create( + $term_id = self::factory()->term->create( array( 'taxonomy' => 'wptests_tax', 'name' => '0', diff --git a/tests/phpunit/tests/user/capabilities.php b/tests/phpunit/tests/user/capabilities.php index 6b916111ce429..c7e836f6e583e 100644 --- a/tests/phpunit/tests/user/capabilities.php +++ b/tests/phpunit/tests/user/capabilities.php @@ -1828,7 +1828,7 @@ public function test_contributor_cannot_edit_scheduled_post() { $contributor = self::$users['contributor']; // Give them a scheduled post. - $post = $this->factory->post->create_and_get( + $post = self::factory()->post->create_and_get( array( 'post_author' => $contributor->ID, 'post_status' => 'future', diff --git a/tests/phpunit/tests/user/query.php b/tests/phpunit/tests/user/query.php index 839ffa2288a19..3626156c01842 100644 --- a/tests/phpunit/tests/user/query.php +++ b/tests/phpunit/tests/user/query.php @@ -1665,7 +1665,7 @@ public function test_calling_prepare_query_a_second_time_should_not_add_another_ */ public function test_search_by_display_name_only() { - $new_user1 = $this->factory->user->create( + $new_user1 = self::factory()->user->create( array( 'user_login' => 'name1', 'display_name' => 'Sophia Andresen', @@ -1693,7 +1693,7 @@ public function test_search_by_display_name_only() { */ public function test_search_by_display_name_only_ignore_others() { - $new_user1 = $this->factory->user->create( + $new_user1 = self::factory()->user->create( array( 'user_login' => 'Sophia Andresen', 'display_name' => 'name1', diff --git a/tests/phpunit/tests/user/wpDropdownUsers.php b/tests/phpunit/tests/user/wpDropdownUsers.php index 2a7bbbffb29b5..a0b6501eb96d4 100644 --- a/tests/phpunit/tests/user/wpDropdownUsers.php +++ b/tests/phpunit/tests/user/wpDropdownUsers.php @@ -13,7 +13,7 @@ class Tests_User_wpDropdownUsers extends WP_UnitTestCase { public function test_default_value_of_show_should_be_display_name() { // Create a user with a different display_name. - $u = $this->factory->user->create( + $u = self::factory()->user->create( array( 'user_login' => 'foo', 'display_name' => 'Foo Person', @@ -37,7 +37,7 @@ public function test_default_value_of_show_should_be_display_name() { public function test_show_should_display_display_name_show_is_specified_as_empty() { // Create a user with a different display_name. - $u = $this->factory->user->create( + $u = self::factory()->user->create( array( 'user_login' => 'foo', 'display_name' => 'Foo Person', @@ -63,7 +63,7 @@ public function test_show_should_display_display_name_show_is_specified_as_empty public function test_show_should_display_user_property_when_the_value_of_show_is_a_valid_user_property() { // Create a user with a different display_name. - $u = $this->factory->user->create( + $u = self::factory()->user->create( array( 'user_login' => 'foo', 'display_name' => 'Foo Person', @@ -89,7 +89,7 @@ public function test_show_should_display_user_property_when_the_value_of_show_is public function test_show_display_name_with_login() { // Create a user with a different display_name. - $u = $this->factory->user->create( + $u = self::factory()->user->create( array( 'user_login' => 'foo', 'display_name' => 'Foo Person',