forked from WordPress/wordpress-develop
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add transient validation methods and corresponding tests
A new function named 'valid_transient' has been introduced to verify if a transient and its value are valid, also by checking if they have not expired. Sites with transient data can use the 'valid_site_transient' function to perform similar checks. Along with these functions, PHPUnit test cases have been added to ensure these functions perform as expected.
- Loading branch information
paul bearne
committed
May 27, 2024
1 parent
43b51f5
commit 014cf5d
Showing
3 changed files
with
175 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
|
||
/** | ||
* @group option | ||
* @group transient | ||
* | ||
* @covers ::valid_transient | ||
*/ | ||
class Tests_Option_ValidTransient extends WP_UnitTestCase { | ||
|
||
/** | ||
* @ticket 37040 | ||
*/ | ||
public function test_valid_transient_with_expired_timeout() { | ||
$transient_name = 'valid_transient_with_expired_timeout'; | ||
$transient_value = 'transient_value'; | ||
|
||
set_transient( $transient_name, $transient_value, 10 ); | ||
|
||
$this->assertTrue( valid_transient( $transient_name ) ); | ||
|
||
update_option( '_transient_timeout_' . $transient_name, time() - 10 ); | ||
|
||
$this->assertFalse( valid_transient( $transient_name ) ); | ||
} | ||
|
||
/** | ||
* @ticket 37040 | ||
*/ | ||
public function test_valid_transient_with_no_timeout() { | ||
$transient_name = 'valid_transient_with_no_timeout'; | ||
$transient_value = 'transient_value'; | ||
|
||
set_transient( $transient_name, $transient_value ); | ||
$this->assertTrue( valid_transient( $transient_name ) ); | ||
} | ||
|
||
/** | ||
* @ticket 37040 | ||
*/ | ||
public function test_valid_transient_with_no_transient() { | ||
$transient_name = 'valid_transient_with_no_transient'; | ||
|
||
$this->assertFalse( valid_transient( $transient_name ) ); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
|
||
/** | ||
* @group option | ||
* @group transient | ||
* | ||
* @covers ::valid_site_transient | ||
*/ | ||
class Tests_Option_ValidSiteTransient extends WP_UnitTestCase { | ||
|
||
/** | ||
* @ticket 37040 | ||
*/ | ||
public function test_valid_site_transient_with_expired_timeout() { | ||
$transient_name = 'valid_site_transient_with_expired_timeout'; | ||
$transient_value = 'transient_value'; | ||
|
||
set_site_transient( $transient_name, $transient_value, 10 ); | ||
|
||
$this->assertTrue( valid_site_transient( $transient_name ) ); | ||
|
||
update_option( '_site_transient_timeout_' . $transient_name, time() - 10 ); | ||
|
||
$this->assertFalse( valid_site_transient( $transient_name ) ); | ||
} | ||
|
||
/** | ||
* @ticket 37040 | ||
*/ | ||
public function test_valid_site_transient_with_no_timeout() { | ||
$transient_name = 'valid_site_transient_with_no_timeout'; | ||
$transient_value = 'transient_value'; | ||
|
||
set_site_transient( $transient_name, $transient_value ); | ||
|
||
$this->assertTrue( valid_site_transient( $transient_name ) ); | ||
} | ||
|
||
/** | ||
* @ticket 37040 | ||
*/ | ||
public function test_valid_site_transient_with_no_transient() { | ||
$transient_name = 'valid_site_transient_with_no_transient'; | ||
|
||
$this->assertFalse( valid_site_transient( $transient_name ) ); | ||
} | ||
|
||
/** | ||
* @ticket 37040 | ||
*/ | ||
public function test_valid_site_transient_with_no_site_transient() { | ||
$transient_name = 'valid_site_transient_with_no_site_transient'; | ||
$transient_value = 'transient_value'; | ||
|
||
set_transient( $transient_name, $transient_value ); | ||
|
||
$this->assertFalse( valid_site_transient( $transient_name ) ); | ||
} | ||
} |