refactor: Theme Builder adapter manifest with three mirrors

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-09-30 01:25:39 +02:00
co-authored by Claude Opus 5.5
parent e972898f52
commit 7fc41bc2ac
7 changed files with 108 additions and 46 deletions
@@ -26,7 +26,6 @@ final class DiviBoundaryTest extends TestCase
private const LEGACY = [
'Integrations/Divi/Design/DesignSystemReader.php',
'Integrations/Divi/DiviCompatibility.php',
'Integrations/Divi/ThemeBuilder/DiviThemeBuilder.php',
'Integrations/Media/MediaUsageFinder.php',
];
@@ -7,6 +7,9 @@ namespace LIT\MCP\Tests\Unit\Integrations\Divi\ThemeBuilder;
use Brain\Monkey\Actions;
use Brain\Monkey\Filters;
use Brain\Monkey\Functions;
use LIT\MCP\Integrations\Divi\Release\Call;
use LIT\MCP\Integrations\Divi\Release\DiviAdapters;
use LIT\MCP\Integrations\Divi\Release\Manifest;
use LIT\MCP\Integrations\Divi\ThemeBuilder\DiviThemeBuilder;
use LIT\MCP\Integrations\Divi\ThemeBuilder\InsertedBeforeFailure;
use LIT\MCP\Tests\Unit\TestCase;
@@ -17,6 +20,23 @@ use WP_Post;
final class DiviThemeBuilderTest extends TestCase
{
public function testIsTheRegisteredThemeBuilderAdapterWithItsMirrors(): void
{
$manifest = DiviThemeBuilder::manifest();
self::assertContains(DiviThemeBuilder::class, DiviAdapters::CLASSES);
self::assertSame(Manifest::THEME_BUILDER, $manifest->area);
self::assertSame(DiviThemeBuilder::postTypes(), $manifest->postTypes);
self::assertSame(
['tb-api-save', 'tb-store-template', 'tb-load-setting-options'],
array_map(static fn ($mirror): string => $mirror->id, $manifest->mirrors)
);
self::assertContains('et_theme_builder_store_template()', array_map(
static fn (Call $call): string => $call->label(),
$manifest->calls
));
}
public function testAreaOfTheLayoutTypes(): void
{
self::assertSame('header', DiviThemeBuilder::areaOf('et_header_layout'));
@@ -383,26 +403,28 @@ final class DiviThemeBuilderTest extends TestCase
(new DiviThemeBuilder())->insertLayout('sidebar', 'Seite');
}
/** E15: a Divi function that moved is reported, never called (no fatal error mid-write). */
/**
* E15: a Divi function that moved is reported, never called (no fatal error mid-write). Own process:
* no other test may have stubbed these names yet, or function_exists() would report them as present
* for the rest of the run (Brain Monkey defines a stubbed function process-wide).
*
* @runInSeparateProcess
*/
public function testMissingDiviFunctionsAreRefusedBeforeWriting(): void
{
Functions\when('current_user_can')->justReturn(true);
Functions\expect('et_theme_builder_insert_layout')->never();
Functions\expect('et_theme_builder_store_template')->never();
$store = Mockery::mock(DiviThemeBuilder::class)->makePartial();
$store->allows('missing')->andReturn(['et_theme_builder_insert_layout', 'et_']);
foreach ([
static fn () => $store->insertLayout('body', 'Person – Inhalt'),
static fn () => $store->storeTemplate(1064, [
static fn (DiviThemeBuilder $store) => $store->insertLayout('body', 'Person – Inhalt'),
static fn (DiviThemeBuilder $store) => $store->storeTemplate(1064, [
'title' => 'Person', 'layouts' => [], 'use_on' => [], 'exclude_from' => [],
]),
] as $call) {
try {
$call();
$call(new DiviThemeBuilder());
self::fail('Divi was called although it is missing');
} catch (RuntimeException $e) {
self::assertStringContainsString('missing', $e->getMessage());
self::assertStringContainsString('Divi function missing', $e->getMessage());
}
}
}