feat: Divi module catalog, attribute paths, short form and lit/divi-catalog

Adds per-path attribute kind (text/richtext/code/url/image/color/enum/
onoff/number/list/icon), derived from Divi's field component metadata
where an attribute path names one unambiguously (module.paths() itself
is unchanged; kinds() is a new, separate lookup exposed as path_kinds
on lit/divi-catalog's module detail). This is not in the task-4 brief;
it is added because 2b's sanitization routing (ruling R3) needs a
metadata-derived field kind per attribute path. Verified live against
the full 100-module catalog (564/4358 paths resolve a kind; the rest
default to "unknown" and fall back to 2b's key-name routing).

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01At3V6SjwbMe6eMzVGW3Hs7
This commit is contained in:
2026-09-26 11:48:27 +02:00
co-authored by Claude Opus 5.5
parent 08d70abfc7
commit 2f4dcf9ce4
14 changed files with 5227 additions and 2 deletions
@@ -0,0 +1,70 @@
<?php
declare(strict_types=1);
namespace LIT\MCP\Tests\Unit\Integrations\Divi\Schema;
use Brain\Monkey\Functions;
use LIT\MCP\Integrations\Divi\Schema\DiviCatalogAbility;
use LIT\MCP\Integrations\Divi\Schema\DiviModules;
use LIT\MCP\Tests\Unit\TestCase;
use Mockery;
final class DiviCatalogAbilityTest extends TestCase
{
private function ability(): DiviCatalogAbility
{
$modules = Mockery::mock(DiviModules::class);
$modules->allows('catalog')->andReturn(ModuleCatalogTest::sampleCatalog());
return new DiviCatalogAbility($modules);
}
public function testListsModulesWithShortformFlag(): void
{
$result = $this->ability()->execute([]);
$button = array_values(array_filter($result['modules'], static fn (array $m): bool => $m['name'] === 'divi/button'));
self::assertSame(
[['name' => 'divi/button', 'title' => 'Button', 'category' => 'module', 'children' => [], 'shortform' => true]],
$button
);
$header = array_values(array_filter(
$result['modules'],
static fn (array $m): bool => $m['name'] === 'divi/fullwidth-header'
));
self::assertFalse($header[0]['shortform']);
self::assertSame(DiviCatalogAbility::CODE_NOTE, $result['notes'][0]);
}
public function testDetailOfOneModule(): void
{
$result = $this->ability()->execute(['module' => 'Accordion']);
self::assertSame('divi/accordion', $result['module']['name']);
self::assertSame(['divi/accordion-item'], $result['module']['children']);
self::assertSame('accordion-item', $result['module']['item_type']);
self::assertContains('title.decoration.font.font', $result['module']['paths']);
$button = $this->ability()->execute(['module' => 'divi/button'])['module'];
self::assertSame('linkUrl', $button['shortform']['url']['sub']);
}
public function testDetailExposesTheAttributePathKindsForSanitizationRouting(): void
{
$button = $this->ability()->execute(['module' => 'divi/button'])['module'];
self::assertSame('url', $button['path_kinds']['button.innerContent']);
self::assertArrayNotHasKey('no.such.path', $button['path_kinds']);
}
public function testUnknownModuleAndPermission(): void
{
self::assertSame('lit_not_found', $this->ability()->execute(['module' => 'slider-pro'])->get_error_code());
Functions\when('current_user_can')->justReturn(false);
self::assertSame('lit_forbidden', $this->ability()->permission([])->get_error_code());
self::assertTrue($this->ability()->annotations()['readonly']);
self::assertTrue($this->ability()->isDirect());
}
}