Making WordPress.org


Ignore:
Timestamp:
09/11/2020 04:41:56 PM (4 years ago)
Author:
iandunn
Message:

Events: Disable caching during manual tests for convenience.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/api.wordpress.org/public_html/events/1.0/index.php

    r10249 r10250  
    4040    // The test suite just needs the functions defined and doesn't want any headers or output
    4141    if ( defined( 'RUNNING_TESTS' ) && RUNNING_TESTS ) {
     42        disable_caching();
    4243        return;
    4344    }
    4445
    45     wp_cache_init();
     46    // Disable object caching during manual testing, unless explicitly testing caching.
     47    if ( is_test_request() && empty( $_GET['cache'] ) ) {
     48        disable_caching();
     49    } else {
     50        wp_cache_init();
     51    }
    4652
    4753    $cache_group   = 'events';
     
    5359
    5460    send_response( $response, $ttl );
     61}
     62
     63/**
     64 * Determine if the current request is a developer manually testing on their sandbox.
     65 *
     66 * @return bool
     67 */
     68function is_test_request() {
     69    $proxied = defined( 'WPORG_PROXIED_REQUEST' ) && WPORG_PROXIED_REQUEST;
     70    $sandbox = defined( 'WPORG_SANDBOXED' ) && WPORG_SANDBOXED;
     71
     72    return $proxied && $sandbox;
     73}
     74
     75/**
     76 * Mock the caching functions.
     77 */
     78function disable_caching() {
     79    /**
     80     * Stub to simulate cache misses, so that the tests always get fresh results
     81     *
     82     * @return false
     83     */
     84    function wp_cache_get( $key, $group = '', $force = false, &$found = null ) {
     85        return false;
     86    }
     87
     88    /**
     89     * Stub to avoid setting production object cache values while testing.
     90     */
     91    function wp_cache_set( $key, $data, $group = '', $expire = 0 ) {
     92        // Intentionally empty
     93    }
    5594}
    5695
Note: See TracChangeset for help on using the changeset viewer.