[oik] plugins.com

WordPress plugins and themes

  • Home
  • About
    • lazy shortcodes
    • smart shortcodes
    • oik base plugin
      • oik – donate
      • oik PayPal buttons
      • oik installation
      • oik Button Shortcode button
      • oik changelog
      • oik FAQ
      • oik plugins on SVN
      • oik plugins on GitHub
  • Plugins
    • oik base plugin
    • FREE oik plugins
    • WordPress plugins
    • Premium oik plugins
    • Bespoke oik plugins
  • Shortcodes
    • Shortcode examples
  • Blocks
    • Block examples
  • APIs
    • ALL action and filter hooks
  • Blog

bootstrap_loaded() – Function to invoke when loaded

Description

Function to invoke when loaded

Having looked at a number of unit test routines for WordPress plugins there appear to be a couple of approaches of getting their code loaded into the test suite.

Using mu_plugins loaded

  1. Load the wordpress-develop-tests functions.php
  2. This provides tests_add_filter() which enables them to register code to run in response to "muplugins_loaded"
  3. Load the wordpress-develop-tests boostrap.php

Using global $wp_tests_options

  1. Adds your plugin to the array of 'active_plugins' in $GLOBALS['wp_tests_options']
  2. Load the wordpress-develop-tests bootstrap.php
This second method appears to have been deprecated, but I don't know when.

Summary of methods used by different plugins

plugin method used env var plugin’s tests dir multisite?
shortcake muplugins_loaded WP_TESTS_DIR php-tests ?
jetpack muplugins_loaded WP_DEVELOP_DIR tests/php php.multisite.xml
WP-cli generated muplugins_loaded WP_TESTS_DIR tests ?
CMB2 muplugins_loaded WP_TESTS_DIR tests ?
BuddyPress muplugins_loaded WP_TESTS_DIR tests/phpunit ?
blobaugh/wordpress-plugin-tests wp_tests_options
bbPress both? WP_TESTS_DIR tests/phpunit multisite.xml
Note: WP-cli's PHPUnit testing is different

Preliminary thoughts on generalizing the solution

  • Most unit test routines hard code the name of the plugin file to load
  • But we can probably do better than that.
  • If we know the name of our bootstrap file then we can determine the plugin name from that; assumption is that the bootstrap file is in wp-content/plugins/$plugin/tests/bootstrap.php
  • Another way of invoking the tests would be to respond to an action hook invoked by wordpress-develop-tests

Requirements for in situ testing

All of the above discusses how plugins cater for running the tests in a vanilla environment. But we want to run our tests in situ, which means our plugin is expected to be loaded already.
  • Therefore we don't need to manually load the plugin.
  • And we certainly don't want to actually run the bootstrap.
  • You might wonder why we looked for it in the first place.
  • So all we need to do is locate and load the files we need

Usage

bootstrap_loaded();

Parameters

Returns

void

Source

File name: oik-batch/tests/bootstrap.php
Lines:
1 to 11 of 11
function bootstrap_loaded() {
  $wordpress_develop_tests = locate_wordpress_develop_tests();
  if ( $wordpress_develop_tests ) {
    load_bootstrap_functions( $wordpress_develop_tests );
    //tests_add_filter( 'muplugins_loaded', '_manually_load_plugin' );
    //continue_loading_bootstrap( $wordpress_develop_tests );
  } else {
    echo "What shall we do now then?" . PHP_EOL;
    die( "Tests cannot be run without the WordPress develop test suite." );
  }
}
 
 View on GitHub

Called by

1 to 1 of 1
  • tests/bootstrap.php

Invoked by

    Calls

    1 to 2 of 2
    • load_bootstrap_functions() – Load the WordPress develop tests functions.php file or our oik-batch replacements for in situ
    • locate_wordpress_develop_tests() – Locate the wordpress-develop-tests code

    Call hooks

    Function name: bootstrap_loaded
    Plugin ref: oik-batch
    Version: 1.0.0
    Sourcefile: tests/bootstrap.php
    File ref: tests/bootstrap.php
    Deprecated?: No
    API Letters: B,L

    Published: March 14, 2017 | Last updated: March 14, 2017

    Information

    Function name: bootstrap_loaded
    Plugin ref: oik-batch
    Version: 1.0.0
    Sourcefile: tests/bootstrap.php
    File ref: tests/bootstrap.php
    Deprecated?: No
    API Letters: B,L

    Recent plugin updates

    oik-weight-zone-shipping v0.2.13 oik-weight-zone-shipping v0.2.13 has been tested with WooCommerce 10.1.2 and WordPress 6.8.2 ...
    SB Children Block v1.3.0 Upgrade to SB Children Block v1.3.0 for support for PHP 8.3 and PHP 8.4  ...
    oik v4.15.3 Update to oik v4.15.3 for a couple of security fixes. Tested with WordPress 6.8.2 ...
    oik-privacy-policy v1.4.9 Update to oik-privacy-policy v1.4.9 for a security fix. Tested with WordPress 6.8.2 and PHP 8.3 and PHP 8.4 ...
    oik-nivo-slider v1.17.0 oik-nivo-slider v1.17.0 introduces the Nivo slider block - oik-nivo-slider/nivo. ...

    Plugins

    • All Plugins
    • oik base plugin
    • FREE oik plugins
    • WordPress plugins
    • Premium oik plugins

    Themes

    • FREE themes
    • Bespoke themes
    • Premium themes

    Blocks

    • All Blocks
    • Block examples
    • About Blocks

    Shortcodes

    • All Shortcodes
    • Shortcode examples
    • About Shortcodes

    Reference

    • About APIs
    • All APIs
    • All Classes
    • All Files
    • All Hooks

    Support

    • Contact
    • Cookies policy
    • Get API key
    • Privacy
    • Request support
    • Sitemap
    • Stay informed
    • Terms and Conditions
    oik-plugins
    Email: herb@bobbingwide.com

    Weight shipping plugins

    Find out which cart weight shipping plugin you need for your WooCommerce site.
    Which cart weight based plugin do I need?

    Site:  www.oik-plugins.com
    © Copyright oik-plugins 2011-2025. All rights reserved.


    Website designed and developed by Herb Miller of Bobbing Wide
    Proudly powered by WordPress and oik-plugins

    WordPress version: 6.8.3

    Gutenberg version: 21.7.0

    PHP version: 8.2.29