PluginProbe
Custom 404 Pro / trunk
Custom 404 Pro vtrunk
3.15.2 3.15.4 3.15.5 3.15.6 3.16.0 3.15.1 3.15.0 3.14.1 3.14.0 3.13.0 trunk 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.1.5 1.1.6 1.2.0 1.3.10 1.3.12 1.3.5 All 100 releases
custom-404-pro / tests / integration / bootstrap.php

bootstrap.php in Custom 404 Pro trunk, at tests/integration/bootstrap.php

59 lines 2.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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