Make WordPress Core

Changeset 29665


Ignore:
Timestamp:
09/02/2014 06:49:11 AM (10 years ago)
Author:
nacin
Message:

Unit tests for has_filter() not resetting the array pointer.

props pento.
fixes #29070. see [29472].

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/plugin.php

    r29472 r29665  
    106106 */
    107107function has_filter($tag, $function_to_check = false) {
     108    // Don't reset the internal array pointer
    108109    $wp_filter = $GLOBALS['wp_filter'];
    109110
  • trunk/tests/phpunit/tests/filters.php

    r29422 r29665  
    294294        $this->assertFalse( has_filter( $tag ) );
    295295    }
     296
     297    /**
     298     * @ticket 29070
     299     */
     300     function test_has_filter_doesnt_reset_wp_filter() {
     301        add_action( 'action_test_has_filter_doesnt_reset_wp_filter', '__return_null', 1 );
     302        add_action( 'action_test_has_filter_doesnt_reset_wp_filter', '__return_null', 2 );
     303        add_action( 'action_test_has_filter_doesnt_reset_wp_filter', '__return_null', 3 );
     304        add_action( 'action_test_has_filter_doesnt_reset_wp_filter', array( $this, '_action_test_has_filter_doesnt_reset_wp_filter' ), 4 );
     305
     306        do_action( 'action_test_has_filter_doesnt_reset_wp_filter' );
     307     }
     308     function _action_test_has_filter_doesnt_reset_wp_filter() {
     309        global $wp_filter;
     310
     311        has_action( 'action_test_has_filter_doesnt_reset_wp_filter', '_function_that_doesnt_exist' );
     312
     313        $filters = current( $wp_filter['action_test_has_filter_doesnt_reset_wp_filter'] );
     314        $the_ = current( $filters );
     315        $this->assertEquals( $the_['function'], array( $this, '_action_test_has_filter_doesnt_reset_wp_filter' ) );
     316     }
    296317}
Note: See TracChangeset for help on using the changeset viewer.