-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbootstrap.php
150 lines (119 loc) · 4.69 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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
<?php
$autoloader_test__suite = realpath(__DIR__.'/../vendor/autoload.php');
if(file_exists($autoloader_test__suite)) {
require_once $autoloader_test__suite;
} else {
throw new \Error('Autoloader in vendor folder not found.');
}
date_default_timezone_set('UTC');
define( 'DISABLE_WP_CRON', true );
define( 'WP_MEMORY_LIMIT', -1 );
define( 'WP_MAX_MEMORY_LIMIT', -1 );
$PHP_SELF = '/index.php';
$GLOBALS['PHP_SELF'] = '/index.php';
$GLOBALS['_wp_die_disabled'] = false;
$_SERVER['PHP_SELF'] = '/index.php';
$_SERVER['SERVER_PROTOCOL'] = $_SERVER['SERVER_PROTOCOL'] ?? null;
$_SERVER['REMOTE_ADDR'] = $_SERVER['REMOTE_ADDR'] ?? '0.0.0.0';
$_SERVER['REQUEST_URI'] = '/php-unit-tests?phpunit=yes';
$_SERVER['HTTP_HOST'] = 'example.com';
$_SERVER['SERVER_NAME'] = 'trtestsys';
function getWordpressPath()
{
$fileToCheck = 'wp-settings.php';
$paths = [];
foreach (range(1, 10) as $level) {
$nested = str_repeat('/..', $level);
array_push($paths, __DIR__ . "$nested/wordpress/$fileToCheck", __DIR__ . "$nested/$fileToCheck");
}
$filtered = array_filter($paths, function ($path) {
return file_exists($path);
});
return str_replace("/$fileToCheck", '', array_shift($filtered));
}
$wp_load = getWordpressPath();
if( ! file_exists($wp_load) ) {
echo 'PHP Unit: WordPress Not Connected at ' . $wp_load . PHP_EOL;
} else {
define('BASE_WP', $wp_load);
define('WP_USE_THEMES', true);
// Disable email
function wp_mail( $to, $subject, $message, $headers = '', $attachments = array() ) { return true; }
global $wp, $wp_query, $wp_the_query, $wp_rewrite, $wp_did_header;
function __test_false() { return false; }
if(! defined( 'ABSPATH' )) {
require BASE_WP . '/wp-load.php';
}
if(!function_exists('wp_signon')) {
require BASE_WP . '/wp-admin/includes/user.php';
}
if(!defined('WP_INSTALLING')) {
require BASE_WP . '/wp-admin/includes/upgrade.php';
}
// Create Mock Tables
function typerocketTestsDatabaseSetup($clear_table, $sql = null)
{
/** @var \wpdb */
global $wpdb;
if($sql) {
dbDelta($sql);
}
$wpdb->query("DELETE FROM {$clear_table}");
$wpdb->query("ALTER TABLE {$clear_table} AUTO_INCREMENT = 1");
}
// terms
typerocketTestsDatabaseSetup('posts_terms', 'CREATE TABLE if not exists `posts_terms` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`terms_id` int(11) DEFAULT NULL,
`posts_id` int(11) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;');
// Products
typerocketTestsDatabaseSetup('products_variants', 'CREATE TABLE `products_variants` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`variant_sku` varchar(11) DEFAULT NULL,
`product_number` int(11) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;');
typerocketTestsDatabaseSetup('products', 'CREATE TABLE if not exists `products` (
`product_number` int(11) UNIQUE,
`title` varchar(11) DEFAULT NULL,
PRIMARY KEY (`product_number`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;');
typerocketTestsDatabaseSetup('variants', 'CREATE TABLE if not exists `variants` (
`sku` varchar(11) UNIQUE,
`barcode` varchar(11) DEFAULT NULL,
PRIMARY KEY (`sku`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;');
// People
typerocketTestsDatabaseSetup('peoples_roles', 'CREATE TABLE if not exists `peoples_roles` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`people_number` int(11) DEFAULT NULL,
`role_number` int(11) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;');
typerocketTestsDatabaseSetup('roles', 'CREATE TABLE if not exists `roles` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`r_number` int(11) DEFAULT NULL,
`name` varchar(11) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;');
typerocketTestsDatabaseSetup('peoples', 'CREATE TABLE if not exists `peoples` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`p_number` int(11) DEFAULT NULL,
`name` varchar(11) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;');
typerocketTestsDatabaseSetup('orders', 'CREATE TABLE if not exists `orders` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`per_number` int(11) DEFAULT NULL,
`name` varchar(11) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;');
typerocketTestsDatabaseSetup('items', 'CREATE TABLE if not exists `items` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`order_id` int(11) DEFAULT NULL,
`name` varchar(11) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;');
}