[ Index ] |
PHP Cross Reference of BuddyPress |
[Summary view] [Print] [Text view]
1 <?php 2 3 /** 4 * @group friends 5 * @group activity 6 */ 7 class BP_Tests_Friends_Activity extends BP_UnitTestCase { 8 /** 9 * @group activity_action 10 * @group bp_friends_format_activity_action_friendship_accepted 11 */ 12 public function test_bp_friends_format_activity_action_friendship_accepted() { 13 $u1 = self::factory()->user->create(); 14 $u2 = self::factory()->user->create(); 15 16 $a = self::factory()->activity->create( array( 17 'component' => buddypress()->friends->id, 18 'type' => 'friendship_accepted', 19 'user_id' => $u1, 20 'secondary_item_id' => $u2, 21 ) ); 22 23 $expected = sprintf( __( '%1$s and %2$s are now friends', 'buddypress' ), bp_core_get_userlink( $u1 ), bp_core_get_userlink( $u2 ) ); 24 25 $a_obj = new BP_Activity_Activity( $a ); 26 27 $this->assertSame( $expected, $a_obj->action ); 28 } 29 30 /** 31 * @group activity_action 32 * @group bp_friends_format_activity_action_friendship_created 33 */ 34 public function test_bp_friends_format_activity_action_friendship_created() { 35 $u1 = self::factory()->user->create(); 36 $u2 = self::factory()->user->create(); 37 38 $a = self::factory()->activity->create( array( 39 'component' => buddypress()->friends->id, 40 'type' => 'friendship_created', 41 'user_id' => $u1, 42 'secondary_item_id' => $u2, 43 ) ); 44 45 $expected = sprintf( __( '%1$s and %2$s are now friends', 'buddypress' ), bp_core_get_userlink( $u1 ), bp_core_get_userlink( $u2 ) ); 46 47 $a_obj = new BP_Activity_Activity( $a ); 48 49 $this->assertSame( $expected, $a_obj->action ); 50 } 51 52 /** 53 * @group friends_delete_activity 54 */ 55 public function test_friends_delete_activity() { 56 $old_user = get_current_user_id(); 57 58 $u1 = self::factory()->user->create(); 59 $u2 = self::factory()->user->create(); 60 61 friends_add_friend( $u2, $u1 ); 62 $friendship_id = friends_get_friendship_id( $u2, $u1 ); 63 64 // Set current user to u1 to accepte the friendship 65 $this->set_current_user( $u1 ); 66 friends_accept_friendship( $friendship_id ); 67 68 // Reset the current user 69 $this->set_current_user( $old_user ); 70 71 // Random activities 72 $au1 = self::factory()->activity->create( array( 'user_id' => $u1 ) ); 73 $au2 = self::factory()->activity->create( array( 'user_id' => $u2 ) ); 74 75 $fc_act = bp_activity_get( array( 76 'component' => buddypress()->friends->id, 77 'item_id' => $friendship_id, 78 'filter' => array( 'action' => array( 'friendship_created' ) ), 79 'show_hidden' => false 80 ) ); 81 82 $this->assertTrue( count( $fc_act['activities'] ) == 1, '1 public activity should be created when a friendship is confirmed' ); 83 84 // Remove the friendship 85 friends_remove_friend( $u2, $u1 ); 86 87 $this->assertFalse( friends_check_friendship( $u2, $u1 ), '2 users should not be friend once the friendship is removed' ); 88 89 $fd_act = bp_activity_get( array( 90 'component' => buddypress()->friends->id, 91 'item_id' => $friendship_id, 92 'filter' => array( 'action' => array( 'friendship_created' ) ), 93 'show_hidden' => true 94 ) ); 95 96 $this->assertTrue( count( $fd_act['activities'] ) == 0, 'friends_delete_activity() should remove "friendship_created" activities about a deleted friendship' ); 97 } 98 99 /** 100 * @group bp_friends_friendship_accepted_activity 101 */ 102 public function test_bp_friends_friendship_accepted_activity() { 103 $old_user = get_current_user_id(); 104 105 $u1 = self::factory()->user->create(); 106 $u2 = self::factory()->user->create(); 107 108 friends_add_friend( $u2, $u1 ); 109 $friendship_id = friends_get_friendship_id( $u2, $u1 ); 110 111 // Set current user to u1 to accept the friendship 112 $this->set_current_user( $u1 ); 113 friends_accept_friendship( $friendship_id ); 114 115 // Reset the current user 116 $this->set_current_user( $old_user ); 117 118 $u1_act = bp_activity_get( array( 119 'component' => buddypress()->friends->id, 120 'item_id' => $friendship_id, 121 'scope' => 'just-me', 122 'filter' => array( 'action' => array( 'friendship_created' ), 'user_id' => $u1 ), 123 ) ); 124 125 $this->assertTrue( count( $u1_act['activities'] ) == 1, 'a public activity should be listed in the friend stream' ); 126 127 $u2_act = bp_activity_get( array( 128 'component' => buddypress()->friends->id, 129 'item_id' => $friendship_id, 130 'scope' => 'just-me', 131 'filter' => array( 'action' => array( 'friendship_created' ), 'user_id' => $u2 ), 132 ) ); 133 134 $this->assertTrue( count( $u2_act['activities'] ) == 1, 'a public activity should be listed in the initiator stream' ); 135 } 136 137 /** 138 * @group bp_cleanup_friendship_activities 139 */ 140 public function test_bp_cleanup_friendship_activities() { 141 $old_user = get_current_user_id(); 142 143 $u1 = self::factory()->user->create(); 144 $u2 = self::factory()->user->create(); 145 $users = array( $u1, $u2 ); 146 147 friends_add_friend( $u2, $u1 ); 148 $friendship_id = friends_get_friendship_id( $u2, $u1 ); 149 150 // Set current user to u1 to accepte the friendship and generate a public activity 151 $this->set_current_user( $u1 ); 152 friends_accept_friendship( $friendship_id ); 153 154 // Reset the current user 155 $this->set_current_user( $old_user ); 156 157 $users[] = self::factory()->user->create(); 158 $users[] = self::factory()->user->create(); 159 160 foreach( $users as $u ) { 161 bp_activity_add( array( 162 'user_id' => $u, 163 'item_id' => $friendship_id, 164 'type' => 'friendship_created', 165 'component' => buddypress()->friends->id, 166 'hide_sitewide' => true, 167 ) ); 168 } 169 170 $hidden = bp_activity_get( array( 171 'component' => buddypress()->friends->id, 172 'filter' => array( 'action' => array( 'friendship_created' ) ), 173 'show_hidden' => true, 174 ) ); 175 176 bp_cleanup_friendship_activities(); 177 178 $check = bp_activity_get( array( 179 'component' => buddypress()->friends->id, 180 'item_id' => $friendship_id, 181 'filter' => array( 'action' => array( 'friendship_created' ) ), 182 'show_hidden' => true, 183 ) ); 184 185 $this->assertTrue( count( $check['activities'] ) == 1 ); 186 } 187 188 /** 189 * @group friends_delete_activity 190 */ 191 public function test_delete_friendship_activity_on_user_delete() { 192 $old_user = get_current_user_id(); 193 194 $u1 = self::factory()->user->create(); 195 $u2 = self::factory()->user->create(); 196 197 friends_add_friend( $u2, $u1 ); 198 $friendship_id = friends_get_friendship_id( $u2, $u1 ); 199 200 // Set current user to u1 to accept the friendship 201 $this->set_current_user( $u1 ); 202 friends_accept_friendship( $friendship_id ); 203 204 // Reset the current user 205 $this->set_current_user( $old_user ); 206 207 // Delete $u1. 208 $this->delete_user( $u1 ); 209 210 // 'friendship_created' activity item should not exist. 211 $friendship_activity = bp_activity_get( array( 212 'component' => buddypress()->friends->id, 213 'filter' => array( 214 'action' => array( 'friendship_created' ), 215 'primary_id' => $friendship_id, 216 ) 217 ) ); 218 219 $this->assertEmpty( $friendship_activity['activities'] ); 220 } 221 222 public function test_delete_user_with_no_activities() { 223 $old_user = get_current_user_id(); 224 $u1 = self::factory()->user->create(); 225 $this->set_current_user( $u1 ); 226 227 bp_activity_remove_all_user_data( $u1 ); 228 wp_cache_delete( $u1, 'bp_last_activity' ); 229 wp_delete_user( $u1 ); 230 231 $this->set_current_user( $old_user ); 232 233 // Remove the following lines when you implement this test. 234 $this->markTestIncomplete( 235 'This test has not been implemented yet.' 236 ); 237 } 238 } 239
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Nov 21 01:00:57 2024 | Cross-referenced by PHPXref 0.7.1 |