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')); } }