Repository navigation
Expand file tree
/
Copy pathbootstrap.php
More file actions
145 lines (129 loc) · 4.16 KB
/
Copy pathbootstrap.php
File metadata and controls
145 lines (129 loc) · 4.16 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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
<?php
/**
* PHPUnit bootstrap file
*
* @package Gutenberg
*/
// Debug settings for parity with WordPress Core's PHPUnit tests.
if ( ! defined( 'WP_DEBUG' ) ) {
define( 'WP_DEBUG', true );
}
if ( ! defined( 'LOCAL_WP_DEBUG_LOG' ) ) {
define( 'LOCAL_WP_DEBUG_LOG', true );
}
if ( ! defined( 'LOCAL_WP_DEBUG_DISPLAY' ) ) {
define( 'LOCAL_WP_DEBUG_DISPLAY', true );
}
if ( ! defined( 'LOCAL_SCRIPT_DEBUG' ) ) {
define( 'LOCAL_SCRIPT_DEBUG', true );
}
if ( ! defined( 'LOCAL_WP_ENVIRONMENT_TYPE' ) ) {
define( 'LOCAL_WP_ENVIRONMENT_TYPE', 'local' );
}
// Require composer dependencies.
require_once dirname( __DIR__ ) . '/vendor/autoload.php';
// If we're running in WP's build directory, ensure that WP knows that, too.
if ( 'build' === getenv( 'LOCAL_DIR' ) ) {
define( 'WP_RUN_CORE_TESTS', true );
}
// Determine the tests directory (from a WP dev checkout).
// Try the WP_TESTS_DIR environment variable first.
$_tests_dir = getenv( 'WP_TESTS_DIR' );
// See if we're installed inside an existing WP dev instance.
if ( ! $_tests_dir ) {
$_try_tests_dir = __DIR__ . '/../../../../../tests/phpunit';
if ( file_exists( $_try_tests_dir . '/includes/functions.php' ) ) {
$_tests_dir = $_try_tests_dir;
}
}
// Fallback.
if ( ! $_tests_dir ) {
$_tests_dir = '/tmp/wordpress-tests-lib';
}
// Give access to tests_add_filter() function.
require_once $_tests_dir . '/includes/functions.php';
// Do not try to load JavaScript files from an external URL - this takes a
// while.
define( 'GUTENBERG_LOAD_VENDOR_SCRIPTS', false );
/**
* Manually load the plugin being tested.
*/
function _manually_load_plugin() {
require dirname( __DIR__ ) . '/lib/load.php';
}
tests_add_filter( 'muplugins_loaded', '_manually_load_plugin' );
/**
* Adds a wp_die handler for use during tests.
*
* If bootstrap.php triggers wp_die, it will not cause the script to fail. This
* means that tests will look like they passed even though they should have
* failed. So we throw an exception if WordPress dies during test setup. This
* way the failure is observable.
*
* @param string|WP_Error $message The error message.
*
* @throws Exception When a `wp_die()` occurs.
*/
function fail_if_died( $message ) {
if ( is_wp_error( $message ) ) {
$message = $message->get_error_message();
}
throw new Exception( 'WordPress died: ' . $message );
}
tests_add_filter( 'wp_die_handler', 'fail_if_died' );
$GLOBALS['wp_tests_options'] = array(
'gutenberg-experiments' => array(
'gutenberg-widget-experiments' => '1',
'gutenberg-full-site-editing' => 1,
),
);
// Enable the widget block editor.
tests_add_filter( 'gutenberg_use_widgets_block_editor', '__return_true' );
/**
* Register test block prior to theme.json generating metadata.
*
* This new block is used to test experimental selectors. It is registered
* via `tests_add_filter()` here during bootstrapping so that it occurs prior
* to theme.json generating block metadata. Once a core block, such as Image,
* uses feature level selectors we could remove this in favour of testing via
* the core block.
*/
function gutenberg_register_test_block_for_feature_selectors() {
WP_Block_Type_Registry::get_instance()->register(
'test/test',
array(
'api_version' => 2,
'attributes' => array(
'textColor' => array(
'type' => 'string',
),
'style' => array(
'type' => 'object',
),
),
'supports' => array(
'__experimentalBorder' => array(
'radius' => true,
'__experimentalSelector' => '.inner',
),
'color' => array(
'text' => true,
),
'spacing' => array(
'padding' => true,
'__experimentalSelector' => '.inner',
),
'typography' => array(
'fontSize' => true,
'__experimentalSelector' => '.sub-heading',
),
'__experimentalSelector' => '.wp-block-test, .wp-block-test__wrapper',
),
)
);
}
tests_add_filter( 'init', 'gutenberg_register_test_block_for_feature_selectors' );
// Start up the WP testing environment.
require $_tests_dir . '/includes/bootstrap.php';
// Use existing behavior for wp_die during actual test execution.
remove_filter( 'wp_die_handler', 'fail_if_died' );