| 219 | |
| 220 | /** |
| 221 | * @group get_recipients |
| 222 | * @group cache |
| 223 | * @group raymsg |
| 224 | */ |
| 225 | public function test_get_recipients_cache_should_be_busted_when_thread_is_read() { |
| 226 | global $wpdb; |
| 227 | |
| 228 | $u1 = $this->factory->user->create(); |
| 229 | $u2 = $this->factory->user->create(); |
| 230 | |
| 231 | $t1 = $this->factory->message->create( array( |
| 232 | 'sender_id' => $u1, |
| 233 | 'recipients' => array( $u2 ), |
| 234 | 'subject' => 'Foo', |
| 235 | ) ); |
| 236 | |
| 237 | $thread = new BP_Messages_Thread( $t1 ); |
| 238 | $recipients = $thread->get_recipients(); |
| 239 | |
| 240 | // Verify that the cache is populated. |
| 241 | $num_queries = $wpdb->num_queries; |
| 242 | $recipients_cached = $thread->get_recipients(); |
| 243 | $this->assertEquals( $num_queries, $wpdb->num_queries ); |
| 244 | |
| 245 | // Mark thread as read |
| 246 | $current_user = get_current_user_id(); |
| 247 | $this->set_current_user( $u2 ); |
| 248 | messages_mark_thread_read( $t1 ); |
| 249 | |
| 250 | // Cache should be empty. |
| 251 | $this->assertFalse( wp_cache_get( 'thread_recipients_' . $t1, 'bp_messages' ) ); |
| 252 | |
| 253 | $this->set_current_user( $current_user ); |
| 254 | } |
| 255 | |
| 256 | /** |
| 257 | * @group get_recipients |
| 258 | * @group cache |
| 259 | */ |
| 260 | public function test_get_recipients_cache_should_be_busted_when_thread_is_unread() { |
| 261 | global $wpdb; |
| 262 | |
| 263 | $u1 = $this->factory->user->create(); |
| 264 | $u2 = $this->factory->user->create(); |
| 265 | |
| 266 | $t1 = $this->factory->message->create( array( |
| 267 | 'sender_id' => $u1, |
| 268 | 'recipients' => array( $u2 ), |
| 269 | 'subject' => 'Foo', |
| 270 | ) ); |
| 271 | |
| 272 | $thread = new BP_Messages_Thread( $t1 ); |
| 273 | $recipients = $thread->get_recipients(); |
| 274 | |
| 275 | // Verify that the cache is populated. |
| 276 | $num_queries = $wpdb->num_queries; |
| 277 | $recipients_cached = $thread->get_recipients(); |
| 278 | $this->assertEquals( $num_queries, $wpdb->num_queries ); |
| 279 | |
| 280 | // Mark thread as unread |
| 281 | $current_user = get_current_user_id(); |
| 282 | $this->set_current_user( $u2 ); |
| 283 | messages_mark_thread_unread( $t1 ); |
| 284 | |
| 285 | // Cache should be empty. |
| 286 | $this->assertFalse( wp_cache_get( 'thread_recipients_' . $t1, 'bp_messages' ) ); |
| 287 | |
| 288 | $this->set_current_user( $current_user ); |
| 289 | } |