Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHP Unit Tests: Use global transients #37122

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/class-wp-rest-url-details-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ private function build_cache_key_for_url( $url ) {
* @return mixed The value from the cache.
*/
private function get_cache( $key ) {
return get_transient( $key );
return get_site_transient( $key );
}

/**
Expand All @@ -406,7 +406,7 @@ private function set_cache( $key, $data = '' ) {
*/
$cache_expiration = apply_filters( 'rest_url_details_cache_expiration', $ttl );

return set_transient( $key, $data, $cache_expiration );
return set_site_transient( $key, $data, $cache_expiration );
}

/**
Expand Down
6 changes: 3 additions & 3 deletions phpunit/class-wp-rest-url-details-controller-test.php
Original file line number Diff line number Diff line change
Expand Up @@ -277,11 +277,11 @@ function( $args, $url ) {
public function test_will_return_from_cache_if_populated() {
$transient_name = 'g_url_details_response_' . md5( static::$url_placeholder );

remove_filter( "pre_transient_{$transient_name}", '__return_null' );
remove_filter( "pre_site_transient_{$transient_name}", '__return_null' );

// Force cache to return a known value as the remote URL http response body.
add_filter(
"pre_transient_{$transient_name}",
"pre_site_transient_{$transient_name}",
function() {
return '<html><head><title>This value from cache.</title></head><body></body></html>';
}
Expand All @@ -301,7 +301,7 @@ function() {
// Data should be that from cache not from mocked network response.
$this->assertContains( 'This value from cache', $data['title'] );

remove_all_filters( "pre_transient_{$transient_name}" );
remove_all_filters( "pre_site_transient_{$transient_name}" );
}

public function test_allows_filtering_data_retrieved_for_a_given_url() {
Expand Down