Changeset 14026 for trunk/tests/phpunit/testcases/groups/activity.php
- Timestamp:
- 09/27/2024 09:11:27 PM (15 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/testcases/groups/activity.php
r13980 r14026 15 15 $u = self::factory()->user->create(); 16 16 $g = self::factory()->group->create(); 17 $a = self::factory()->activity->create( array( 18 'component' => buddypress()->groups->id, 19 'type' => 'created_group', 20 'user_id' => $u, 21 'item_id' => $g, 22 ) ); 17 $a = self::factory()->activity->create( 18 array( 19 'component' => buddypress()->groups->id, 20 'type' => 'created_group', 21 'user_id' => $u, 22 'item_id' => $g, 23 ) 24 ); 23 25 24 26 $a_obj = new BP_Activity_Activity( $a ); 25 27 $g_obj = groups_get_group( $g ); 26 28 27 $expected = sprintf( __( '% s created the group %s', 'buddypress' ), bp_core_get_userlink( $u ),'<a href="' . esc_url( bp_get_group_url( $g_obj ) ) . '">' . $g_obj->name . '</a>' );29 $expected = sprintf( __( '%1$s created the group %2$s', 'buddypress' ), bp_core_get_userlink( $u ), '<a href="' . esc_url( bp_get_group_url( $g_obj ) ) . '">' . $g_obj->name . '</a>' ); 28 30 29 31 $this->assertSame( $expected, $a_obj->action ); … … 37 39 $u = self::factory()->user->create(); 38 40 $g = self::factory()->group->create(); 39 $a = self::factory()->activity->create( array( 40 'component' => buddypress()->groups->id, 41 'type' => 'joined_group', 42 'user_id' => $u, 43 'item_id' => $g, 44 ) ); 41 $a = self::factory()->activity->create( 42 array( 43 'component' => buddypress()->groups->id, 44 'type' => 'joined_group', 45 'user_id' => $u, 46 'item_id' => $g, 47 ) 48 ); 45 49 46 50 $a_obj = new BP_Activity_Activity( $a ); 47 51 $g_obj = groups_get_group( $g ); 48 52 49 $expected = sprintf( __( '% s joined the group %s', 'buddypress' ), bp_core_get_userlink( $u ),'<a href="' . esc_url( bp_get_group_url( $g_obj ) ) . '">' . $g_obj->name . '</a>' );53 $expected = sprintf( __( '%1$s joined the group %2$s', 'buddypress' ), bp_core_get_userlink( $u ), '<a href="' . esc_url( bp_get_group_url( $g_obj ) ) . '">' . $g_obj->name . '</a>' ); 50 54 51 55 $this->assertSame( $expected, $a_obj->action ); … … 58 62 public function test_bp_groups_format_activity_action_group_details_updated_with_no_change() { 59 63 $group = self::factory()->group->create_and_get(); 60 groups_edit_base_group_details( array( 64 groups_edit_base_group_details( 65 array( 61 66 'group_id' => $group->id, 62 67 'name' => $group->name, … … 64 69 'description' => $group->description, 65 70 'notify_members' => true, 66 ) ); 67 68 $a = bp_activity_get( array( 69 'component' => buddypress()->groups->id, 70 'action' => 'group_details_updated', 71 'item_id' => $group->id, 72 ) ); 71 ) 72 ); 73 74 $a = bp_activity_get( 75 array( 76 'component' => buddypress()->groups->id, 77 'action' => 'group_details_updated', 78 'item_id' => $group->id, 79 ) 80 ); 73 81 74 82 $this->assertTrue( empty( $a['activities'] ) ); … … 81 89 public function test_bp_groups_format_activity_action_group_details_updated_with_notify_members_false() { 82 90 $group = self::factory()->group->create_and_get(); 83 groups_edit_base_group_details( array( 84 'group_id' => $group->id, 85 'name' => 'Foo', 86 'slug' => $group->slug, 87 'description' => $group->description, 88 'notify_members' => false, 89 ) ); 90 91 $a = bp_activity_get( array( 92 'component' => buddypress()->groups->id, 93 'action' => 'group_details_updated', 94 'item_id' => $group->id, 95 ) ); 91 groups_edit_base_group_details( 92 array( 93 'group_id' => $group->id, 94 'name' => 'Foo', 95 'slug' => $group->slug, 96 'description' => $group->description, 97 'notify_members' => false, 98 ) 99 ); 100 101 $a = bp_activity_get( 102 array( 103 'component' => buddypress()->groups->id, 104 'action' => 'group_details_updated', 105 'item_id' => $group->id, 106 ) 107 ); 96 108 97 109 $this->assertTrue( empty( $a['activities'] ) ); … … 104 116 public function test_bp_groups_format_activity_action_group_details_updated_with_updated_name() { 105 117 $old_user = get_current_user_id(); 106 $u = self::factory()->user->create();118 $u = self::factory()->user->create(); 107 119 self::set_current_user( $u ); 108 120 109 121 $group = self::factory()->group->create_and_get(); 110 groups_edit_base_group_details( array( 111 'group_id' => $group->id, 112 'name' => 'Foo', 113 'slug' => $group->slug, 114 'description' => $group->description, 115 'notify_members' => true, 116 ) ); 117 118 $a = bp_activity_get( array( 119 'component' => buddypress()->groups->id, 120 'action' => 'group_details_updated', 121 'item_id' => $group->id, 122 ) ); 122 groups_edit_base_group_details( 123 array( 124 'group_id' => $group->id, 125 'name' => 'Foo', 126 'slug' => $group->slug, 127 'description' => $group->description, 128 'notify_members' => true, 129 ) 130 ); 131 132 $a = bp_activity_get( 133 array( 134 'component' => buddypress()->groups->id, 135 'action' => 'group_details_updated', 136 'item_id' => $group->id, 137 ) 138 ); 123 139 124 140 $this->assertNotEmpty( $a['activities'] ); 125 141 126 $expected = sprintf( esc_html__( '% s changed the name of the group %s from "%s" to "%s"', 'buddypress' ), bp_core_get_userlink( $u ),'<a href="' . esc_url( bp_get_group_url( $group ) ) . '">Foo</a>', $group->name, 'Foo' );142 $expected = sprintf( esc_html__( '%1$s changed the name of the group %2$s from "%3$s" to "%4$s"', 'buddypress' ), bp_core_get_userlink( $u ), '<a href="' . esc_url( bp_get_group_url( $group ) ) . '">Foo</a>', $group->name, 'Foo' ); 127 143 $this->assertSame( $expected, $a['activities'][0]->action ); 128 144 … … 136 152 public function test_bp_groups_format_activity_action_group_details_updated_with_updated_description() { 137 153 $old_user = get_current_user_id(); 138 $u = self::factory()->user->create();154 $u = self::factory()->user->create(); 139 155 self::set_current_user( $u ); 140 156 141 157 $group = self::factory()->group->create_and_get(); 142 groups_edit_base_group_details( array( 143 'group_id' => $group->id, 144 'name' => $group->name, 145 'slug' => $group->slug, 146 'description' => 'Bar', 147 'notify_members' => true, 148 ) ); 149 150 $a = bp_activity_get( array( 151 'component' => buddypress()->groups->id, 152 'action' => 'group_details_updated', 153 'item_id' => $group->id, 154 ) ); 158 groups_edit_base_group_details( 159 array( 160 'group_id' => $group->id, 161 'name' => $group->name, 162 'slug' => $group->slug, 163 'description' => 'Bar', 164 'notify_members' => true, 165 ) 166 ); 167 168 $a = bp_activity_get( 169 array( 170 'component' => buddypress()->groups->id, 171 'action' => 'group_details_updated', 172 'item_id' => $group->id, 173 ) 174 ); 155 175 156 176 $this->assertNotEmpty( $a['activities'] ); 157 177 158 $expected = sprintf( esc_html__( '% s changed the description of the group %s from "%s" to "%s"', 'buddypress' ), bp_core_get_userlink( $u ),'<a href="' . esc_url( bp_get_group_url( $group ) ) . '">' . $group->name . '</a>', $group->description, 'Bar' );178 $expected = sprintf( esc_html__( '%1$s changed the description of the group %2$s from "%3$s" to "%4$s"', 'buddypress' ), bp_core_get_userlink( $u ), '<a href="' . esc_url( bp_get_group_url( $group ) ) . '">' . $group->name . '</a>', $group->description, 'Bar' ); 159 179 $this->assertSame( $expected, $a['activities'][0]->action ); 160 180 … … 168 188 public function test_bp_groups_format_activity_action_group_details_updated_with_updated_slug() { 169 189 $old_user = get_current_user_id(); 170 $u = self::factory()->user->create();190 $u = self::factory()->user->create(); 171 191 self::set_current_user( $u ); 172 192 173 193 $group = self::factory()->group->create_and_get(); 174 groups_edit_base_group_details( array( 175 'group_id' => $group->id, 176 'name' => $group->name, 177 'slug' => 'flaxen', 178 'description' => $group->description, 179 'notify_members' => true, 180 ) ); 194 groups_edit_base_group_details( 195 array( 196 'group_id' => $group->id, 197 'name' => $group->name, 198 'slug' => 'flaxen', 199 'description' => $group->description, 200 'notify_members' => true, 201 ) 202 ); 181 203 $new_group_details = groups_get_group( $group->id ); 182 204 183 $a = bp_activity_get( array( 184 'component' => buddypress()->groups->id, 185 'action' => 'group_details_updated', 186 'item_id' => $group->id, 187 ) ); 205 $a = bp_activity_get( 206 array( 207 'component' => buddypress()->groups->id, 208 'action' => 'group_details_updated', 209 'item_id' => $group->id, 210 ) 211 ); 188 212 189 213 $this->assertNotEmpty( $a['activities'] ); 190 214 191 $expected = sprintf( __( '% s changed the permalink of the group %s.', 'buddypress' ), bp_core_get_userlink( $u ),'<a href="' . esc_url( bp_get_group_url( $new_group_details ) ) . '">' . $group->name . '</a>' );215 $expected = sprintf( __( '%1$s changed the permalink of the group %2$s.', 'buddypress' ), bp_core_get_userlink( $u ), '<a href="' . esc_url( bp_get_group_url( $new_group_details ) ) . '">' . $group->name . '</a>' ); 192 216 $this->assertSame( $expected, $a['activities'][0]->action ); 193 217 … … 201 225 public function test_bp_groups_format_activity_action_group_details_updated_with_updated_name_and_description() { 202 226 $old_user = get_current_user_id(); 203 $u = self::factory()->user->create();227 $u = self::factory()->user->create(); 204 228 self::set_current_user( $u ); 205 229 206 230 $group = self::factory()->group->create_and_get(); 207 groups_edit_base_group_details( array( 208 'group_id' => $group->id, 209 'name' => 'Foo', 210 'slug' => $group->slug, 211 'description' => 'Bar', 212 'notify_members' => true, 213 ) ); 214 215 $a = bp_activity_get( array( 216 'component' => buddypress()->groups->id, 217 'action' => 'group_details_updated', 218 'item_id' => $group->id, 219 ) ); 231 groups_edit_base_group_details( 232 array( 233 'group_id' => $group->id, 234 'name' => 'Foo', 235 'slug' => $group->slug, 236 'description' => 'Bar', 237 'notify_members' => true, 238 ) 239 ); 240 241 $a = bp_activity_get( 242 array( 243 'component' => buddypress()->groups->id, 244 'action' => 'group_details_updated', 245 'item_id' => $group->id, 246 ) 247 ); 220 248 221 249 $this->assertNotEmpty( $a['activities'] ); 222 250 223 $expected = sprintf( __( '% s changed the name and description of the group %s', 'buddypress' ), bp_core_get_userlink( $u ),'<a href="' . esc_url( bp_get_group_url( $group ) ) . '">Foo</a>' );251 $expected = sprintf( __( '%1$s changed the name and description of the group %2$s', 'buddypress' ), bp_core_get_userlink( $u ), '<a href="' . esc_url( bp_get_group_url( $group ) ) . '">Foo</a>' ); 224 252 $this->assertSame( $expected, $a['activities'][0]->action ); 225 253 … … 234 262 $u = self::factory()->user->create(); 235 263 $g = self::factory()->group->create(); 236 $a = self::factory()->activity->create( array( 237 'component' => buddypress()->groups->id, 238 'type' => 'activity_update', 239 'user_id' => $u, 240 'item_id' => $g, 241 ) ); 264 $a = self::factory()->activity->create( 265 array( 266 'component' => buddypress()->groups->id, 267 'type' => 'activity_update', 268 'user_id' => $u, 269 'item_id' => $g, 270 ) 271 ); 242 272 243 273 $a_obj = new BP_Activity_Activity( $a ); 244 274 $g_obj = groups_get_group( $g ); 245 275 246 $expected = sprintf( esc_html__( '%1$s posted an update in the group %2$s', 'buddypress' ), bp_core_get_userlink( $u ), '<a href="' . esc_url( bp_get_group_url( $g_obj ) ) . '">' . esc_html( $g_obj->name ) . '</a>' );276 $expected = sprintf( esc_html__( '%1$s posted an update in the group %2$s', 'buddypress' ), bp_core_get_userlink( $u ), '<a href="' . esc_url( bp_get_group_url( $g_obj ) ) . '">' . esc_html( $g_obj->name ) . '</a>' ); 247 277 248 278 $this->assertSame( $expected, $a_obj->action ); … … 296 326 ); 297 327 298 $a = groups_post_update( $activity_args );328 $a = groups_post_update( $activity_args ); 299 329 $a_obj = new BP_Activity_Activity( $a ); 300 330 … … 310 340 public function test_groups_activity_can_comment() { 311 341 $old_user = get_current_user_id(); 312 $u1 = self::factory()->user->create();313 $u2 = self::factory()->user->create();342 $u1 = self::factory()->user->create(); 343 $u2 = self::factory()->user->create(); 314 344 315 345 $g = self::factory()->group->create(); … … 318 348 groups_join_group( $g, $u1 ); 319 349 320 $a = self::factory()->activity->create( array( 321 'component' => buddypress()->groups->id, 322 'type' => 'created_group', 323 'user_id' => $u1, 324 'item_id' => $g, 325 ) ); 350 $a = self::factory()->activity->create( 351 array( 352 'component' => buddypress()->groups->id, 353 'type' => 'created_group', 354 'user_id' => $u1, 355 'item_id' => $g, 356 ) 357 ); 326 358 327 359 self::set_current_user( $u1 ); 328 360 if ( bp_has_activities( array( 'in' => $a ) ) ) { 329 while ( bp_activities() ) : bp_the_activity(); 361 while ( bp_activities() ) : 362 bp_the_activity(); 330 363 // User 1 should be able to comment. 331 364 $this->assertTrue( bp_activity_can_comment() ); … … 335 368 self::set_current_user( $u2 ); 336 369 if ( bp_has_activities( array( 'in' => $a ) ) ) { 337 while ( bp_activities() ) : bp_the_activity(); 370 while ( bp_activities() ) : 371 bp_the_activity(); 338 372 // User 2 should not be able to comment. 339 373 $this->assertFalse( bp_activity_can_comment() ); … … 345 379 346 380 public function groups_post_update_args( $args = array() ) { 347 $this->groups_post_update_args = array_intersect_key( $args, array( 348 'content' => true, 349 'user_id' => true, 350 'item_id' => true, 351 'error_type' => true, 352 ) ); 381 $this->groups_post_update_args = array_intersect_key( 382 $args, 383 array( 384 'content' => true, 385 'user_id' => true, 386 'item_id' => true, 387 'error_type' => true, 388 ) 389 ); 353 390 354 391 return $args; … … 359 396 */ 360 397 public function test_user_can_delete_group_activity() { 361 $u1 = self::factory()->user->create();362 $u2 = self::factory()->user->create();398 $u1 = self::factory()->user->create(); 399 $u2 = self::factory()->user->create(); 363 400 $original_user = bp_loggedin_user_id(); 364 401 … … 416 453 417 454 // Misc user can't delete activity. 418 $misc_user = self::factory()->user->create( array( 'role' => 'subscriber' ));455 $misc_user = self::factory()->user->create(); 419 456 self::set_current_user( $misc_user ); 420 457 $this->assertFalse( bp_activity_user_can_delete( $activity ) ); 421 458 422 459 // Misc group member can't delete activity. 423 $misc_user_2 = self::factory()->user->create( array( 'role' => 'subscriber' ));460 $misc_user_2 = self::factory()->user->create(); 424 461 self::add_user_to_group( $misc_user_2, $g ); 425 462 self::set_current_user( $misc_user_2 ); … … 427 464 428 465 // Group mod can delete activity. 429 $misc_user_3 = self::factory()->user->create( array( 'role' => 'subscriber' ));430 self::add_user_to_group( $misc_user_3, $g, [ 'is_mod' => true ]);466 $misc_user_3 = self::factory()->user->create(); 467 self::add_user_to_group( $misc_user_3, $g, array( 'is_mod' => true ) ); 431 468 self::set_current_user( $misc_user_3 ); 432 469 $this->assertTrue( bp_activity_user_can_delete( $activity ) ); 433 470 434 471 // Group admin can delete activity. 435 $misc_user_4 = self::factory()->user->create( array( 'role' => 'subscriber' ));436 self::add_user_to_group( $misc_user_4, $g, [ 'is_admin' => true ]);472 $misc_user_4 = self::factory()->user->create(); 473 self::add_user_to_group( $misc_user_4, $g, array( 'is_admin' => true ) ); 437 474 self::set_current_user( $misc_user_4 ); 438 475 $this->assertTrue( bp_activity_user_can_delete( $activity ) ); … … 455 492 $a = self::factory()->activity->create( 456 493 array( 457 'user_id' => $u1,458 'content' => 'Random Activity content',494 'user_id' => $u1, 495 'content' => 'Random Activity content', 459 496 ) 460 497 ); … … 484 521 485 522 // Add u2 as Admin of g2. 486 self::add_user_to_group( $u2, $g, [ 'is_admin' => true ]);523 self::add_user_to_group( $u2, $g, array( 'is_admin' => true ) ); 487 524 488 525 self::set_current_user( $u2 );
Note: See TracChangeset
for help on using the changeset viewer.