Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
07/02/2021 01:10:12 AM (4 years ago)
Author:
espellcaste
Message:

Adding a user ID parameter to the messages_mark_thread_read and messages_mark_thread_unread functions.

Allowing those functions to be used in other BuddyPress API.

Props imath
Fixes #8489 (trunk)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/testcases/messages/class.bp-messages-thread.php

    r11737 r12984  
    320320
    321321    /**
     322     * @group cache
     323     */
     324    public function test_marking_a_thread_as_read_with_specific_user_id() {
     325        $u1      = self::factory()->user->create();
     326        $u2      = self::factory()->user->create();
     327        $message = self::factory()->message->create_and_get( array(
     328            'sender_id'  => $u1,
     329            'recipients' => array( $u2 ),
     330            'subject'    => 'Foo',
     331        ) );
     332
     333        $thread_id = $message->thread_id;
     334
     335        // Cache should be populated.
     336        $this->assertTrue( (bool) wp_cache_get( 'thread_recipients_' . $thread_id, 'bp_messages' ) );
     337
     338        // Mark thread as read.
     339        messages_mark_thread_read( $thread_id, $u2 );
     340
     341        // Cache should be empty.
     342        $this->assertFalse( wp_cache_get( 'thread_recipients_' . $thread_id, 'bp_messages' ) );
     343
     344        $thread = new BP_Messages_Thread( $thread_id );
     345
     346        $this->assertFalse( (bool) $thread->unread_count );
     347        $this->assertFalse( (bool) $thread->recipients[ $u1 ]->unread_count );
     348        $this->assertFalse( (bool) $thread->recipients[ $u2 ]->unread_count );
     349    }
     350
     351    /**
     352     * @group cache
     353     */
     354    public function test_marking_a_thread_as_unread_with_specific_user_id() {
     355        $u1      = self::factory()->user->create();
     356        $u2      = self::factory()->user->create();
     357        $message = self::factory()->message->create_and_get( array(
     358            'sender_id'  => $u1,
     359            'recipients' => array( $u2 ),
     360            'subject'    => 'Foo',
     361        ) );
     362
     363        $thread_id = $message->thread_id;
     364
     365        // Cache should be populated.
     366        $this->assertTrue( (bool) wp_cache_get( 'thread_recipients_' . $thread_id, 'bp_messages' ) );
     367
     368        // Mark thread as unread.
     369        messages_mark_thread_unread( $thread_id, $u2 );
     370
     371        // Cache should be empty.
     372        $this->assertFalse( wp_cache_get( 'thread_recipients_' . $thread_id, 'bp_messages' ) );
     373
     374        $thread = new BP_Messages_Thread( $thread_id );
     375
     376        $this->assertFalse( (bool) $thread->recipients[ $u1 ]->unread_count );
     377        $this->assertTrue( (bool) $thread->recipients[ $u2 ]->unread_count );
     378    }
     379
     380    /**
    322381     * @group get_recipients
    323382     * @group cache
Note: See TracChangeset for help on using the changeset viewer.