1 | <?php |
---|
2 | /** |
---|
3 | * Installs WordPress for the purpose of the unit-tests |
---|
4 | * |
---|
5 | * @todo Reuse the init/load code in init.php |
---|
6 | */ |
---|
7 | error_reporting( E_ALL & ~E_DEPRECATED & ~E_STRICT ); |
---|
8 | |
---|
9 | $config_file_path = $argv[1]; |
---|
10 | $multisite = ! empty( $argv[2] ); |
---|
11 | |
---|
12 | define( 'WP_INSTALLING', true ); |
---|
13 | require_once $config_file_path; |
---|
14 | require_once dirname( __FILE__ ) . '/functions.php'; |
---|
15 | |
---|
16 | tests_reset__SERVER(); |
---|
17 | |
---|
18 | $PHP_SELF = $GLOBALS['PHP_SELF'] = $_SERVER['PHP_SELF'] = '/index.php'; |
---|
19 | |
---|
20 | require_once ABSPATH . '/wp-settings.php'; |
---|
21 | |
---|
22 | require_once ABSPATH . '/wp-admin/includes/upgrade.php'; |
---|
23 | require_once ABSPATH . '/wp-includes/wp-db.php'; |
---|
24 | |
---|
25 | // Override the PHPMailer |
---|
26 | global $phpmailer; |
---|
27 | require_once( dirname( __FILE__ ) . '/mock-mailer.php' ); |
---|
28 | $phpmailer = new MockPHPMailer(); |
---|
29 | |
---|
30 | /* |
---|
31 | * default_storage_engine and storage_engine are the same option, but storage_engine |
---|
32 | * was deprecated in MySQL (and MariaDB) 5.5.3, and removed in 5.7. |
---|
33 | */ |
---|
34 | if ( version_compare( $wpdb->db_version(), '5.5.3', '>=' ) ) { |
---|
35 | $wpdb->query( 'SET default_storage_engine = InnoDB' ); |
---|
36 | } else { |
---|
37 | $wpdb->query( 'SET storage_engine = InnoDB' ); |
---|
38 | } |
---|
39 | $wpdb->select( DB_NAME, $wpdb->dbh ); |
---|
40 | |
---|
41 | echo "Installing..." . PHP_EOL; |
---|
42 | |
---|
43 | foreach ( $wpdb->tables() as $table => $prefixed_table ) { |
---|
44 | $wpdb->query( "DROP TABLE IF EXISTS $prefixed_table" ); |
---|
45 | } |
---|
46 | |
---|
47 | foreach ( $wpdb->tables( 'ms_global' ) as $table => $prefixed_table ) { |
---|
48 | $wpdb->query( "DROP TABLE IF EXISTS $prefixed_table" ); |
---|
49 | |
---|
50 | // We need to create references to ms global tables. |
---|
51 | if ( $multisite ) |
---|
52 | $wpdb->$table = $prefixed_table; |
---|
53 | } |
---|
54 | |
---|
55 | // Prefill a permalink structure so that WP doesn't try to determine one itself. |
---|
56 | add_action( 'populate_options', '_set_default_permalink_structure_for_tests' ); |
---|
57 | |
---|
58 | wp_install( WP_TESTS_TITLE, 'admin', WP_TESTS_EMAIL, true, null, 'password' ); |
---|
59 | |
---|
60 | // Delete dummy permalink structure, as prefilled above. |
---|
61 | if ( ! is_multisite() ) { |
---|
62 | delete_option( 'permalink_structure' ); |
---|
63 | } |
---|
64 | remove_action( 'populate_options', '_set_default_permalink_structure_for_tests' ); |
---|
65 | |
---|
66 | if ( $multisite ) { |
---|
67 | echo "Installing network..." . PHP_EOL; |
---|
68 | |
---|
69 | define( 'WP_INSTALLING_NETWORK', true ); |
---|
70 | |
---|
71 | $title = WP_TESTS_TITLE . ' Network'; |
---|
72 | $subdomain_install = false; |
---|
73 | |
---|
74 | install_network(); |
---|
75 | populate_network( 1, WP_TESTS_DOMAIN, WP_TESTS_EMAIL, $title, '/', $subdomain_install ); |
---|
76 | $wp_rewrite->set_permalink_structure( '' ); |
---|
77 | } |
---|