Skip to:
Content

BuddyPress.org

Opened 6 years ago

Closed 6 years ago

#5965 closed defect (bug) (fixed)

test suite doesn't reset globals if go_to() is used twice in one test

Reported by: DJPaul Owned by: djpaul
Milestone: 2.2 Priority: normal
Severity: normal Version:
Component: Build/Test Tools Keywords:
Cc:

Description

The unit test suite doesn't reset all BP's globals if go_to is used twice in one test. There aren't many places this happens in existing core tests (test_visibility_private is one instance), I discovered this while writing tests for #5865.

We rely on clean_up_global_scope to tidy up, and WordPress calls that method during each test's setUp method -- which is fine, assuming each test only uses go_to once.

Change History (2)

#1 @DJPaul
6 years ago

We already override go_to in our test suite so I'm going to add in a call to clean_up_global_scope .

Writing tests to test our test suite seems a bit meta, but you can demo the bug like this:

//bug
$this->go_to( bp_get_activity_directory_permalink() );
$this->go_to( bp_get_root_domain() . '/' . strtoupper( bp_get_activity_root_slug() ) . '/' );
die(var_dump( buddypress()->current_component ));  // returns "activity"

vs.

//desired behaviour (this reveals a bug in the router code, but that's another issue).
$this->go_to( bp_get_activity_directory_permalink() );
$this->go_to( bp_get_root_domain() . '/' . strtoupper( bp_get_activity_root_slug() ) . '/' );
die(var_dump( buddypress()->current_component ));  // returns "" (empty string)

#2 @djpaul
6 years ago

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

In 9093:

Tests: make sure globals are reset when the go_to helper method is used to simulate a GET request.

This fixes a problem where go_to is used multiple times in one test, and the globals end up with incorrect/unexpected values for the second call; a situation which is likely to occur very infrequently.

Fixes #5965

Note: See TracTickets for help on using tickets.