Make WordPress Core

Opened 12 years ago

Closed 12 years ago

Last modified 3 years ago

#23690 closed enhancement (fixed)

Allow plugin test bootstraps access to tests_add_filter() earlier

Reported by: scribu's profile scribu Owned by: scribu's profile scribu
Milestone: WordPress.org Priority: normal
Severity: normal Version:
Component: Unit Tests Keywords:
Focuses: Cc:

Description (last modified by scribu)

Currently, plugins that have their own unit tests have a bootstrap.php file that looks like this:

<?php

$GLOBALS['wp_tests_options'] = array(
    'active_plugins' => array( basename( dirname( dirname( __FILE__ ) ) ) . '/my-plugin.php' ),
);

require getenv( 'WP_TESTS_DIR' ) . '/includes/bootstrap.php';

The problem is that the plugin folder needs to be inside WP_CONTENT_DIR . '/plugins/', which is an artificial requirement.

The bootstrap file could just require() the plugin file themselves and everything will work, *except* for one thing: hooks such as 'plugins_loaded' or 'init'.

With the attached patch, the file could look like this:

<?php

require_once getenv( 'WP_TESTS_DIR' ) . '/includes/functions.php';

tests_add_filter( 'muplugins_loaded', function() {
	require __DIR__ . '/../my-plugin.php';
} );

require getenv( 'WP_TESTS_DIR' ) . '/includes/bootstrap.php';

Attachments (1)

23690.diff (433 bytes) - added by scribu 12 years ago.

Download all attachments as: .zip

Change History (3)

@scribu
12 years ago

#1 @scribu
12 years ago

  • Owner set to scribu
  • Resolution set to fixed
  • Status changed from new to closed

In 1232/tests:

Use require_once to load includes/functions.php

fixes #23690

#2 @scribu
12 years ago

  • Description modified (diff)
Note: See TracTickets for help on using tickets.