feat: add sync context and operation state
This commit is contained in:
@@ -51,6 +51,18 @@ if ( ! function_exists( 'sanitize_text_field' ) ) {
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'sanitize_key' ) ) {
|
||||
/**
|
||||
* Minimal WordPress-compatible key sanitizer for unit tests.
|
||||
*
|
||||
* @param mixed $key Key to sanitize.
|
||||
* @return string
|
||||
*/
|
||||
function sanitize_key( $key ) {
|
||||
return strtolower( preg_replace( '/[^a-zA-Z0-9_\-]/', '', (string) $key ) );
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wp_strip_all_tags' ) ) {
|
||||
/**
|
||||
* Minimal tag stripper for unit tests.
|
||||
@@ -223,6 +235,36 @@ if ( ! function_exists( 'delete_transient' ) ) {
|
||||
*/
|
||||
function delete_transient( $name ) {
|
||||
unset( $GLOBALS['wpcs_test_transients'][ $name ] );
|
||||
unset( $GLOBALS['wpcs_test_transient_expiration'][ $name ] );
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'get_transient' ) ) {
|
||||
/**
|
||||
* Minimal WordPress transient reader for unit tests.
|
||||
*
|
||||
* @param string $name Transient name.
|
||||
* @return mixed
|
||||
*/
|
||||
function get_transient( $name ) {
|
||||
return $GLOBALS['wpcs_test_transients'][ $name ] ?? false;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'set_transient' ) ) {
|
||||
/**
|
||||
* Minimal WordPress transient writer for unit tests.
|
||||
*
|
||||
* @param string $name Transient name.
|
||||
* @param mixed $value Transient value.
|
||||
* @param int $expiration Expiration in seconds.
|
||||
* @return bool
|
||||
*/
|
||||
function set_transient( $name, $value, $expiration = 0 ) {
|
||||
$GLOBALS['wpcs_test_transients'][ $name ] = $value;
|
||||
$GLOBALS['wpcs_test_transient_expiration'][ $name ] = $expiration;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user