Deactivation now clears the endpoint-check transient and the cached rewrite rules (forcing WordPress to regenerate them without this plugin's routes on the next request) and activation asks mcp-oauth to re-flush its own rules. uninstall.php removes all own options/transient/cron/table across every site of a network, delegating to the new self-contained LIT\MCP\Uninstaller class so it works without the plugin's autoloader and is unit-testable on its own. mcp-oauth's data (JWT secret, rewrite marker, refresh-token meta, application passwords) is left untouched, as is every post/attachment/revision. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01At3V6SjwbMe6eMzVGW3Hs7
70 lines
2.4 KiB
PHP
70 lines
2.4 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace LIT\MCP\Tests\Unit;
|
|
|
|
use Brain\Monkey\Functions;
|
|
use LIT\MCP\Abilities\ExposurePolicy;
|
|
use LIT\MCP\Access;
|
|
use LIT\MCP\Admin\ConnectionStatus;
|
|
use LIT\MCP\ChangeLog\ChangeLogCleanup;
|
|
use LIT\MCP\ChangeLog\ChangeLogInstaller;
|
|
use LIT\MCP\Limits;
|
|
use LIT\MCP\Uninstaller;
|
|
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();
|
|
Functions\expect('delete_transient')->once()->with(ConnectionStatus::ENDPOINT_TRANSIENT);
|
|
Functions\expect('wp_clear_scheduled_hook')->once()->with(ChangeLogCleanup::HOOK);
|
|
$deleted = [];
|
|
Functions\when('delete_option')->alias(static function (string $option) use (&$deleted): bool {
|
|
$deleted[] = $option;
|
|
return true;
|
|
});
|
|
|
|
Uninstaller::run();
|
|
|
|
self::assertSame(
|
|
[Access::OPTION, ExposurePolicy::OPTION, Limits::OPTION, ChangeLogInstaller::VERSION_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();
|
|
Functions\expect('delete_transient')->twice()->with(ConnectionStatus::ENDPOINT_TRANSIENT);
|
|
Functions\expect('wp_clear_scheduled_hook')->twice()->with(ChangeLogCleanup::HOOK);
|
|
Functions\when('delete_option')->justReturn(true);
|
|
|
|
Uninstaller::run();
|
|
}
|
|
}
|