forked from Automattic/jetpack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbootstrap.php
More file actions
113 lines (95 loc) · 3.75 KB
/
bootstrap.php
File metadata and controls
113 lines (95 loc) · 3.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<?php
/**
* Bootstrap the plugin unit testing environment.
*
* Edit 'active_plugins' setting below to point to your main plugin file.
*
* @package wordpress-plugin-tests
*/
/**
* For tests that should be skipped in Jetpack but run in WPCOM (or vice versa), test against this constant.
*
* if ( defined( 'TESTING_IN_JETPACK' ) && TESTING_IN_JETPACK ) {
* self::markTestSkipped( 'This test only runs on WPCOM' );
* }
*/
define( 'TESTING_IN_JETPACK', true );
// Support for:
// 1. `WP_DEVELOP_DIR` environment variable
// 2. Plugin installed inside of WordPress.org developer checkout
// 3. Tests checked out to /tmp
if( false !== getenv( 'WP_DEVELOP_DIR' ) ) {
// Defined on command line
$test_root = getenv( 'WP_DEVELOP_DIR' );
} else if ( file_exists( '../../../../tests/phpunit/includes/bootstrap.php' ) ) {
// Installed inside wordpress-develop
$test_root = '../../../../tests/phpunit';
} else if ( file_exists( '/vagrant/www/wordpress-develop/public_html/tests/phpunit/includes/bootstrap.php' ) ) {
// VVV
$test_root = '/vagrant/www/wordpress-develop/public_html/tests/phpunit';
} else if ( file_exists( '/tmp/wordpress-develop/tests/phpunit/includes/bootstrap.php' ) ) {
// Manual checkout
$test_root = '/tmp/wordpress-develop/tests/phpunit';
} else if ( file_exists( '/tmp/wordpress-tests-lib/includes/bootstrap.php' ) ) {
// Legacy tests
$test_root = '/tmp/wordpress-tests-lib';
}
echo "Using test root $test_root\n";
if ( '1' != getenv( 'WP_MULTISITE' ) &&
( defined( 'WP_TESTS_MULTISITE') && ! WP_TESTS_MULTISITE ) ) {
echo "To run Jetpack multisite, use -c tests/php.multisite.xml" . PHP_EOL;
echo "Disregard Core's -c tests/phpunit/multisite.xml notice below." . PHP_EOL;
}
if ( '1' != getenv( 'JETPACK_TEST_WOOCOMMERCE' ) ) {
echo "To run Jetpack woocommerce tests, prefix phpunit with JETPACK_TEST_WOOCOMMERCE=1" . PHP_EOL;
} else {
define( 'JETPACK_WOOCOMMERCE_INSTALL_DIR', dirname( __FILE__ ) . '/../../../woocommerce' );
}
if ( false === function_exists( 'wp_cache_is_enabled' ) ) {
/**
* "Mocking" function so that it exists and Jetpack_Sync_Actions will load Jetpack_Sync_Module_WP_Super_Cache
*/
function wp_cache_is_enabled() {
}
}
require $test_root . '/includes/functions.php';
// Activates this plugin in WordPress so it can be tested.
function _manually_load_plugin() {
if ( '1' == getenv( 'JETPACK_TEST_WOOCOMMERCE' ) ) {
require JETPACK_WOOCOMMERCE_INSTALL_DIR . '/woocommerce.php';
}
require dirname( __FILE__ ) . '/../../jetpack.php';
}
function _manually_install_woocommerce() {
global $wp_version;
// clean existing install first
define( 'WP_UNINSTALL_PLUGIN', true );
define( 'WC_REMOVE_ALL_DATA', true );
include( JETPACK_WOOCOMMERCE_INSTALL_DIR . '/uninstall.php' );
WC_Install::install();
// reload capabilities after install, see https://core.trac.wordpress.org/ticket/28374
if ( version_compare( $wp_version, '4.7.0' ) >= 0 ) {
$GLOBALS['wp_roles'] = new WP_Roles();
} else {
$GLOBALS['wp_roles']->reinit();
}
echo "Installing WooCommerce..." . PHP_EOL;
}
// If we are running the uninstall tests don't load jepack.
if ( ! ( in_running_uninstall_group() ) ) {
tests_add_filter( 'plugins_loaded', '_manually_load_plugin', 1 );
if ( '1' == getenv( 'JETPACK_TEST_WOOCOMMERCE' ) ) {
tests_add_filter( 'setup_theme', '_manually_install_woocommerce' );
}
}
require $test_root . '/includes/bootstrap.php';
// Load the shortcodes module to test properly.
if ( ! function_exists( 'shortcode_new_to_old_params' ) && ! in_running_uninstall_group() ) {
require dirname( __FILE__ ) . '/../../modules/shortcodes.php';
}
// Load attachment helper methods.
require dirname( __FILE__ ) . '/attachment_test_case.php';
function in_running_uninstall_group() {
global $argv;
return is_array( $argv ) && in_array( '--group=uninstall', $argv );
}