Skip to content

Commit

Permalink
Build/Test Tools: Check if the WordPress Importer plugin is installed…
Browse files Browse the repository at this point in the history
… in test bootstrap.

If a hard requirement for the test suite is not fulfilled, running the tests should be blocked from the test bootstrap. A test should only fail when it doesn't produce the expected result.

Since the WordPress Importer plugin is considered a hard requirement for the test suite at this time, this commit moves the check whether the plugin is installed from individual tests to the test bootstrap.

Includes defining a global constant for the path to the file for reuse in the tests.

Reference: [https://make.wordpress.org/core/handbook/contribute/git/#unit-tests Core Contributor Handbook: The Code Repository (Git): Unit Tests].

Follow-up to [40531], [40532], [41090], [41169], [48592], [49535], [49571].

Props jrf, hellofromTonya.
See #61530.

git-svn-id: https://develop.svn.wordpress.org/trunk@59085 602fd350-edb4-49c9-b593-d223f7449a82
  • Loading branch information
SergeyBiryukov committed Sep 24, 2024
1 parent ec80646 commit 60a66de
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 16 deletions.
7 changes: 7 additions & 0 deletions tests/phpunit/includes/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,13 @@
define( 'WP_TESTS_TABLE_PREFIX', $table_prefix );
define( 'DIR_TESTDATA', __DIR__ . '/../data' );
define( 'DIR_TESTROOT', realpath( dirname( __DIR__ ) ) );
define( 'IMPORTER_PLUGIN_FOR_TESTS', DIR_TESTDATA . '/plugins/wordpress-importer/wordpress-importer.php' );

if ( ! 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' ) );

Expand Down
9 changes: 3 additions & 6 deletions tests/phpunit/tests/import/import.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
*/
class Tests_Import_Import extends WP_Import_UnitTestCase {
public function set_up() {
global $wpdb;

parent::set_up();

if ( ! defined( 'WP_IMPORTING' ) ) {
Expand All @@ -19,13 +21,8 @@ public function set_up() {

add_filter( 'import_allow_create_users', '__return_true' );

if ( ! file_exists( DIR_TESTDATA . '/plugins/wordpress-importer/wordpress-importer.php' ) ) {
$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;

require_once DIR_TESTDATA . '/plugins/wordpress-importer/wordpress-importer.php';

global $wpdb;
// 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 ) {
$wpdb->query( "DELETE FROM {$wpdb->$table}" );
Expand Down
6 changes: 1 addition & 5 deletions tests/phpunit/tests/import/parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,7 @@ public function set_up() {
define( 'WP_LOAD_IMPORTERS', true );
}

if ( ! file_exists( DIR_TESTDATA . '/plugins/wordpress-importer/wordpress-importer.php' ) ) {
$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 DIR_TESTDATA . '/plugins/wordpress-importer/wordpress-importer.php';
require_once IMPORTER_PLUGIN_FOR_TESTS;
}

/**
Expand Down
6 changes: 1 addition & 5 deletions tests/phpunit/tests/import/postmeta.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,7 @@ public function set_up() {
define( 'WP_LOAD_IMPORTERS', true );
}

if ( ! file_exists( DIR_TESTDATA . '/plugins/wordpress-importer/wordpress-importer.php' ) ) {
$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 DIR_TESTDATA . '/plugins/wordpress-importer/wordpress-importer.php';
require_once IMPORTER_PLUGIN_FOR_TESTS;
}

public function test_serialized_postmeta_no_cdata() {
Expand Down

0 comments on commit 60a66de

Please sign in to comment.