Skip to:
Content

BuddyPress.org


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

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

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

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

File:
1 edited

Legend:

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

    r13980 r13991  
    55 */
    66 class BP_Tests_Optouts extends BP_UnitTestCase {
     7
     8         /**
     9          * @ticket BP8552
     10          */
     11         public function test_bp_optouts_query_cache_results() {
     12                 global $wpdb;
     13
     14                 self::factory()->optout->create_many( 2 );
     15
     16                 // Reset.
     17                 $wpdb->num_queries = 0;
     18
     19                 $first_query = BP_Optout::get(
     20                         array( 'cache_results' => true )
     21                 );
     22
     23                 $queries_before = get_num_queries();
     24
     25                 $second_query = BP_Optout::get(
     26                         array( 'cache_results' => false )
     27                 );
     28
     29                 $queries_after = get_num_queries();
     30
     31                 $this->assertNotSame( $queries_before, $queries_after, 'Assert that queries are run' );
     32                 $this->assertSame( 3, $queries_after, 'Assert that the uncached query was run' );
     33                 $this->assertEquals( $first_query, $second_query, 'Results of the query are expected to match.' );
     34         }
     35
    736        public function test_bp_optouts_add_optout_vanilla() {
    837                $old_current_user = get_current_user_id();
     
    1746                        'email_type'        => 'annoyance'
    1847                );
    19                 $i1 = bp_add_optout( $args );
     48                $i1 = self::factory()->optout->create( $args );
    2049                $args['email_address'] = 'two@wp.org';
    21                 $i2 = bp_add_optout( $args );
     50                $i2 = self::factory()->optout->create( $args );
    2251
    2352                $get_args = array(
     
    6291                        'email_type'        => 'annoyance'
    6392                );
    64                 $i1 = bp_add_optout( $args );
     93                $i1 = self::factory()->optout->create( $args );
    6594                bp_delete_optout_by_id( $i1 );
    6695
     
    7099                );
    71100                $optouts = bp_get_optouts( $get_args );
    72                 $this->assertTrue( empty( $optouts ) );
     101                $this->assertEmpty( $optouts );
    73102
    74103                self::set_current_user( $old_current_user );
     
    87116                        'email_type'        => 'annoyance'
    88117                );
    89                 $i1 = bp_add_optout( $args );
     118                $i1 = self::factory()->optout->create( $args );
    90119                $args['email_address'] = 'two@wp.org';
    91                 $i2 = bp_add_optout( $args );
     120                self::factory()->optout->create( $args );
    92121
    93122                $get_args = array(
     
    113142                        'email_type'        => 'annoyance'
    114143                );
    115                 $i1 = bp_add_optout( $args );
     144                $i1 = self::factory()->optout->create( $args );
    116145                $args['email_address'] = 'two@WP.org';
    117                 $i2 = bp_add_optout( $args );
     146                self::factory()->optout->create( $args );
    118147
    119148                $get_args = array(
     
    139168                        'email_type'        => 'annoyance'
    140169                );
    141                 $i1 = bp_add_optout( $args );
     170                $i1 = self::factory()->optout->create( $args );
    142171                $args['email_address'] = 'two@WP.org';
    143                 $i2 = bp_add_optout( $args );
     172                self::factory()->optout->create( $args );
    144173
    145174                $get_args = array(
     
    166195                        'email_type'        => 'annoyance'
    167196                );
    168                 $i1 = bp_add_optout( $args );
     197                $i1 = self::factory()->optout->create( $args );
    169198                // Update it.
    170199                $oo_class                = new BP_Optout( $i1 );
     
    193222                        'email_type'        => 'annoyance'
    194223                );
    195                 $i1 = bp_add_optout( $args );
     224                self::factory()->optout->create( $args );
    196225                $email = new BP_Email( 'activity-at-message' );
    197226                $email->set_from( 'test1@example.com' )->set_to( 'test2@example.com' )->set_subject( 'testing' );
Note: See TracChangeset for help on using the changeset viewer.