diff options
author | Andrew Nacin <nacin@git.wordpress.org> | 2013-08-29 18:39:34 +0000 |
---|---|---|
committer | Andrew Nacin <nacin@git.wordpress.org> | 2013-08-29 18:39:34 +0000 |
commit | 8045afd81b7c80f6ef5b327c115a5bbb43e4b65c (patch) | |
tree | 15d457007610c451577debda89bd9e9cd3d74551 /tests/phpunit/includes/install.php | |
parent | d34baebc1d8111c9c1014e11001957face778e52 (diff) | |
download | wordpress-8045afd81b7c80f6ef5b327c115a5bbb43e4b65c.tar.gz wordpress-8045afd81b7c80f6ef5b327c115a5bbb43e4b65c.zip |
Move PHPUnit tests into a tests/phpunit directory.
wp-tests-config.php can/should reside in the root of a develop checkout. `phpunit` should be run from the root.
see #25088.
git-svn-id: https://develop.svn.wordpress.org/trunk@25165 602fd350-edb4-49c9-b593-d223f7449a82
Diffstat (limited to 'tests/phpunit/includes/install.php')
-rw-r--r-- | tests/phpunit/includes/install.php | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/tests/phpunit/includes/install.php b/tests/phpunit/includes/install.php new file mode 100644 index 0000000000..63de9d2185 --- /dev/null +++ b/tests/phpunit/includes/install.php @@ -0,0 +1,67 @@ +<?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]; +$multisite = ! empty( $argv[2] ); + +define( 'WP_INSTALLING', true ); +require_once $config_file_path; +require_once dirname( __FILE__ ) . '/functions.php'; + +$_SERVER['SERVER_PROTOCOL'] = 'HTTP/1.1'; +$_SERVER['HTTP_HOST'] = WP_TESTS_DOMAIN; +$PHP_SELF = $GLOBALS['PHP_SELF'] = $_SERVER['PHP_SELF'] = '/index.php'; + +require_once ABSPATH . '/wp-settings.php'; + +require_once ABSPATH . '/wp-admin/includes/upgrade.php'; +require_once ABSPATH . '/wp-includes/wp-db.php'; + +define( 'WP_TESTS_VERSION_FILE', ABSPATH . '.wp-tests-version' ); + +$wpdb->suppress_errors(); +$installed = $wpdb->get_var( "SELECT option_value FROM $wpdb->options WHERE option_name = 'siteurl'" ); +$wpdb->suppress_errors( false ); + +$hash = get_option( 'db_version' ) . ' ' . (int) $multisite . ' ' . sha1_file( $config_file_path ); + +if ( $installed && file_exists( WP_TESTS_VERSION_FILE ) && file_get_contents( WP_TESTS_VERSION_FILE ) == $hash ) + return; + +$wpdb->query( 'SET storage_engine = INNODB' ); +$wpdb->select( DB_NAME, $wpdb->dbh ); + +echo "Installing..." . PHP_EOL; + +foreach ( $wpdb->tables() as $table => $prefixed_table ) { + $wpdb->query( "DROP TABLE IF EXISTS $prefixed_table" ); +} + +foreach ( $wpdb->tables( 'ms_global' ) as $table => $prefixed_table ) { + $wpdb->query( "DROP TABLE IF EXISTS $prefixed_table" ); + + // We need to create references to ms global tables. + if ( $multisite ) + $wpdb->$table = $prefixed_table; +} + +wp_install( WP_TESTS_TITLE, 'admin', WP_TESTS_EMAIL, true, null, 'password' ); + +if ( $multisite ) { + echo "Installing network..." . PHP_EOL; + + define( 'WP_INSTALLING_NETWORK', true ); + + $title = WP_TESTS_TITLE . ' Network'; + $subdomain_install = false; + + install_network(); + populate_network( 1, WP_TESTS_DOMAIN, WP_TESTS_EMAIL, $title, '/', $subdomain_install ); +} + +file_put_contents( WP_TESTS_VERSION_FILE, $hash ); |