Make WordPress Core

source: trunk/tests/includes/install.php @ 25002

Last change on this file since 25002 was 25002, checked in by nacin, 12 years ago

Initial import of unit-tests repository into develop.svn.wordpress.org.

Imported from https://unit-tests.svn.wordpress.org/trunk@1337

see #24976.

File size: 2.0 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
16$_SERVER['SERVER_PROTOCOL'] = 'HTTP/1.1';
17$_SERVER['HTTP_HOST'] = WP_TESTS_DOMAIN;
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
25define( 'WP_TESTS_VERSION_FILE', ABSPATH . '.wp-tests-version' );
26
27$wpdb->suppress_errors();
28$installed = $wpdb->get_var( "SELECT option_value FROM $wpdb->options WHERE option_name = 'siteurl'" );
29$wpdb->suppress_errors( false );
30
31$hash = get_option( 'db_version' ) . ' ' . (int) $multisite . ' ' . sha1_file( $config_file_path );
32
33if ( $installed && file_exists( WP_TESTS_VERSION_FILE ) && file_get_contents( WP_TESTS_VERSION_FILE ) == $hash )
34        return;
35
36$wpdb->query( 'SET storage_engine = INNODB' );
37$wpdb->select( DB_NAME, $wpdb->dbh );
38
39echo "Installing..." . PHP_EOL;
40
41foreach ( $wpdb->tables() as $table => $prefixed_table ) {
42        $wpdb->query( "DROP TABLE IF EXISTS $prefixed_table" );
43}
44
45foreach ( $wpdb->tables( 'ms_global' ) as $table => $prefixed_table ) {
46        $wpdb->query( "DROP TABLE IF EXISTS $prefixed_table" );
47
48        // We need to create references to ms global tables.
49        if ( $multisite )
50                $wpdb->$table = $prefixed_table;
51}
52
53wp_install( WP_TESTS_TITLE, 'admin', WP_TESTS_EMAIL, true, null, 'password' );
54
55if ( $multisite ) {
56        echo "Installing network..." . PHP_EOL;
57
58        define( 'WP_INSTALLING_NETWORK', true );
59
60        $title = WP_TESTS_TITLE . ' Network';
61        $subdomain_install = false;
62
63        install_network();
64        populate_network( 1, WP_TESTS_DOMAIN, WP_TESTS_EMAIL, $title, '/', $subdomain_install );
65}
66
67file_put_contents( WP_TESTS_VERSION_FILE, $hash );
Note: See TracBrowser for help on using the repository browser.