Opened 11 years ago
Closed 11 years ago
#5420 closed defect (bug) (fixed)
unit tests failing because of using bp_group_has_members() outside group context
Reported by: | DJPaul | Owned by: | djpaul |
---|---|---|---|
Milestone: | 2.0 | Priority: | normal |
Severity: | normal | Version: | |
Component: | Build/Test Tools | Keywords: | commit |
Cc: |
Description
I've been getting a few unit test failures locally from trunk recently, though travis-ci has been passing fine. I fixed some missing variable problems in r7972 the other night but have multiple failures in group-related tests. They all fail for the same BP functions; sample output for one is included below, and you can see everything at https://gist.github.com/paulgibbs/ea67e423c8c37063845a.
1) BP_Tests_Groups_Template::test_bp_group_has_members_vanilla Trying to get property of non-object /Users/paul/Sites/example.com/src/wp-content/plugins/buddypress/bp-groups/bp-groups-template.php:575 /Users/paul/Sites/example.com/src/wp-content/plugins/buddypress/bp-groups/bp-groups-template.php:2032 /Users/paul/Sites/example.com/src/wp-content/plugins/buddypress/bp-groups/bp-groups-template.php:2163 /Users/paul/Sites/example.com/src/wp-content/plugins/buddypress/tests/testcases/groups/template.php:115
This test uses bp_group_has_members()
which uses the BP_Groups_Group_Members_Template
class. This class in its constructor method uses groups_get_current_group()
, which uses $bp->groups->current_group
. This property is primarily set in the Group's setup_globals()
method when we're viewing a single group. This unit test, of course, doesn't use go_to
, so this property is never set.
I have checked with a couple of other people and I am not sure why I am seeing these failed tests and no-one else is. For further investigation and review, the attached patch fixes the issue for me.
I am running PHP 5.4.19 with no caching module and no object caching.
The real mystery here is not why you're getting the error, it's why the rest of us are not.
The fact that we're assuming the current group in this context seems like an outright bug. Your fix looks good to me.