From 4d57f4ee3c451b58bb36f0daf0be81bbc556da38 Mon Sep 17 00:00:00 2001 From: Brian Henry Date: Wed, 11 Sep 2024 13:43:37 -0700 Subject: [PATCH] Use `\set_transient()` on Bluehost Cloud --- includes/Helpers/Transient.php | 3 ++- .../includes/Helpers/TransientTest.php | 27 +++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/includes/Helpers/Transient.php b/includes/Helpers/Transient.php index a4e6c73..1124140 100644 --- a/includes/Helpers/Transient.php +++ b/includes/Helpers/Transient.php @@ -14,7 +14,8 @@ class Transient { */ protected static function should_use_transients(): bool { require_once constant( 'ABSPATH' ) . '/wp-admin/includes/plugin.php'; - return ! array_key_exists( 'object-cache.php', get_dropins() ); + return ! array_key_exists( 'object-cache.php', get_dropins() ) + || 'atomic' === \NewfoldLabs\WP\Context\getContext( 'platform' ); // Bluehost Cloud. } /** diff --git a/tests/phpunit/includes/Helpers/TransientTest.php b/tests/phpunit/includes/Helpers/TransientTest.php index a65bee0..8f4c4e4 100644 --- a/tests/phpunit/includes/Helpers/TransientTest.php +++ b/tests/phpunit/includes/Helpers/TransientTest.php @@ -196,4 +196,31 @@ public function test_instance_call_method(): void { $this->assertEquals( $return_value, $result ); } + + /** + * @covers ::should_use_transients + */ + public function test_should_use_transients_bluehost_cloud(): void { + + $test_transient_name = uniqid( __FUNCTION__ ); + + \WP_Mock::userFunction( 'get_dropins' ) + ->once() + ->andReturn( array() ); + + \WP_Mock::userFunction( 'set_transient' ) + ->once() + ->with( $test_transient_name, 'value', 999 ) + ->andReturnTrue(); + + \WP_Mock::userFunction( 'update_option' ) + ->never(); + + \NewfoldLabs\WP\Context\setContext( 'platform', 'atomic' ); + + Transient::set( $test_transient_name, 'value', 999 ); + + $this->assertConditionsMet(); + + } }