SuperCacheProbe prüft beim Prüfen, ob wp_cache_post_edit die Cache-Datei einer Testseite entfernt; während der Probe ist nur der Einzelseiten-Purge erlaubt, der Pfad kommt aus home und es werden nur feste Dateinamen gelöscht. ProbeStep bündelt die Schrittlogik von Pods und WP Super Cache; ThrowawayPost hält Marker und Titel zentral und räumt auch private Probe-Seiten auf (WP Super Cache wie Pods beim Laden des Reiters). super-cache-smoke.sh prüft gegen das echte Plugin; lib.sh sperrt parallele Smoke-Läufe per flock, wp-config.php wird atomar wiederhergestellt. Doku: Host-Abhängigkeit des Einzel-Purges, WP-Cron für den Nachlauf, Komplett-Purge durch Divi beim Prüfen. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
122 lines
4.5 KiB
PHP
122 lines
4.5 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace LIT\MCP\Tests\Unit\Integrations\SuperCache;
|
|
|
|
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\SuperCache\SuperCacheCheckSteps;
|
|
use LIT\MCP\Integrations\SuperCache\SuperCacheCompatibility;
|
|
use LIT\MCP\Integrations\SuperCache\SuperCacheFeature;
|
|
use LIT\MCP\Tests\Unit\TestCase;
|
|
|
|
final class SuperCacheCompatibilityTest extends TestCase
|
|
{
|
|
public function testDescribesSuperCacheAsALockOnFailurePlugin(): void
|
|
{
|
|
$profile = SuperCacheCompatibility::profile();
|
|
|
|
self::assertSame('wpsc', $profile->id);
|
|
self::assertSame('WP Super Cache', $profile->label);
|
|
self::assertSame(Tier::LockOnFailure, $profile->tier);
|
|
self::assertSame(['3.1.5'], $profile->testedVersions);
|
|
self::assertNull($profile->minVersion);
|
|
self::assertSame(SuperCacheFeature::cases(), $profile->capabilities);
|
|
}
|
|
|
|
/** Argument counts are those the listener passes; wp_cache_clear_cache($blog_id = 0) gets the blog. */
|
|
public function testTheManifestHoldsTheTwoPurgeFunctionsWithTheirArgumentCounts(): void
|
|
{
|
|
$manifest = SuperCacheCompatibility::profile()->manifests[0];
|
|
$calls = [];
|
|
foreach ($manifest->calls as $call) {
|
|
$calls[$call->symbol] = [$call->args, $call->features()];
|
|
}
|
|
|
|
self::assertSame([
|
|
'wp_cache_post_edit' => [1, [SuperCacheFeature::PurgePost]],
|
|
'wp_cache_clear_cache' => [1, [SuperCacheFeature::PurgeAll]],
|
|
], $calls);
|
|
self::assertContainsOnlyInstancesOf(Call::class, $manifest->calls);
|
|
}
|
|
|
|
/** Both purge functions read $cache_path; wp_cache_post_edit also $blog_cache_dir. */
|
|
public function testTheGlobalsTheFunctionsReadAreRequired(): void
|
|
{
|
|
$manifest = SuperCacheCompatibility::profile()->manifests[0];
|
|
|
|
self::assertSame(['WPCACHEHOME'], array_map(static fn ($c) => $c->name, $manifest->constants));
|
|
$globals = [];
|
|
foreach ($manifest->globals as $global) {
|
|
$globals[$global->name] = $global->features();
|
|
}
|
|
self::assertSame(
|
|
['cache_path' => SuperCacheFeature::cases(), 'blog_cache_dir' => [SuperCacheFeature::PurgePost]],
|
|
$globals
|
|
);
|
|
}
|
|
|
|
/**
|
|
* @runInSeparateProcess
|
|
* @preserveGlobalState disabled
|
|
*/
|
|
public function testActiveAndVersionFollowTheCacheHomeConstantAndThePluginHeader(): void
|
|
{
|
|
$profile = SuperCacheCompatibility::profile();
|
|
self::assertFalse(($profile->active)());
|
|
self::assertNull(($profile->version)());
|
|
|
|
define('WPCACHEHOME', '/plugins/wp-super-cache/');
|
|
Functions\expect('get_file_data')
|
|
->once()
|
|
->with('/plugins/wp-super-cache/wp-cache.php', ['Version' => 'Version'])
|
|
->andReturn(['Version' => '3.1.5']);
|
|
|
|
self::assertTrue(($profile->active)());
|
|
self::assertSame('3.1.5', ($profile->version)());
|
|
}
|
|
|
|
/**
|
|
* @runInSeparateProcess
|
|
* @preserveGlobalState disabled
|
|
*/
|
|
public function testAnUnreadableHeaderIsAnUnknownVersion(): void
|
|
{
|
|
define('WPCACHEHOME', '/plugins/wp-super-cache/');
|
|
Functions\when('get_file_data')->justReturn(['Version' => '']);
|
|
|
|
self::assertNull((SuperCacheCompatibility::profile()->version)());
|
|
}
|
|
|
|
public function testTheCheckHasTheProbeAsExtraStep(): void
|
|
{
|
|
$profile = SuperCacheCompatibility::profile();
|
|
|
|
self::assertNotNull($profile->extraSteps);
|
|
$steps = ($profile->extraSteps)(false);
|
|
self::assertSame([SuperCacheCheckSteps::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(SuperCacheCheckSteps::PROBE, []))
|
|
);
|
|
}
|
|
|
|
public function testAllProfilesCoexistWithoutIdCollision(): void
|
|
{
|
|
$compatibility = new Compatibility(
|
|
[DiviProfile::profile(), PodsCompatibility::profile(), SuperCacheCompatibility::profile()]
|
|
);
|
|
|
|
self::assertSame(['divi', 'pods', 'wpsc'], array_map(static fn ($p) => $p->id, $compatibility->profiles()));
|
|
self::assertSame(SuperCacheFeature::PurgeAll, $compatibility->capability('wpsc-purge-all'));
|
|
}
|
|
}
|