Make WordPress Core

source: trunk/tests/phpunit/includes/install.php @ 37475

Last change on this file since 37475 was 36721, checked in by johnbillion, 9 years ago

Remove (or at least reduce) the need to reset common $_SERVER variables before assertions or between tests, by introducing a method which automatically resets them during test setup.

See #35954

File size: 2.2 KB
Line 
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 */
7error_reporting( E_ALL & ~E_DEPRECATED & ~E_STRICT );
8
9$config_file_path = $argv[1];
10$multisite = ! empty( $argv[2] );
11
12define( 'WP_INSTALLING', true );
13require_once $config_file_path;
14require_once dirname( __FILE__ ) . '/functions.php';
15
16tests_reset__SERVER();
17
18$PHP_SELF = $GLOBALS['PHP_SELF'] = $_SERVER['PHP_SELF'] = '/index.php';
19
20require_once ABSPATH . '/wp-settings.php';
21
22require_once ABSPATH . '/wp-admin/includes/upgrade.php';
23require_once ABSPATH . '/wp-includes/wp-db.php';
24
25// Override the PHPMailer
26global $phpmailer;
27require_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 */
34if ( 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
41echo "Installing..." . PHP_EOL;
42
43foreach ( $wpdb->tables() as $table => $prefixed_table ) {
44        $wpdb->query( "DROP TABLE IF EXISTS $prefixed_table" );
45}
46
47foreach ( $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.
56add_action( 'populate_options', '_set_default_permalink_structure_for_tests' );
57
58wp_install( WP_TESTS_TITLE, 'admin', WP_TESTS_EMAIL, true, null, 'password' );
59
60// Delete dummy permalink structure, as prefilled above.
61if ( ! is_multisite() ) {
62        delete_option( 'permalink_structure' );
63}
64remove_action( 'populate_options', '_set_default_permalink_structure_for_tests' );
65
66if ( $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}
Note: See TracBrowser for help on using the repository browser.