Skip to:
Content

BuddyPress.org

Opened 10 years ago

Closed 10 years ago

#5420 closed defect (bug) (fixed)

unit tests failing because of using bp_group_has_members() outside group context

Reported by: djpaul's profile DJPaul Owned by: djpaul's profile 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.

Attachments (1)

5420.01.patch (1.2 KB) - added by DJPaul 10 years ago.

Download all attachments as: .zip

Change History (4)

@DJPaul
10 years ago

#1 @boonebgorges
10 years ago

  • Keywords commit added

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.

#2 @boonebgorges
10 years ago

  • Milestone changed from Awaiting Review to 2.0

#3 @djpaul
10 years ago

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

In 7978:

Groups: When preparing the Group Members template loop, use the details of the group passed to the class rather than always using $bp->groups->current_group.

The global property is usually set to the currently-displayed group according to BP's URI parsing, but if the Group Members template loop is used outside a typical Groups context (such as in 3rd party plugin, or a unit test), then this variable isn't set. At worse, it'd use the wrong group's details to build the template loop.

Fixes #5420

Note: See TracTickets for help on using tickets.