| | 236 | |
| | 237 | /** |
| | 238 | * @group bp_notifications_delete_notifications_on_user_delete |
| | 239 | */ |
| | 240 | public function test_bp_notifications_delete_notifications_on_user_delete_should_delete_all_notifications() { |
| | 241 | $u = $this->factory->user->create(); |
| | 242 | |
| | 243 | // Create notifications |
| | 244 | $n1 = $this->factory->notification->create( array( |
| | 245 | 'component_name' => 'messages', |
| | 246 | 'component_action' => 'new_message', |
| | 247 | 'item_id' => 99, |
| | 248 | 'user_id' => $u, |
| | 249 | ) ); |
| | 250 | |
| | 251 | $n2 = $this->factory->notification->create( array( |
| | 252 | 'component_name' => 'activity', |
| | 253 | 'component_action' => 'new_at_mention', |
| | 254 | 'item_id' => 99, |
| | 255 | 'user_id' => $u, |
| | 256 | ) ); |
| | 257 | |
| | 258 | $n3 = $this->factory->notification->create( array( |
| | 259 | 'component_name' => 'groups', |
| | 260 | 'user_id' => $u, |
| | 261 | ) ); |
| | 262 | |
| | 263 | $n4 = $this->factory->notification->create( array( |
| | 264 | 'component_name' => 'friends', |
| | 265 | 'component_action' => 'friendship_request', |
| | 266 | 'user_id' => $u, |
| | 267 | ) ); |
| | 268 | |
| | 269 | // Create notification for non-core component |
| | 270 | $n5 = $this->factory->notification->create( array( |
| | 271 | 'component_name' => 'foo', |
| | 272 | 'component_action' => 'bar', |
| | 273 | 'item_id' => 99, |
| | 274 | 'user_id' => $u, |
| | 275 | ) ); |
| | 276 | |
| | 277 | global $wpdb, $bp; |
| | 278 | |
| | 279 | /** |
| | 280 | * Get use BP_Notifications_Notification::get(), because class::parse_args, |
| | 281 | * checks against bp_notifications_get_registered_components() |
| | 282 | * and if component is disabled it will be ignored. |
| | 283 | */ |
| | 284 | $query = $wpdb->prepare( "SELECT id FROM {$bp->notifications->table_name} WHERE user_id = %d and is_new = 1", $u ); |
| | 285 | |
| | 286 | // Make sure notifications are added |
| | 287 | $found1 = $wpdb->get_col( $query ); |
| | 288 | $this->assertEqualSets( array( $n1, $n2, $n3, $n4, $n5 ), $found1 ); |
| | 289 | |
| | 290 | wp_delete_user( $u ); |
| | 291 | |
| | 292 | // Check, if notifications are deleted. |
| | 293 | $found2 = $wpdb->get_col( $query ); |
| | 294 | $this->assertEmpty( $found2 ); |
| | 295 | } |