Build/Test Tools: Fix and standardise calls to the setUp() and setUpBeforeClass() methods in the test suite.

The parent methods should always be called before any test-specific functionality is set up, unless there is a specific and documented reason.

See #52625


git-svn-id: https://develop.svn.wordpress.org/trunk@50449 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
John Blackbourn 2021-02-27 16:54:52 +00:00
parent 22e72cbdf2
commit 3542c3b4c0
21 changed files with 21 additions and 52 deletions

View File

@ -116,6 +116,8 @@ abstract class WP_Ajax_UnitTestCase extends WP_UnitTestCase {
);
public static function setUpBeforeClass() {
parent::setUpBeforeClass();
remove_action( 'admin_init', '_maybe_update_core' );
remove_action( 'admin_init', '_maybe_update_plugins' );
remove_action( 'admin_init', '_maybe_update_themes' );
@ -126,8 +128,6 @@ abstract class WP_Ajax_UnitTestCase extends WP_UnitTestCase {
add_action( 'wp_ajax_' . $action, 'wp_ajax_' . str_replace( '-', '_', $action ), 1 );
}
}
parent::setUpBeforeClass();
}
/**

View File

@ -15,13 +15,6 @@ class Block_Supported_Styles_Test extends WP_UnitTestCase {
*/
private $registered_block_names = array();
/**
* Sets up each test method.
*/
public function setUp() {
parent::setUp();
}
/**
* Tear down each test method.
*/

View File

@ -156,8 +156,8 @@ class Tests_Admin_includesScreen extends WP_UnitTestCase {
);
function setUp() {
set_current_screen( 'front' );
parent::setUp();
set_current_screen( 'front' );
}
function tearDown() {

View File

@ -15,9 +15,9 @@ class Tests_AdminBar extends WP_UnitTestCase {
protected static $user_ids = array();
public static function setUpBeforeClass() {
require_once ABSPATH . WPINC . '/class-wp-admin-bar.php';
parent::setUpBeforeClass();
require_once ABSPATH . WPINC . '/class-wp-admin-bar.php';
}
public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) {

View File

@ -1,17 +1,11 @@
<?php
class Tests_Get_Comment_Excerpt extends WP_UnitTestCase {
protected static $bacon_comment;
public static function setUpBeforeClass() {
parent::setUpBeforeClass();
self::$bacon_comment = 'Bacon ipsum dolor amet porchetta capicola sirloin prosciutto brisket shankle jerky. Ham hock filet mignon boudin ground round, prosciutto alcatra spare ribs meatball turducken pork beef ribs ham beef. Bacon pastrami short loin, venison tri-tip ham short ribs doner swine. Tenderloin pig tongue pork jowl doner. Pork loin rump t-bone, beef strip steak flank drumstick tri-tip short loin capicola jowl. Cow filet mignon hamburger doner rump. Short loin jowl drumstick, tongue tail beef ribs pancetta flank brisket landjaeger chuck venison frankfurter turkey.
protected static $bacon_comment = 'Bacon ipsum dolor amet porchetta capicola sirloin prosciutto brisket shankle jerky. Ham hock filet mignon boudin ground round, prosciutto alcatra spare ribs meatball turducken pork beef ribs ham beef. Bacon pastrami short loin, venison tri-tip ham short ribs doner swine. Tenderloin pig tongue pork jowl doner. Pork loin rump t-bone, beef strip steak flank drumstick tri-tip short loin capicola jowl. Cow filet mignon hamburger doner rump. Short loin jowl drumstick, tongue tail beef ribs pancetta flank brisket landjaeger chuck venison frankfurter turkey.
Brisket shank rump, tongue beef ribs swine fatback turducken capicola meatball picanha chicken cupim meatloaf turkey. Bacon biltong shoulder tail frankfurter boudin cupim turkey drumstick. Porchetta pig shoulder, jerky flank pork tail meatball hamburger. Doner ham hock ribeye tail jerky swine. Leberkas ribeye pancetta, tenderloin capicola doner turducken chicken venison ground round boudin pork chop. Tail pork loin pig spare ribs, biltong ribeye brisket pork chop cupim. Short loin leberkas spare ribs jowl landjaeger tongue kevin flank bacon prosciutto.
Shankle pork chop prosciutto ribeye ham hock pastrami. T-bone shank brisket bacon pork chop. Cupim hamburger pork loin short loin. Boudin ball tip cupim ground round ham shoulder. Sausage rump cow tongue bresaola pork pancetta biltong tail chicken turkey hamburger. Kevin flank pork loin salami biltong. Alcatra landjaeger pastrami andouille kielbasa ham tenderloin drumstick sausage turducken tongue corned beef.';
}
public function test_get_comment_excerpt() {
$comment_id = self::factory()->comment->create(

View File

@ -13,10 +13,6 @@ class Tests_Comment_Query extends WP_UnitTestCase {
self::$post_id = $factory->post->create();
}
function setUp() {
parent::setUp();
}
public function test_query() {
$c1 = self::factory()->comment->create(
array(

View File

@ -79,6 +79,8 @@ class Tests_dbDelta extends WP_UnitTestCase {
)
);
// This has to be called after the `CREATE TABLE` above as the `_create_temporary_tables` filter
// causes it to create a temporary table, and a temporary table cannot use a FULLTEXT index.
parent::setUp();
}

View File

@ -17,6 +17,8 @@
*/
class Tests_WP_SimplePie_File extends WP_UnitTestCase {
public static function setUpBeforeClass() {
parent::setUpBeforeClass();
require_once ABSPATH . '/wp-includes/class-simplepie.php';
require_once ABSPATH . '/wp-includes/class-wp-simplepie-file.php';
}

View File

@ -19,6 +19,7 @@ class Tests_Image_Editor extends WP_Image_UnitTestCase {
require_once DIR_TESTDATA . '/../includes/mock-image-editor.php';
// This needs to come after the mock image editor class is loaded.
parent::setUp();
}

View File

@ -17,6 +17,7 @@ class Tests_Image_Editor_GD extends WP_Image_UnitTestCase {
require_once ABSPATH . WPINC . '/class-wp-image-editor.php';
require_once ABSPATH . WPINC . '/class-wp-image-editor-gd.php';
// This needs to come after the mock image editor class is loaded.
parent::setUp();
}

View File

@ -18,6 +18,7 @@ class Tests_Image_Editor_Imagick extends WP_Image_UnitTestCase {
require_once ABSPATH . WPINC . '/class-wp-image-editor-imagick.php';
require_once DIR_TESTROOT . '/includes/class-wp-test-stream.php';
// This needs to come after the mock image editor class is loaded.
parent::setUp();
}

View File

@ -21,6 +21,7 @@ class Test_Image_Resize_GD extends WP_Tests_Image_Resize_UnitTestCase {
require_once ABSPATH . WPINC . '/class-wp-image-editor.php';
require_once ABSPATH . WPINC . '/class-wp-image-editor-gd.php';
// This needs to come after the mock image editor class is loaded.
parent::setUp();
}

View File

@ -21,6 +21,7 @@ class Test_Image_Resize_Imagick extends WP_Tests_Image_Resize_UnitTestCase {
require_once ABSPATH . WPINC . '/class-wp-image-editor.php';
require_once ABSPATH . WPINC . '/class-wp-image-editor-imagick.php';
// This needs to come after the mock image editor class is loaded.
parent::setUp();
}
}

View File

@ -23,7 +23,6 @@ class Tests_Menu_Walker_Nav_Menu extends WP_UnitTestCase {
$this->walker = new Walker_Nav_Menu();
$this->_wp_nav_menu_max_depth = $_wp_nav_menu_max_depth;
parent::setUp();
}
/**

View File

@ -16,9 +16,10 @@ class Tests_Menu_WpAjaxMenuQuickSeach extends WP_UnitTestCase {
* Set up. Workaround set_current_screen( null ) not working due to $hook_suffix not being set.
*/
function setUp() {
parent::setUp();
global $current_screen;
$this->current_screen = $current_screen;
parent::setUp();
}
/**

View File

@ -4,10 +4,6 @@
* @group post
*/
class Tests_Post_Formats extends WP_UnitTestCase {
function setUp() {
parent::setUp();
}
function test_set_get_post_format_for_post() {
$post_id = self::factory()->post->create();

View File

@ -5,10 +5,6 @@
*/
class Tests_Post_GetPages extends WP_UnitTestCase {
function setUp() {
parent::setUp();
}
/**
* @ticket 23167
*/

View File

@ -11,20 +11,6 @@ class Tests_Query_SetupPostdata extends WP_UnitTestCase {
protected $pages_global;
public function setUp() {
parent::setUp();
return;
foreach ( $this->global_keys as $global_key ) {
if ( isset( $GLOBALS[ $global_key ] ) ) {
$this->global_data[ $global_key ] = $GLOBALS[ $global_key ];
unset( $GLOBALS[ $global_key ] );
} else {
$this->global_data[ $global_key ] = null;
}
}
}
public function test_id() {
$p = self::factory()->post->create_and_get();
setup_postdata( $p );

View File

@ -133,11 +133,12 @@ class REST_Block_Renderer_Controller_Test extends WP_Test_REST_Controller_Testca
* @since 5.0.0
*/
public function setUp() {
parent::setUp();
$this->register_test_block();
$this->register_post_context_test_block();
$this->register_non_dynamic_block();
$this->register_dynamic_block_with_boolean_attributes();
parent::setUp();
}
/**

View File

@ -8,8 +8,8 @@ class Tests_Upload extends WP_UnitTestCase {
public $siteurl;
function setUp() {
$this->_reset_options();
parent::setUp();
$this->_reset_options();
}
function _reset_options() {

View File

@ -9,11 +9,9 @@
class Tests_Walker extends WP_UnitTestCase {
function setUp() {
$this->walker = new Walker_Test();
parent::setUp();
$this->walker = new Walker_Test();
}
function test_single_item() {