[wp-trac] [WordPress Trac] #23690: Allow plugin test bootstraps access to tests_add_filter() earlier

WordPress Trac noreply at wordpress.org
Mon Mar 4 18:27:54 UTC 2013


#23690: Allow plugin test bootstraps access to tests_add_filter() earlier
-------------------------+----------------------------
 Reporter:  scribu       |       Owner:  scribu
     Type:  enhancement  |      Status:  closed
 Priority:  normal       |   Milestone:  WordPress.org
Component:  Unit Tests   |     Version:
 Severity:  normal       |  Resolution:  fixed
 Keywords:               |
-------------------------+----------------------------
Description changed by scribu:

Old description:

> 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( 'plugins_loaded', function() {
>         require __DIR__ . '/../my-plugin.php';
> }, 0 );
>
> require getenv( 'WP_TESTS_DIR' ) . '/includes/bootstrap.php';
> }}}

New description:

 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';
 }}}

--

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/23690#comment:2>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list