feature: Add reset-cache action to settings page

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.
This commit is contained in:
Keith Solomon
2026-08-24 11:05:16 -05:00
parent 0a6cf92146
commit 7887f7d9ce
3 changed files with 188 additions and 0 deletions
+42
View File
@@ -7,6 +7,9 @@
use PHPUnit\Framework\TestCase;
require_once dirname( __DIR__ ) . '/src/Scheduler.php';
require_once dirname( __DIR__ ) . '/src/Admin/Settings.php';
/**
* Verifies project-level invariants without loading WordPress.
*/
@@ -133,4 +136,43 @@ final class SmokeTest extends TestCase {
'fingerprint' => str_repeat( 'b', 64 ),
);
}
/**
* Verify that clear_feed_cache deletes the SimplePie feed-cache option
* rows, the importer's per-feed lock, and the multisite site-transient
* variants derived from the configured feed URL.
*/
public function test_clear_feed_cache_removes_lock_and_simplepie_transient_keys(): void {
rss2cpt_test_reset_delete_logs();
$importer = new RSS2CPT\Import\Importer();
$settings = new RSS2CPT\Admin\Settings( $importer, new RSS2CPT\Scheduler( $importer ) );
$cleared = $settings->clear_feed_cache( 'https://example.test/feed.xml', 'podcast_episode' );
$this->assertTrue( $cleared );
$this->assertContains( '_transient_feed_' . md5( 'https://example.test/feed.xml' ), $GLOBALS['rss2cpt_test_deleted_options'] );
$this->assertContains( '_transient_timeout_feed_' . md5( 'https://example.test/feed.xml' ), $GLOBALS['rss2cpt_test_deleted_options'] );
$this->assertContains( '_transient_feed_mod_' . md5( 'https://example.test/feed.xml' ), $GLOBALS['rss2cpt_test_deleted_options'] );
$this->assertContains( '_transient_timeout_feed_mod_' . md5( 'https://example.test/feed.xml' ), $GLOBALS['rss2cpt_test_deleted_options'] );
$this->assertContains( 'rss2cpt_lock_' . md5( 'https://example.test/feed.xml|podcast_episode' ), $GLOBALS['rss2cpt_test_deleted_options'] );
$this->assertContains( 'feed_' . md5( 'https://example.test/feed.xml' ), $GLOBALS['rss2cpt_test_deleted_site_transients'] );
$this->assertContains( 'feed_mod_' . md5( 'https://example.test/feed.xml' ), $GLOBALS['rss2cpt_test_deleted_site_transients'] );
}
/**
* Verify that clear_feed_cache refuses to do anything destructive when
* the feed URL is empty (so an unconfigured install cannot wipe someone
* else's transient rows by accident).
*/
public function test_clear_feed_cache_is_noop_when_feed_url_empty(): void {
rss2cpt_test_reset_delete_logs();
$importer = new RSS2CPT\Import\Importer();
$settings = new RSS2CPT\Admin\Settings( $importer, new RSS2CPT\Scheduler( $importer ) );
$cleared = $settings->clear_feed_cache( '', 'podcast_episode' );
$this->assertFalse( $cleared );
$this->assertSame( array(), $GLOBALS['rss2cpt_test_deleted_options'] );
$this->assertSame( array(), $GLOBALS['rss2cpt_test_deleted_site_transients'] );
}
}