install.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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 = in_array( 'run_ms_tests', $argv, true );
  10. if ( ! defined( 'WP_RUN_CORE_TESTS' ) && in_array( 'run_core_tests', $argv, true ) ) {
  11. define( 'WP_RUN_CORE_TESTS', true );
  12. }
  13. define( 'WP_INSTALLING', true );
  14. require_once $config_file_path;
  15. require_once __DIR__ . '/functions.php';
  16. // Set the theme to our special empty theme, to avoid interference from the current Twenty* theme.
  17. if ( ! defined( 'WP_DEFAULT_THEME' ) ) {
  18. define( 'WP_DEFAULT_THEME', 'default' );
  19. }
  20. tests_reset__SERVER();
  21. $PHP_SELF = '/index.php';
  22. $GLOBALS['PHP_SELF'] = '/index.php';
  23. $_SERVER['PHP_SELF'] = '/index.php';
  24. tests_add_filter( 'wp_die_handler', '_wp_die_handler_filter_exit' );
  25. require_once ABSPATH . '/wp-settings.php';
  26. require_once ABSPATH . '/wp-admin/includes/upgrade.php';
  27. require_once ABSPATH . '/wp-includes/wp-db.php';
  28. // Override the PHPMailer.
  29. global $phpmailer;
  30. require_once __DIR__ . '/mock-mailer.php';
  31. $phpmailer = new MockPHPMailer();
  32. register_theme_directory( __DIR__ . '/../data/themedir1' );
  33. /*
  34. * default_storage_engine and storage_engine are the same option, but storage_engine
  35. * was deprecated in MySQL (and MariaDB) 5.5.3, and removed in 5.7.
  36. */
  37. if ( version_compare( $wpdb->db_version(), '5.5.3', '>=' ) ) {
  38. $wpdb->query( 'SET default_storage_engine = InnoDB' );
  39. } else {
  40. $wpdb->query( 'SET storage_engine = InnoDB' );
  41. }
  42. $wpdb->select( DB_NAME, $wpdb->dbh );
  43. echo 'Installing...' . PHP_EOL;
  44. $wpdb->query( 'SET foreign_key_checks = 0' );
  45. foreach ( $wpdb->tables() as $table => $prefixed_table ) {
  46. //phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
  47. $wpdb->query( "DROP TABLE IF EXISTS $prefixed_table" );
  48. }
  49. foreach ( $wpdb->tables( 'ms_global' ) as $table => $prefixed_table ) {
  50. //phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
  51. $wpdb->query( "DROP TABLE IF EXISTS $prefixed_table" );
  52. // We need to create references to ms global tables.
  53. if ( $multisite ) {
  54. $wpdb->$table = $prefixed_table;
  55. }
  56. }
  57. $wpdb->query( 'SET foreign_key_checks = 1' );
  58. // Prefill a permalink structure so that WP doesn't try to determine one itself.
  59. add_action( 'populate_options', '_set_default_permalink_structure_for_tests' );
  60. wp_install( WP_TESTS_TITLE, 'admin', WP_TESTS_EMAIL, true, null, 'password' );
  61. // Delete dummy permalink structure, as prefilled above.
  62. if ( ! is_multisite() ) {
  63. delete_option( 'permalink_structure' );
  64. }
  65. remove_action( 'populate_options', '_set_default_permalink_structure_for_tests' );
  66. if ( $multisite ) {
  67. echo 'Installing network...' . PHP_EOL;
  68. define( 'WP_INSTALLING_NETWORK', true );
  69. $title = WP_TESTS_TITLE . ' Network';
  70. $subdomain_install = false;
  71. install_network();
  72. $error = populate_network( 1, WP_TESTS_DOMAIN, WP_TESTS_EMAIL, $title, '/', $subdomain_install );
  73. if ( is_wp_error( $error ) ) {
  74. wp_die( $error );
  75. }
  76. $wp_rewrite->set_permalink_structure( '' );
  77. }