- Timestamp:
- 02/22/2022 07:23:34 PM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/10.0/tests/phpunit/testcases/notifications/functions.php
r13112 r13244 5 5 */ 6 6 class BP_Tests_Notifications_Functions extends BP_UnitTestCase { 7 8 /**9 * @group cache10 */11 public function test_cache_invalidation_all_for_user_on_save() {12 $u = self::factory()->user->create();13 14 self::factory()->notification->create( array(15 'component_name' => 'groups',16 'user_id' => $u17 ) );18 self::factory()->notification->create( array(19 'component_name' => 'messages',20 'user_id' => $u,21 'item_id' => 122 ) );23 24 // prime cache25 $count = bp_notifications_get_unread_notification_count( $u );26 27 // just to be sure...28 $this->assertEquals( 2, $count, 'Cache count should be 2 before invalidation.' );29 30 // Trigger invalidation via save31 self::factory()->notification->create( array(32 'component_name' => 'messages',33 'user_id' => $u,34 'item_id' => 235 ) );36 37 $this->assertFalse( wp_cache_get( 'all_for_user_' . $u, 'bp_notifications' ) );38 $this->assertFalse( wp_cache_get( $u, 'bp_notifications_unread_count' ) );39 }40 41 /**42 * @group cache43 */44 public function test_cache_invalidation_all_for_user_on_delete() {45 $u = self::factory()->user->create();46 $n1 = self::factory()->notification->create( array(47 'component_name' => 'groups',48 'user_id' => $u49 ) );50 self::factory()->notification->create( array(51 'component_name' => 'messages',52 'user_id' => $u53 ) );54 55 // prime cache56 $count = bp_notifications_get_unread_notification_count( $u );57 58 // just to be sure...59 $this->assertEquals( 2, $count, 'Cache count should be 2 before invalidation.' );60 61 // delete62 BP_Notifications_Notification::delete( array( 'id' => $n1, ) );63 64 $this->assertFalse( wp_cache_get( 'all_for_user_' . $u, 'bp_notifications' ) );65 $this->assertFalse( wp_cache_get( $u, 'bp_notifications_unread_count' ) );66 }67 68 /**69 * @group cache70 */71 public function test_cache_invalidation_all_for_user_on_update_user_id() {72 $u = self::factory()->user->create();73 74 self::factory()->notification->create( array(75 'component_name' => 'groups',76 'user_id' => $u77 ) );78 self::factory()->notification->create( array(79 'component_name' => 'messages',80 'user_id' => $u81 ) );82 83 // prime cache84 $count = bp_notifications_get_unread_notification_count( $u );85 86 // just to be sure...87 $this->assertEquals( 2, $count, 'Cache count should be 2 before invalidation.' );88 89 // mark all notifications by user as read90 BP_Notifications_Notification::update(91 array( 'is_new' => false ),92 array( 'user_id' => $u )93 );94 95 $this->assertFalse( wp_cache_get( 'all_for_user_' . $u, 'bp_notifications' ) );96 $this->assertFalse( wp_cache_get( $u, 'bp_notifications_unread_count' ) );97 }98 99 /**100 * @group cache101 */102 public function test_cache_invalidation_all_for_user_on_update_id() {103 $u = self::factory()->user->create();104 $n1 = self::factory()->notification->create( array(105 'component_name' => 'groups',106 'user_id' => $u107 ) );108 109 self::factory()->notification->create( array(110 'component_name' => 'messages',111 'user_id' => $u112 ) );113 114 // prime cache115 $count = bp_notifications_get_unread_notification_count( $u );116 117 // just to be sure...118 $this->assertEquals( 2, $count, 'Cache count should be 2 before invalidation.' );119 120 // mark one notification as read121 BP_Notifications_Notification::update(122 array( 'is_new' => false ),123 array( 'id' => $n1 )124 );125 126 $this->assertFalse( wp_cache_get( 'all_for_user_' . $u, 'bp_notifications' ) );127 $this->assertFalse( wp_cache_get( $u, 'bp_notifications_unread_count' ) );128 }129 130 /**131 * @group bp_notifications_update_meta_cache132 */133 public function test_bp_notifications_update_meta_cache() {134 $u = self::factory()->user->create();135 136 $n1 = self::factory()->notification->create( array(137 'component_name' => 'messages',138 'user_id' => $u139 ) );140 141 $n2 = self::factory()->notification->create( array(142 'component_name' => 'groups',143 'user_id' => $u144 ) );145 146 // Add cache for each notification.147 bp_notifications_update_meta( $n1, 'meta', 'data' );148 bp_notifications_update_meta( $n1, 'data', 'meta' );149 bp_notifications_update_meta( $n2, 'meta', 'human' );150 151 // Prime cache.152 bp_notifications_get_meta( $n1, 'meta' );153 154 // Ensure an empty cache for second notification.155 wp_cache_delete( $n2, 'notification_meta' );156 157 // Update notification meta cache.158 bp_notifications_update_meta_cache( array( $n1, $n2 ) );159 160 $expected = array(161 $n1 => array(162 'meta' => array(163 'data',164 ),165 'data' => array(166 'meta',167 ),168 ),169 $n2 => array(170 'meta' => array(171 'human',172 ),173 ),174 );175 176 $found = array(177 $n1 => wp_cache_get( $n1, 'notification_meta' ),178 $n2 => wp_cache_get( $n2, 'notification_meta' ),179 );180 181 $this->assertEquals( $expected, $found );182 }183 7 184 8 /**
Note: See TracChangeset
for help on using the changeset viewer.