Files
WP-LIT-MCP/tests/Unit/Integrations/FastestCache/FastestCacheCompatibilityTest.php
Jan-Niclas LoosenandClaude Opus 5.5 bee9da3a86 feat(cache): WP Fastest Cache statt WP Super Cache
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>
2026-11-06 19:57:55 +01:00

137 lines
5.5 KiB
PHP

<?php
declare(strict_types=1);
namespace LIT\MCP\Tests\Unit\Integrations\FastestCache;
use Brain\Monkey\Functions;
use LIT\MCP\Compatibility\Call;
use LIT\MCP\Compatibility\CheckStep;
use LIT\MCP\Compatibility\Compatibility;
use LIT\MCP\Compatibility\Tier;
use LIT\MCP\Integrations\Divi\Release\DiviProfile;
use LIT\MCP\Integrations\Pods\PodsCompatibility;
use LIT\MCP\Integrations\FastestCache\FastestCacheCheckSteps;
use LIT\MCP\Integrations\FastestCache\FastestCacheCompatibility;
use LIT\MCP\Integrations\FastestCache\FastestCacheFeature;
use LIT\MCP\Tests\Unit\TestCase;
final class FastestCacheCompatibilityTest extends TestCase
{
public function testDescribesFastestCacheAsALockOnFailurePlugin(): void
{
$profile = FastestCacheCompatibility::profile();
self::assertSame('wpfc', $profile->id);
self::assertSame('WP Fastest Cache', $profile->label);
self::assertSame(Tier::LockOnFailure, $profile->tier);
self::assertSame(['1.5.5'], $profile->testedVersions);
self::assertNull($profile->minVersion);
self::assertSame(FastestCacheFeature::cases(), $profile->capabilities);
}
/** Argument counts are those the purger and the probe pass. */
public function testTheManifestHoldsTheTwoPurgeFunctionsWithTheirArgumentCounts(): void
{
$manifest = FastestCacheCompatibility::profile()->manifests[0];
$calls = [];
foreach ($manifest->calls as $call) {
$calls[$call->symbol] = [$call->args, $call->features()];
}
self::assertSame([
'wpfc_clear_post_cache_by_id' => [1, [FastestCacheFeature::PurgePost]],
'wpfc_clear_all_cache' => [0, [FastestCacheFeature::PurgeAll]],
'WpFastestCache::singleDeleteCache' => [3, [FastestCacheFeature::PurgePost]],
'WpFastestCache::getWpContentDir' => [1, [FastestCacheFeature::PurgePost]],
], $calls);
self::assertContainsOnlyInstancesOf(Call::class, $manifest->calls);
}
/** The instance that hooks the purge actions and the decoded options with the cache switch. */
public function testTheGlobalsTheFunctionsReadAreRequired(): void
{
$manifest = FastestCacheCompatibility::profile()->manifests[0];
self::assertSame(['WPFC_MAIN_PATH'], array_map(static fn ($c) => $c->name, $manifest->constants));
$globals = [];
foreach ($manifest->globals as $global) {
$globals[$global->name] = $global->features();
}
self::assertSame(
['wp_fastest_cache' => FastestCacheFeature::cases(), 'wp_fastest_cache_options' => FastestCacheFeature::cases()],
$globals
);
}
/**
* @runInSeparateProcess
* @preserveGlobalState disabled
*/
public function testActiveAndVersionFollowTheMainPathConstantAndThePluginHeader(): void
{
$profile = FastestCacheCompatibility::profile();
self::assertFalse(($profile->active)());
self::assertNull(($profile->version)());
define('WPFC_MAIN_PATH', '/plugins/wp-fastest-cache/');
Functions\expect('get_file_data')
->once()
->with('/plugins/wp-fastest-cache/wpFastestCache.php', ['Version' => 'Version'])
->andReturn(['Version' => '1.5.5']);
self::assertTrue(($profile->active)());
self::assertSame('1.5.5', ($profile->version)());
}
/**
* @runInSeparateProcess
* @preserveGlobalState disabled
*/
public function testAnUnreadableHeaderIsAnUnknownVersion(): void
{
define('WPFC_MAIN_PATH', '/plugins/wp-fastest-cache/');
Functions\when('get_file_data')->justReturn(['Version' => '']);
self::assertNull((FastestCacheCompatibility::profile()->version)());
}
public function testTheCheckHasTheProbeAsExtraStep(): void
{
$profile = FastestCacheCompatibility::profile();
self::assertNotNull($profile->extraSteps);
$steps = ($profile->extraSteps)(false);
self::assertSame([FastestCacheCheckSteps::PROBE], array_map(static fn ($step): string => $step->key, $steps));
self::assertTrue($steps[0]->skipped);
self::assertNotNull($profile->stepLabel);
self::assertSame(
'Leeren-Test an einer Wegwerf-Seite im Cache',
($profile->stepLabel)(new CheckStep(FastestCacheCheckSteps::PROBE, []))
);
}
public function testTheCacheIsOnlyEnabledWhileTheSwitchInTheDecodedOptionsIsOn(): void
{
unset($GLOBALS['wp_fastest_cache_options']);
self::assertFalse(FastestCacheCompatibility::cacheEnabled());
$GLOBALS['wp_fastest_cache_options'] = [];
self::assertFalse(FastestCacheCompatibility::cacheEnabled(), 'WPFC stores [] when the option is missing');
$GLOBALS['wp_fastest_cache_options'] = (object) ['wpFastestCacheMinifyHtml' => 'on'];
self::assertFalse(FastestCacheCompatibility::cacheEnabled());
$GLOBALS['wp_fastest_cache_options'] = (object) ['wpFastestCacheStatus' => 'on'];
self::assertTrue(FastestCacheCompatibility::cacheEnabled());
unset($GLOBALS['wp_fastest_cache_options']);
}
public function testAllProfilesCoexistWithoutIdCollision(): void
{
$compatibility = new Compatibility(
[DiviProfile::profile(), PodsCompatibility::profile(), FastestCacheCompatibility::profile()]
);
self::assertSame(['divi', 'pods', 'wpfc'], array_map(static fn ($p) => $p->id, $compatibility->profiles()));
self::assertSame(FastestCacheFeature::PurgeAll, $compatibility->capability('wpfc-purge-all'));
}
}