• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer
WordPress develop tests

WordPress develop tests

WordPress develop tests a2z

  • Home
  • Plugins
  • Shortcodes
  • APIs
  • Classes
  • Files
  • Hooks
  • Sitemap
  • Blog
Home / Files / phpunit/includes/install.php


Lines:

1 to 95 of 95
<?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';

// Set the theme to our special empty theme, to avoid interference from the current Twenty* theme.
if ( ! defined( 'WP_DEFAULT_THEME' ) ) {
  define( 'WP_DEFAULT_THEME', 'default' );
}

tests_reset__SERVER();

$PHP_SELF            = '/index.php';
$GLOBALS['PHP_SELF'] = '/index.php';
$_SERVER['PHP_SELF'] = '/index.php';

tests_add_filter( 'wp_die_handler', '_wp_die_handler_filter_exit' );

require_once ABSPATH . '/wp-settings.php';

require_once ABSPATH . '/wp-admin/includes/upgrade.php';
require_once ABSPATH . '/wp-includes/wp-db.php';

// Override the PHPMailer
global $phpmailer;
require_once( dirname( __FILE__ ) . '/mock-mailer.php' );
$phpmailer = new MockPHPMailer();

register_theme_directory( dirname( __FILE__ ) . '/../data/themedir1' );

/*
 * default_storage_engine and storage_engine are the same option, but storage_engine
 * was deprecated in MySQL (and MariaDB) 5.5.3, and removed in 5.7.
 */
if ( version_compare( $wpdb->db_version(), '5.5.3', '>=' ) ) {
  $wpdb->query( 'SET default_storage_engine = InnoDB' );
} else {
  $wpdb->query( 'SET storage_engine = InnoDB' );
}
$wpdb->select( DB_NAME, $wpdb->dbh );

echo 'Installing...' . PHP_EOL;

$wpdb->query( 'SET foreign_key_checks = 0' );
foreach ( $wpdb->tables() as $table => $prefixed_table ) {
  //phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
  $wpdb->query( "DROP TABLE IF EXISTS $prefixed_table" );
}

foreach ( $wpdb->tables( 'ms_global' ) as $table => $prefixed_table ) {
  //phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
  $wpdb->query( "DROP TABLE IF EXISTS $prefixed_table" );

  // We need to create references to ms global tables.
  if ( $multisite ) {
    $wpdb->$table = $prefixed_table;
  }
}
$wpdb->query( 'SET foreign_key_checks = 1' );

// Prefill a permalink structure so that WP doesn't try to determine one itTelf.
add_action( 'populate_options', '_set_default_permalink_structure_for_tests' );

wp_install( WP_TESTS_TITLE, 'admin', WP_TESTS_EMAIL, true, null, 'password' );

// Delete dummy permalink structure, as prefilled above.
if ( ! is_multisite() ) {
  delete_option( 'permalink_structure' );
}
remove_action( 'populate_options', '_set_default_permalink_structure_for_tests' );

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 );
  $wp_rewrite->set_permalink_structure( '' );
}
 

 View on GitHub

Called by

    Invoked by

      Calls

      1 to 2 of 2
      • tests_add_filter() – Adds hooks before loading WP.
      • tests_reset__SERVER() – Resets various `$_SERVER` variables that can get altered during tests.

      Call hooks

      File name: phpunit/includes/install.php
      Plugin ref: WordPress develop tests
      Version: 5.3
      Deprecated?: No
      API Letters: I,P

      Published: 26th November 2019 | Last updated: 26th November 2019

      Primary Sidebar

      Information

      File name: phpunit/includes/install.php
      Plugin ref: WordPress develop tests
      Version: 5.3
      Deprecated?: No
      API Letters: I,P

      phpunit/includes

      Footer

      WordPress develop tests WordPress develop tests
      WordPress develop tests a2z
      WordPress 5.3
      WordPress a2z
      WordPress core a2z
      Genesis Theme Framework a2z
      Jetpack a2z
      WordPress develop tests
      Easy Digital Downloads a2z
      WooCommerce a2z
      Yoast SEO a2z
      WordPress Blocks

      Site:  develop.wp-a2z.org
      © Copyright WordPress develop tests 2014-2019. All rights reserved.


      Website designed and developed by Herb Miller
      Proudly powered by WordPress and oik plugins

      • Home
      • Blog
      • Sitemap
      • Sites