Skip to:
Content

BuddyPress.org

#7703 closed defect (bug) (fixed)

Unit tests: Run `'bp_template_redirect'` hook in `go_to()` method

Reported by: r-a-y Owned by: r-a-y
Milestone: 3.0 Priority: normal
Severity: normal Version:
Component: Build/Test Tools Keywords: has-patch commit
Cc:

Description

While looking at conditional loading in #7218, I ran into some issues with how we use the go_to() method to mock a visit to a page in PHPUnit.

In the go_to() method, we only run 'bp_init', which gets us halfway there. We also need to run 'bp_template_redirect' so hooks running on 'bp_actions' or 'bp_screens' can also run.

I'm guessing the issue why we never ran 'bp_template_redirect' is due to the use of wp_redirect(), which causes "headers are already sent" notices when running PHPUnit.

Attached patch alters bp_core_redirect() to only redirect if PHPUnit isn't running.

This also allows us to remove some hacky attempts at running certain hooks in our tests, most notably in @group mentions. This was the main problem that led me to fix this!

Let me know if you have any questions.

Attachments (1)

7703.01.patch (4.1 KB) - added by r-a-y 19 months ago.

Download all attachments as: .zip

Change History (5)

@r-a-y
19 months ago

#1 @r-a-y
19 months ago

  • Owner changed from netweb to r-a-y
  • Status changed from new to assigned

Sorry @netweb! BP Trac auto-assigned you to this issue because you're the Build/Test Tools maintainer.

#2 @DJPaul
19 months ago

let's give it a go. I remember how much of a pain it was to get go_to() "working" originally so not surprised that it's sort of broken. :)

#3 @DJPaul
19 months ago

  • Keywords commit added

#4 @r-a-y
19 months ago

  • Resolution set to fixed
  • Status changed from assigned to closed

In 11882:

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.

Note: See TracTickets for help on using tickets.