| 1 |
<?php |
| 2 |
/** |
| 3 |
* Integration test bootstrap — loads the real WordPress test suite. |
| 4 |
* |
| 5 |
* Requires bin/install-wp-tests.sh to have been run first so that |
| 6 |
* /tmp/wordpress-tests-lib and /tmp/wordpress exist on the filesystem. |
| 7 |
* |
| 8 |
* @package Custom_404_Pro |
| 9 |
*/ |
| 10 |
|
| 11 |
$_tests_dir = getenv( 'WP_TESTS_DIR' ) ?: '/tmp/wordpress-tests-lib'; |
| 12 |
|
| 13 |
if ( ! file_exists( $_tests_dir . '/includes/functions.php' ) ) { |
| 14 |
echo "Could not find WordPress test suite at '{$_tests_dir}'." . PHP_EOL; |
| 15 |
echo 'Run bin/install-wp-tests.sh first.' . PHP_EOL; |
| 16 |
exit( 1 ); |
| 17 |
} |
| 18 |
|
| 19 |
// The WP test suite (5.9+) requires the PHPUnit Polyfills library. |
| 20 |
// Point it to our Composer-installed copy before loading the WP bootstrap. |
| 21 |
define( 'WP_TESTS_PHPUNIT_POLYFILLS_PATH', dirname( __DIR__, 2 ) . '/vendor/yoast/phpunit-polyfills' ); |
| 22 |
|
| 23 |
// Load WP test functions so we can hook into muplugins_loaded. |
| 24 |
require_once $_tests_dir . '/includes/functions.php'; |
| 25 |
|
| 26 |
/** |
| 27 |
* Manually loads the plugin classes before WordPress fully initialises. |
| 28 |
* |
| 29 |
* This mirrors what would happen if the plugin were activated. We do not call |
| 30 |
* register_activation_hook here because that hook never fires in the test suite. |
| 31 |
*/ |
| 32 |
function _c404p_manually_load_plugin() { |
| 33 |
$plugin_dir = dirname( __DIR__, 2 ); |
| 34 |
|
| 35 |
// The main plugin file is not loaded here, so define the version constant |
| 36 |
// from it directly. Without this the db-version upgrade gate short-circuits |
| 37 |
// and every upgrade-path test silently passes against a no-op. |
| 38 |
if ( ! defined( 'CUSTOM_404_PRO_VERSION' ) ) { |
| 39 |
preg_match( |
| 40 |
"/define\(\s*'CUSTOM_404_PRO_VERSION',\s*'([^']+)'\s*\)/", |
| 41 |
file_get_contents( $plugin_dir . '/custom-404-pro.php' ), |
| 42 |
$version_match |
| 43 |
); |
| 44 |
define( 'CUSTOM_404_PRO_VERSION', $version_match[1] ?? '0.0.0' ); |
| 45 |
} |
| 46 |
|
| 47 |
require_once $plugin_dir . '/admin/class-helpers.php'; |
| 48 |
require_once $plugin_dir . '/admin/class-adminclass.php'; |
| 49 |
require_once $plugin_dir . '/admin/class-logsclass.php'; |
| 50 |
require_once $plugin_dir . '/includes/class-activateclass.php'; |
| 51 |
require_once $plugin_dir . '/includes/class-deactivateclass.php'; |
| 52 |
require_once $plugin_dir . '/includes/class-uninstallclass.php'; |
| 53 |
require_once $plugin_dir . '/includes/class-pluginclass.php'; |
| 54 |
} |
| 55 |
tests_add_filter( 'muplugins_loaded', '_c404p_manually_load_plugin' ); |
| 56 |
|
| 57 |
// Bootstrap WordPress. |
| 58 |
require_once $_tests_dir . '/includes/bootstrap.php'; |
| 59 |
|