Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
07/27/2024 08:14:28 PM (2 years ago)
Author:
espellcaste
Message:

Core: Add cache_results flag to the BP_Invitation::get getter.

When performing a request with cache_results, it stops the invite information retrieved from being added to the cache.

See #8552
Closes ​https://github.com/buddypress/buddypress/pull/346/

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/testcases/core/invitations.php

    r13980 r13990  
    88 */
    99 class BP_Tests_Invitations extends BP_UnitTestCase {
     10
     11         /**
     12          * @ticket BP8552
     13          * @group cache
     14          */
     15         public function test_invitation_query_with_ids_cache_results() {
     16                 global $wpdb;
     17
     18                 $u1 = self::factory()->user->create();
     19                 $u2 = self::factory()->user->create();
     20                 $u3 = self::factory()->user->create();
     21
     22                 $invites_class = new BPTest_Invitation_Manager_Extension();
     23
     24                 // Create a couple of invitations.
     25                 $invite_args = array(
     26                         'user_id'           => $u3,
     27                         'inviter_id'           => $u1,
     28                         'item_id'           => 1,
     29                         'send_invite'       => 'sent',
     30                 );
     31
     32                 $invites_class->add_invitation( $invite_args );
     33
     34                 $invite_args['inviter_id'] = $u2;
     35
     36                 $invites_class->add_invitation( $invite_args );
     37
     38                 $wpdb->num_queries = 0;
     39
     40                 $first_query = BP_Invitation::get(
     41                         array(
     42                                 'cache_results' => true,
     43                                 'fields'        => 'ids',
     44                         )
     45                 );
     46
     47                 $queries_before = get_num_queries();
     48
     49                 $second_query = BP_Invitation::get(
     50                         array(
     51                                 'cache_results' => false,
     52                                 'fields'        => 'ids',
     53                         )
     54                 );
     55
     56                 $queries_after = get_num_queries();
     57
     58                 $this->assertNotSame( $queries_before, $queries_after, 'Assert that queries are run' );
     59                 $this->assertSame( 2, $queries_after, 'Assert that the uncached query was run' );
     60                 $this->assertSameSets( $first_query, $second_query, 'Results of the query are expected to match.' );
     61         }
     62
     63         /**
     64          * @ticket BP8552
     65          * @group cache
     66          */
     67         public function test_invitation_query_with_all_cache_results() {
     68                 global $wpdb;
     69
     70                 $u1 = self::factory()->user->create();
     71                 $u2 = self::factory()->user->create();
     72                 $u3 = self::factory()->user->create();
     73
     74                 $invites_class = new BPTest_Invitation_Manager_Extension();
     75
     76                 // Create a couple of invitations.
     77                 $invite_args = array(
     78                         'user_id'     => $u3,
     79                         'inviter_id'  => $u1,
     80                         'item_id'     => 1,
     81                         'send_invite' => 'sent',
     82                 );
     83
     84                 $invites_class->add_invitation( $invite_args );
     85
     86                 $invite_args['inviter_id'] = $u2;
     87
     88                 $invites_class->add_invitation( $invite_args );
     89
     90                 $wpdb->num_queries = 0;
     91
     92                 $first_query = BP_Invitation::get(
     93                         array( 'cache_results' => true )
     94                 );
     95
     96                 $queries_before = get_num_queries();
     97
     98                 $second_query = BP_Invitation::get(
     99                         array( 'cache_results' => false )
     100                 );
     101
     102                 $queries_after = get_num_queries();
     103
     104                 $this->assertNotSame( $queries_before, $queries_after, 'Assert that queries are run' );
     105                 $this->assertSame( 3, $queries_after, 'Assert that the uncached query was run' );
     106                 $this->assertEquals( $first_query, $second_query, 'Results of the query are expected to match.' );
     107         }
     108
    10109        public function test_bp_invitations_add_invitation_vanilla() {
    11110                $old_current_user = get_current_user_id();
Note: See TracChangeset for help on using the changeset viewer.