install.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. $config_file_path = $argv[1];
  9. $multisite = ! empty( $argv[2] );
  10. define( 'WP_INSTALLING', true );
  11. require_once $config_file_path;
  12. require_once dirname( __FILE__ ) . '/functions.php';
  13. $_SERVER['SERVER_PROTOCOL'] = 'HTTP/1.1';
  14. $_SERVER['HTTP_HOST'] = WP_TESTS_DOMAIN;
  15. $PHP_SELF = $GLOBALS['PHP_SELF'] = $_SERVER['PHP_SELF'] = '/index.php';
  16. require_once ABSPATH . '/wp-settings.php';
  17. require_once ABSPATH . '/wp-admin/includes/upgrade.php';
  18. require_once ABSPATH . '/wp-includes/wp-db.php';
  19. // Override the PHPMailer
  20. global $phpmailer;
  21. require_once( dirname( __FILE__ ) . '/mock-mailer.php' );
  22. $phpmailer = new MockPHPMailer();
  23. $wpdb->query( 'SET storage_engine = INNODB' );
  24. $wpdb->select( DB_NAME, $wpdb->dbh );
  25. echo "Installing..." . PHP_EOL;
  26. foreach ( $wpdb->tables() as $table => $prefixed_table ) {
  27. $wpdb->query( "DROP TABLE IF EXISTS $prefixed_table" );
  28. }
  29. foreach ( $wpdb->tables( 'ms_global' ) as $table => $prefixed_table ) {
  30. $wpdb->query( "DROP TABLE IF EXISTS $prefixed_table" );
  31. // We need to create references to ms global tables.
  32. if ( $multisite )
  33. $wpdb->$table = $prefixed_table;
  34. }
  35. wp_install( WP_TESTS_TITLE, 'admin', WP_TESTS_EMAIL, true, null, 'password' );
  36. if ( $multisite ) {
  37. echo "Installing network..." . PHP_EOL;
  38. define( 'WP_INSTALLING_NETWORK', true );
  39. $title = WP_TESTS_TITLE . ' Network';
  40. $subdomain_install = false;
  41. install_network();
  42. populate_network( 1, WP_TESTS_DOMAIN, WP_TESTS_EMAIL, $title, '/', $subdomain_install );
  43. }