[ Index ] |
PHP Cross Reference of BuddyPress |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * @group members 4 */ 5 class BP_Tests_Members_Template extends BP_UnitTestCase { 6 public function test_bp_has_members_include_on_user_page() { 7 $u1 = self::factory()->user->create(); 8 $u2 = self::factory()->user->create(); 9 10 $this->go_to( bp_core_get_user_domain( $u1 ) ); 11 12 global $members_template; 13 bp_has_members( array( 14 'include' => array( $u1, $u2 ), 15 ) ); 16 17 $users = is_array( $members_template->members ) ? array_values( $members_template->members ) : array(); 18 $user_ids = wp_list_pluck( $users, 'ID' ); 19 sort( $user_ids ); 20 21 $shouldbe = array( $u1, $u2 ); 22 sort( $shouldbe ); 23 24 $this->assertEquals( $user_ids, $shouldbe ); 25 } 26 27 /** 28 * @ticket BP5898 29 * @group bp_has_members 30 */ 31 public function test_bp_has_members_search_pagination_with_spaces() { 32 $u1 = self::factory()->user->create( array( 'display_name' => '~ tilde u1' ) ); 33 $u2 = self::factory()->user->create( array( 'display_name' => '~ tilde u2' ) ); 34 35 $template_args = array( 36 'search_terms' => '~ tilde', 37 'per_page' => 1, 38 ); 39 40 global $members_template; 41 $reset_members_template = $members_template; 42 43 bp_has_members( $template_args ); 44 45 preg_match( '/&members_search=(.*)(\'|\")/', $members_template->pag_links, $matches ); 46 47 $this->assertEquals( urldecode( $matches[1] ), urldecode( $template_args['search_terms'] ) ); 48 49 // reset the members template global 50 $members_template = $reset_members_template; 51 } 52 53 public function test_bp_has_members_friendship_requests() { 54 $u1 = self::factory()->user->create(); 55 $u2 = self::factory()->user->create(); 56 57 friends_add_friend( $u1, $u2 ); 58 59 $old_user = get_current_user_id(); 60 $this->set_current_user( $u2 ); 61 62 $this->go_to( bp_core_get_user_domain( $u2 ) . bp_get_friends_slug() . '/requests/' ); 63 $this->restore_admins(); 64 65 global $members_template; 66 bp_has_members( array( 67 'include' => bp_get_friendship_requests( $u2 ), 68 ) ); 69 70 $requests = is_array( $members_template->members ) ? array_values( $members_template->members ) : array(); 71 $request_ids = wp_list_pluck( $requests, 'ID' ); 72 $this->assertEquals( $request_ids, array( $u1 ) ); 73 74 $this->set_current_user( $old_user ); 75 } 76 77 /** 78 * @group bp_has_members 79 * @group friends 80 * @ticket BP5071 81 */ 82 public function test_bp_has_members_friendship_requests_with_no_requests() { 83 $u1 = self::factory()->user->create(); 84 $u2 = self::factory()->user->create(); 85 86 $old_user = get_current_user_id(); 87 $this->set_current_user( $u2 ); 88 89 // For some reason, in all the user switching, the cache gets 90 // confused. Never comes up when BP runs normally, because the 91 // loggedin_user doesn't change on a pageload. @todo Fix for 92 // real in BP 93 wp_cache_delete( 'bp_user_domain_' . $u2, 'bp' ); 94 95 $this->go_to( bp_core_get_user_domain( $u2 ) . bp_get_friends_slug() . '/requests/' ); 96 $this->restore_admins(); 97 98 global $members_template; 99 bp_has_members( array( 100 'include' => bp_get_friendship_requests( $u2 ), 101 ) ); 102 103 $requests = is_array( $members_template->members ) ? array_values( $members_template->members ) : array(); 104 $request_ids = wp_list_pluck( $requests, 'ID' ); 105 $this->assertEquals( array(), $request_ids ); 106 107 $this->set_current_user( $old_user ); 108 } 109 110 /** 111 * @group bp_has_members 112 */ 113 public function test_bp_has_members_should_pass_member_type_param_to_query() { 114 bp_register_member_type( 'foo' ); 115 bp_register_member_type( 'bar' ); 116 $users = self::factory()->user->create_many( 3 ); 117 bp_set_member_type( $users[0], 'foo' ); 118 bp_set_member_type( $users[1], 'bar' ); 119 120 global $members_template; 121 $old_members_template = $members_template; 122 123 bp_has_members( array( 124 'member_type' => 'bar', 125 ) ); 126 127 $members = is_array( $members_template->members ) ? array_values( $members_template->members ) : array(); 128 $member_ids = wp_list_pluck( $members, 'ID' ); 129 $this->assertEquals( array( $users[1]), $member_ids ); 130 131 $GLOBALS['members_template'] = $old_members_template; 132 } 133 134 /** 135 * @group bp_has_members 136 * @ticket BP6286 137 */ 138 public function test_bp_has_members_should_infer_member_type_from_get_param() { 139 bp_register_member_type( 'foo' ); 140 bp_register_member_type( 'bar' ); 141 $users = self::factory()->user->create_many( 3 ); 142 bp_set_member_type( $users[0], 'foo' ); 143 bp_set_member_type( $users[1], 'bar' ); 144 145 global $members_template; 146 $old_members_template = $members_template; 147 148 $old_get = $_GET; 149 $_GET['member_type'] = 'bar'; 150 151 bp_has_members(); 152 153 $members = is_array( $members_template->members ) ? array_values( $members_template->members ) : array(); 154 $member_ids = wp_list_pluck( $members, 'ID' ); 155 $this->assertEquals( array( $users[1] ), $member_ids ); 156 157 $GLOBALS['members_template'] = $old_members_template; 158 } 159 160 /** 161 * @group bp_has_members 162 * @ticket BP6286 163 */ 164 public function test_bp_has_members_should_infer_member_type_from_get_param_comma_sep() { 165 bp_register_member_type( 'foo' ); 166 bp_register_member_type( 'bar' ); 167 bp_register_member_type( 'baz' ); 168 $users = self::factory()->user->create_many( 4 ); 169 bp_set_member_type( $users[0], 'foo' ); 170 bp_set_member_type( $users[1], 'bar' ); 171 bp_set_member_type( $users[2], 'baz' ); 172 173 global $members_template; 174 $old_members_template = $members_template; 175 176 $old_get = $_GET; 177 $_GET['member_type'] = 'foo,bar'; 178 179 bp_has_members(); 180 181 $members = is_array( $members_template->members ) ? array_values( $members_template->members ) : array(); 182 $member_ids = wp_list_pluck( $members, 'ID' ); 183 $this->assertEqualSets( array( $users[0], $users[1] ), $member_ids ); 184 185 $GLOBALS['members_template'] = $old_members_template; 186 } 187 188 /** 189 * @group bp_has_members 190 * @ticket BP8309 191 */ 192 public function test_bp_has_members_xprofile_query() { 193 $group_id = self::factory()->xprofile_group->create(); 194 $field_id = self::factory()->xprofile_field->create( array( 195 'field_group_id' => $group_id, 196 'type' => 'textbox', 197 ) ); 198 $users = self::factory()->user->create_many( 2 ); 199 200 xprofile_set_field_data( $field_id, $users[0], 'foo' ); 201 xprofile_set_field_data( $field_id, $users[1], 'bar' ); 202 203 global $members_template; 204 $old_members_template = $members_template; 205 206 $args = array( 207 'xprofile_query' => array( 208 array( 209 'field' => $field_id, 210 'value' => 'foo', 211 ), 212 ), 213 ); 214 215 bp_has_members( $args ); 216 217 $members = is_array( $members_template->members ) ? array_values( $members_template->members ) : array(); 218 $member_ids = wp_list_pluck( $members, 'ID' ); 219 $this->assertEqualSets( array( $users[0] ), $member_ids ); 220 221 $GLOBALS['members_template'] = $old_members_template; 222 } 223 224 225 /** 226 * @group bp_get_member_last_active 227 */ 228 public function test_bp_get_member_last_active_default_params() { 229 // Fake the global 230 global $members_template; 231 232 $time = date( 'Y-m-d H:i:s', time() - 24*60*60 ); 233 $members_template = new stdClass; 234 $members_template->member = new stdClass; 235 $members_template->member->last_activity = $time; 236 237 $this->assertEquals( bp_core_get_last_activity( $time, __( 'Active %s', 'buddypress' ) ), bp_get_member_last_active() ); 238 } 239 240 /** 241 * @group bp_get_member_last_active 242 */ 243 public function test_bp_get_member_last_active_active_format_true() { 244 // Fake the global 245 global $members_template; 246 247 $time = date( 'Y-m-d H:i:s', time() - 24*60*60 ); 248 $members_template = new stdClass; 249 $members_template->member = new stdClass; 250 $members_template->member->last_activity = $time; 251 252 $this->assertEquals( bp_core_get_last_activity( $time, __( 'Active %s', 'buddypress' ) ), bp_get_member_last_active( array( 'active_format' => true, ) ) ); 253 } 254 255 /** 256 * @group bp_get_member_last_active 257 */ 258 public function test_bp_get_member_last_active_active_format_false() { 259 // Fake the global 260 global $members_template; 261 262 $time = date( 'Y-m-d H:i:s', time() - 24*60*60 ); 263 $members_template = new stdClass; 264 $members_template->member = new stdClass; 265 $members_template->member->last_activity = $time; 266 267 $this->assertEquals( bp_core_time_since( $time ), bp_get_member_last_active( array( 'active_format' => false, ) ) ); 268 } 269 270 /** 271 * @group pagination 272 * @group BP_Core_Members_Template 273 */ 274 public function test_bp_groups_template_should_give_precedence_to_upage_URL_param() { 275 $request = $_REQUEST; 276 $_REQUEST['upage'] = '5'; 277 278 $r = array( 279 'type' => 'active', 280 'page' => 8, 281 'per_page' => 20, 282 'max' => false, 283 'page_arg' => 'upage', 284 'include' => false, 285 'exclude' => false, 286 'user_id' => 0, 287 'member_type' => '', 288 'search_terms' => null, 289 'meta_key' => false, 290 'meta_value' => false, 291 'populate_extras' => true, 292 'search_terms' => '' 293 ); 294 295 $at = new BP_Core_Members_Template( $r ); 296 297 $this->assertEquals( 5, $at->pag_page ); 298 299 $_REQUEST = $request; 300 } 301 302 /** 303 * @group pagination 304 * @group BP_Core_Members_Template 305 */ 306 public function test_bp_members_template_should_reset_0_pag_page_URL_param_to_default_pag_page_value() { 307 $request = $_REQUEST; 308 $_REQUEST['upage'] = '0'; 309 310 $r = array( 311 'type' => 'active', 312 'page' => 8, 313 'per_page' => 20, 314 'max' => false, 315 'page_arg' => 'upage', 316 'include' => false, 317 'exclude' => false, 318 'user_id' => 0, 319 'member_type' => '', 320 'search_terms' => null, 321 'meta_key' => false, 322 'meta_value' => false, 323 'populate_extras' => true, 324 'search_terms' => '' 325 ); 326 327 $at = new BP_Core_Members_Template( $r ); 328 329 $this->assertEquals( 8, $at->pag_page ); 330 331 $_REQUEST = $request; 332 } 333 334 /** 335 * @group pagination 336 * @group BP_Core_Members_Template 337 */ 338 public function test_bp_members_template_should_give_precedence_to_num_URL_param() { 339 $request = $_REQUEST; 340 $_REQUEST['num'] = '14'; 341 342 $r = array( 343 'type' => 'active', 344 'page' => 1, 345 'per_page' => 13, 346 'max' => false, 347 'page_arg' => 'upage', 348 'include' => false, 349 'exclude' => false, 350 'user_id' => 0, 351 'member_type' => '', 352 'search_terms' => null, 353 'meta_key' => false, 354 'meta_value' => false, 355 'populate_extras' => true, 356 'search_terms' => '' 357 ); 358 359 $at = new BP_Core_Members_Template( $r ); 360 361 $this->assertEquals( 14, $at->pag_num ); 362 363 $_REQUEST = $request; 364 } 365 366 /** 367 * @group pagination 368 * @group BP_Core_Members_Template 369 */ 370 public function test_bp_members_template_should_reset_0_pag_num_URL_param_to_default_pag_num_value() { 371 $request = $_REQUEST; 372 $_REQUEST['num'] = '0'; 373 374 $r = array( 375 'type' => 'active', 376 'page' => 1, 377 'per_page' => 13, 378 'max' => false, 379 'page_arg' => 'upage', 380 'include' => false, 381 'exclude' => false, 382 'user_id' => 0, 383 'member_type' => '', 384 'search_terms' => null, 385 'meta_key' => false, 386 'meta_value' => false, 387 'populate_extras' => true, 388 'search_terms' => '' 389 ); 390 391 $at = new BP_Core_Members_Template( $r ); 392 393 $this->assertEquals( 13, $at->pag_num ); 394 395 $_REQUEST = $request; 396 } 397 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Dec 5 01:00:58 2024 | Cross-referenced by PHPXref 0.7.1 |