PHP Classes

File: tests/phpunit/bootstrap.php

Recommend this page to a friend!
  Classes of Maniruzzaman Akash   WP Emailer   tests/phpunit/bootstrap.php   Download  
File: tests/phpunit/bootstrap.php
Role: Example script
Content type: text/plain
Description: Example script
Class: WP Emailer
Allow WordPress users to configure email settings
Author: By
Last change:
Date: 1 year ago
Size: 2,757 bytes
 

Contents

Class file image Download
<?php

/**
 * PHPUnit bootstrap file.
 *
 * Loads the necessary setup to run the tests.
 * This file will be called first by the test runner.
 * Before running any tests.
 */

// Composer auto-loader must be loaded before WP_PHPUNIT__DIR will be available
require_once dirname( __FILE__, 3 ) . '/vendor/autoload.php';
$_tests_dir = getenv( 'WP_TESTS_DIR' ) ? getenv( 'WP_TESTS_DIR' ) : getenv( 'WP_PHPUNIT__DIR' );

if ( !
$_tests_dir ) {
   
$_tests_dir = rtrim( sys_get_temp_dir(), '/\\' ) . '/wordpress-tests-lib';
}

if ( !
file_exists( "{$_tests_dir}/includes/functions.php" ) ) {
    echo
"Could not find {$_tests_dir}/includes/functions.php, have you run bin/install-wp-tests.sh ?" . PHP_EOL; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
   
exit( 1 );
}

// Give access to tests_add_filter() function.
require_once "{$_tests_dir}/includes/functions.php";

/**
 * Manually load the plugin being tested.
 *
 * @since WP_EMAILER_SINCE
 *
 * @return void
 */
function _manually_load_plugin(): void {
   
_manually_load_required_plugins();
    require_once
dirname( dirname( dirname( __FILE__ ) ) ) . '/wpemailer.php';
}

/**
 * Load any external plugin if needs.
 *
 * @since WP_EMAILER_SINCE
 *
 * @example for Woocommerce Installation
 *
 * @return void
 */
function _manually_load_required_plugins(): void {
   
/*
    Handle if needs any additional plugin.
    In our case, we don't need any dependent library.
    */
}

tests_add_filter( 'muplugins_loaded', '_manually_load_plugin' );

/**
 * Install database tables for this plugin.
 *
 * @since WP_EMAILER_SINCE
 *
 * @return void
 */
function install_plugin_databases(): void {
   
_manually_load_plugin();

   
$installer = new \Akash\WpEmailer\Setup\Installer();
   
$installer->run();
}

/**
 * After setup theme install any needed plugins.
 *
 * @since WP_EMAILER_SINCE
 *
 * @example for Woocommerce Installation
 *
 * @return void
 */
function install_necessary_plugins(): void {
   
// clean existing install first
    /*
    define( 'WP_UNINSTALL_PLUGIN', true );
    define( 'WC_REMOVE_ALL_DATA', true );
    include dirname( dirname( dirname( dirname( __FILE__ ) ) ) ) . '/woocommerce/uninstall.php';
    WC_Install::install();
    // Reload capabilities after install, see https://core.trac.wordpress.org/ticket/28374.
    if ( version_compare( $GLOBALS['wp_version'], '4.7', '<' ) ) {
        $GLOBALS['wp_roles']->reinit();
    } else {
        $GLOBALS['wp_roles'] = null; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
        wp_roles();
    }
    echo esc_html( 'Installing WooCommerce...' . PHP_EOL );
    */
}

tests_add_filter( 'setup_theme', 'install_plugin_databases' );
tests_add_filter( 'setup_theme', 'install_necessary_plugins' );

// Start up the WP testing environment.
require "{$_tests_dir}/includes/bootstrap.php";