forked from woocommerce/woocommerce
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbootstrap.php
136 lines (108 loc) · 4.05 KB
/
bootstrap.php
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
<?php
/**
* WooCommerce Unit Tests Bootstrap
*
* @since 2.2
*/
class WC_Unit_Tests_Bootstrap {
/** @var WC_Unit_Tests_Bootstrap instance */
protected static $instance = null;
/** @var string directory where wordpress-tests-lib is installed */
public $wp_tests_dir;
/** @var string testing directory */
public $tests_dir;
/** @var string plugin directory */
public $plugin_dir;
/**
* Setup the unit testing environment.
*
* @since 2.2
*/
public function __construct() {
ini_set( 'display_errors','on' );
error_reporting( E_ALL );
// Ensure server variable is set for WP email functions.
if ( ! isset( $_SERVER['SERVER_NAME'] ) ) {
$_SERVER['SERVER_NAME'] = 'localhost';
}
$this->tests_dir = dirname( __FILE__ );
$this->plugin_dir = dirname( $this->tests_dir );
$this->wp_tests_dir = getenv( 'WP_TESTS_DIR' ) ? getenv( 'WP_TESTS_DIR' ) : '/tmp/wordpress-tests-lib';
// load test function so tests_add_filter() is available
require_once( $this->wp_tests_dir . '/includes/functions.php' );
// load WC
tests_add_filter( 'muplugins_loaded', array( $this, 'load_wc' ) );
// install WC
tests_add_filter( 'setup_theme', array( $this, 'install_wc' ) );
// load the WP testing environment
require_once( $this->wp_tests_dir . '/includes/bootstrap.php' );
// load WC testing framework
$this->includes();
}
/**
* Load WooCommerce.
*
* @since 2.2
*/
public function load_wc() {
require_once( $this->plugin_dir . '/woocommerce.php' );
}
/**
* Install WooCommerce after the test environment and WC have been loaded.
*
* @since 2.2
*/
public function install_wc() {
// clean existing install first
define( 'WP_UNINSTALL_PLUGIN', true );
define( 'WC_REMOVE_ALL_DATA', true );
include( $this->plugin_dir . '/uninstall.php' );
WC_Install::install();
// reload capabilities after install, see https://core.trac.wordpress.org/ticket/28374
$GLOBALS['wp_roles']->reinit();
echo "Installing WooCommerce..." . PHP_EOL;
}
/**
* Load WC-specific test cases and factories.
*
* @since 2.2
*/
public function includes() {
// factories
require_once( $this->tests_dir . '/framework/factories/class-wc-unit-test-factory-for-webhook.php' );
require_once( $this->tests_dir . '/framework/factories/class-wc-unit-test-factory-for-webhook-delivery.php' );
// framework
require_once( $this->tests_dir . '/framework/class-wc-unit-test-factory.php' );
require_once( $this->tests_dir . '/framework/class-wc-mock-session-handler.php' );
require_once( $this->tests_dir . '/framework/class-wc-mock-wc-data.php' );
require_once( $this->tests_dir . '/framework/class-wc-payment-token-stub.php' );
require_once( $this->tests_dir . '/framework/vendor/class-wp-test-spy-rest-server.php' );
// test cases
require_once( $this->tests_dir . '/framework/class-wc-unit-test-case.php' );
require_once( $this->tests_dir . '/framework/class-wc-api-unit-test-case.php' );
require_once( $this->tests_dir . '/framework/class-wc-rest-unit-test-case.php' );
// Helpers
require_once( $this->tests_dir . '/framework/helpers/class-wc-helper-product.php' );
require_once( $this->tests_dir . '/framework/helpers/class-wc-helper-coupon.php' );
require_once( $this->tests_dir . '/framework/helpers/class-wc-helper-fee.php' );
require_once( $this->tests_dir . '/framework/helpers/class-wc-helper-shipping.php' );
require_once( $this->tests_dir . '/framework/helpers/class-wc-helper-customer.php' );
require_once( $this->tests_dir . '/framework/helpers/class-wc-helper-order.php' );
require_once( $this->tests_dir . '/framework/helpers/class-wc-helper-shipping-zones.php' );
require_once( $this->tests_dir . '/framework/helpers/class-wc-helper-payment-token.php' );
require_once( $this->tests_dir . '/framework/helpers/class-wc-helper-settings.php' );
}
/**
* Get the single class instance.
*
* @since 2.2
* @return WC_Unit_Tests_Bootstrap
*/
public static function instance() {
if ( is_null( self::$instance ) ) {
self::$instance = new self();
}
return self::$instance;
}
}
WC_Unit_Tests_Bootstrap::instance();