Ticket #5148: 5148.class.01b.patch
File 5148.class.01b.patch, 24.7 KB (added by , 11 years ago) |
---|
-
bp-activity/bp-activity-notifications.php
if ( !defined( 'ABSPATH' ) ) exit; 39 39 */ 40 40 function bp_activity_at_message_notification( $activity_id, $receiver_user_id ) { 41 41 42 // Don't leave multiple notifications for the same activity item 43 $notifications = BP_Core_Notification::get_all_for_user( $receiver_user_id, 'all' ); 44 45 foreach( $notifications as $notification ) { 46 if ( $activity_id == $notification->item_id ) { 47 return; 48 } 42 // Check to see if an at-mention notification exists for this activity item 43 $notifications = BP_Core_Notification::get( array( 44 'user_id' => $receiver_user_id, 45 'item_id' => $notification->item_id, 46 'component_action' => 'new_at_mention' 47 ) ); 48 49 // At-mention notification already exists, so stop! 50 if ( ! empty( $notifications ) ) { 51 return; 49 52 } 50 53 54 // Setup new BP notification 51 55 $activity = new BP_Activity_Activity( $activity_id ); 52 56 53 57 $subject = ''; -
bp-core/bp-core-classes.php
class BP_Core_Notification { 1314 1314 /** 1315 1315 * Update or insert notification details into the database. 1316 1316 * 1317 * @global BuddyPress $bp The one true BuddyPress instance1318 1317 * @global wpdb $wpdb WordPress database object 1319 1318 * @return bool Success or failure 1320 1319 */ 1321 1320 public function save() { 1322 global $bp, $wpdb; 1321 global $wpdb; 1322 1323 $bp = buddypress(); 1324 1325 // Allow manipulation before saving 1326 do_action_ref_array( 'bp_notification_before_save', array( &$this ) ); 1327 1328 // Make sure there's a user ID before saving. If not, stop now! 1329 // This allows plugin devs to bail out of saving notifications if necessary 1330 if ( empty( $this->user_id ) ) { 1331 return false; 1332 } 1323 1333 1324 1334 // Update 1325 1335 if ( !empty( $this->id ) ) { 1326 $sql = $wpdb->prepare( "UPDATE {$bp->core->table_name_notifications} SET item_id = %d, secondary_item_id = %d, user_id = %d, component_name = %s, component_action = %d, date_notified = %s, is_new = %d )WHERE id = %d", $this->item_id, $this->secondary_item_id, $this->user_id, $this->component_name, $this->component_action, $this->date_notified, $this->is_new, $this->id );1336 $sql = $wpdb->prepare( "UPDATE {$bp->core->table_name_notifications} SET item_id = %d, secondary_item_id = %d, user_id = %d, component_name = %s, component_action = %d, date_notified = %s, is_new = %d WHERE id = %d", $this->item_id, $this->secondary_item_id, $this->user_id, $this->component_name, $this->component_action, $this->date_notified, $this->is_new, $this->id ); 1327 1337 1328 1338 // Save 1329 1339 } else { … … class BP_Core_Notification { 1335 1345 1336 1346 $this->id = $wpdb->insert_id; 1337 1347 1348 // Allow manipulation after saving 1349 do_action_ref_array( 'bp_notification_after_save', array( &$this ) ); 1350 1338 1351 return true; 1339 1352 } 1340 1353 … … class BP_Core_Notification { 1343 1356 /** 1344 1357 * Fetches the notification data from the database. 1345 1358 * 1346 * @global BuddyPress $bp The one true BuddyPress instance1347 1359 * @global wpdb $wpdb WordPress database object 1348 1360 */ 1349 1361 public function populate() { 1350 global $bp, $wpdb; 1362 global $wpdb; 1363 1364 $bp = buddypress(); 1351 1365 1352 1366 if ( $notification = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$bp->core->table_name_notifications} WHERE id = %d", $this->id ) ) ) { 1353 $this->item_id = $notification->item_id;1367 $this->item_id = $notification->item_id; 1354 1368 $this->secondary_item_id = $notification->secondary_item_id; 1355 1369 $this->user_id = $notification->user_id; 1356 1370 $this->component_name = $notification->component_name; … … class BP_Core_Notification { 1363 1377 /** Static Methods ********************************************************/ 1364 1378 1365 1379 public static function check_access( $user_id, $notification_id ) { 1366 global $wpdb, $bp; 1380 global $wpdb; 1381 1382 $bp = buddypress(); 1367 1383 1368 1384 return $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(id) FROM {$bp->core->table_name_notifications} WHERE id = %d AND user_id = %d", $notification_id, $user_id ) ); 1369 1385 } 1370 1386 1371 1387 /** 1388 * Get notifications. 1389 * 1390 * @since BuddyPress (1.9) 1391 * 1392 * @param array $args The parameters to get notifications { 1393 * @type int|string $id If integer, the notification ID. If string, list of 1394 * comma-delimited notification IDs. 1395 * @type int $user_id The user ID to filter by 1396 * @type int $item_id The item ID to filter by 1397 * @type int $secondary_item_id The secondary item ID to filter by 1398 * @type string $component_name The component name to filter by 1399 * @type string $component_action The component action to filter by 1400 * @type int $is_new Whether to filter by new notifications. Either 1 or 0. 1401 * } 1402 */ 1403 public static function get( $args = array() ) { 1404 global $wpdb; 1405 1406 $bp = buddypress(); 1407 1408 $defaults = array( 1409 'id' => false, // the notificaton ID; can be comma-delimited to grab multiple notifications 1410 'user_id' => bp_loggedin_user_id(), // the user ID you want to grab notifications for 1411 'item_id' => false, 1412 'secondary_item_id' => false, 1413 'component_name' => false, // the BP component ID 1414 'component_action' => false, // the notification action 1415 'is_new' => false, // check if the notification is new 1416 ); 1417 1418 $r = wp_parse_args( $args, $defaults ); 1419 1420 // SQL statement begins 1421 $select_sql = "SELECT *"; 1422 $from_sql = "FROM {$bp->core->table_name_notifications}"; 1423 $where_sql = self::get_where_sql( $r ); 1424 1425 // Apply a filter for plugin devs 1426 $sql = apply_filters( 'bp_notifications_get_sql', 1427 "{$select_sql} {$from_sql} {$where_sql}", 1428 $r 1429 ); 1430 1431 return $wpdb->get_results( $sql ); 1432 } 1433 1434 /** 1435 * Delete notifications. 1436 * 1437 * @since BuddyPress (1.9) 1438 * 1439 * @param int|array If int, the notification ID. Otherwise, an array of parameters to delete notifications { 1440 * @type int|string $id If integer, the notification ID. If string, comma-delimited 1441 * notification IDs. 1442 * @type int $user_id The user ID to filter by 1443 * @type int $item_id The item ID to filter by 1444 * @type int $secondary_item_id The secondary item ID to filter by 1445 * @type string $component_name The component name to filter by 1446 * @type string $component_action The component action to filter by 1447 * @type int $is_new Whether to filter by new notifications. Either 1 or 0. 1448 * } 1449 */ 1450 public static function delete( $args = array() ) { 1451 global $wpdb; 1452 1453 $bp = buddypress(); 1454 1455 // support older integer parameter as referenced in 1456 // bp_core_delete_notification() 1457 if ( is_numeric( $args ) ) { 1458 $r = array(); 1459 $r['id'] = $args; 1460 1461 // new way of doing things 1462 } else { 1463 $defaults = array( 1464 'id' => false, // the notificaton ID; can be comma-delimited to grab multiple notifications 1465 'user_id' => false, // the user ID you want to grab notifications for 1466 'item_id' => false, 1467 'secondary_item_id' => false, 1468 'component_name' => false, // the BP component ID 1469 'component_action' => false, // the notification action 1470 'is_new' => false, // check if the notification is new 1471 ); 1472 1473 $r = wp_parse_args( $args, $defaults ); 1474 } 1475 1476 // generate WHERE sql 1477 $where_sql = self::get_where_sql( $r ); 1478 1479 // Apply a filter for plugin devs 1480 $sql = apply_filters( 'bp_notifications_delete_sql', 1481 "DELETE FROM {$bp->core->table_name_notifications} {$where_sql}", 1482 $r 1483 ); 1484 1485 // Finally remove the group entry from the DB 1486 if ( ! $wpdb->query( $sql ) ) { 1487 return false; 1488 } 1489 1490 return true; 1491 } 1492 1493 /** 1494 * Utility method to generate the WHERE sql statement used in the 1495 * {@link BP_Core_Notication::get()} and {@link BP_Core_Notication::delete()} methods. 1496 * 1497 * @since BuddyPress (1.9) 1498 * 1499 * @todo 'date_notified' column is omitted currently. 1500 * 1501 * @param array $params See BP_Core_Notication::get() for full description. 1502 */ 1503 protected static function get_where_sql( $params = array() ) { 1504 global $wpdb; 1505 1506 $where_conditions = array(); 1507 1508 if ( ! empty( $params['id'] ) ) { 1509 $in = implode( ',', wp_parse_id_list( $in ) ); 1510 $where_conditions['id'] = "id IN ({$in})"; 1511 } 1512 1513 if ( ! empty( $params['user_id'] ) ) { 1514 $where_conditions['user_id'] = $wpdb->prepare( "user_id = %d", $params['user_id'] ); 1515 } 1516 1517 if ( ! empty( $params['item_id'] ) ) { 1518 $where_conditions['item_id'] = $wpdb->prepare( "item_id = %d", $params['item_id'] ); 1519 } 1520 1521 if ( isset( $params['secondary_item_id'] ) && $params['secondary_item_id'] !== false ) { 1522 $where_conditions['secondary_item_id'] = $wpdb->prepare( "secondary_item_id = %d", $params['secondary_item_id'] ); 1523 } 1524 1525 if ( ! empty( $params['component_name'] ) ) { 1526 $where_conditions['component_name'] = $wpdb->prepare( "component_name = %s", $params['component_name'] ); 1527 } 1528 1529 if ( ! empty( $params['component_action'] ) ) { 1530 $where_conditions['component_action'] = $wpdb->prepare( "component_action = %s", $params['component_action'] ); 1531 } 1532 1533 if ( isset( $params['is_new'] ) && $params['is_new'] !== false ) { 1534 $where_conditions['is_new'] = $wpdb->prepare( "is_new = %d", $params['is_new'] ); 1535 } 1536 1537 return 'WHERE ' . join( ' AND ', $where_conditions ); 1538 1539 } 1540 1541 /** Deprecated ************************************************************/ 1542 1543 /** 1372 1544 * Fetches all the notifications in the database for a specific user. 1373 1545 * 1374 * @global BuddyPress $bp The one true BuddyPress instance 1375 * @global wpdb $wpdb WordPress database object 1546 * @deprecated 1.9 Use BP_Core_Notification::get() with the 'user_id' and 'is_new' 1547 * parameters instead. 1548 * 1376 1549 * @param integer $user_id User ID 1377 1550 * @param string $status 'is_new' or 'all' 1378 1551 * @return array Associative array 1379 1552 * @static 1380 1553 */ 1381 1554 public static function get_all_for_user( $user_id, $status = 'is_new' ) { 1382 global $bp, $wpdb; 1383 1384 $is_new = ( 'is_new' == $status ) ? ' AND is_new = 1 ' : ''; 1555 _deprecated_function( __METHOD__, '1.9', "BP_Core_Notification::get() with the 'user_id' and 'is_new' parameters" ); 1385 1556 1386 return $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$bp->core->table_name_notifications} WHERE user_id = %d {$is_new}", $user_id ) ); 1557 return self::get( array( 1558 'user_id' => $user_id, 1559 'is_new' => ( 'is_new' == $status ) ? 1 : false 1560 ) ); 1387 1561 } 1388 1562 1389 1563 /** 1390 * Delete all the notifications for a user based on the component name and action. 1564 * Delete all the notifications for a user based on the component name and 1565 * action. 1566 * 1567 * @deprecated 1.9 Use BP_Core_Notification::get() with the 'user_id', 'component_name', 1568 * and 'component_action' parameters instead. 1391 1569 * 1392 * @global BuddyPress $bp The one true BuddyPress instance1393 * @global wpdb $wpdb WordPress database object1394 1570 * @param integer $user_id 1395 1571 * @param string $component_name 1396 1572 * @param string $component_action 1397 1573 * @static 1398 1574 */ 1399 1575 public static function delete_for_user_by_type( $user_id, $component_name, $component_action ) { 1400 global $bp, $wpdb;1576 _deprecated_function( __METHOD__, '1.9', "BP_Core_Notification::get() with the 'user_id', 'component_name' and 'component_action' parameters" ); 1401 1577 1402 return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->core->table_name_notifications} WHERE user_id = %d AND component_name = %s AND component_action = %s", $user_id, $component_name, $component_action ) ); 1578 return self::delete( array( 1579 'user_id' => $user_id, 1580 'component_name' => $component_name, 1581 'component_action' => $component_action 1582 ) ); 1403 1583 } 1404 1584 1405 1585 /** 1406 * Delete all the notifications that have a specific item id, component name and action. 1586 * Delete all the notifications that have a specific item id, component name 1587 * and action. 1588 * 1589 * @deprecated 1.9 Use BP_Core_Notification::get() with the 'user_id', 'item_id', 1590 * 'component_name', 'component_action' and 'secondary_item_id' parameters instead. 1407 1591 * 1408 * @global BuddyPress $bp The one true BuddyPress instance1409 * @global wpdb $wpdb WordPress database object1410 1592 * @param integer $user_id The ID of the user who the notifications are for. 1411 1593 * @param integer $item_id The item ID of the notifications we wish to delete. 1412 1594 * @param string $component_name The name of the component that the notifications we wish to delete. … … class BP_Core_Notification { 1415 1597 * @static 1416 1598 */ 1417 1599 public static function delete_for_user_by_item_id( $user_id, $item_id, $component_name, $component_action, $secondary_item_id = false ) { 1418 global $bp, $wpdb; 1419 1420 $secondary_item_sql = !empty( $secondary_item_id ) ? $wpdb->prepare( " AND secondary_item_id = %d", $secondary_item_id ) : ''; 1421 1422 return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->core->table_name_notifications} WHERE user_id = %d AND item_id = %d AND component_name = %s AND component_action = %s{$secondary_item_sql}", $user_id, $item_id, $component_name, $component_action ) ); 1600 _deprecated_function( __METHOD__, '1.9', "BP_Core_Notification::get() with the 'user_id', 'item_id', 'component_name', 'component_action' and 'secondary_item_id' parameters." ); 1601 1602 return self::delete( array( 1603 'user_id' => $user_id, 1604 'item_id' => $item_id, 1605 'component_name' => $component_name, 1606 'component_action' => $component_action, 1607 'secondary_item_id' => $secondary_item_id, 1608 ) ); 1423 1609 } 1424 1610 1425 1611 /** 1426 * Deletes all the notifications sent by a specific user, by component and action. 1612 * Deletes all the notifications sent by a specific user, by component and 1613 * action. 1614 * 1615 * @deprecated 1.9 Use BP_Core_Notification::get() with the 'user_id', 'component_name' 1616 * and 'secondary_item_id' parameters instead. 1427 1617 * 1428 * @global BuddyPress $bp The one true BuddyPress instance1429 * @global wpdb $wpdb WordPress database object1430 1618 * @param integer $user_id The ID of the user whose sent notifications we wish to delete. 1431 1619 * @param string $component_name The name of the component the notification was sent from. 1432 1620 * @param string $component_action The action of the component the notification was sent from. 1433 1621 * @static 1434 1622 */ 1435 1623 public static function delete_from_user_by_type( $user_id, $component_name, $component_action ) { 1436 global $bp, $wpdb;1624 _deprecated_function( __METHOD__, '1.9', "BP_Core_Notification::get() with the 'user_id', 'component_name' and 'component_action' parameters" ); 1437 1625 1438 return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->core->table_name_notifications} WHERE item_id = %d AND component_name = %s AND component_action = %s", $user_id, $component_name, $component_action ) ); 1626 return self::delete( array( 1627 'user_id' => $user_id, 1628 'component_name' => $component_name, 1629 'component_action' => $component_action 1630 ) ); 1439 1631 } 1440 1632 1441 1633 /** 1442 * Deletes all the notifications for all users by item id, and optional secondary item id, and component name and action. 1634 * Deletes all the notifications for all users by item id, and optional 1635 * secondary item id, and component name and action. 1636 * 1637 * @deprecated 1.9 Use BP_Core_Notification::get() with the 'item_id', 'component_name' 1638 * and 'secondary_item_id' parameters instead. 1443 1639 * 1444 * @global BuddyPress $bp The one true BuddyPress instance1445 * @global wpdb $wpdb WordPress database object1446 1640 * @param string $item_id The item id that they notifications are to be for. 1447 1641 * @param string $component_name The component that the notifications are to be from. 1448 1642 * @param string $component_action The action that the notificationsa are to be from. … … class BP_Core_Notification { 1450 1644 * @static 1451 1645 */ 1452 1646 public static function delete_all_by_type( $item_id, $component_name, $component_action, $secondary_item_id ) { 1453 global $bp, $wpdb; 1454 1455 if ( $component_action ) 1456 $component_action_sql = $wpdb->prepare( "AND component_action = %s", $component_action ); 1457 else 1458 $component_action_sql = ''; 1459 1460 if ( $secondary_item_id ) 1461 $secondary_item_sql = $wpdb->prepare( "AND secondary_item_id = %d", $secondary_item_id ); 1462 else 1463 $secondary_item_sql = ''; 1464 1465 return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->core->table_name_notifications} WHERE item_id = %d AND component_name = %s {$component_action_sql} {$secondary_item_sql}", $item_id, $component_name ) ); 1647 _deprecated_function( __METHOD__, '1.9', "BP_Core_Notification::get() with the 'item_id', 'component_name', 'component_action' and 'secondary_item_id' parameters" ); 1648 1649 return self::delete( array( 1650 'item_id' => $item_id, 1651 'component_name' => $component_name, 1652 'component_action' => $component_action, 1653 'secondary_item_id' => $secondary_item_id, 1654 ) ); 1466 1655 } 1467 1656 } 1468 1657 -
bp-core/deprecated/1.5.php
To view and respond to the message, log in and visit: %4$s 381 381 */ 382 382 function bp_core_delete_notifications_for_user_by_type( $user_id, $component_name, $component_action ) { 383 383 _deprecated_function( __FUNCTION__, '1.5', 'bp_core_delete_notifications_by_type()' ); 384 return BP_Core_Notification::delete_for_user_by_type( $user_id, $component_name, $component_action );384 return bp_core_delete_notifications_by_type( $user_id, $component_name, $component_action ); 385 385 } 386 386 387 387 function bp_core_delete_notifications_for_user_by_item_id( $user_id, $item_id, $component_name, $component_action, $secondary_item_id = false ) { 388 388 _deprecated_function( __FUNCTION__, '1.5', 'bp_core_delete_notifications_by_item_id()' ); 389 return BP_Core_Notification::delete_for_user_by_item_id( $user_id, $item_id, $component_name, $component_action, $secondary_item_id );389 return bp_core_delete_notifications_by_item_id( $user_id, $item_id, $component_name, $component_action, $secondary_item_id ); 390 390 } 391 391 392 392 /** -
bp-members/bp-members-notifications.php
function bp_core_get_notification( $id ) { 83 83 function bp_core_get_notifications_for_user( $user_id, $format = 'simple' ) { 84 84 global $bp; 85 85 86 $notifications = BP_Core_Notification::get _all_for_user( $user_id);86 $notifications = BP_Core_Notification::get( array( 'user_id' => $user_id ) ); 87 87 $grouped_notifications = array(); // Notification groups 88 88 $renderable = array(); // Renderable notifications 89 89 … … function bp_core_get_notifications_for_user( $user_id, $format = 'simple' ) { 184 184 * @return boolean True on success, false on fail 185 185 */ 186 186 function bp_core_delete_notifications_by_type( $user_id, $component_name, $component_action ) { 187 return BP_Core_Notification::delete_for_user_by_type( $user_id, $component_name, $component_action ); 187 return BP_Core_Notification::delete( array( 188 'user_id' => $user_id, 189 'component_name' => $component_name, 190 'component_action' => $component_action 191 ) ); 188 192 } 189 193 190 194 /** … … function bp_core_delete_notifications_by_type( $user_id, $component_name, $compo 200 204 * @return boolean True on success, false on fail 201 205 */ 202 206 function bp_core_delete_notifications_by_item_id( $user_id, $item_id, $component_name, $component_action, $secondary_item_id = false ) { 203 return BP_Core_Notification::delete_for_user_by_item_id( $user_id, $item_id, $component_name, $component_action, $secondary_item_id ); 207 return BP_Core_Notification::delete( array( 208 'user_id' => $user_id, 209 'item_id' => $item_id, 210 'component_name' => $component_name, 211 'component_action' => $component_action, 212 'secondary_item_id' => $secondary_item_id 213 ) ); 204 214 } 205 215 206 216 /** … … function bp_core_delete_notifications_by_item_id( $user_id, $item_id, $component 215 225 * @return boolean True on success, false on fail 216 226 */ 217 227 function bp_core_delete_all_notifications_by_type( $item_id, $component_name, $component_action = false, $secondary_item_id = false ) { 218 return BP_Core_Notification::delete_all_by_type( $item_id, $component_name, $component_action, $secondary_item_id ); 228 return BP_Core_Notification::delete( array( 229 'item_id' => $item_id, 230 'component_name' => $component_name, 231 'component_action' => $component_action, 232 'secondary_item_id' => $secondary_item_id 233 ) ); 219 234 } 220 235 221 236 /** … … function bp_core_delete_all_notifications_by_type( $item_id, $component_name, $c 230 245 * @return boolean True on success, false on fail 231 246 */ 232 247 function bp_core_delete_notifications_from_user( $user_id, $component_name, $component_action ) { 233 return BP_Core_Notification::delete_from_user_by_type( $user_id, $component_name, $component_action ); 248 return BP_Core_Notification::delete( array( 249 'user_id' => $user_id, 250 'component_name' => $component_name, 251 'component_action' => $component_action 252 ) ); 234 253 } 235 254 236 255 /** -
tests/testcases/notifications/class-bp-core-notification.php
new file mode 100644
1 <?php 2 /** 3 * @group notifications 4 */ 5 class BP_Tests_BP_Core_Notification_TestCases extends BP_UnitTestCase { 6 public function setUp() { 7 if ( ! method_exists( 'BP_Core_Notification', 'get') ) { 8 $this->markTestSkipped( 9 'BP_Core_Notification::get() is only available in BP 1.9.' 10 ); 11 12 } 13 14 parent::setUp(); 15 } 16 17 public function tearDown() { 18 parent::tearDown(); 19 } 20 21 /** 22 * Tests the WHERE sql statement generated by {@link BP_Core_Notification::get_all_for_user()}. 23 */ 24 public function test_get_all_for_user_sql() { 25 $expected = 'WHERE user_id = 1'; 26 27 $this->assertEquals( 28 $expected, 29 _BP_Core_Notification::_get_where_sql( array( 30 'user_id' => 1 31 ) ) 32 ); 33 } 34 35 /** 36 * Tests the WHERE sql statement generated by {@link BP_Core_Notification::get_all_for_user()}. 37 */ 38 public function test_get_all_for_user_is_new_sql() { 39 $expected = 'WHERE user_id = 1 AND is_new = 1'; 40 41 $this->assertEquals( 42 $expected, 43 _BP_Core_Notification::_get_where_sql( array( 44 'user_id' => 1, 45 'is_new' => 1 46 ) ) 47 ); 48 } 49 50 /** 51 * Tests the WHERE sql statement generated by {@link BP_Core_Notification::delete_for_user_by_type()}. 52 */ 53 public function test_delete_for_user_by_type_sql() { 54 $expected = "WHERE user_id = 1 AND component_name = 'activity' AND component_action = 'new_at_mention'"; 55 56 // emulates bp_core_delete_notifications_by_type() as used in 57 // bp_activity_remove_screen_notifications() 58 $this->assertEquals( 59 $expected, 60 _BP_Core_Notification::_get_where_sql( array( 61 'user_id' => 1, 62 'component_name' => 'activity', 63 'component_action' => 'new_at_mention' 64 ) ) 65 ); 66 } 67 68 /** 69 * Tests the WHERE sql statement generated by {@link BP_Core_Notification::delete_for_user_by_item_id()}. 70 */ 71 public function test_delete_for_user_by_item_id_sql() { 72 $expected = "WHERE user_id = 1 AND item_id = 1 AND component_name = 'groups' AND component_action = 'group_invite'"; 73 74 // emulates bp_core_delete_notifications_by_item_id() as used in 75 // groups_accept_invite() 76 $this->assertEquals( 77 $expected, 78 _BP_Core_Notification::_get_where_sql( array( 79 'user_id' => 1, 80 'item_id' => 1, 81 'component_name' => 'groups', 82 'component_action' => 'group_invite' 83 ) ) 84 ); 85 } 86 87 /** 88 * Tests the WHERE sql statement generated by {@link BP_Core_Notification::delete_from_user_by_type()}. 89 */ 90 public function test_delete_from_user_by_type_sql() { 91 $expected = "WHERE item_id = 1 AND component_name = 'groups' AND component_action = 'new_membership_request'"; 92 93 // emulates bp_core_delete_notifications_from_user() as used in 94 // groups_remove_data_for_user() 95 $this->assertEquals( 96 $expected, 97 _BP_Core_Notification::_get_where_sql( array( 98 'item_id' => 1, 99 'component_name' => 'groups', 100 'component_action' => 'new_membership_request' 101 ) ) 102 ); 103 } 104 105 /** 106 * Tests the WHERE sql statement generated by {@link BP_Core_Notification::delete_all_by_type()}. 107 */ 108 public function test_delete_all_by_type_sql() { 109 $expected = "WHERE item_id = 1 AND component_name = 'groups'"; 110 111 // emulates bp_core_delete_all_notifications_by_type() as used in 112 // groups_delete_group() 113 $this->assertEquals( 114 $expected, 115 _BP_Core_Notification::_get_where_sql( array( 116 'item_id' => 1, 117 'component_name' => 'groups' 118 ) ) 119 ); 120 } 121 122 } 123 124 /** 125 * Stub class for accessing protected methods 126 */ 127 class _BP_Core_Notification extends BP_Core_Notification { 128 public static function _get_where_sql( $params = array() ) { 129 return self::get_where_sql( $params ); 130 } 131 }