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