Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
07/27/2024 08:12:32 PM (12 months ago)
Author:
espellcaste
Message:

Members: Add cache_results flag to the BP_Signup::get getter.

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

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/testcases/members/class-bp-signup.php

    r13980 r13989  
    359359
    360360    /**
     361     * @ticket BP8552
     362     * @group cache
     363     */
     364    public function test_signup_query_with_ids_cache_results() {
     365        global $wpdb;
     366
     367        self::factory()->signup->create_many( 2 );
     368
     369        // Reset.
     370        $wpdb->num_queries = 0;
     371
     372        $first_query = BP_Signup::get(
     373            array(
     374                'cache_results' => true,
     375                'fields'        => 'ids',
     376            )
     377        );
     378
     379        $queries_before = get_num_queries();
     380
     381        $second_query = BP_Signup::get(
     382            array(
     383                'cache_results' => false,
     384                'fields'        => 'ids',
     385            )
     386        );
     387
     388        $queries_after = get_num_queries();
     389
     390        $this->assertNotSame( $queries_before, $queries_after, 'Assert that queries are run' );
     391        $this->assertSame( 4, $queries_after, 'Assert that the uncached query was run' );
     392        $this->assertSameSets( $first_query['signups'], $second_query['signups'], 'Results of the query are expected to match.' );
     393        $this->assertSame( $first_query['total'], $second_query['total'], 'Results of the query are expected to match.' );
     394    }
     395
     396    /**
     397     * @ticket BP8552
     398     * @group cache
     399     */
     400    public function test_signup_query_with_all_cache_results() {
     401        global $wpdb;
     402
     403        self::factory()->signup->create_many( 2 );
     404
     405        // Reset.
     406        $wpdb->num_queries = 0;
     407
     408        $first_query = BP_Signup::get(
     409            array( 'cache_results' => true )
     410        );
     411
     412        $queries_before = get_num_queries();
     413
     414        $second_query = BP_Signup::get(
     415            array( 'cache_results' => false )
     416        );
     417
     418        $queries_after = get_num_queries();
     419
     420        $this->assertNotSame( $queries_before, $queries_after, 'Assert that queries are run' );
     421        $this->assertSame( 5, $queries_after, 'Assert that the uncached query was run' );
     422        $this->assertSame( $first_query['total'], $second_query['total'], 'Results of the query are expected to match.' );
     423    }
     424
     425    /**
    361426     * @group cache
    362427     */
     
    364429        global $wpdb;
    365430
    366         $s = self::factory()->signup->create();
    367 
    368         $found1 = BP_Signup::get(
    369             array(
    370                 'fields' => 'ids',
    371             )
    372         );
    373 
    374         $num_queries = $wpdb->num_queries;
    375 
    376         $found2 = BP_Signup::get(
    377             array(
    378                 'fields' => 'ids',
    379             )
    380         );
    381 
    382         $this->assertEqualSets( $found1, $found2 );
    383         $this->assertSame( $num_queries, $wpdb->num_queries );
     431        self::factory()->signup->create_many( 2 );
     432
     433        // Reset.
     434        $wpdb->num_queries = 0;
     435
     436        $args = array( 'fields' => 'ids' );
     437
     438        $first_query = BP_Signup::get( $args );
     439
     440        $queries_before = get_num_queries();
     441
     442        $second_query = BP_Signup::get( $args );
     443
     444        $queries_after = get_num_queries();
     445
     446        $this->assertSame( $queries_before, $queries_after, 'Assert that queries are run' );
     447        $this->assertSame( 2, $queries_after, 'Assert that the uncached query was run' );
     448        $this->assertSameSets( $first_query['signups'], $second_query['signups'], 'Results of the query are expected to match.' );
    384449    }
    385450
     
    388453     */
    389454    public function test_get_query_caches_should_be_busted_by_add() {
    390         $s1 = self::factory()->signup->create();
    391 
    392         $found1 = BP_Signup::get(
    393             array(
    394                 'fields' => 'ids',
    395             )
    396         );
     455        $s1   = self::factory()->signup->create();
     456        $args = array( 'fields' => 'ids' );
     457
     458        $found1 = BP_Signup::get( $args );
    397459        $this->assertEqualSets( array( $s1 ), $found1['signups'] );
    398460
    399461        $s2 = self::factory()->signup->create();
    400         $found2 = BP_Signup::get(
    401             array(
    402                 'fields' => 'ids',
    403             )
    404         );
     462        $found2 = BP_Signup::get( $args );
    405463        $this->assertEqualSets( array( $s2 ), $found2['signups'] );
    406464    }
     
    521579        $this->assertEqualSets( array( $s1, $s2 ), $found1['signups'] );
    522580
    523         $activate = BP_Signup::activate( (array) $s2 );
     581        BP_Signup::activate( (array) $s2 );
    524582
    525583        $found2 = BP_Signup::get(
     
    570628        $this->assertFalse( $found1->active );
    571629
    572         $activate = BP_Signup::activate( (array) $s1 );
     630        BP_Signup::activate( (array) $s1 );
    573631
    574632        $found2 = new BP_Signup( $s1 );
Note: See TracChangeset for help on using the changeset viewer.