From 7be4c4650dfa71fd073c3714df5e518355e87361 Mon Sep 17 00:00:00 2001 From: Peter Wilson Date: Wed, 30 Oct 2024 23:45:53 +0000 Subject: [PATCH] Tests/Build tools: Only fail importer tests if plugin is missing. Reverts an earlier change to the test suite in which the PHPUnit tests could not run if the importer plugin was not available. This update allows the test suite to run and will fail importer tests if the plugin is not available. Follow up to r59085. Merges [59326] to the 6.7 branch. Props peterwilsoncc, azaozz. See #62325. git-svn-id: https://develop.svn.wordpress.org/branches/6.7@59327 602fd350-edb4-49c9-b593-d223f7449a82 --- tests/phpunit/includes/bootstrap.php | 6 ------ tests/phpunit/tests/import/base.php | 15 +++++++++++++++ tests/phpunit/tests/import/import.php | 2 +- tests/phpunit/tests/import/parser.php | 2 +- tests/phpunit/tests/import/postmeta.php | 2 +- 5 files changed, 18 insertions(+), 9 deletions(-) diff --git a/tests/phpunit/includes/bootstrap.php b/tests/phpunit/includes/bootstrap.php index 4e369c1f45363..5ee8f38b5753f 100644 --- a/tests/phpunit/includes/bootstrap.php +++ b/tests/phpunit/includes/bootstrap.php @@ -216,12 +216,6 @@ define( 'DIR_TESTROOT', realpath( dirname( __DIR__ ) ) ); define( 'IMPORTER_PLUGIN_FOR_TESTS', DIR_TESTDATA . '/plugins/wordpress-importer/wordpress-importer.php' ); -if ( defined( 'WP_RUN_CORE_TESTS' ) && WP_RUN_CORE_TESTS && ! file_exists( IMPORTER_PLUGIN_FOR_TESTS ) ) { - echo 'The test suite requires the WordPress Importer plugin to be available in the `/data/plugins/` directory.' - . ' See: https://make.wordpress.org/core/handbook/contribute/git/#unit-tests' . PHP_EOL, - exit( 1 ); -} - define( 'WP_LANG_DIR', realpath( DIR_TESTDATA . '/languages' ) ); if ( defined( 'WP_RUN_CORE_TESTS' ) && WP_RUN_CORE_TESTS ) { diff --git a/tests/phpunit/tests/import/base.php b/tests/phpunit/tests/import/base.php index d0fefb1a925ec..84cb179b97d78 100644 --- a/tests/phpunit/tests/import/base.php +++ b/tests/phpunit/tests/import/base.php @@ -1,6 +1,19 @@ fail( 'This test requires the WordPress Importer plugin to be installed in the test suite. See: https://make.wordpress.org/core/handbook/contribute/git/#unit-tests' ); + } + require_once IMPORTER_PLUGIN_FOR_TESTS; + } + /** * Import a WXR file. * @@ -21,6 +34,8 @@ abstract class WP_Import_UnitTestCase extends WP_UnitTestCase { * @param bool $fetch_files Whether or not do download remote attachments */ protected function _import_wp( $filename, $users = array(), $fetch_files = true ) { + $this->require_importer(); + $importer = new WP_Import(); $file = realpath( $filename ); diff --git a/tests/phpunit/tests/import/import.php b/tests/phpunit/tests/import/import.php index a73791314fe70..f00fb797261c5 100644 --- a/tests/phpunit/tests/import/import.php +++ b/tests/phpunit/tests/import/import.php @@ -21,7 +21,7 @@ public function set_up() { add_filter( 'import_allow_create_users', '__return_true' ); - require_once IMPORTER_PLUGIN_FOR_TESTS; + $this->require_importer(); // Crude but effective: make sure there's no residual data in the main tables. foreach ( array( 'posts', 'postmeta', 'comments', 'terms', 'term_taxonomy', 'term_relationships', 'users', 'usermeta' ) as $table ) { diff --git a/tests/phpunit/tests/import/parser.php b/tests/phpunit/tests/import/parser.php index a28a7ade3e799..41bc1d917fd0e 100644 --- a/tests/phpunit/tests/import/parser.php +++ b/tests/phpunit/tests/import/parser.php @@ -17,7 +17,7 @@ public function set_up() { define( 'WP_LOAD_IMPORTERS', true ); } - require_once IMPORTER_PLUGIN_FOR_TESTS; + $this->require_importer(); } /** diff --git a/tests/phpunit/tests/import/postmeta.php b/tests/phpunit/tests/import/postmeta.php index 6af937c7eaf63..b84ec925b03d9 100644 --- a/tests/phpunit/tests/import/postmeta.php +++ b/tests/phpunit/tests/import/postmeta.php @@ -19,7 +19,7 @@ public function set_up() { define( 'WP_LOAD_IMPORTERS', true ); } - require_once IMPORTER_PLUGIN_FOR_TESTS; + $this->require_importer(); } public function test_serialized_postmeta_no_cdata() {