Die Cache-Integration war für WP Super Cache gebaut, eingesetzt wird aber WP Fastest Cache. Profil (wpfc), Listener, Drosselung, lit/cache-clear und Leeren-Probe laufen jetzt über die öffentlichen WPFC-Funktionen wpfc_clear_post_cache_by_id/wpfc_clear_all_cache; die Probe leert nur die Wegwerf-Seite (singleDeleteCache ohne Elternseiten) und prüft, dass WPFC den Hook noch verarbeitet. Smoke fastest-cache-smoke.sh ersetzt den WPSC-Smoke. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
125 lines
5.0 KiB
PHP
125 lines
5.0 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace LIT\MCP\Tests\Unit;
|
|
|
|
use LIT\MCP\Integrations\Divi\Design\DesignLock;
|
|
use Brain\Monkey\Functions;
|
|
use LIT\MCP\Abilities\ExposurePolicy;
|
|
use LIT\MCP\Access;
|
|
use LIT\MCP\Admin\ConnectionStatus;
|
|
use LIT\MCP\Admin\LogTab;
|
|
use LIT\MCP\ChangeLog\ChangeLogCleanup;
|
|
use LIT\MCP\ChangeLog\ChangeLogInstaller;
|
|
use LIT\MCP\Integrations\Divi\Release\ReleaseResolver;
|
|
use LIT\MCP\Integrations\FastestCache\FastestCacheListener;
|
|
use LIT\MCP\Limits;
|
|
use LIT\MCP\Uninstaller;
|
|
use LIT\MCP\Updater\RecheckOnInstall;
|
|
use Mockery;
|
|
|
|
/**
|
|
* Unit tests for the cleanup logic itself (extracted from uninstall.php so it is
|
|
* testable without requiring that top-level script). tests/Unit/UninstallTest.php
|
|
* additionally exercises uninstall.php's wiring to this class.
|
|
*/
|
|
final class UninstallerTest extends TestCase
|
|
{
|
|
protected function tearDown(): void
|
|
{
|
|
unset($GLOBALS['wpdb']);
|
|
parent::tearDown();
|
|
}
|
|
|
|
public function testRunRemovesOwnDataOnceOnASingleSite(): void
|
|
{
|
|
$db = Mockery::mock(\wpdb::class)->makePartial();
|
|
$db->expects('query')->once()->with('DROP TABLE IF EXISTS wp_lit_mcp_log');
|
|
$GLOBALS['wpdb'] = $db;
|
|
Functions\when('is_multisite')->justReturn(false);
|
|
Functions\expect('switch_to_blog')->never();
|
|
Functions\expect('restore_current_blog')->never();
|
|
$transients = [];
|
|
Functions\when('delete_transient')->alias(static function (string $transient) use (&$transients): bool {
|
|
$transients[] = $transient;
|
|
return true;
|
|
});
|
|
$hooks = [];
|
|
Functions\when('wp_clear_scheduled_hook')->alias(static function (string $hook) use (&$hooks): int {
|
|
$hooks[] = $hook;
|
|
return 0;
|
|
});
|
|
// Review m-8: the Protokoll screen option is user meta (network-wide): removed once.
|
|
Functions\expect('delete_metadata')->once()->with('user', 0, LogTab::PER_PAGE_OPTION, '', true);
|
|
$deleted = [];
|
|
Functions\when('delete_option')->alias(static function (string $option) use (&$deleted): bool {
|
|
$deleted[] = $option;
|
|
return true;
|
|
});
|
|
|
|
Uninstaller::run();
|
|
|
|
self::assertSame(
|
|
[ConnectionStatus::ENDPOINT_TRANSIENT, ReleaseResolver::CACHE, FastestCacheListener::PURGED_AT],
|
|
$transients
|
|
);
|
|
self::assertSame([ChangeLogCleanup::HOOK, FastestCacheListener::TRAILING_HOOK], $hooks);
|
|
self::assertSame(
|
|
[
|
|
Access::OPTION, ExposurePolicy::OPTION, Limits::OPTION, ChangeLogInstaller::VERSION_OPTION,
|
|
'lit_mcp_divi_releases', 'lit_mcp_divi_check_report', 'lit_mcp_divi_check_lock',
|
|
'lit_mcp_pods_releases', 'lit_mcp_pods_check_report', 'lit_mcp_pods_check_lock',
|
|
'lit_mcp_wpfc_releases', 'lit_mcp_wpfc_check_report', 'lit_mcp_wpfc_check_lock',
|
|
'lit_mcp_snapshots_colors', 'lit_mcp_snapshots_variables', 'lit_mcp_snapshots_presets',
|
|
'lit_mcp_snapshots_theme_options', 'lit_mcp_snapshots_custom_css',
|
|
DesignLock::option('colors'), DesignLock::option('variables'), DesignLock::option('presets'), DesignLock::option('custom_css'),
|
|
// Locks of versions before the shared one (audit L5) may still sit in the table.
|
|
'lit_mcp_lock_colors', 'lit_mcp_lock_theme_options',
|
|
RecheckOnInstall::OPTION,
|
|
],
|
|
$deleted
|
|
);
|
|
}
|
|
|
|
public function testRunRemovesDataOnEverySiteOfAMultisiteNetwork(): void
|
|
{
|
|
$db = Mockery::mock(\wpdb::class)->makePartial();
|
|
$db->expects('query')->twice()->with('DROP TABLE IF EXISTS wp_lit_mcp_log');
|
|
$GLOBALS['wpdb'] = $db;
|
|
Functions\when('is_multisite')->justReturn(true);
|
|
Functions\when('get_sites')->justReturn([1, 2]);
|
|
Functions\expect('switch_to_blog')->twice();
|
|
Functions\expect('restore_current_blog')->twice();
|
|
$transients = [];
|
|
Functions\when('delete_transient')->alias(static function (string $transient) use (&$transients): bool {
|
|
$transients[] = $transient;
|
|
return true;
|
|
});
|
|
$hooks = [];
|
|
Functions\when('wp_clear_scheduled_hook')->alias(static function (string $hook) use (&$hooks): int {
|
|
$hooks[] = $hook;
|
|
return 0;
|
|
});
|
|
Functions\expect('delete_metadata')->once()->with('user', 0, LogTab::PER_PAGE_OPTION, '', true);
|
|
Functions\when('delete_option')->justReturn(true);
|
|
|
|
Uninstaller::run();
|
|
|
|
self::assertSame(
|
|
[
|
|
ConnectionStatus::ENDPOINT_TRANSIENT, ReleaseResolver::CACHE, FastestCacheListener::PURGED_AT,
|
|
ConnectionStatus::ENDPOINT_TRANSIENT, ReleaseResolver::CACHE, FastestCacheListener::PURGED_AT,
|
|
],
|
|
$transients
|
|
);
|
|
self::assertSame(
|
|
[
|
|
ChangeLogCleanup::HOOK, FastestCacheListener::TRAILING_HOOK,
|
|
ChangeLogCleanup::HOOK, FastestCacheListener::TRAILING_HOOK,
|
|
],
|
|
$hooks
|
|
);
|
|
}
|
|
}
|