• Skip to main content
  • Skip to primary sidebar
  • Skip to footer

[oik] plugins.com

WordPress plugins and themes

  • 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

You appear to be a bot. Output may be restricted

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

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

Primary Sidebar

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-fields v1.55.1
oik-fields v1.55.1 oik-fields v1.55.1 has been tested with WordPress 7.1. ...
oik v4.16.0
oik v4.16.0 Upgrade to oik v4.16.0 for many accessibility (a11y) improvements for both the front end and admin areas, plus a security fix. ...
oik-fields v1.55.0
oik-fields v1.55.0 Upgrade to oik-fields v1.55.0 for accessibility improvements to the featured image virtual field. ...
oik-css v2.4.0
oik-css v2.4.0 Upgrade to oik-css v2.4.0 for accessibility improvements for Low Color Contrast errors. ...
oik-unloader v0.4.0
oik-unloader v0.4.0 Update to oik-unloader v0.4.0 for improved accessibility of the active-plugins shortcode. Tested with WordPress 6.9 and PHP 8.4 ...

Footer

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-2026. All rights reserved.


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

WordPress version: 7.1.2

Gutenberg version: 24.0.0

PHP version: 8.2.35