refactor: Divi-Boot-Schritte in DiviIntegration::boot() (Bootable) – Upgrader-Hook, Prüf-Route, CLI und Reiter „Divi“ über lit_mcp_admin_tabs; IntegrationRegistry::boot() bootet jede Integration genau einmal; Prüfseiten-Aufräumen im load-Hook statt beim Rendern

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Jan-Niclas Loosen
2026-10-18 21:53:04 +02:00
co-authored by Claude Opus 5.5
parent 06148fb8c1
commit 6c59934caa
10 changed files with 293 additions and 37 deletions
@@ -4,14 +4,21 @@ declare(strict_types=1);
namespace LIT\MCP\Tests\Unit\Integrations\Divi;
use Brain\Monkey\Actions;
use Brain\Monkey\Filters;
use Brain\Monkey\Functions;
use LIT\MCP\Abilities\Ability;
use LIT\MCP\Admin\AdminTab;
use LIT\MCP\Admin\DiviTab;
use LIT\MCP\Admin\SettingsPage;
use LIT\MCP\Integrations\Core\EnvironmentComponent;
use LIT\MCP\Integrations\Divi\DiviBuilderDetector;
use LIT\MCP\Integrations\Divi\DiviEnvironmentComponent;
use LIT\MCP\Integrations\Divi\DiviIntegration;
use LIT\MCP\Integrations\Divi\DiviLogoUsage;
use LIT\MCP\Integrations\Divi\Pages\DiviContentComposer;
use LIT\MCP\Integrations\Divi\Release\DiviCheckRoute;
use LIT\MCP\Integrations\Divi\Release\ReleaseResolver;
use LIT\MCP\Integrations\Media\MediaUsageSource;
use LIT\MCP\Integrations\WordPress\BuilderDetector;
use LIT\MCP\Integrations\WordPress\Schema\ContentSchema;
@@ -251,4 +258,36 @@ final class DiviIntegrationTest extends TestCase
self::assertSame(1, $asked);
self::assertFalse((new DiviIntegration($schema, FakeChangeLog::forbidden()))->libraryIdsVisible());
}
/** Bootable: Divi's own hooks – upgrader cache reset, check route, tab "Divi" after the plugin's tabs. */
public function testBootRegistersDivisOwnHooks(): void
{
$upgraded = null;
$tabs = null;
Actions\expectAdded('upgrader_process_complete')->once()->whenHappen(
static function (callable $callback) use (&$upgraded): void {
$upgraded = $callback;
}
);
Actions\expectAdded('rest_api_init')->once()->with(Mockery::on(
static fn (array $callback): bool => $callback[0] instanceof DiviCheckRoute
));
Filters\expectAdded(SettingsPage::TABS_FILTER)->once()->whenHappen(
static function (callable $callback) use (&$tabs): void {
$tabs = $callback;
}
);
Functions\expect('delete_transient')->once()->with(ReleaseResolver::CACHE)->andReturn(true);
$base = Mockery::mock(AdminTab::class);
(new DiviIntegration(Mockery::mock(ContentSchema::class), FakeChangeLog::forbidden()))->boot();
self::assertIsCallable($upgraded);
$upgraded();
self::assertIsCallable($tabs);
$all = $tabs([$base]);
self::assertCount(2, $all);
self::assertSame($base, $all[0]);
self::assertInstanceOf(DiviTab::class, $all[1]);
}
}
@@ -6,6 +6,7 @@ namespace LIT\MCP\Tests\Unit\Integrations;
use Brain\Monkey\Functions;
use LIT\MCP\Abilities\Ability;
use LIT\MCP\Integrations\Bootable;
use LIT\MCP\Integrations\Core\CoreIntegration;
use LIT\MCP\Integrations\Divi\DiviIntegration;
use LIT\MCP\Integrations\Integration;
@@ -79,6 +80,33 @@ final class IntegrationRegistryTest extends TestCase
self::assertSame('Divi', (new DiviIntegration($schema, FakeChangeLog::forbidden()))->label());
}
/** Integration-owned boot steps run once each, in registry order, whether or not the integration is available. */
public function testBootsEveryBootableIntegrationOnce(): void
{
$booted = [];
$bootable = function (string $id, bool $available) use (&$booted): Integration {
$integration = Mockery::mock(Integration::class . ', ' . Bootable::class);
$integration->allows('id')->andReturn($id);
$integration->allows('isAvailable')->andReturn($available);
$integration->expects('abilities')->never();
$integration->expects('boot')->once()->andReturnUsing(static function () use (&$booted, $id): void {
$booted[] = $id;
});
return $integration;
};
$registry = new IntegrationRegistry(
$this->integration('core', true, []),
$bootable('divi', false),
$bootable('pods', true)
);
$registry->boot();
$registry->boot();
self::assertSame(['divi', 'pods'], $booted);
}
private function ability(string $name, bool $direct): Ability
{
$ability = Mockery::mock(Ability::class);