From 898eb5fc515ae4296c6d61b5658adb31da202124 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Sat, 19 Sep 2020 11:11:00 +0000 Subject: [PATCH] Tests: Speed up slashed data tests by reusing some more shared fixtures. Follow-up to [35249], [49003]. See #51344. git-svn-id: https://develop.svn.wordpress.org/trunk@49005 602fd350-edb4-49c9-b593-d223f7449a82 --- tests/phpunit/tests/comment/slashes.php | 10 ++++++---- tests/phpunit/tests/meta/slashes.php | 12 +++++++----- tests/phpunit/tests/post/slashes.php | 6 ++++-- tests/phpunit/tests/user/slashes.php | 6 ++++-- 4 files changed, 21 insertions(+), 13 deletions(-) diff --git a/tests/phpunit/tests/comment/slashes.php b/tests/phpunit/tests/comment/slashes.php index beb998e11c..ed6f2834f7 100644 --- a/tests/phpunit/tests/comment/slashes.php +++ b/tests/phpunit/tests/comment/slashes.php @@ -7,10 +7,12 @@ */ class Tests_Comment_Slashes extends WP_UnitTestCase { protected static $author_id; + protected static $post_id; public static function wpSetUpBeforeClass( $factory ) { // We need an admin user to bypass comment flood protection. self::$author_id = $factory->user->create( array( 'role' => 'administrator' ) ); + self::$post_id = $factory->post->create(); } function setUp() { @@ -33,7 +35,7 @@ class Tests_Comment_Slashes extends WP_UnitTestCase { * Tests the extended model function that expects slashed data. */ function test_wp_new_comment() { - $post_id = self::factory()->post->create(); + $post_id = self::$post_id; // Not testing comment_author_email or comment_author_url // as slashes are not permitted in that data. @@ -72,7 +74,7 @@ class Tests_Comment_Slashes extends WP_UnitTestCase { * Tests the controller function that expects slashed data. */ function test_edit_comment() { - $post_id = self::factory()->post->create(); + $post_id = self::$post_id; $comment_id = self::factory()->comment->create( array( 'comment_post_ID' => $post_id, @@ -118,7 +120,7 @@ class Tests_Comment_Slashes extends WP_UnitTestCase { * Tests the model function that expects slashed data. */ function test_wp_insert_comment() { - $post_id = self::factory()->post->create(); + $post_id = self::$post_id; $comment_id = wp_insert_comment( array( @@ -149,7 +151,7 @@ class Tests_Comment_Slashes extends WP_UnitTestCase { * Tests the model function that expects slashed data. */ function test_wp_update_comment() { - $post_id = self::factory()->post->create(); + $post_id = self::$post_id; $comment_id = self::factory()->comment->create( array( 'comment_post_ID' => $post_id, diff --git a/tests/phpunit/tests/meta/slashes.php b/tests/phpunit/tests/meta/slashes.php index 125cbaaae4..6ef581ba2d 100644 --- a/tests/phpunit/tests/meta/slashes.php +++ b/tests/phpunit/tests/meta/slashes.php @@ -9,11 +9,13 @@ class Tests_Meta_Slashes extends WP_UnitTestCase { protected static $editor_id; protected static $post_id; protected static $comment_id; + protected static $user_id; public static function wpSetUpBeforeClass( $factory ) { self::$editor_id = $factory->user->create( array( 'role' => 'editor' ) ); self::$post_id = $factory->post->create(); self::$comment_id = $factory->comment->create( array( 'comment_post_ID' => self::$post_id ) ); + self::$user_id = $factory->user->create(); } function setUp() { @@ -34,7 +36,7 @@ class Tests_Meta_Slashes extends WP_UnitTestCase { * Tests the controller function that expects slashed data. */ function test_edit_post() { - $post_id = self::factory()->post->create(); + $post_id = self::$post_id; if ( function_exists( 'wp_add_post_meta' ) ) { $meta_1 = wp_add_post_meta( $post_id, 'slash_test_1', 'foo' ); @@ -111,7 +113,7 @@ class Tests_Meta_Slashes extends WP_UnitTestCase { * Tests the legacy model function that expects slashed data. */ function test_add_post_meta() { - $post_id = self::factory()->post->create(); + $post_id = self::$post_id; add_post_meta( $post_id, 'slash_test_1', addslashes( $this->slash_1 ) ); add_post_meta( $post_id, 'slash_test_2', addslashes( $this->slash_3 ) ); @@ -126,7 +128,7 @@ class Tests_Meta_Slashes extends WP_UnitTestCase { * Tests the legacy model function that expects slashed data. */ function test_update_post_meta() { - $post_id = self::factory()->post->create(); + $post_id = self::$post_id; update_post_meta( $post_id, 'slash_test_1', addslashes( $this->slash_1 ) ); update_post_meta( $post_id, 'slash_test_2', addslashes( $this->slash_3 ) ); @@ -191,7 +193,7 @@ class Tests_Meta_Slashes extends WP_UnitTestCase { * Tests the model function that expects slashed data. */ function test_add_user_meta() { - $user_id = self::factory()->user->create(); + $user_id = self::$user_id; add_user_meta( $user_id, 'slash_test_1', $this->slash_1 ); add_user_meta( $user_id, 'slash_test_2', $this->slash_3 ); @@ -214,7 +216,7 @@ class Tests_Meta_Slashes extends WP_UnitTestCase { * Tests the model function that expects slashed data. */ function test_update_user_meta() { - $user_id = self::factory()->user->create(); + $user_id = self::$user_id; add_user_meta( $user_id, 'slash_test_1', 'foo' ); add_user_meta( $user_id, 'slash_test_2', 'foo' ); diff --git a/tests/phpunit/tests/post/slashes.php b/tests/phpunit/tests/post/slashes.php index 25a0240576..d2622c4d80 100644 --- a/tests/phpunit/tests/post/slashes.php +++ b/tests/phpunit/tests/post/slashes.php @@ -7,9 +7,11 @@ */ class Tests_Post_Slashes extends WP_UnitTestCase { protected static $author_id; + protected static $post_id; public static function wpSetUpBeforeClass( $factory ) { self::$author_id = $factory->user->create( array( 'role' => 'editor' ) ); + self::$post_id = $factory->post->create(); } function setUp() { @@ -32,7 +34,7 @@ class Tests_Post_Slashes extends WP_UnitTestCase { * Tests the controller function that expects slashed data. */ function test_edit_post() { - $post_id = self::factory()->post->create(); + $post_id = self::$post_id; $_POST = array(); $_POST['post_ID'] = $post_id; @@ -105,7 +107,7 @@ class Tests_Post_Slashes extends WP_UnitTestCase { * Tests the model function that expects slashed data. */ function test_wp_update_post() { - $post_id = self::factory()->post->create(); + $post_id = self::$post_id; wp_update_post( array( diff --git a/tests/phpunit/tests/user/slashes.php b/tests/phpunit/tests/user/slashes.php index ee54b5efc3..5e2722ae0b 100644 --- a/tests/phpunit/tests/user/slashes.php +++ b/tests/phpunit/tests/user/slashes.php @@ -7,9 +7,11 @@ */ class Tests_User_Slashes extends WP_UnitTestCase { protected static $author_id; + protected static $user_id; public static function wpSetUpBeforeClass( $factory ) { self::$author_id = $factory->user->create( array( 'role' => 'administrator' ) ); + self::$user_id = $factory->user->create(); } function setUp() { @@ -87,7 +89,7 @@ class Tests_User_Slashes extends WP_UnitTestCase { * Tests the controller function that expects slashed data. */ function test_edit_user() { - $user_id = self::factory()->user->create(); + $user_id = self::$user_id; $_POST = array(); $_GET = array(); @@ -185,7 +187,7 @@ class Tests_User_Slashes extends WP_UnitTestCase { * Tests the model function that expects slashed data. */ function test_wp_update_user() { - $user_id = self::factory()->user->create(); + $user_id = self::$user_id; $user_id = wp_update_user( array( 'ID' => $user_id,