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>
87 lines
3.6 KiB
PHP
87 lines
3.6 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace LIT\MCP\Tests\Unit\Integrations\FastestCache;
|
|
|
|
use Brain\Monkey\Functions;
|
|
use LIT\MCP\Admin\CompatibilityTab;
|
|
use LIT\MCP\Compatibility\ProvidesCompatibility;
|
|
use LIT\MCP\Integrations\Bootable;
|
|
use LIT\MCP\Integrations\Integration;
|
|
use LIT\MCP\Integrations\FastestCache\FastestCacheCompatibility;
|
|
use LIT\MCP\Integrations\FastestCache\FastestCacheIntegration;
|
|
use LIT\MCP\Integrations\FastestCache\FastestCachePurger;
|
|
use LIT\MCP\Tests\Support\FakeChangeLog;
|
|
use LIT\MCP\Tests\Unit\TestCase;
|
|
|
|
final class FastestCacheIntegrationTest extends TestCase
|
|
{
|
|
private static function purger(): FastestCachePurger
|
|
{
|
|
return new FastestCachePurger(static fn (): bool => true);
|
|
}
|
|
|
|
public function testIsAnIntegrationThatProvidesItsProfileAndTheCacheClearTool(): void
|
|
{
|
|
$integration = new FastestCacheIntegration(null, self::purger(), FakeChangeLog::forbidden());
|
|
|
|
self::assertInstanceOf(Integration::class, $integration);
|
|
self::assertInstanceOf(ProvidesCompatibility::class, $integration);
|
|
self::assertSame('wpfc', $integration->id());
|
|
self::assertSame('WP Fastest Cache', $integration->label());
|
|
self::assertEquals(['lit/cache-clear'], array_map(static fn ($a): string => $a->name(), $integration->abilities()));
|
|
self::assertEquals([FastestCacheCompatibility::profile()], $integration->compatibilities());
|
|
}
|
|
|
|
/**
|
|
* The same constant the profile's active() reads: WP Fastest Cache defines it when its plugin file loads.
|
|
*
|
|
* @runInSeparateProcess
|
|
* @preserveGlobalState disabled
|
|
*/
|
|
public function testIsAvailableOnlyWithFastestCache(): void
|
|
{
|
|
$integration = new FastestCacheIntegration(null, self::purger(), FakeChangeLog::forbidden());
|
|
self::assertFalse($integration->isAvailable());
|
|
|
|
define('WPFC_MAIN_PATH', '/plugins/wp-fastest-cache/');
|
|
self::assertTrue($integration->isAvailable());
|
|
self::assertTrue((FastestCacheCompatibility::profile()->active)());
|
|
}
|
|
|
|
public function testBootHooksTheOrphanCleanupIntoTheProfileLoad(): void
|
|
{
|
|
$integration = new FastestCacheIntegration(null, self::purger(), FakeChangeLog::forbidden());
|
|
$integration->boot();
|
|
|
|
self::assertInstanceOf(Bootable::class, $integration);
|
|
self::assertNotFalse(has_action(CompatibilityTab::LOAD_ACTION, [$integration, 'removeOrphans']));
|
|
}
|
|
|
|
public function testNoCleanupForAnotherProfileWithoutWpscOrWithoutTheCapability(): void
|
|
{
|
|
Functions\expect('get_posts')->never();
|
|
Functions\when('current_user_can')->justReturn(true);
|
|
(new FastestCacheIntegration(static fn (): bool => true, self::purger(), FakeChangeLog::forbidden()))->removeOrphans('pods');
|
|
(new FastestCacheIntegration(static fn (): bool => false, self::purger(), FakeChangeLog::forbidden()))->removeOrphans('wpfc');
|
|
|
|
Functions\when('current_user_can')->justReturn(false);
|
|
(new FastestCacheIntegration(static fn (): bool => true, self::purger(), FakeChangeLog::forbidden()))->removeOrphans('wpfc');
|
|
$this->addToAssertionCount(1);
|
|
}
|
|
|
|
public function testCleansUpPagesForTheAdministratorWithWpsc(): void
|
|
{
|
|
Functions\when('current_user_can')->justReturn(true);
|
|
Functions\expect('get_posts')->once()->andReturnUsing(static function (array $args): array {
|
|
self::assertSame('page', $args['post_type']);
|
|
self::assertSame(['draft', 'private'], $args['post_status']);
|
|
|
|
return [];
|
|
});
|
|
|
|
(new FastestCacheIntegration(static fn (): bool => true, self::purger(), FakeChangeLog::forbidden()))->removeOrphans('wpfc');
|
|
}
|
|
}
|