Adds a 'Reset cache' button to the Podcast RSS Import settings page that clears the SimplePie feed-cache rows (both the cached XML and the modification timestamp) plus the importer's per-feed import lock for the configured feed. Multisite site-transient variants are also cleared. Use this when the importer is skipping items or refusing to re-fetch a feed that has changed at the source. The next 'Import now' click will re-pull the XML from the network. clear_feed_cache() is exposed as a public method so it is unit-testable, and a do_action hook (rss2cpt_cache_cleared) lets other code react when the cache is cleared. Two smoke tests pin down the expected option and site-transient names, and a third ensures an empty feed URL is a no-op.
103 lines
2.5 KiB
PHP
103 lines
2.5 KiB
PHP
<?php
|
|
/**
|
|
* PHPUnit bootstrap.
|
|
*
|
|
* @package RSS2CPT
|
|
*/
|
|
|
|
define( 'ABSPATH', dirname( __DIR__ ) . '/' );
|
|
define( 'MINUTE_IN_SECONDS', 60 );
|
|
|
|
/**
|
|
* Minimal option stub for isolated settings tests.
|
|
*
|
|
* @param string $option Option name.
|
|
* @param mixed $default_value Default value.
|
|
* @return mixed
|
|
*/
|
|
function get_option( $option, $default_value = false ) {
|
|
unset( $option );
|
|
return $default_value;
|
|
}
|
|
|
|
/**
|
|
* Minimal wp_parse_args stub for isolated settings tests.
|
|
*
|
|
* @param array $args Supplied values.
|
|
* @param array $defaults Default values.
|
|
* @return array
|
|
*/
|
|
function wp_parse_args( $args, $defaults = array() ) {
|
|
return array_merge( $defaults, $args );
|
|
}
|
|
|
|
/**
|
|
* Minimal get_date_from_gmt stub matching WordPress's MySQL-string behavior.
|
|
*
|
|
* @param string $date_string GMT timestamp in MySQL date format.
|
|
* @return string Timestamp converted to the site's local timezone.
|
|
*/
|
|
function get_date_from_gmt( $date_string ) {
|
|
return get_gmt_from_date( $date_string );
|
|
}
|
|
|
|
/**
|
|
* Minimal get_gmt_from_date stub: the inverse of get_date_from_gmt.
|
|
*
|
|
* @param string $date_string Local timestamp in MySQL date format.
|
|
* @return string Timestamp converted to GMT (UTC).
|
|
*/
|
|
function get_gmt_from_date( $date_string ) {
|
|
$timestamp = strtotime( $date_string . ' UTC' );
|
|
if ( false === $timestamp ) {
|
|
return $date_string;
|
|
}
|
|
return gmdate( 'Y-m-d H:i:s', $timestamp );
|
|
}
|
|
|
|
/**
|
|
* In-memory option store for isolated tests.
|
|
*
|
|
* @param string $name Option name.
|
|
* @return bool Always true; the test asserts via $GLOBALS['rss2cpt_test_deleted_options'].
|
|
*/
|
|
function delete_option( $name ) {
|
|
$GLOBALS['rss2cpt_test_deleted_options'][] = $name;
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* In-memory site-transient store for isolated tests.
|
|
*
|
|
* @param string $name Transient name.
|
|
* @return bool Always true; the test asserts via $GLOBALS['rss2cpt_test_deleted_site_transients'].
|
|
*/
|
|
function delete_site_transient( $name ) {
|
|
$GLOBALS['rss2cpt_test_deleted_site_transients'][] = $name;
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* Reset recorded delete_* call logs between tests.
|
|
*
|
|
* @return void
|
|
*/
|
|
function rss2cpt_test_reset_delete_logs() {
|
|
$GLOBALS['rss2cpt_test_deleted_options'] = array();
|
|
$GLOBALS['rss2cpt_test_deleted_site_transients'] = array();
|
|
}
|
|
rss2cpt_test_reset_delete_logs();
|
|
|
|
/**
|
|
* Minimal do_action stub for isolated tests.
|
|
*
|
|
* @param string $hook Hook name.
|
|
* @param mixed ...$args Hook arguments.
|
|
*/
|
|
function do_action( $hook, ...$args ) {
|
|
unset( $hook, $args );
|
|
}
|
|
|
|
require_once dirname( __DIR__ ) . '/src/Options.php';
|
|
require_once dirname( __DIR__ ) . '/src/Import/Importer.php';
|