Ticket #5423: 5423.03.patch
File 5423.03.patch, 37.4 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 6106e46..0315704 100644
class BP_Groups_Group { 1447 1447 /** 1448 1448 * Query for the members of a group. 1449 1449 * 1450 * Special notes about the group members data schema: 1451 * - *Members* are entries with is_confirmed = 1 1452 * - *Pending requests* are entries with is_confirmed = 0 and inviter_id = 0 1453 * - *Pending and sent invitations* are entries with is_confirmed = 0 and 1454 * inviter_id != 0 and invite_sent = 1 1455 * - *Pending and unsent invitations* are entries with is_confirmed = 0 and 1456 * inviter_id != 0 and invite_sent = 0 1457 * 1450 1458 * @since BuddyPress (1.8.0) 1451 1459 */ 1452 1460 class BP_Group_Member_Query extends BP_User_Query { … … class BP_Group_Member_Query extends BP_User_Query { 1501 1509 'group_id' => 0, 1502 1510 'group_role' => array( 'member' ), 1503 1511 'is_confirmed' => true, 1512 'invite_sent' => null, 1513 'inviter_id' => null, 1504 1514 'type' => 'last_joined', 1505 1515 ) ); 1506 1516 … … class BP_Group_Member_Query extends BP_User_Query { 1550 1560 $is_confirmed = ! empty( $this->query_vars['is_confirmed'] ) ? 1 : 0; 1551 1561 $sql['where'][] = $wpdb->prepare( "is_confirmed = %d", $is_confirmed ); 1552 1562 1563 // invite_sent 1564 if ( ! is_null( $this->query_vars['invite_sent'] ) ) { 1565 $invite_sent = ! empty( $this->query_vars['invite_sent'] ) ? 1 : 0; 1566 $sql['where'][] = $wpdb->prepare( "invite_sent = %d", $invite_sent ); 1567 } 1568 1569 // inviter_id 1570 if ( ! is_null( $this->query_vars['inviter_id'] ) ) { 1571 $inviter_id = $this->query_vars['inviter_id']; 1572 1573 // Empty: inviter_id = 0. (pass false, 0, or empty array) 1574 if ( empty( $inviter_id ) ) { 1575 $sql['where'][] = "inviter_id = 0"; 1576 1577 // The string 'any' matches any non-zero value (inviter_id != 0) 1578 } else if ( 'any' === $inviter_id ) { 1579 $sql['where'][] = "inviter_id != 0"; 1580 1581 // Assume that a list of inviter IDs has been passed 1582 } else { 1583 // Parse and sanitize 1584 $inviter_ids = wp_parse_id_list( $inviter_id ); 1585 if ( ! empty( $inviter_ids ) ) { 1586 $inviter_ids_sql = implode( ',', $inviter_ids ); 1587 $sql['where'][] = "inviter_id IN ({$inviter_ids_sql})"; 1588 } 1589 } 1590 } 1591 1553 1592 // Role information is stored as follows: admins have 1554 1593 // is_admin = 1, mods have is_mod = 1, banned have is_banned = 1555 1594 // 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 fe6c837..70f4350 100644
class BP_Groups_Invite_Template { 3085 3085 var $pag_links; 3086 3086 var $total_invite_count; 3087 3087 3088 function __construct( $user_id, $group_id ) { 3089 $this->invites = groups_get_invites_for_group( $user_id, $group_id ); 3090 $this->invite_count = count( $this->invites ); 3088 public function __construct( $args = array() ) { 3089 3090 // Backward compatibility with old method of passing arguments 3091 if ( ! is_array( $args ) || func_num_args() > 1 ) { 3092 _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__ ) ); 3093 3094 $old_args_keys = array( 3095 0 => 'user_id', 3096 1 => 'group_id', 3097 ); 3098 3099 $func_args = func_get_args(); 3100 $args = bp_core_parse_args_array( $old_args_keys, $func_args ); 3101 } 3102 3103 $r = wp_parse_args( $args, array( 3104 'user_id' => bp_loggedin_user_id(), 3105 'group_id' => bp_get_current_group_id(), 3106 'page' => 1, 3107 'per_page' => 10, 3108 ) ); 3109 3110 $this->pag_num = intval( $r['per_page'] ); 3111 $this->pag_page = isset( $_REQUEST['invitepage'] ) ? intval( $_REQUEST['invitepage'] ) : $r['page']; 3112 3113 $iquery = new BP_Group_Member_Query( array( 3114 'group_id' => $r['group_id'], 3115 'type' => 'first_joined', 3116 'per_page' => $this->pag_num, 3117 'page' => $this->pag_page, 3118 3119 // These filters ensure we get only pending invites 3120 'is_confirmed' => false, 3121 'inviter_id' => $r['user_id'], 3122 ) ); 3123 $this->invite_data = $iquery->results; 3124 3125 $this->total_invite_count = $iquery->total_users; 3126 $this->invites = array_values( wp_list_pluck( $this->invite_data, 'ID' ) ); 3127 $this->invite_count = count( $this->invites ); 3128 3129 $this->pag_links = paginate_links( array( 3130 'base' => add_query_arg( 'invitepage', '%#%' ), 3131 'format' => '', 3132 'total' => ceil( $this->total_invite_count / $this->pag_num ), 3133 'current' => $this->pag_page, 3134 'prev_text' => '←', 3135 'next_text' => '→', 3136 'mid_size' => 1, 3137 ) ); 3091 3138 } 3092 3139 3093 3140 function has_invites() { … … class BP_Groups_Invite_Template { 3125 3172 3126 3173 function the_invite() { 3127 3174 global $group_id; 3128 3129 3175 $this->in_the_loop = true; 3130 3176 $user_id = $this->next_invite(); 3177 3131 3178 $this->invite = new stdClass; 3132 $this->invite->user = new BP_Core_User( $user_id ); 3179 $this->invite->user = $this->invite_data[ $user_id ]; 3180 3181 // This method previously populated the user object with 3182 // BP_Core_User. We manually configure BP_Core_User data for 3183 // backward compatibility. 3184 $this->invite->user->profile_data = BP_XProfile_ProfileData::get_all_for_user( $user_id ); 3185 $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 ) ) ); 3186 $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 ) ) ); 3187 $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 ) ); 3188 $this->invite->user->email = $this->invite->user->user_email; 3189 $this->invite->user->user_url = bp_core_get_user_domain( $user_id, $this->invite->user->user_nicename, $this->invite->user->user_login ); 3190 $this->invite->user->user_link = "<a href='{$this->invite->user->user_url}' title='{$this->invite->user->fullname}'>{$this->invite->user->fullname}</a>"; 3191 $this->invite->user->last_active = bp_core_get_last_activity( $this->invite->user->last_activity, __( 'active %s', 'buddypress' ) ); 3192 3133 3193 $this->invite->group_id = $group_id; // Globaled in bp_group_has_invites() 3134 3194 3135 3195 if ( 0 == $this->current_invite ) // loop has just started … … class BP_Groups_Invite_Template { 3138 3198 } 3139 3199 3140 3200 function bp_group_has_invites( $args = '' ) { 3141 global $bp, $invites_template, $group_id; 3201 global $invites_template, $group_id; 3202 $bp = buddypress(); 3142 3203 3143 3204 $defaults = array( 3144 'group_id' => false, 3145 'user_id' => bp_loggedin_user_id() 3205 'group_id' => false, 3206 'user_id' => bp_loggedin_user_id(), 3207 'per_page' => 10, 3208 'page' => 1 3146 3209 ); 3147 3210 3148 3211 $r = wp_parse_args( $args, $defaults ); 3149 extract( $r, EXTR_SKIP );3150 3212 3151 if ( !$ group_id) {3213 if ( !$r['group_id'] ) { 3152 3214 // Backwards compatibility 3153 3215 if ( !empty( $bp->groups->current_group ) ) 3154 $ group_id= $bp->groups->current_group->id;3216 $r['group_id'] = $bp->groups->current_group->id; 3155 3217 3156 3218 if ( !empty( $bp->groups->new_group_id ) ) 3157 $ group_id= $bp->groups->new_group_id;3219 $r['group_id'] = $bp->groups->new_group_id; 3158 3220 } 3159 3221 3160 if ( !$ group_id)3222 if ( !$r['group_id'] ) 3161 3223 return false; 3162 3224 3163 $invites_template = new BP_Groups_Invite_Template( $ user_id, $group_id);3225 $invites_template = new BP_Groups_Invite_Template( $r ); 3164 3226 return apply_filters( 'bp_group_has_invites', $invites_template->has_invites(), $invites_template ); 3165 3227 } 3166 3228 … … function bp_group_invite_user_remove_invite_url() { 3221 3283 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' ); 3222 3284 } 3223 3285 3286 /** 3287 * Output pagination links for group invitations. 3288 * 3289 * @since BuddyPress (2.0.0) 3290 */ 3291 function bp_group_invite_pagination_links() { 3292 echo bp_get_group_invite_pagination_links(); 3293 } 3294 /** 3295 * Get pagination links for group invitations. 3296 * 3297 * @since BuddyPress (2.0.0) 3298 */ 3299 function bp_get_group_invite_pagination_links() { 3300 global $invites_template; 3301 return apply_filters( 'bp_get_group_invite_pagination_links', $invites_template->pag_links ); 3302 } 3303 3304 /** 3305 * Output pagination count text for group invitations. 3306 * 3307 * @since BuddyPress (2.0.0) 3308 */ 3309 function bp_group_invite_pagination_count() { 3310 echo bp_get_group_invite_pagination_count(); 3311 } 3312 /** 3313 * Get pagination count text for group invitations. 3314 * 3315 * @since BuddyPress (2.0.0) 3316 */ 3317 function bp_get_group_invite_pagination_count() { 3318 global $invites_template; 3319 3320 $start_num = intval( ( $invites_template->pag_page - 1 ) * $invites_template->pag_num ) + 1; 3321 $from_num = bp_core_number_format( $start_num ); 3322 $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 ) ); 3323 $total = bp_core_number_format( $invites_template->total_invite_count ); 3324 3325 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 ); 3326 } 3327 3224 3328 /*** 3225 3329 * Groups RSS Feed Template Tags 3226 3330 */ -
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..5df7144
- + 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 No newline at end of file -
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..6f3d9ef 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 14 <?php /* This is important, don't forget it */ ?> 66 15 <input type="hidden" name="group_id" id="group_id" value="<?php bp_group_id(); ?>" /> 67 16 68 17 </form><!-- #send-invite-form --> 69 18 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 19 <?php endif; ?> 77 20 78 21 <?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..5b84784 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() { 926 929 if ( jq("#message") ) 927 930 jq("#message").hide(); 928 931 929 jq('.ajax-loader').toggle(); 930 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 jq('.item-list-tabs li.selected').removeClass('loading'); 932 // Refresh entire list (keeps pagination and totals up to date) 933 bp_filter_request( 'invite', 'bp-invite-filter', 'bp-invite-scope', 'div.invite', false, 1, '', '', '' ); 938 934 }); 939 935 }); 940 936 941 937 /* Remove a user from the list of users to invite to a group */ 942 jq("# friend-list").on('click', 'lia.remove', function() {938 jq("#send-invite-form").on('click', 'a.remove', function() { 943 939 jq('.ajax-loader').toggle(); 944 940 945 941 var friend_id = jq(this).attr('id'); … … jq(document).ready( function() { 956 952 }, 957 953 function(response) 958 954 { 959 jq('.ajax-loader').toggle(); 960 jq('#friend-list #uid-' + friend_id).remove(); 961 jq('#invite-list #f-' + friend_id).prop('checked', false); 955 // Refresh entire list (keeps pagination and totals up to date) 956 bp_filter_request( 'invite', 'bp-invite-filter', 'bp-invite-scope', 'div.invite', false, 1, '', '', '' ); 962 957 }); 963 958 964 959 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 8a5c279..b335317 100644
class BP_Tests_Groups_Template extends BP_UnitTestCase { 407 407 $ids = wp_parse_id_list( wp_list_pluck( $members_template->members, 'user_id' ) ); 408 408 $this->assertEquals( array( $u1, $u3, $u2, ), $ids ); 409 409 } 410 411 /** 412 * @group bp_group_has_invites 413 * @group BP_Groups_Invite_Template 414 */ 415 public function test_bp_group_has_invites_pagination() { 416 $u1 = $this->create_user( array( 417 'last_activity' => gmdate( 'Y-m-d H:i:s', time() - 60 ), 418 ) ); 419 420 $g = $this->factory->group->create( array( 421 'creator_id' => $u1, 422 ) ); 423 424 $users = array(); 425 for ( $i = 1; $i < 15; $i++ ) { 426 $users[ $i ] = $this->create_user( array( 427 'last_activity' => gmdate( 'Y-m-d H:i:s', time() - $i ), 428 ) ); 429 430 $this->add_user_to_group( $users[ $i ], $g, array( 431 'date_modified' => gmdate( 'Y-m-d H:i:s', time() - $i ), 432 'is_confirmed' => 0, 433 'inviter_id' => $u1, 434 'invite_sent' => true, 435 ) ); 436 } 437 438 // Populate the global 439 bp_group_has_invites( array( 440 'group_id' => $g, 441 'user_id' => $u1, 442 'page' => 2, 443 'per_page' => 5, 444 ) ); 445 446 global $invites_template; 447 448 $this->assertEquals( array( $users[ 9 ], $users[ 8 ], $users[ 7 ], $users[ 6 ], $users[ 5 ], ), $invites_template->invites ); 449 } 410 450 } -
new file tests/testcases/groups/template.php.orig
diff --git tests/testcases/groups/template.php.orig tests/testcases/groups/template.php.orig new file mode 100644 index 0000000..8a5c279
- + 1 <?php 2 /** 3 * @group groups 4 * @group template 5 */ 6 class BP_Tests_Groups_Template extends BP_UnitTestCase { 7 public function setUp() { 8 parent::setUp(); 9 } 10 11 public function tearDown() { 12 parent::tearDown(); 13 } 14 15 /** 16 * Integration test to make sure meta_query is getting passed through 17 * 18 * @group bp_has_groups 19 */ 20 public function test_bp_has_groups_with_meta_query() { 21 $g1 = $this->factory->group->create(); 22 $g2 = $this->factory->group->create(); 23 groups_update_groupmeta( $g1, 'foo', 'bar' ); 24 25 global $groups_template; 26 bp_has_groups( array( 27 'meta_query' => array( 28 array( 29 'key' => 'foo', 30 'value' => 'bar', 31 ), 32 ), 33 ) ); 34 35 $ids = wp_list_pluck( $groups_template->groups, 'id' ); 36 $this->assertEquals( $ids, array( $g1, ) ); 37 } 38 39 /** 40 * Integration test to make sure order and orderby are interpreted when 41 * no 'type' value has been passed 42 * 43 * @group bp_has_groups 44 */ 45 public function test_bp_has_groups_with_order_orderby_with_null_type() { 46 $g1 = $this->factory->group->create( array( 47 'name' => 'AAAAA', 48 'date_created' => gmdate( 'Y-m-d H:i:s', time() - 100 ), 49 'last_activity' => gmdate( 'Y-m-d H:i:s', time() - 1000000 ), 50 ) ); 51 $g2 = $this->factory->group->create( array( 52 'name' => 'BBBBB', 53 'date_created' => gmdate( 'Y-m-d H:i:s', time() - 1000000 ), 54 'last_activity' => gmdate( 'Y-m-d H:i:s', time() - 10000 ), 55 ) ); 56 $g3 = $this->factory->group->create( array( 57 'name' => 'CCCCC', 58 'date_created' => gmdate( 'Y-m-d H:i:s', time() - 10000 ), 59 'last_activity' => gmdate( 'Y-m-d H:i:s', time() - 10 ), 60 ) ); 61 62 global $groups_template; 63 bp_has_groups( array( 64 'order' => 'ASC', 65 'orderby' => 'name', 66 ) ); 67 68 $ids = wp_parse_id_list( wp_list_pluck( $groups_template->groups, 'id' ) ); 69 $this->assertEquals( array( $g1, $g2, $g3, ), $ids ); 70 } 71 72 /** 73 * Integration test to make sure 'order' is set to 'DESC' and 'orderby' 74 * to 'last_activity' when no type or order/orderby params are passed. 75 * This ensures backpat with the old system, where 'active' was the 76 * default type param, and there were no order/orderby params. 77 * 78 * @group bp_has_groups 79 */ 80 public function test_bp_has_groups_defaults_to_DESC_last_activity_for_default_type_active_backpat() { 81 $g1 = $this->factory->group->create( array( 82 'name' => 'AAAAA', 83 'last_activity' => gmdate( 'Y-m-d H:i:s', time() - 100 ), 84 ) ); 85 $g2 = $this->factory->group->create( array( 86 'name' => 'BBBBB', 87 'last_activity' => gmdate( 'Y-m-d H:i:s', time() - 1000000 ), 88 ) ); 89 $g3 = $this->factory->group->create( array( 90 'name' => 'CCCCC', 91 'last_activity' => gmdate( 'Y-m-d H:i:s', time() - 10000 ), 92 ) ); 93 94 global $groups_template; 95 bp_has_groups(); 96 97 $ids = wp_parse_id_list( wp_list_pluck( $groups_template->groups, 'id' ) ); 98 $this->assertEquals( array( $g1, $g3, $g2, ), $ids ); 99 } 100 101 /** 102 * @group bp_group_has_members 103 */ 104 public function test_bp_group_has_members_vanilla() { 105 $g = $this->factory->group->create(); 106 $u1 = $this->create_user(); 107 $u2 = $this->create_user(); 108 109 $this->add_user_to_group( $u1, $g ); 110 111 global $members_template; 112 bp_group_has_members( array( 113 'group_id' => $g, 114 'exclude_admins_mods' => false, 115 ) ); 116 117 $ids = wp_parse_id_list( wp_list_pluck( $members_template->members, 'user_id' ) ); 118 $this->assertEquals( array( $u1, ), $ids ); 119 } 120 121 /** 122 * Switching from BP_Groups_Member to BP_Group_Member_Query meant a 123 * change in the format of the values returned from the query. For 124 * backward compatibility, we translate some of the return values 125 * of BP_Group_Member_Query to the older format. This test makes sure 126 * that the translation happens properly. 127 * 128 * @group bp_group_has_members 129 */ 130 public function test_bp_group_has_members_backpat_retval_format() { 131 $u1 = $this->create_user(); 132 $u2 = $this->create_user(); 133 $g = $this->factory->group->create( array( 'creator_id' => $u2 ) ); 134 135 $date_modified = gmdate( 'Y-m-d H:i:s', time() - 100 ); 136 137 $this->add_user_to_group( $u1, $g, array( 'date_modified' => $date_modified ) ); 138 139 global $members_template; 140 bp_group_has_members( array( 141 'group_id' => $g, 142 ) ); 143 144 $u1_object = new WP_User( $u1 ); 145 146 $expected = new stdClass; 147 $expected->user_id = $u1; 148 $expected->date_modified = $date_modified; 149 $expected->is_banned = 0; 150 $expected->user_login = $u1_object->user_login; 151 $expected->user_nicename = $u1_object->user_nicename; 152 $expected->user_email = $u1_object->user_email; 153 $expected->display_name = $u1_object->display_name; 154 155 // In order to use assertEquals, we need to discard the 156 // irrelevant properties of the found object. Hack alert 157 $found = new stdClass; 158 foreach ( array( 'user_id', 'date_modified', 'is_banned', 'user_login', 'user_nicename', 'user_email', 'display_name' ) as $key ) { 159 if ( isset( $members_template->members[0]->{$key} ) ) { 160 $found->{$key} = $members_template->members[0]->{$key}; 161 } 162 } 163 164 $this->assertEquals( $expected, $found ); 165 } 166 167 /** 168 * @group bp_group_has_members 169 */ 170 public function test_bp_group_has_members_with_per_page() { 171 $g = $this->factory->group->create(); 172 173 $users = array(); 174 for ( $i = 1; $i <= 10; $i++ ) { 175 $users[ $i ] = $this->create_user(); 176 } 177 178 $expected = array(); 179 $now = time(); 180 for ( $i = 3; $i <= 10; $i++ ) { 181 $this->add_user_to_group( $users[ $i ], $g, array( 182 'date_modified' => $now - 60 * $i, 183 ) ); 184 $expected[] = $users[ $i ]; 185 } 186 187 // hack it down to 5 (per page arg below) 188 $expected = array_slice( $expected, 0, 5 ); 189 190 global $members_template; 191 bp_group_has_members( array( 192 'group_id' => $g, 193 'per_page' => 5, 194 ) ); 195 196 $ids = wp_parse_id_list( wp_list_pluck( $members_template->members, 'user_id' ) ); 197 $this->assertEquals( $expected, $ids ); 198 } 199 200 /** 201 * Note: 'max' is a weird parameter. It just changes the member_count 202 * in the global - not the sql query at all. I'm testing what it 203 * appears to be designed to do, not what it feels like it ought to do 204 * if it made any sense. Programming is fun, QED. 205 * 206 * @group bp_group_has_members 207 */ 208 public function test_bp_group_has_members_with_max() { 209 $g = $this->factory->group->create(); 210 211 $users = array(); 212 for ( $i = 1; $i <= 10; $i++ ) { 213 $users[ $i ] = $this->create_user(); 214 } 215 216 $expected = array(); 217 for ( $i = 3; $i <= 10; $i++ ) { 218 $this->add_user_to_group( $users[ $i ], $g ); 219 $expected[] = $users[ $i ]; 220 } 221 222 global $members_template; 223 bp_group_has_members( array( 224 'group_id' => $g, 225 'max' => 5, 226 ) ); 227 228 $this->assertEquals( 5, $members_template->member_count ); 229 } 230 231 /** 232 * @group bp_group_has_members 233 */ 234 public function test_bp_group_has_members_with_exclude() { 235 $g = $this->factory->group->create(); 236 $u1 = $this->create_user(); 237 $u2 = $this->create_user(); 238 239 $this->add_user_to_group( $u1, $g ); 240 $this->add_user_to_group( $u2, $g ); 241 242 global $members_template; 243 bp_group_has_members( array( 244 'group_id' => $g, 245 'exclude' => $u1, 246 ) ); 247 248 $ids = wp_parse_id_list( wp_list_pluck( $members_template->members, 'user_id' ) ); 249 $this->assertEquals( array( $u2 ), $ids ); 250 } 251 252 /** 253 * @group bp_group_has_members 254 */ 255 public function test_bp_group_has_members_with_exclude_admins_mods_1() { 256 $g = $this->factory->group->create(); 257 $u1 = $this->create_user(); 258 $u2 = $this->create_user(); 259 $u3 = $this->create_user(); 260 261 $this->add_user_to_group( $u1, $g ); 262 $this->add_user_to_group( $u2, $g ); 263 $this->add_user_to_group( $u3, $g ); 264 265 $m1 = new BP_Groups_Member( $u1, $g ); 266 $m1->promote( 'admin' ); 267 $m2 = new BP_Groups_Member( $u2, $g ); 268 $m2->promote( 'mod' ); 269 270 global $members_template; 271 bp_group_has_members( array( 272 'group_id' => $g, 273 'exclude_admins_mods' => 1, 274 ) ); 275 276 $ids = wp_parse_id_list( wp_list_pluck( $members_template->members, 'user_id' ) ); 277 $this->assertEquals( array( $u3 ), $ids ); 278 } 279 280 /** 281 * @group bp_group_has_members 282 */ 283 public function test_bp_group_has_members_with_exclude_admins_mods_0() { 284 $u1 = $this->create_user(); 285 $u2 = $this->create_user(); 286 $u3 = $this->create_user(); 287 $g = $this->factory->group->create( array( 288 'creator_id' => $u1, 289 ) ); 290 291 $now = time(); 292 $this->add_user_to_group( $u2, $g, array( 293 'date_modified' => $now - 60, 294 ) ); 295 $this->add_user_to_group( $u3, $g, array( 296 'date_modified' => $now - 60*60, 297 ) ); 298 299 $m1 = new BP_Groups_Member( $u1, $g ); 300 $m1->promote( 'admin' ); 301 $m2 = new BP_Groups_Member( $u2, $g ); 302 $m2->promote( 'mod' ); 303 304 global $members_template; 305 bp_group_has_members( array( 306 'group_id' => $g, 307 'exclude_admins_mods' => 0, 308 ) ); 309 310 $ids = wp_parse_id_list( wp_list_pluck( $members_template->members, 'user_id' ) ); 311 $this->assertEquals( array( $u1, $u2, $u3 ), $ids ); 312 } 313 314 /** 315 * @group bp_group_has_members 316 */ 317 public function test_bp_group_has_members_with_exclude_banned_1() { 318 $g = $this->factory->group->create(); 319 $u1 = $this->create_user(); 320 $u2 = $this->create_user(); 321 322 $this->add_user_to_group( $u1, $g ); 323 $this->add_user_to_group( $u2, $g ); 324 325 $m1 = new BP_Groups_Member( $u1, $g ); 326 $m1->ban(); 327 328 global $members_template; 329 bp_group_has_members( array( 330 'group_id' => $g, 331 'exclude_banned' => 1, 332 ) ); 333 334 $ids = wp_parse_id_list( wp_list_pluck( $members_template->members, 'user_id' ) ); 335 $this->assertEquals( array( $u2, ), $ids ); 336 } 337 338 /** 339 * @group bp_group_has_members 340 */ 341 public function test_bp_group_has_members_with_exclude_banned_0() { 342 $u1 = $this->create_user(); 343 $u2 = $this->create_user(); 344 $u3 = $this->create_user(); 345 346 $g = $this->factory->group->create( array( 347 'creator_id' => $u1, 348 ) ); 349 350 $this->add_user_to_group( $u2, $g, array( 351 'date_modified' => gmdate( 'Y-m-d H:i:s', time() - 60*60*24 ), 352 ) ); 353 $this->add_user_to_group( $u3, $g, array( 354 'date_modified' => gmdate( 'Y-m-d H:i:s', time() - 60*60*12 ), 355 ) ); 356 357 $m2 = new BP_Groups_Member( $u2, $g ); 358 $m2->ban(); 359 360 global $members_template; 361 bp_group_has_members( array( 362 'group_id' => $g, 363 'exclude_banned' => 0, 364 'exclude_admins_mods' => false, 365 ) ); 366 367 $ids = wp_parse_id_list( wp_list_pluck( $members_template->members, 'user_id' ) ); 368 $this->assertEquals( array( $u1, $u3, $u2 ), $ids ); 369 } 370 371 /** 372 * Default sort order should be the joined date 373 * 374 * @tickett BP5106 375 * @group bp_group_has_members 376 */ 377 public function test_bp_group_has_members_default_order() { 378 $u1 = $this->create_user( array( 379 'last_activity' => gmdate( 'Y-m-d H:i:s', time() - 60 ), 380 ) ); 381 $u2 = $this->create_user( array( 382 'last_activity' => gmdate( 'Y-m-d H:i:s', time() - 600 ), 383 ) ); 384 $u3 = $this->create_user( array( 385 'last_activity' => gmdate( 'Y-m-d H:i:s', time() - 6000 ), 386 ) ); 387 388 $g = $this->factory->group->create( array( 389 'creator_id' => $u1, 390 ) ); 391 392 $this->add_user_to_group( $u2, $g, array( 393 'date_modified' => gmdate( 'Y-m-d H:i:s', time() - 60*60*24 ), 394 ) ); 395 396 $this->add_user_to_group( $u3, $g, array( 397 'date_modified' => gmdate( 'Y-m-d H:i:s', time() - 60*60*12 ), 398 ) ); 399 400 global $members_template; 401 bp_group_has_members( array( 402 'group_id' => $g, 403 'exclude_banned' => 0, 404 'exclude_admins_mods' => false, 405 ) ); 406 407 $ids = wp_parse_id_list( wp_list_pluck( $members_template->members, 'user_id' ) ); 408 $this->assertEquals( array( $u1, $u3, $u2, ), $ids ); 409 } 410 }