WordPress.org

Making WordPress.org

Changeset 10250


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

Events: Disable caching during manual tests for convenience.

Location:
sites/trunk/api.wordpress.org/public_html/events/1.0
Files:
2 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
  • sites/trunk/api.wordpress.org/public_html/events/1.0/tests/test-index.php

    r9785 r10250  
    15301530}
    15311531
    1532 /**
    1533  * Stub to simulate cache misses, so that the tests always get fresh results
    1534  *
    1535  * @return false
    1536  */
    1537 function wp_cache_get( $key, $group = '', $force = false, &$found = null ) {
    1538     return false;
    1539 }
    1540 
    1541 /**
    1542  * Stub to simulate cache misses, so that the tests always get fresh results
    1543  */
    1544 function wp_cache_set( $key, $data, $group = '', $expire = 0 ) {
    1545     // Intentionally empty
    1546 }
    1547 
    1548 
    15491532define( 'VERBOSE_OUTPUT', in_array( '--verbose', $argv, true ) );
    15501533
Note: See TracChangeset for help on using the changeset viewer.