| 1 |
<?php |
| 2 |
|
| 3 |
require_once dirname(__DIR__) . '/vendor/autoload.php'; |
| 4 |
|
| 5 |
$_tests_dir = getenv('WP_TESTS_DIR') ?: getenv('WP_PHPUNIT__DIR'); |
| 6 |
|
| 7 |
require_once $_tests_dir . '/includes/functions.php'; |
| 8 |
|
| 9 |
tests_add_filter('muplugins_loaded', function () { |
| 10 |
require_once dirname(__DIR__) . '/vendor/autoload.php'; |
| 11 |
|
| 12 |
// The plugin defines this in bootstrap.php, which the test harness never |
| 13 |
// loads. Config::$requiredCapability reads it at class-load, so any test |
| 14 |
// touching Config (e.g. the QuickEdit taggers' capability check) needs it. |
| 15 |
// Guarded so a real WP install that already defined it wins. |
| 16 |
if (!defined('EXTENDIFY_REQUIRED_CAPABILITY')) { |
| 17 |
define('EXTENDIFY_REQUIRED_CAPABILITY', 'manage_options'); |
| 18 |
} |
| 19 |
|
| 20 |
if (getenv('EXTENDIFY_TEST_SKIP_OPTIONAL_PLUGINS') === '1') { |
| 21 |
return; |
| 22 |
} |
| 23 |
|
| 24 |
$required = [ |
| 25 |
'WooCommerce' => WP_CONTENT_DIR . '/plugins/woocommerce/woocommerce.php', |
| 26 |
'WPForms Lite' => WP_CONTENT_DIR . '/plugins/wpforms-lite/wpforms.php', |
| 27 |
]; |
| 28 |
|
| 29 |
foreach ($required as $label => $entrypoint) { |
| 30 |
if (!is_readable($entrypoint)) { |
| 31 |
fwrite( |
| 32 |
STDERR, |
| 33 |
"extendify-sdk tests require $label at $entrypoint.\n" |
| 34 |
. "Install it under WP_CONTENT_DIR/plugins/ or set " |
| 35 |
. "EXTENDIFY_TEST_SKIP_OPTIONAL_PLUGINS=1 to skip the " |
| 36 |
. "WooCommerce + WPForms test paths.\n" |
| 37 |
); |
| 38 |
exit(1); |
| 39 |
} |
| 40 |
require_once $entrypoint; |
| 41 |
} |
| 42 |
}); |
| 43 |
|
| 44 |
// WC builds its custom tables on activation; a bare require_once doesn't, and |
| 45 |
// its own init-time self-install is too late for the first test on the fresh |
| 46 |
// DB CI provisions each run. Mirrors WC's own PHPUnit bootstrap. |
| 47 |
tests_add_filter('setup_theme', function () { |
| 48 |
if (!class_exists('WC_Install')) { |
| 49 |
return; |
| 50 |
} |
| 51 |
\WC_Install::install(); |
| 52 |
$GLOBALS['wp_roles'] = new \WP_Roles(); // install() grants WC caps to roles |
| 53 |
}); |
| 54 |
|
| 55 |
require $_tests_dir . '/includes/bootstrap.php'; |
| 56 |
|