Skip to content

Commit

Permalink
6.7 backport of test changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
peterwilsoncc committed Oct 30, 2024
1 parent 4cfb064 commit 5218f5a
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 5218f5a

Please sign in to comment.