Skip to:
Content

BuddyPress.org

Changeset 11882


Ignore:
Timestamp:
03/04/2018 09:35:46 PM (6 years ago)
Author:
r-a-y
Message:

Unit Tests: Run 'bp_template_redirect' hook in go_to() method.

In PHPUnit, we mock page visits with the go_to() method, however we
previously only ran the 'bp_init' hook, which sets up various internal
page routing properties, but doesn't run any screen hooks.

This commit adds the 'bp_template_redirect' hook to the go_to() method,
which allows hooks like 'bp_actions' and 'bp_screens' to run. In order
for those hooks to run without errors in PHPUnit, we need to adjust our
bp_core_redirect() function so it doesn't kill execution. Also, for
PHPUnit, we do not allow redirects to occur since they cause 'headers
already sent' notices.

Lastly, we can adjust some unit tests to just use the go_to() method,
instead of needing to manually call a screen hook.

Fixes #7703.

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-core/bp-core-functions.php

    r11848 r11882  
    10381038
    10391039    wp_safe_redirect( $location, $status );
    1040     die;
     1040
     1041    // If PHPUnit is running, do not kill execution.
     1042    if ( ! defined( 'BP_TESTS_DIR' ) ) {
     1043        die;
     1044    }
    10411045}
    10421046
  • trunk/tests/phpunit/includes/loader.php

    r10470 r11882  
    99require dirname( __FILE__ ) . '/../../../src/bp-loader.php';
    1010
     11// Bail from redirects as they throw 'headers already sent' warnings.
     12tests_add_filter( 'wp_redirect', '__return_false' );
     13
    1114require_once( dirname( __FILE__ ) . '/mock-mailer.php' );
    1215function _bp_mock_mailer( $class ) {
  • trunk/tests/phpunit/includes/testcase.php

    r11739 r11882  
    194194
    195195        do_action( 'bp_init' );
     196        do_action( 'bp_template_redirect' );
    196197    }
    197198
  • trunk/tests/phpunit/testcases/activity/notifications.php

    r11737 r11882  
    5151
    5252        // Go to the activity permalink page
    53         $this->go_to( bp_activity_get_permalink( $this->a1 ) );
    54         $activity = bp_activity_get_specific( array( 'activity_ids' => $this->a1, 'show_hidden' => true, 'spam' => 'ham_only', ) );
    55         do_action( 'bp_activity_screen_single_activity_permalink', $activity['activities'][0] );
     53        $this->go_to( bp_core_get_user_domain( $this->u1 ) . 'activity/' . $this->a1 );
    5654
    5755        $notifications = BP_Notifications_Notification::get( array(
     
    8179
    8280        // Go to the activity permalink page
    83         $this->go_to( bp_activity_get_permalink( $this->a1 ) );
    84         $activity = bp_activity_get_specific( array( 'activity_ids' => $this->a1, 'show_hidden' => true, 'spam' => 'ham_only', ) );
    85         do_action( 'bp_activity_screen_single_activity_permalink', $activity['activities'][0] );
     81        $this->go_to( bp_core_get_user_domain( $this->u1 ) . 'activity/' . $this->a1 );
    8682
    8783        $notifications = BP_Notifications_Notification::get( array(
     
    113109
    114110        // Go to the activity permalink page
    115         $this->go_to( bp_activity_get_permalink( $this->a1 ) );
    116         $activity = bp_activity_get_specific( array( 'activity_ids' => $this->a1, 'show_hidden' => true, 'spam' => 'ham_only', ) );
    117         do_action( 'bp_activity_screen_single_activity_permalink', $activity['activities'][0] );
     111        $this->go_to( bp_core_get_user_domain( $this->u1 ) . 'activity/' . $this->a1 );
    118112
    119113        $notifications = BP_Notifications_Notification::get( array(
     
    143137        // Go to the My Activity page
    144138        $this->go_to( bp_core_get_user_domain( $this->u1 ) . bp_get_activity_slug() . '/mentions/' );
    145         do_action( 'bp_activity_screen_mentions' );
    146139
    147140        $notifications = BP_Notifications_Notification::get( array(
     
    172165        // Go to the My Activity page
    173166        $this->go_to( bp_core_get_user_domain( $this->u1 ) . bp_get_activity_slug() . '/mentions/' );
    174         do_action( 'bp_activity_screen_mentions' );
    175167
    176168        $notifications = BP_Notifications_Notification::get( array(
     
    204196        // Go to the My Activity page
    205197        $this->go_to( bp_core_get_user_domain( $this->u1 ) . bp_get_activity_slug() . '/mentions/' );
    206         do_action( 'bp_activity_screen_mentions' );
    207198
    208199        $notifications = BP_Notifications_Notification::get( array(
Note: See TracChangeset for help on using the changeset viewer.