From 95751aeec2fd66b145f6d8ca9cbb88ae0c3910e9 Mon Sep 17 00:00:00 2001 From: Peter Wilson Date: Wed, 25 Nov 2020 04:09:41 +0000 Subject: [PATCH] Build/Test Tools: Remove unused posts from AJAX test `setUp()`. Removes the creation of five posts from the AJAX test suite `setUp()` function, replacing it with a shared fixture only where required. See #51802. git-svn-id: https://develop.svn.wordpress.org/trunk@49696 602fd350-edb4-49c9-b593-d223f7449a82 --- tests/phpunit/includes/testcase-ajax.php | 3 -- tests/phpunit/tests/ajax/CustomizeMenus.php | 33 +++++++++++++++++++-- 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/tests/phpunit/includes/testcase-ajax.php b/tests/phpunit/includes/testcase-ajax.php index d9f44d9590..e351ad2e49 100644 --- a/tests/phpunit/includes/testcase-ajax.php +++ b/tests/phpunit/includes/testcase-ajax.php @@ -149,9 +149,6 @@ abstract class WP_Ajax_UnitTestCase extends WP_UnitTestCase { // Suppress warnings from "Cannot modify header information - headers already sent by". $this->_error_level = error_reporting(); error_reporting( $this->_error_level & ~E_WARNING ); - - // Make some posts. - self::factory()->post->create_many( 5 ); } /** diff --git a/tests/phpunit/tests/ajax/CustomizeMenus.php b/tests/phpunit/tests/ajax/CustomizeMenus.php index 861a4ab6ba..20f76be168 100644 --- a/tests/phpunit/tests/ajax/CustomizeMenus.php +++ b/tests/phpunit/tests/ajax/CustomizeMenus.php @@ -16,6 +16,36 @@ class Tests_Ajax_CustomizeMenus extends WP_Ajax_UnitTestCase { */ public $wp_customize; + /** + * Page IDs. + * + * @var int[] + */ + public static $pages; + + /** + * Post IDs. + * + * @var int[] + */ + public static $posts; + + /** + * Term IDs. + * + * @var int[] + */ + public static $terms; + + public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) { + // Make some post objects. + self::$posts = $factory->post->create_many( 5 ); + self::$pages = $factory->post->create_many( 5, array( 'post_type' => 'page' ) ); + + // Some terms too. + self::$terms = $factory->term->create_many( 5 ); + } + /** * Set up the test fixture. */ @@ -341,9 +371,6 @@ class Tests_Ajax_CustomizeMenus extends WP_Ajax_UnitTestCase { 'url', ); - // Create some terms and pages. - self::factory()->term->create_many( 5 ); - self::factory()->post->create_many( 5, array( 'post_type' => 'page' ) ); $auto_draft_post = $this->wp_customize->nav_menus->insert_auto_draft_post( array( 'post_title' => 'Test Auto Draft',