2013-08-07 08:38:38 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Installs WordPress for the purpose of the unit-tests
|
|
|
|
*
|
|
|
|
* @todo Reuse the init/load code in init.php
|
|
|
|
*/
|
|
|
|
error_reporting( E_ALL & ~E_DEPRECATED & ~E_STRICT );
|
|
|
|
|
|
|
|
$config_file_path = $argv[1];
|
2017-12-01 00:09:33 +01:00
|
|
|
$multisite = ! empty( $argv[2] );
|
2013-08-07 08:38:38 +02:00
|
|
|
|
2016-10-25 13:05:17 +02:00
|
|
|
define( 'WP_INSTALLING', true );
|
|
|
|
require_once $config_file_path;
|
|
|
|
require_once dirname( __FILE__ ) . '/functions.php';
|
|
|
|
|
2016-10-25 12:24:57 +02:00
|
|
|
// Set the theme to our special empty theme, to avoid interference from the current Twenty* theme.
|
|
|
|
if ( ! defined( 'WP_DEFAULT_THEME' ) ) {
|
|
|
|
define( 'WP_DEFAULT_THEME', 'default' );
|
|
|
|
}
|
2013-08-07 08:38:38 +02:00
|
|
|
|
2016-02-26 03:08:47 +01:00
|
|
|
tests_reset__SERVER();
|
2015-10-22 01:51:45 +02:00
|
|
|
|
2019-07-02 06:43:01 +02:00
|
|
|
$PHP_SELF = '/index.php';
|
|
|
|
$GLOBALS['PHP_SELF'] = '/index.php';
|
|
|
|
$_SERVER['PHP_SELF'] = '/index.php';
|
2013-08-07 08:38:38 +02:00
|
|
|
|
2017-10-21 16:13:37 +02:00
|
|
|
tests_add_filter( 'wp_die_handler', '_wp_die_handler_filter_exit' );
|
|
|
|
|
2013-08-07 08:38:38 +02:00
|
|
|
require_once ABSPATH . '/wp-settings.php';
|
|
|
|
|
|
|
|
require_once ABSPATH . '/wp-admin/includes/upgrade.php';
|
2016-08-31 18:30:48 +02:00
|
|
|
require_once ABSPATH . '/wp-includes/wp-db.php';
|
2013-08-07 08:38:38 +02:00
|
|
|
|
2020-01-29 01:43:23 +01:00
|
|
|
// Override the PHPMailer.
|
2014-01-14 22:55:41 +01:00
|
|
|
global $phpmailer;
|
|
|
|
require_once( dirname( __FILE__ ) . '/mock-mailer.php' );
|
|
|
|
$phpmailer = new MockPHPMailer();
|
|
|
|
|
2016-10-25 13:05:17 +02:00
|
|
|
register_theme_directory( dirname( __FILE__ ) . '/../data/themedir1' );
|
|
|
|
|
2015-12-21 23:26:52 +01:00
|
|
|
/*
|
|
|
|
* default_storage_engine and storage_engine are the same option, but storage_engine
|
|
|
|
* was deprecated in MySQL (and MariaDB) 5.5.3, and removed in 5.7.
|
|
|
|
*/
|
|
|
|
if ( version_compare( $wpdb->db_version(), '5.5.3', '>=' ) ) {
|
|
|
|
$wpdb->query( 'SET default_storage_engine = InnoDB' );
|
|
|
|
} else {
|
|
|
|
$wpdb->query( 'SET storage_engine = InnoDB' );
|
|
|
|
}
|
2013-08-07 08:38:38 +02:00
|
|
|
$wpdb->select( DB_NAME, $wpdb->dbh );
|
|
|
|
|
2017-12-01 00:09:33 +01:00
|
|
|
echo 'Installing...' . PHP_EOL;
|
2013-08-07 08:38:38 +02:00
|
|
|
|
2017-12-01 00:09:33 +01:00
|
|
|
$wpdb->query( 'SET foreign_key_checks = 0' );
|
2013-08-07 08:38:38 +02:00
|
|
|
foreach ( $wpdb->tables() as $table => $prefixed_table ) {
|
2019-07-08 02:55:20 +02:00
|
|
|
//phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
|
2013-08-07 08:38:38 +02:00
|
|
|
$wpdb->query( "DROP TABLE IF EXISTS $prefixed_table" );
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ( $wpdb->tables( 'ms_global' ) as $table => $prefixed_table ) {
|
2019-07-08 02:55:20 +02:00
|
|
|
//phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
|
2013-08-07 08:38:38 +02:00
|
|
|
$wpdb->query( "DROP TABLE IF EXISTS $prefixed_table" );
|
|
|
|
|
|
|
|
// We need to create references to ms global tables.
|
2017-12-01 00:09:33 +01:00
|
|
|
if ( $multisite ) {
|
2013-08-07 08:38:38 +02:00
|
|
|
$wpdb->$table = $prefixed_table;
|
2017-12-01 00:09:33 +01:00
|
|
|
}
|
2013-08-07 08:38:38 +02:00
|
|
|
}
|
2017-12-01 00:09:33 +01:00
|
|
|
$wpdb->query( 'SET foreign_key_checks = 1' );
|
2013-08-07 08:38:38 +02:00
|
|
|
|
2015-04-17 01:59:01 +02:00
|
|
|
// Prefill a permalink structure so that WP doesn't try to determine one itself.
|
|
|
|
add_action( 'populate_options', '_set_default_permalink_structure_for_tests' );
|
|
|
|
|
2013-08-07 08:38:38 +02:00
|
|
|
wp_install( WP_TESTS_TITLE, 'admin', WP_TESTS_EMAIL, true, null, 'password' );
|
|
|
|
|
2015-04-17 01:59:01 +02:00
|
|
|
// Delete dummy permalink structure, as prefilled above.
|
|
|
|
if ( ! is_multisite() ) {
|
|
|
|
delete_option( 'permalink_structure' );
|
|
|
|
}
|
|
|
|
remove_action( 'populate_options', '_set_default_permalink_structure_for_tests' );
|
|
|
|
|
2013-08-07 08:38:38 +02:00
|
|
|
if ( $multisite ) {
|
2017-12-01 00:09:33 +01:00
|
|
|
echo 'Installing network...' . PHP_EOL;
|
2013-08-07 08:38:38 +02:00
|
|
|
|
|
|
|
define( 'WP_INSTALLING_NETWORK', true );
|
|
|
|
|
2017-12-01 00:09:33 +01:00
|
|
|
$title = WP_TESTS_TITLE . ' Network';
|
2013-08-07 08:38:38 +02:00
|
|
|
$subdomain_install = false;
|
|
|
|
|
|
|
|
install_network();
|
|
|
|
populate_network( 1, WP_TESTS_DOMAIN, WP_TESTS_EMAIL, $title, '/', $subdomain_install );
|
2014-11-07 02:24:19 +01:00
|
|
|
$wp_rewrite->set_permalink_structure( '' );
|
2013-08-07 08:38:38 +02:00
|
|
|
}
|