From 0b38eb09db3b88eac2efbfe23710497722d78a45 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Mon, 13 Feb 2023 19:35:13 +0000 Subject: [PATCH] Tests: Declare the `$post_id` property in `wp_comments_personal_data_exporter()` tests. Use the same approach in `wp_comments_personal_data_eraser()` for consistency and to minimize the number of fixtures created in each individual test. Follow-up to [55319], [55321]. Props hellofromTonya. See #56793. git-svn-id: https://develop.svn.wordpress.org/trunk@55322 602fd350-edb4-49c9-b593-d223f7449a82 --- .../comment/wpCommentsPersonalDataEraser.php | 25 ++++++++++--------- .../wpCommentsPersonalDataExporter.php | 6 +++++ 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/tests/phpunit/tests/comment/wpCommentsPersonalDataEraser.php b/tests/phpunit/tests/comment/wpCommentsPersonalDataEraser.php index c6a03d5102..c5d3312e79 100644 --- a/tests/phpunit/tests/comment/wpCommentsPersonalDataEraser.php +++ b/tests/phpunit/tests/comment/wpCommentsPersonalDataEraser.php @@ -8,6 +8,12 @@ */ class Tests_Comment_wpCommentsPersonalDataEraser extends WP_UnitTestCase { + protected static $post_id; + + public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) { + self::$post_id = $factory->post->create(); + } + /** * The `wp_comments_personal_data_eraser()` function should erase user's comments. * @@ -15,12 +21,11 @@ class Tests_Comment_wpCommentsPersonalDataEraser extends WP_UnitTestCase { */ public function test_wp_comments_personal_data_eraser() { - $post_id = self::factory()->post->create(); $user_id = self::factory()->user->create(); $args = array( 'user_id' => $user_id, - 'comment_post_ID' => $post_id, + 'comment_post_ID' => self::$post_id, 'comment_author' => 'Comment Author', 'comment_author_email' => 'personal@local.host', 'comment_author_url' => 'https://local.host/', @@ -89,9 +94,8 @@ class Tests_Comment_wpCommentsPersonalDataEraser extends WP_UnitTestCase { */ public function test_wp_comments_personal_data_eraser_non_empty_first_page_output() { - $post_id = self::factory()->post->create(); - $args = array( - 'comment_post_ID' => $post_id, + $args = array( + 'comment_post_ID' => self::$post_id, 'comment_author' => 'Comment Author', 'comment_author_email' => 'personal@local.host', 'comment_author_url' => 'https://local.host/', @@ -120,9 +124,8 @@ class Tests_Comment_wpCommentsPersonalDataEraser extends WP_UnitTestCase { */ public function test_wp_comments_personal_data_eraser_empty_second_page_output() { - $post_id = self::factory()->post->create(); - $args = array( - 'comment_post_ID' => $post_id, + $args = array( + 'comment_post_ID' => self::$post_id, 'comment_author' => 'Comment Author', 'comment_author_email' => 'personal@local.host', 'comment_author_url' => 'https://local.host/', @@ -151,9 +154,8 @@ class Tests_Comment_wpCommentsPersonalDataEraser extends WP_UnitTestCase { */ public function test_wp_anonymize_comment_filter_to_prevent_comment_anonymization() { - $post_id = self::factory()->post->create(); $args = array( - 'comment_post_ID' => $post_id, + 'comment_post_ID' => self::$post_id, 'comment_author' => 'Comment Author', 'comment_author_email' => 'personal@local.host', 'comment_author_url' => 'https://local.host/', @@ -187,9 +189,8 @@ class Tests_Comment_wpCommentsPersonalDataEraser extends WP_UnitTestCase { */ public function test_wp_anonymize_comment_filter_to_prevent_comment_anonymization_with_custom_message() { - $post_id = self::factory()->post->create(); $args = array( - 'comment_post_ID' => $post_id, + 'comment_post_ID' => self::$post_id, 'comment_author' => 'Comment Author', 'comment_author_email' => 'personal@local.host', 'comment_author_url' => 'https://local.host/', diff --git a/tests/phpunit/tests/comment/wpCommentsPersonalDataExporter.php b/tests/phpunit/tests/comment/wpCommentsPersonalDataExporter.php index ac539a8939..ad60ccceeb 100644 --- a/tests/phpunit/tests/comment/wpCommentsPersonalDataExporter.php +++ b/tests/phpunit/tests/comment/wpCommentsPersonalDataExporter.php @@ -8,6 +8,12 @@ */ class Tests_Comment_wpCommentsPersonalDataExporter extends WP_UnitTestCase { + protected static $post_id; + + public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) { + self::$post_id = $factory->post->create(); + } + /** * Testing the `wp_comments_personal_data_exporter()` function. *