From bfdc8eff8333d448aaf31176da14f430c139b340 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Tue, 6 Sep 2022 22:03:10 +0000 Subject: [PATCH] Tests: Correctly use the factory method. This replaces all non-static calls to the `WP_UnitTestCase_Base::factory()` method with static function calls, since the method is declared as static. This is a consistency improvement for the test suite. Follow up to [35225], [35242], [49603], [54087]. Props jrf. See #55652. git-svn-id: https://develop.svn.wordpress.org/trunk@54088 602fd350-edb4-49c9-b593-d223f7449a82 --- tests/phpunit/tests/adminbar.php | 2 +- tests/phpunit/tests/ajax/CustomizeManager.php | 12 ++++---- tests/phpunit/tests/ajax/CustomizeMenus.php | 4 +-- tests/phpunit/tests/auth.php | 4 +-- tests/phpunit/tests/blocks/context.php | 2 +- tests/phpunit/tests/blocks/editor.php | 2 +- tests/phpunit/tests/comment/checkComment.php | 4 +-- tests/phpunit/tests/customize/control.php | 8 ++--- .../tests/customize/custom-css-setting.php | 8 ++--- tests/phpunit/tests/customize/manager.php | 30 +++++++++---------- tests/phpunit/tests/customize/nav-menus.php | 18 +++++------ tests/phpunit/tests/customize/setting.php | 10 +++---- tests/phpunit/tests/feed/rss2.php | 14 ++++----- .../tests/formatting/excerptRemoveBlocks.php | 2 +- .../tests/formatting/wpTargetedLinkRel.php | 2 +- tests/phpunit/tests/general/template.php | 10 +++---- tests/phpunit/tests/l10n.php | 22 +++++++------- tests/phpunit/tests/l10n/getUserLocale.php | 6 ++-- tests/phpunit/tests/l10n/wpLocaleSwitcher.php | 6 ++-- tests/phpunit/tests/multisite/network.php | 2 +- tests/phpunit/tests/multisite/site.php | 2 +- tests/phpunit/tests/oembed/WpEmbed.php | 16 +++++----- tests/phpunit/tests/oembed/controller.php | 14 ++++----- tests/phpunit/tests/oembed/headers.php | 2 +- tests/phpunit/tests/post.php | 6 ++-- .../tests/post/isPostPubliclyViewable.php | 2 +- tests/phpunit/tests/post/nav-menu.php | 6 ++-- tests/phpunit/tests/post/wpInsertPost.php | 10 +++---- .../tests/rest-api/rest-posts-controller.php | 2 +- ...wpRestBlockPatternCategoriesController.php | 2 +- .../wpRestBlockPatternsController.php | 2 +- .../tests/term/isTermPubliclyViewable.php | 2 +- tests/phpunit/tests/term/termCounts.php | 6 ++-- tests/phpunit/tests/theme.php | 2 +- tests/phpunit/tests/user.php | 4 +-- .../tests/widgets/wpWidgetCustomHtml.php | 6 ++-- tests/phpunit/tests/widgets/wpWidgetMedia.php | 4 +-- tests/phpunit/tests/widgets/wpWidgetText.php | 6 ++-- 38 files changed, 131 insertions(+), 131 deletions(-) diff --git a/tests/phpunit/tests/adminbar.php b/tests/phpunit/tests/adminbar.php index 24ace35da4..228063e911 100644 --- a/tests/phpunit/tests/adminbar.php +++ b/tests/phpunit/tests/adminbar.php @@ -656,7 +656,7 @@ class Tests_AdminBar extends WP_UnitTestCase { $this->go_to( home_url( "/?customize_changeset_uuid=$uuid" ) ); wp_set_current_user( self::$admin_id ); - $this->factory()->post->create( + self::factory()->post->create( array( 'post_type' => 'customize_changeset', 'post_status' => 'auto-draft', diff --git a/tests/phpunit/tests/ajax/CustomizeManager.php b/tests/phpunit/tests/ajax/CustomizeManager.php index 7300bb5ed0..6116aea2c4 100644 --- a/tests/phpunit/tests/ajax/CustomizeManager.php +++ b/tests/phpunit/tests/ajax/CustomizeManager.php @@ -307,7 +307,7 @@ class Tests_Ajax_CustomizeManager extends WP_Ajax_UnitTestCase { public function test_save_success_publish_edit() { $uuid = wp_generate_uuid4(); - $post_id = $this->factory()->post->create( + $post_id = self::factory()->post->create( array( 'post_name' => $uuid, 'post_title' => 'Original', @@ -346,7 +346,7 @@ class Tests_Ajax_CustomizeManager extends WP_Ajax_UnitTestCase { */ public function test_success_save_post_date() { $uuid = wp_generate_uuid4(); - $post_id = $this->factory()->post->create( + $post_id = self::factory()->post->create( array( 'post_name' => $uuid, 'post_title' => 'Original', @@ -446,7 +446,7 @@ class Tests_Ajax_CustomizeManager extends WP_Ajax_UnitTestCase { public function test_save_autosave() { $uuid = wp_generate_uuid4(); - $post_id = $this->factory()->post->create( + $post_id = self::factory()->post->create( array( 'post_name' => $uuid, 'post_type' => 'customize_changeset', @@ -614,12 +614,12 @@ class Tests_Ajax_CustomizeManager extends WP_Ajax_UnitTestCase { $this->assertFalse( $this->_last_response_parsed['success'] ); $this->assertSame( 'no_auto_draft_to_delete', $this->_last_response_parsed['data'] ); - $other_user_id = $this->factory()->user->create(); + $other_user_id = self::factory()->user->create(); // Create auto-drafts. $user_auto_draft_ids = array(); for ( $i = 0; $i < 3; $i++ ) { - $user_auto_draft_ids[] = $this->factory()->post->create( + $user_auto_draft_ids[] = self::factory()->post->create( array( 'post_name' => wp_generate_uuid4(), 'post_type' => 'customize_changeset', @@ -631,7 +631,7 @@ class Tests_Ajax_CustomizeManager extends WP_Ajax_UnitTestCase { } $other_user_auto_draft_ids = array(); for ( $i = 0; $i < 3; $i++ ) { - $other_user_auto_draft_ids[] = $this->factory()->post->create( + $other_user_auto_draft_ids[] = self::factory()->post->create( array( 'post_name' => wp_generate_uuid4(), 'post_type' => 'customize_changeset', diff --git a/tests/phpunit/tests/ajax/CustomizeMenus.php b/tests/phpunit/tests/ajax/CustomizeMenus.php index 927354bec8..92a1263919 100644 --- a/tests/phpunit/tests/ajax/CustomizeMenus.php +++ b/tests/phpunit/tests/ajax/CustomizeMenus.php @@ -706,7 +706,7 @@ class Tests_Ajax_CustomizeMenus extends WP_Ajax_UnitTestCase { $this->assertSame( 'bad_nonce', $response['data'] ); // Bad nonce. - wp_set_current_user( $this->factory()->user->create( array( 'role' => 'subscriber' ) ) ); + wp_set_current_user( self::factory()->user->create( array( 'role' => 'subscriber' ) ) ); $_POST = wp_slash( array( 'customize-menus-nonce' => wp_create_nonce( 'customize-menus' ), @@ -719,7 +719,7 @@ class Tests_Ajax_CustomizeMenus extends WP_Ajax_UnitTestCase { $this->assertSame( 'customize_not_allowed', $response['data'] ); // Missing params. - wp_set_current_user( $this->factory()->user->create( array( 'role' => 'administrator' ) ) ); + wp_set_current_user( self::factory()->user->create( array( 'role' => 'administrator' ) ) ); $_POST = wp_slash( array( 'customize-menus-nonce' => wp_create_nonce( 'customize-menus' ), diff --git a/tests/phpunit/tests/auth.php b/tests/phpunit/tests/auth.php index 3936f0772d..2581312415 100644 --- a/tests/phpunit/tests/auth.php +++ b/tests/phpunit/tests/auth.php @@ -421,7 +421,7 @@ class Tests_Auth extends WP_UnitTestCase { 'user_email' => "mail\'@example.com", 'user_pass' => 'password', ); - $this->factory()->user->create( $user_args ); + self::factory()->user->create( $user_args ); $_POST['log'] = $user_args['user_email']; $_POST['pwd'] = $user_args['user_pass']; @@ -436,7 +436,7 @@ class Tests_Auth extends WP_UnitTestCase { * @covers ::wp_validate_application_password */ public function test_application_password_authentication() { - $user_id = $this->factory()->user->create( + $user_id = self::factory()->user->create( array( 'user_login' => 'http_auth_login', 'user_pass' => 'http_auth_pass', // Shouldn't be allowed for API login. diff --git a/tests/phpunit/tests/blocks/context.php b/tests/phpunit/tests/blocks/context.php index d1b321ab51..04f9a88176 100644 --- a/tests/phpunit/tests/blocks/context.php +++ b/tests/phpunit/tests/blocks/context.php @@ -36,7 +36,7 @@ class Tests_Blocks_Context extends WP_UnitTestCase { 'post_excerpt' => '', ); - $post = $this->factory()->post->create_and_get( $args ); + $post = self::factory()->post->create_and_get( $args ); setup_postdata( $post ); } diff --git a/tests/phpunit/tests/blocks/editor.php b/tests/phpunit/tests/blocks/editor.php index 9eadae9941..f08c350168 100644 --- a/tests/phpunit/tests/blocks/editor.php +++ b/tests/phpunit/tests/blocks/editor.php @@ -28,7 +28,7 @@ class Tests_Blocks_Editor extends WP_UnitTestCase { 'post_title' => 'Example', ); - $post = $this->factory()->post->create_and_get( $args ); + $post = self::factory()->post->create_and_get( $args ); global $wp_rest_server; $wp_rest_server = new Spy_REST_Server; diff --git a/tests/phpunit/tests/comment/checkComment.php b/tests/phpunit/tests/comment/checkComment.php index c6ac824a24..0f02b63dbf 100644 --- a/tests/phpunit/tests/comment/checkComment.php +++ b/tests/phpunit/tests/comment/checkComment.php @@ -138,7 +138,7 @@ class Tests_Comment_CheckComment extends WP_UnitTestCase { * @ticket 28603 */ public function test_should_return_true_when_comment_previously_approved_is_enabled_and_user_has_previously_approved_comments_with_different_email() { - $subscriber_id = $this->factory()->user->create( + $subscriber_id = self::factory()->user->create( array( 'role' => 'subscriber', 'email' => 'sub@example.com', @@ -170,7 +170,7 @@ class Tests_Comment_CheckComment extends WP_UnitTestCase { * @ticket 28603 */ public function test_should_return_false_when_comment_previously_approved_is_enabled_and_user_does_not_have_a_previously_approved_comment_with_any_email() { - $subscriber_id = $this->factory()->user->create( + $subscriber_id = self::factory()->user->create( array( 'role' => 'subscriber', 'email' => 'zig@example.com', diff --git a/tests/phpunit/tests/customize/control.php b/tests/phpunit/tests/customize/control.php index c83418c301..2131bdc844 100644 --- a/tests/phpunit/tests/customize/control.php +++ b/tests/phpunit/tests/customize/control.php @@ -26,7 +26,7 @@ class Test_WP_Customize_Control extends WP_UnitTestCase { */ public function set_up() { parent::set_up(); - wp_set_current_user( $this->factory()->user->create( array( 'role' => 'administrator' ) ) ); + wp_set_current_user( self::factory()->user->create( array( 'role' => 'administrator' ) ) ); require_once ABSPATH . WPINC . '/class-wp-customize-manager.php'; $GLOBALS['wp_customize'] = new WP_Customize_Manager(); $this->wp_customize = $GLOBALS['wp_customize']; @@ -138,21 +138,21 @@ class Test_WP_Customize_Control extends WP_UnitTestCase { $this->assertStringContainsString( '