[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

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

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.6 oik-weight-zone-shipping v0.2.6 has been tested with WooCommerce 7.4.0. ...
sb-chart-block v1.2.3 SB Chart Block v1.2.3 contains a fix for an Uncaught Error: Call to undefined function bw_trace2()  ...
SB Chart Block v1.2.1 Update to SB Chart Block v1.2.0 for custom colors, font size options and multiple y-axis charts.  ...
oik-css v2.1.0 Update to oik-css v2.1.0 for the ability to style CSS and GeSHi output in documentation. ...
oik-types v2.3.0 Update to oik-types v2.3.0 for improved control over sort order on archives ...

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


Website designed and developed by Herb Miller of Bobbing Wide
Proudly powered by WordPress and oik-plugins
WordPress 6.1.1. PHP: 7.4.33. Memory limit: 768M