- Timestamp:
- 05/21/2015 08:05:12 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/testcases/notifications/functions.php
r9819 r9888 5 5 */ 6 6 class BP_Tests_Notifications_Functions extends BP_UnitTestCase { 7 8 /** 9 * @group cache 10 */ 7 11 public function test_cache_invalidation_all_for_user_on_save() { 8 12 $u = $this->factory->user->create(); 13 14 $this->factory->notification->create( array( 15 'component_name' => 'groups', 16 'user_id' => $u 17 ) ); 18 $this->factory->notification->create( array( 19 'component_name' => 'messages', 20 'user_id' => $u, 21 'item_id' => 1 22 ) ); 23 24 // prime cache 25 $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 save 31 $this->factory->notification->create( array( 32 'component_name' => 'messages', 33 'user_id' => $u, 34 'item_id' => 2 35 ) ); 36 37 $this->assertFalse( wp_cache_get( 'all_for_user_' . $u, 'bp_notifications' ) ); 38 } 39 40 /** 41 * @group cache 42 */ 43 public function test_cache_invalidation_all_for_user_on_delete() { 44 $u = $this->factory->user->create(); 9 45 $n1 = $this->factory->notification->create( array( 10 46 'component_name' => 'groups', 11 'user_id' => $u, 12 ) ); 13 $n2 = $this->factory->notification->create( array( 14 'component_name' => 'messages', 15 'user_id' => $u, 16 'item_id' => 1, 17 ) ); 18 19 // prime cache 20 $count = bp_notifications_get_unread_notification_count( $u ); 21 22 // just to be sure... 23 $this->assertEquals( 2, $count, 'Cache count should be 2 before invalidation.' ); 24 25 // Trigger invalidation via save 26 $n3 = $this->factory->notification->create( array( 27 'component_name' => 'messages', 28 'user_id' => $u, 29 'item_id' => 2, 30 ) ); 31 32 $this->assertFalse( wp_cache_get( 'all_for_user_' . $u, 'bp_notifications' ) ); 33 } 34 35 public function test_cache_invalidation_all_for_user_on_delete() { 36 $u = $this->factory->user->create(); 37 $n1 = $this->factory->notification->create( array( 38 'component_name' => 'groups', 39 'user_id' => $u, 40 ) ); 41 $n2 = $this->factory->notification->create( array( 42 'component_name' => 'messages', 43 'user_id' => $u, 47 'user_id' => $u 48 ) ); 49 $this->factory->notification->create( array( 50 'component_name' => 'messages', 51 'user_id' => $u 44 52 ) ); 45 53 … … 57 65 58 66 /** 67 * @group cache 68 */ 69 public function test_cache_invalidation_all_for_user_on_update_user_id() { 70 $u = $this->factory->user->create(); 71 72 $this->factory->notification->create( array( 73 'component_name' => 'groups', 74 'user_id' => $u 75 ) ); 76 $this->factory->notification->create( array( 77 'component_name' => 'messages', 78 'user_id' => $u 79 ) ); 80 81 // prime cache 82 $count = bp_notifications_get_unread_notification_count( $u ); 83 84 // just to be sure... 85 $this->assertEquals( 2, $count, 'Cache count should be 2 before invalidation.' ); 86 87 // mark all notifications by user as read 88 BP_Notifications_Notification::update( 89 array( 'is_new' => false ), 90 array( 'user_id' => $u ) 91 ); 92 93 $this->assertFalse( wp_cache_get( 'all_for_user_' . $u, 'bp_notifications' ) ); 94 } 95 96 /** 97 * @group cache 98 */ 99 public function test_cache_invalidation_all_for_user_on_update_id() { 100 $u = $this->factory->user->create(); 101 $n1 = $this->factory->notification->create( array( 102 'component_name' => 'groups', 103 'user_id' => $u 104 ) ); 105 106 $this->factory->notification->create( array( 107 'component_name' => 'messages', 108 'user_id' => $u 109 ) ); 110 111 // prime cache 112 $count = bp_notifications_get_unread_notification_count( $u ); 113 114 // just to be sure... 115 $this->assertEquals( 2, $count, 'Cache count should be 2 before invalidation.' ); 116 117 // mark one notification as read 118 BP_Notifications_Notification::update( 119 array( 'is_new' => false ), 120 array( 'id' => $n1 ) 121 ); 122 123 $this->assertFalse( wp_cache_get( 'all_for_user_' . $u, 'bp_notifications' ) ); 124 } 125 126 /** 59 127 * @group bp_notifications_add_notification 60 128 */ 61 129 public function test_bp_notifications_add_notification_no_dupes() { 62 130 $args = array( 63 'user_id' => 5,64 'item_id' => 10,131 'user_id' => 5, 132 'item_id' => 10, 65 133 'secondary_item_id' => 25, 66 'component_name' => 'messages',67 'component_action' => 'new_message',68 ); 69 70 $ n = $this->factory->notification->create( $args );134 'component_name' => 'messages', 135 'component_action' => 'new_message' 136 ); 137 138 $this->factory->notification->create( $args ); 71 139 72 140 $this->assertFalse( bp_notifications_add_notification( $args ) ); … … 78 146 public function test_bp_notifications_add_notification_allow_duplicate() { 79 147 $args = array( 80 'user_id' => 5,81 'item_id' => 10,148 'user_id' => 5, 149 'item_id' => 10, 82 150 'secondary_item_id' => 25, 83 'component_name' => 'messages',84 'component_action' => 'new_message',85 ); 86 87 $ n = $this->factory->notification->create( $args );151 'component_name' => 'messages', 152 'component_action' => 'new_message' 153 ); 154 155 $this->factory->notification->create( $args ); 88 156 89 157 $args['allow_duplicate'] = true; … … 100 168 $u2 = $this->factory->user->create(); 101 169 102 $ n1 = $this->factory->notification->create( array(170 $this->factory->notification->create( array( 103 171 'component_name' => 'messages', 104 172 'component_action' => 'new_message', … … 106 174 'user_id' => $u2, 107 175 'secondary_item_id' => $u1, 108 'is_new' => true ,176 'is_new' => true 109 177 ) ); 110 178 … … 130 198 131 199 // create a mixture of different notifications 132 $ n1 = $this->factory->notification->create( array(200 $this->factory->notification->create( array( 133 201 'component_name' => 'messages', 134 202 'component_action' => 'new_message', … … 136 204 'user_id' => $u2, 137 205 'secondary_item_id' => $u1, 138 'is_new' => true ,139 ) ); 140 141 $ n2 = $this->factory->notification->create( array(206 'is_new' => true 207 ) ); 208 209 $this->factory->notification->create( array( 142 210 'component_name' => 'activity', 143 211 'component_action' => 'new_at_mention', … … 145 213 'user_id' => $u2, 146 214 'secondary_item_id' => $u1, 147 'is_new' => true ,148 ) ); 149 150 $ n3 = $this->factory->notification->create( array(215 'is_new' => true 216 ) ); 217 218 $this->factory->notification->create( array( 151 219 'component_name' => 'activity', 152 220 'component_action' => 'new_at_mention', … … 154 222 'user_id' => $u2, 155 223 'secondary_item_id' => $u1, 156 'is_new' => true ,224 'is_new' => true 157 225 ) ); 158 226 … … 160 228 bp_has_notifications( array( 161 229 'component_name' => 'activity', 162 'user_id' => $u2,230 'user_id' => $u2 163 231 ) ); 164 232
Note: See TracChangeset
for help on using the changeset viewer.