Ticket #5423: 5423.02.patch
File 5423.02.patch, 24.9 KB (added by , 11 years ago) |
---|
-
bp-groups/bp-groups-classes.php
diff --git bp-groups/bp-groups-classes.php bp-groups/bp-groups-classes.php index de6110a..0fe6d89 100644
class BP_Groups_Group { 1448 1448 /** 1449 1449 * Query for the members of a group. 1450 1450 * 1451 * Special notes about the group members data schema: 1452 * - *Members* are entries with is_confirmed = 1 1453 * - *Pending requests* are entries with is_confirmed = 0 and inviter_id = 0 1454 * - *Pending and sent invitations* are entries with is_confirmed = 0 and 1455 * inviter_id != 0 and invite_sent = 1 1456 * - *Pending and unsent invitations* are entries with is_confirmed = 0 and 1457 * inviter_id != 0 and invite_sent = 0 1458 * 1451 1459 * @since BuddyPress (1.8.0) 1452 1460 * 1453 1461 * @param array $args { … … class BP_Group_Member_Query extends BP_User_Query { 1515 1523 'group_id' => 0, 1516 1524 'group_role' => array( 'member' ), 1517 1525 'is_confirmed' => true, 1526 'invite_sent' => null, 1527 'inviter_id' => null, 1518 1528 'type' => 'last_joined', 1519 1529 ) ); 1520 1530 … … class BP_Group_Member_Query extends BP_User_Query { 1564 1574 $is_confirmed = ! empty( $this->query_vars['is_confirmed'] ) ? 1 : 0; 1565 1575 $sql['where'][] = $wpdb->prepare( "is_confirmed = %d", $is_confirmed ); 1566 1576 1577 // invite_sent 1578 if ( ! is_null( $this->query_vars['invite_sent'] ) ) { 1579 $invite_sent = ! empty( $this->query_vars['invite_sent'] ) ? 1 : 0; 1580 $sql['where'][] = $wpdb->prepare( "invite_sent = %d", $invite_sent ); 1581 } 1582 1583 // inviter_id 1584 if ( ! is_null( $this->query_vars['inviter_id'] ) ) { 1585 $inviter_id = $this->query_vars['inviter_id']; 1586 1587 // Empty: inviter_id = 0. (pass false, 0, or empty array) 1588 if ( empty( $inviter_id ) ) { 1589 $sql['where'][] = "inviter_id = 0"; 1590 1591 // The string 'any' matches any non-zero value (inviter_id != 0) 1592 } else if ( 'any' === $inviter_id ) { 1593 $sql['where'][] = "inviter_id != 0"; 1594 1595 // Assume that a list of group IDs has been passed 1596 } else { 1597 // Parse and sanitize 1598 $inviter_ids = wp_parse_id_list( $inviter_id ); 1599 if ( ! empty( $inviter_ids ) ) { 1600 $inviter_ids_sql = implode( ',', $inviter_ids ); 1601 $sql['where'][] = "inviter_id IN ({$inviter_ids_sql})"; 1602 } 1603 } 1604 } 1605 1567 1606 // Role information is stored as follows: admins have 1568 1607 // is_admin = 1, mods have is_mod = 1, banned have is_banned = 1569 1608 // 1, and members have all three set to 0. -
bp-groups/bp-groups-template.php
diff --git bp-groups/bp-groups-template.php bp-groups/bp-groups-template.php index bb351b0..0c9b9b5 100644
class BP_Groups_Invite_Template { 3094 3094 var $pag_links; 3095 3095 var $total_invite_count; 3096 3096 3097 function __construct( $user_id, $group_id ) { 3098 $this->invites = groups_get_invites_for_group( $user_id, $group_id ); 3099 $this->invite_count = count( $this->invites ); 3097 public function __construct( $args = array() ) { 3098 3099 // Backward compatibility with old method of passing arguments 3100 if ( ! is_array( $args ) || func_num_args() > 1 ) { 3101 _deprecated_argument( __METHOD__, '2.0.0', sprintf( __( 'Arguments passed to %1$s should be in an associative array. See the inline documentation at %2$s for more details.', 'buddypress' ), __METHOD__, __FILE__ ) ); 3102 3103 $old_args_keys = array( 3104 0 => 'user_id', 3105 1 => 'group_id', 3106 ); 3107 3108 $func_args = func_get_args(); 3109 $args = bp_core_parse_args_array( $old_args_keys, $func_args ); 3110 } 3111 3112 $r = wp_parse_args( $args, array( 3113 'user_id' => bp_loggedin_user_id(), 3114 'group_id' => bp_get_current_group_id(), 3115 'page' => 1, 3116 'per_page' => 10, 3117 ) ); 3118 3119 $this->pag_page = isset( $_REQUEST['invitepage'] ) ? intval( $_REQUEST['invite_page'] ) : $r['page']; 3120 $this->pag_num = intval( $r['per_page'] ); 3121 3122 $iquery = new BP_Group_Member_Query( array( 3123 'group_id' => $r['group_id'], 3124 'type' => 'first_joined', 3125 'page' => $r['page'], 3126 'per_page' => $r['per_page'], 3127 3128 // These filters ensure we get only pending invites 3129 'is_confirmed' => false, 3130 'inviter_id' => $r['user_id'], 3131 ) ); 3132 $this->invite_data = $iquery->results; 3133 3134 $this->total_invite_count = $iquery->total_users; 3135 $this->invites = array_values( wp_list_pluck( $this->invite_data, 'ID' ) ); 3136 $this->invite_count = count( $this->invites ); 3137 3138 $this->pag_links = paginate_links( array( 3139 'base' => add_query_arg( 'invitepage', '%#%' ), 3140 'format' => '', 3141 'total' => ceil( $this->total_invite_count / $this->pag_num ), 3142 'current' => $this->pag_page, 3143 'prev_text' => '←', 3144 'next_text' => '→', 3145 'mid_size' => 1, 3146 ) ); 3100 3147 } 3101 3148 3102 3149 function has_invites() { … … class BP_Groups_Invite_Template { 3134 3181 3135 3182 function the_invite() { 3136 3183 global $group_id; 3137 3138 3184 $this->in_the_loop = true; 3139 3185 $user_id = $this->next_invite(); 3186 3140 3187 $this->invite = new stdClass; 3141 $this->invite->user = new BP_Core_User( $user_id ); 3188 $this->invite->user = $this->invite_data[ $user_id ]; 3189 3190 // This method previously populated the user object with 3191 // BP_Core_User. We manually configure BP_Core_User data for 3192 // backward compatibility. 3193 $this->invite->user->profile_data = BP_XProfile_ProfileData::get_all_for_user( $user_id ); 3194 $this->invite->user->avatar = bp_core_fetch_avatar( array( 'item_id' => $user_id, 'type' => 'full', 'alt' => sprintf( __( 'Avatar of %s', 'buddypress' ), $this->invite->user->fullname ) ) ); 3195 $this->invite->user->avatar_thumb = bp_core_fetch_avatar( array( 'item_id' => $user_id, 'type' => 'thumb', 'alt' => sprintf( __( 'Avatar of %s', 'buddypress' ), $this->invite->user->fullname ) ) ); 3196 $this->invite->user->avatar_mini = bp_core_fetch_avatar( array( 'item_id' => $user_id, 'type' => 'thumb', 'alt' => sprintf( __( 'Avatar of %s', 'buddypress' ), $this->invite->user->fullname ), 'width' => 30, 'height' => 30 ) ); 3197 $this->invite->user->email = $this->invite->user->user_email; 3198 $this->invite->user->user_url = bp_core_get_user_domain( $user_id, $this->invite->user->user_nicename, $this->invite->user->user_login ); 3199 $this->invite->user->user_link = "<a href='{$this->invite->user->user_url}' title='{$this->invite->user->fullname}'>{$this->invite->user->fullname}</a>"; 3200 $this->invite->user->last_active = bp_core_get_last_activity( $this->invite->user->last_activity, __( 'active %s', 'buddypress' ) ); 3201 3142 3202 $this->invite->group_id = $group_id; // Globaled in bp_group_has_invites() 3143 3203 3144 3204 if ( 0 == $this->current_invite ) // loop has just started … … function bp_group_has_invites( $args = '' ) { 3151 3211 3152 3212 $r = wp_parse_args( $args, array( 3153 3213 'group_id' => false, 3154 'user_id' => bp_loggedin_user_id() 3214 'user_id' => bp_loggedin_user_id(), 3215 'page' => 1, 3216 'per_page' => 10, 3155 3217 ) ); 3156 3218 3157 3219 if ( empty( $r['group_id'] ) ) { … … function bp_group_has_invites( $args = '' ) { 3171 3233 return false; 3172 3234 } 3173 3235 3174 $invites_template = new BP_Groups_Invite_Template( $r ['user_id'], $r['group_id']);3236 $invites_template = new BP_Groups_Invite_Template( $r ); 3175 3237 return apply_filters( 'bp_group_has_invites', $invites_template->has_invites(), $invites_template ); 3176 3238 } 3177 3239 … … function bp_group_invite_user_remove_invite_url() { 3232 3294 return wp_nonce_url( site_url( bp_get_groups_slug() . '/' . $invites_template->invite->group_id . '/invites/remove/' . $invites_template->invite->user->id ), 'groups_invite_uninvite_user' ); 3233 3295 } 3234 3296 3297 /** 3298 * Output pagination links for group invitations. 3299 * 3300 * @since BuddyPress (2.0.0) 3301 */ 3302 function bp_group_invite_pagination_links() { 3303 echo bp_get_group_invite_pagination_links(); 3304 } 3305 /** 3306 * Get pagination links for group invitations. 3307 * 3308 * @since BuddyPress (2.0.0) 3309 */ 3310 function bp_get_group_invite_pagination_links() { 3311 global $invites_template; 3312 return apply_filters( 'bp_get_group_invite_pagination_links', $invites_template->pag_links ); 3313 } 3314 3315 /** 3316 * Output pagination count text for group invitations. 3317 * 3318 * @since BuddyPress (2.0.0) 3319 */ 3320 function bp_group_invite_pagination_count() { 3321 echo bp_get_group_invite_pagination_count(); 3322 } 3323 /** 3324 * Get pagination count text for group invitations. 3325 * 3326 * @since BuddyPress (2.0.0) 3327 */ 3328 function bp_get_group_invite_pagination_count() { 3329 global $invites_template; 3330 3331 $start_num = intval( ( $invites_template->pag_page -1 ) * $invites_template->pag_num ) + 1; 3332 $from_num = bp_core_number_format( $start_num ); 3333 $to_num = bp_core_number_format( ( $start_num + ( $invites_template->pag_num - 1 ) > $invites_template->total_invite_count ) ? $invites_template->total_invite_count : $start_num + ( $invites_template->pag_num - 1 ) ); 3334 $total = bp_core_number_format( $invites_template->total_invite_count ); 3335 3336 return apply_filters( 'bp_get_groups_pagination_count', sprintf( _n( 'Viewing invitation %1$s to %2$s (of %3$s invitation)', 'Viewing invitation %1$s to %2$s (of %3$s invitations)', $total, 'buddypress' ), $from_num, $to_num, $total ), $from_num, $to_num, $total ); 3337 } 3338 3235 3339 /*** 3236 3340 * Groups RSS Feed Template Tags 3237 3341 */ -
bp-templates/bp-legacy/buddypress-functions.php
diff --git bp-templates/bp-legacy/buddypress-functions.php bp-templates/bp-legacy/buddypress-functions.php index d8963f5..93efcef 100644
class BP_Legacy extends BP_Theme_Compat { 139 139 'groups_filter' => 'bp_legacy_theme_object_template_loader', 140 140 'members_filter' => 'bp_legacy_theme_object_template_loader', 141 141 'messages_filter' => 'bp_legacy_theme_messages_template_loader', 142 'invite_filter' => 'bp_legacy_theme_invite_template_loader', 142 143 143 144 // Friends 144 145 'accept_friendship' => 'bp_legacy_theme_ajax_accept_friendship', … … function bp_legacy_theme_messages_template_loader() { 601 602 } 602 603 603 604 /** 605 * Load group invitations loop to handle pagination requests sent via AJAX. 606 * 607 * @since BuddyPress (2.0.0) 608 */ 609 function bp_legacy_theme_invite_template_loader() { 610 bp_get_template_part( 'groups/single/invites-loop' ); 611 exit(); 612 } 613 614 /** 604 615 * Load the activity loop template when activity is requested via AJAX, 605 616 * 606 617 * @return string JSON object containing 'contents' (output of the template loop -
new file p-templates/bp-legacy/buddypress/groups/single/invites-loop.php
diff --git bp-templates/bp-legacy/buddypress/groups/single/invites-loop.php bp-templates/bp-legacy/buddypress/groups/single/invites-loop.php new file mode 100644 index 0000000..ef37f26
- + 1 <div class="left-menu"> 2 3 <div id="invite-list"> 4 5 <ul> 6 <?php bp_new_group_invite_friend_list(); ?> 7 </ul> 8 9 <?php wp_nonce_field( 'groups_invite_uninvite_user', '_wpnonce_invite_uninvite_user' ); ?> 10 11 </div> 12 13 </div><!-- .left-menu --> 14 15 <div class="main-column"> 16 17 <div id="message" class="info"> 18 <p><?php _e('Select people to invite from your friends list.', 'buddypress' ); ?></p> 19 </div> 20 21 <?php do_action( 'bp_before_group_send_invites_list' ); ?> 22 23 <?php if ( bp_group_has_invites( bp_ajax_querystring( 'invite' ) ) ) : ?> 24 25 <div id="pag-top" class="pagination"> 26 27 <div class="pag-count" id="group-invite-count-top"> 28 29 <?php bp_group_invite_pagination_count(); ?> 30 31 </div> 32 33 <div class="pagination-links" id="group-invite-pag-top"> 34 35 <?php bp_group_invite_pagination_links(); ?> 36 37 </div> 38 39 </div> 40 41 <?php /* The ID 'friend-list' is important for AJAX support. */ ?> 42 <ul id="friend-list" class="item-list"> 43 44 <?php while ( bp_group_invites() ) : bp_group_the_invite(); ?> 45 46 <li id="<?php bp_group_invite_item_id(); ?>"> 47 <?php bp_group_invite_user_avatar(); ?> 48 49 <h4><?php bp_group_invite_user_link(); ?></h4> 50 <span class="activity"><?php bp_group_invite_user_last_active(); ?></span> 51 52 <?php do_action( 'bp_group_send_invites_item' ); ?> 53 54 <div class="action"> 55 <a class="button remove" href="<?php bp_group_invite_user_remove_invite_url(); ?>" id="<?php bp_group_invite_item_id(); ?>"><?php _e( 'Remove Invite', 'buddypress' ); ?></a> 56 57 <?php do_action( 'bp_group_send_invites_item_action' ); ?> 58 </div> 59 </li> 60 61 <?php endwhile; ?> 62 63 </ul><!-- #friend-list --> 64 65 <div id="pag-bottom" class="pagination"> 66 67 <div class="pag-count" id="group-invite-count-bottom"> 68 69 <?php bp_group_invite_pagination_count(); ?> 70 71 </div> 72 73 <div class="pagination-links" id="group-invite-pag-bottom"> 74 75 <?php bp_group_invite_pagination_links(); ?> 76 77 </div> 78 79 </div> 80 81 <?php endif; ?> 82 83 <?php do_action( 'bp_after_group_send_invites_list' ); ?> 84 85 </div><!-- .main-column --> 86 87 <div class="clear"></div> 88 89 <div class="submit"> 90 <input type="submit" name="submit" id="submit" value="<?php esc_attr_e( 'Send Invites', 'buddypress' ); ?>" /> 91 </div> 92 93 <?php wp_nonce_field( 'groups_send_invites', '_wpnonce_send_invites' ); ?> 94 95 <?php /* This is important, don't forget it */ ?> 96 <input type="hidden" name="group_id" id="group_id" value="<?php bp_group_id(); ?>" /> -
bp-templates/bp-legacy/buddypress/groups/single/send-invites.php
diff --git bp-templates/bp-legacy/buddypress/groups/single/send-invites.php bp-templates/bp-legacy/buddypress/groups/single/send-invites.php index c2f0500..bf6e82d 100644
2 2 3 3 <?php if ( bp_get_total_friend_count( bp_loggedin_user_id() ) ) : ?> 4 4 5 <?php /* 'send-invite-form' is important for AJAX support */ ?> 5 6 <form action="<?php bp_group_send_invite_form_action(); ?>" method="post" id="send-invite-form" class="standard-form" role="main"> 6 7 7 <div class=" left-menu">8 <div class="invite"> 8 9 9 <div id="invite-list"> 10 <ul> 11 <?php bp_new_group_invite_friend_list(); ?> 12 </ul> 10 <?php bp_get_template_part( 'groups/single/invites-loop' ); ?> 13 11 14 <?php wp_nonce_field( 'groups_invite_uninvite_user', '_wpnonce_invite_uninvite_user' ); ?>15 </div>16 17 </div><!-- .left-menu -->18 19 <div class="main-column">20 21 <div id="message" class="info">22 <p><?php _e('Select people to invite from your friends list.', 'buddypress' ); ?></p>23 </div>24 25 <?php do_action( 'bp_before_group_send_invites_list' ); ?>26 27 <?php /* The ID 'friend-list' is important for AJAX support. */ ?>28 <ul id="friend-list" class="item-list">29 <?php if ( bp_group_has_invites() ) : ?>30 31 <?php while ( bp_group_invites() ) : bp_group_the_invite(); ?>32 33 <li id="<?php bp_group_invite_item_id(); ?>">34 <?php bp_group_invite_user_avatar(); ?>35 36 <h4><?php bp_group_invite_user_link(); ?></h4>37 <span class="activity"><?php bp_group_invite_user_last_active(); ?></span>38 39 <?php do_action( 'bp_group_send_invites_item' ); ?>40 41 <div class="action">42 <a class="button remove" href="<?php bp_group_invite_user_remove_invite_url(); ?>" id="<?php bp_group_invite_item_id(); ?>"><?php _e( 'Remove Invite', 'buddypress' ); ?></a>43 44 <?php do_action( 'bp_group_send_invites_item_action' ); ?>45 </div>46 </li>47 48 <?php endwhile; ?>49 50 <?php endif; ?>51 </ul><!-- #friend-list -->52 53 <?php do_action( 'bp_after_group_send_invites_list' ); ?>54 55 </div><!-- .main-column -->56 57 <div class="clear"></div>58 59 <div class="submit">60 <input type="submit" name="submit" id="submit" value="<?php esc_attr_e( 'Send Invites', 'buddypress' ); ?>" />61 12 </div> 62 13 63 <?php wp_nonce_field( 'groups_send_invites', '_wpnonce_send_invites' ); ?>64 65 <?php /* This is important, don't forget it */ ?>66 <input type="hidden" name="group_id" id="group_id" value="<?php bp_group_id(); ?>" />67 68 14 </form><!-- #send-invite-form --> 69 15 70 <?php else : ?>71 72 <div id="message" class="info" role="main">73 <p><?php _e( 'Once you have built up friend connections you will be able to invite others to your group.', 'buddypress' ); ?></p>74 </div>75 76 16 <?php endif; ?> 77 17 78 18 <?php do_action( 'bp_after_group_send_invites_content' ); ?> -
bp-templates/bp-legacy/css/buddypress.css
diff --git bp-templates/bp-legacy/css/buddypress.css bp-templates/bp-legacy/css/buddypress.css index 6c13c70..feed445 100644
a.bp-title-button { 764 764 765 765 #buddypress form.standard-form .main-column ul#friend-list { 766 766 clear:none; 767 float: left; 767 768 } 768 769 769 770 #buddypress form.standard-form .main-column ul#friend-list h4 { … … a.bp-title-button { 1087 1088 background-color: #ffd; 1088 1089 border: 1px solid #cb2; 1089 1090 color: #440; 1090 1091 1091 1092 } 1092 1093 #buddypress div#item-header { 1093 1094 overflow: hidden; -
bp-templates/bp-legacy/js/buddypress.js
diff --git bp-templates/bp-legacy/js/buddypress.js bp-templates/bp-legacy/js/buddypress.js index 3afc762..fb29d1c 100644
jq(document).ready( function() { 901 901 /** Invite Friends Interface ****************************************/ 902 902 903 903 /* Select a user from the list of friends and add them to the invite list */ 904 jq("# invite-list input").on( 'click', function() {904 jq("#send-invite-form").on( 'click', '#invite-list input', function() { 905 905 jq('.ajax-loader').toggle(); 906 906 907 // Dim the form until the response arrives 908 jq( this ).parents( 'ul' ).find( 'input' ).prop( 'disabled', true ); 909 907 910 var friend_id = jq(this).val(); 908 911 909 912 if ( jq(this).prop('checked') == true ) … … jq(document).ready( function() { 928 931 929 932 jq('.ajax-loader').toggle(); 930 933 931 if ( friend_action == 'invite' ) {932 jq('#friend-list').append(response);933 } else if ( friend_action == 'uninvite' ) {934 jq('#friend-list li#uid-' + friend_id).remove();935 }936 937 934 jq('.item-list-tabs li.selected').removeClass('loading'); 935 }) 936 .done( function() { 937 // Refresh entire list (keeps pagination and totals up to date) 938 bp_filter_request( 'invite', 'bp-invite-filter', 'bp-invite-scope', 'div.invite', false, 1, '', '', '' ); 938 939 }); 939 940 }); 940 941 … … jq(document).ready( function() { 957 958 function(response) 958 959 { 959 960 jq('.ajax-loader').toggle(); 960 jq('#friend-list #uid-' + friend_id).remove(); 961 jq('#invite-list #f-' + friend_id).prop('checked', false); 961 }) 962 .done( function() { 963 // Refresh entire list (keeps pagination and totals up to date) 964 bp_filter_request( 'invite', 'bp-invite-filter', 'bp-invite-scope', 'div.invite', false, 1, '', '', '' ); 962 965 }); 963 966 964 967 return false; -
tests/includes/testcase.php
diff --git tests/includes/testcase.php tests/includes/testcase.php index 2556db1..aa91133 100644
class BP_UnitTestCase extends WP_UnitTestCase { 241 241 $r = wp_parse_args( $args, array( 242 242 'date_modified' => bp_core_current_time(), 243 243 'is_confirmed' => 1, 244 'invite_sent' => 0, 245 'inviter_id' => 0, 244 246 ) ); 245 247 246 248 $new_member = new BP_Groups_Member; … … class BP_UnitTestCase extends WP_UnitTestCase { 251 253 $new_member->user_title = ''; 252 254 $new_member->date_modified = $r['date_modified']; 253 255 $new_member->is_confirmed = $r['is_confirmed']; 256 $new_member->invite_sent = $r['invite_sent']; 257 $new_member->inviter_id = $r['inviter_id']; 254 258 255 259 $new_member->save(); 256 260 return $new_member->id; -
tests/testcases/groups/class-bp-group-member-query.php
diff --git tests/testcases/groups/class-bp-group-member-query.php tests/testcases/groups/class-bp-group-member-query.php index b38943f..955a86b 100644
class BP_Tests_BP_Group_Member_Query_TestCases extends BP_UnitTestCase { 422 422 $ids = wp_parse_id_list( array_keys( $query_members->results ) ); 423 423 $this->assertEquals( array( $u1, $u3, $u2 ), $ids ); 424 424 } 425 426 /** 427 * @group invite_sent 428 */ 429 public function test_with_invite_sent_true() { 430 $g = $this->factory->group->create(); 431 $u1 = $this->create_user(); 432 $u2 = $this->create_user(); 433 $time = time(); 434 435 $this->add_user_to_group( $u1, $g, array( 436 'date_modified' => gmdate( 'Y-m-d H:i:s', $time - 100 ), 437 'is_confirmed' => 0, 438 'invite_sent' => 0, 439 ) ); 440 441 $this->add_user_to_group( $u2, $g, array( 442 'date_modified' => gmdate( 'Y-m-d H:i:s', $time - 100 ), 443 'is_confirmed' => 0, 444 'invite_sent' => 1, 445 ) ); 446 447 $query_members = new BP_Group_Member_Query( array( 448 'group_id' => $g, 449 'is_confirmed' => false, 450 'invite_sent' => true, 451 ) ); 452 453 $ids = wp_parse_id_list( array_keys( $query_members->results ) ); 454 $this->assertEquals( array( $u2 ), $ids ); 455 } 456 457 /** 458 * @group invite_sent 459 */ 460 public function test_with_invite_sent_false() { 461 $g = $this->factory->group->create(); 462 $u1 = $this->create_user(); 463 $u2 = $this->create_user(); 464 $time = time(); 465 466 $this->add_user_to_group( $u1, $g, array( 467 'date_modified' => gmdate( 'Y-m-d H:i:s', $time - 100 ), 468 'is_confirmed' => 0, 469 'invite_sent' => 0, 470 ) ); 471 472 $this->add_user_to_group( $u2, $g, array( 473 'date_modified' => gmdate( 'Y-m-d H:i:s', $time - 100 ), 474 'is_confirmed' => 0, 475 'invite_sent' => 1, 476 ) ); 477 478 $query_members = new BP_Group_Member_Query( array( 479 'group_id' => $g, 480 'is_confirmed' => false, 481 'invite_sent' => false, 482 ) ); 483 484 $ids = wp_parse_id_list( array_keys( $query_members->results ) ); 485 $this->assertEquals( array( $u1 ), $ids ); 486 } 487 488 /** 489 * @group inviter_id 490 */ 491 public function test_with_inviter_id_false() { 492 $g = $this->factory->group->create(); 493 $u1 = $this->create_user(); 494 $u2 = $this->create_user(); 495 $time = time(); 496 497 $this->add_user_to_group( $u1, $g, array( 498 'date_modified' => gmdate( 'Y-m-d H:i:s', $time - 100 ), 499 'inviter_id' => 0, 500 ) ); 501 502 $this->add_user_to_group( $u2, $g, array( 503 'date_modified' => gmdate( 'Y-m-d H:i:s', $time - 100 ), 504 'inviter_id' => 1, 505 ) ); 506 507 $query_members = new BP_Group_Member_Query( array( 508 'group_id' => $g, 509 'inviter_id' => false, 510 ) ); 511 512 $ids = wp_parse_id_list( array_keys( $query_members->results ) ); 513 $this->assertEquals( array( $u1 ), $ids ); 514 } 515 516 /** 517 * @group inviter_id 518 */ 519 public function test_with_inviter_id_specific() { 520 $g = $this->factory->group->create(); 521 $u1 = $this->create_user(); 522 $u2 = $this->create_user(); 523 $u3 = $this->create_user(); 524 $u4 = $this->create_user(); 525 $time = time(); 526 527 $this->add_user_to_group( $u1, $g, array( 528 'date_modified' => gmdate( 'Y-m-d H:i:s', $time - 100 ), 529 'inviter_id' => 0, 530 ) ); 531 532 $this->add_user_to_group( $u2, $g, array( 533 'date_modified' => gmdate( 'Y-m-d H:i:s', $time - 200 ), 534 'inviter_id' => 1, 535 ) ); 536 537 $this->add_user_to_group( $u3, $g, array( 538 'date_modified' => gmdate( 'Y-m-d H:i:s', $time - 300 ), 539 'inviter_id' => 6, 540 ) ); 541 542 $this->add_user_to_group( $u4, $g, array( 543 'date_modified' => gmdate( 'Y-m-d H:i:s', $time - 400 ), 544 'inviter_id' => 2, 545 ) ); 546 547 $query_members = new BP_Group_Member_Query( array( 548 'group_id' => $g, 549 'inviter_id' => array( 2, 6 ), 550 ) ); 551 552 $ids = wp_parse_id_list( array_keys( $query_members->results ) ); 553 $this->assertEquals( array( $u3, $u4 ), $ids ); 554 } 555 556 /** 557 * @group inviter_id 558 */ 559 public function test_with_inviter_id_any() { 560 $g = $this->factory->group->create(); 561 $u1 = $this->create_user(); 562 $u2 = $this->create_user(); 563 $u3 = $this->create_user(); 564 $u4 = $this->create_user(); 565 $time = time(); 566 567 $this->add_user_to_group( $u1, $g, array( 568 'date_modified' => gmdate( 'Y-m-d H:i:s', $time - 100 ), 569 'inviter_id' => 0, 570 ) ); 571 572 $this->add_user_to_group( $u2, $g, array( 573 'date_modified' => gmdate( 'Y-m-d H:i:s', $time - 200 ), 574 'inviter_id' => 1, 575 ) ); 576 577 $this->add_user_to_group( $u3, $g, array( 578 'date_modified' => gmdate( 'Y-m-d H:i:s', $time - 300 ), 579 'inviter_id' => 6, 580 ) ); 581 582 $this->add_user_to_group( $u4, $g, array( 583 'date_modified' => gmdate( 'Y-m-d H:i:s', $time - 400 ), 584 'inviter_id' => 2, 585 ) ); 586 587 $query_members = new BP_Group_Member_Query( array( 588 'group_id' => $g, 589 'inviter_id' => 'any', 590 ) ); 591 592 $ids = wp_parse_id_list( array_keys( $query_members->results ) ); 593 $this->assertEquals( array( $u2, $u3, $u4 ), $ids ); 594 } 425 595 } -
tests/testcases/groups/template.php
diff --git tests/testcases/groups/template.php tests/testcases/groups/template.php index 41a5b39..0f9cf72 100644
class BP_Tests_Groups_Template extends BP_UnitTestCase { 480 480 $counter++; 481 481 endwhile; 482 482 } 483 484 /** 485 * @group bp_group_has_invites 486 * @group BP_Groups_Invite_Template 487 */ 488 public function test_bp_group_has_invites_pagination() { 489 $u1 = $this->create_user( array( 490 'last_activity' => gmdate( 'Y-m-d H:i:s', time() - 60 ), 491 ) ); 492 493 $g = $this->factory->group->create( array( 494 'creator_id' => $u1, 495 ) ); 496 497 $users = array(); 498 for ( $i = 1; $i < 15; $i++ ) { 499 $users[ $i ] = $this->create_user( array( 500 'last_activity' => gmdate( 'Y-m-d H:i:s', time() - $i ), 501 ) ); 502 503 $this->add_user_to_group( $users[ $i ], $g, array( 504 'date_modified' => gmdate( 'Y-m-d H:i:s', time() - $i ), 505 'is_confirmed' => 0, 506 'inviter_id' => $u1, 507 'invite_sent' => true, 508 ) ); 509 } 510 511 // Populate the global 512 bp_group_has_invites( array( 513 'group_id' => $g, 514 'user_id' => $u1, 515 'page' => 2, 516 'per_page' => 5, 517 ) ); 518 519 global $invites_template; 520 521 $this->assertEquals( array( $users[ 9 ], $users[ 8 ], $users[ 7 ], $users[ 6 ], $users[ 5 ], ), $invites_template->invites ); 522 } 483 523 }