Skip to content

Commit

Permalink
Tests/Build tools: Only fail importer tests if plugin is missing.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
peterwilsoncc committed Oct 30, 2024
1 parent 4cfb064 commit 7be4c46
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 9 deletions.
6 changes: 0 additions & 6 deletions tests/phpunit/includes/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand Down
15 changes: 15 additions & 0 deletions tests/phpunit/tests/import/base.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
<?php

abstract class WP_Import_UnitTestCase extends WP_UnitTestCase {

/**
* Require the WordPress Importer plugin.
*
* Fails the test if the plugin is not installed.
*/
protected function require_importer() {
if ( ! file_exists( IMPORTER_PLUGIN_FOR_TESTS ) ) {
$this->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.
*
Expand All @@ -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 );

Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/tests/import/import.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/tests/import/parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public function set_up() {
define( 'WP_LOAD_IMPORTERS', true );
}

require_once IMPORTER_PLUGIN_FOR_TESTS;
$this->require_importer();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/tests/import/postmeta.php
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 7be4c46

Please sign in to comment.