lit/divi-catalog's path_kinds previously named one kind per whole attribute path, built from Divi's metadata component name alone. For a composite path (Divi groups several named sub-fields, "subName", under one path – e.g. buttonOne.innerContent holds "text" and "linkUrl") that was wrong: the whole path got one guessed kind (or none), even though the sub-fields can differ (fullwidth-header's buttonOne/buttonTwo.innerContent -> "text", though it also carries a "linkUrl"; image.innerContent -> "image", though the value also carries alt/id/titleText the metadata never names on its own). AttrPathIndex::kinds() now resolves a composite path to a map subName => kind instead, preferring Divi's features.dynamicContent.type over the (often shared/generic) field component for a named sub-field – this is what tells a button's plain text sub-field apart from its linkUrl sub-field, both of which use the same generic "divi/text" component. A plain (non- composite) path is unaffected. Any subName the metadata never names (or that disagrees between candidates) is therefore simply absent from the map, and ModuleCatalog::pathKind() defaults it, like every unresolved path, to "unknown" - the strictest routing for 2b's sanitizer, never a guess. ModuleCatalog::pathKind() gains an optional $subName parameter to read a composite path's map. docs/guides/divi-attrs.md documents the new shape and that lit-divi-catalog without `module` lists all modules. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
86 lines
3.4 KiB
PHP
86 lines
3.4 KiB
PHP
<?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('text', $button['path_kinds']['module.meta.adminLabel']);
|
|
self::assertArrayNotHasKey('no.such.path', $button['path_kinds']);
|
|
// Composite ("group") paths are left out rather than guessing a single kind.
|
|
self::assertArrayNotHasKey('button.innerContent', $button['path_kinds']);
|
|
}
|
|
|
|
/** A composite path (several named sub-fields under one attribute path) surfaces as a
|
|
* subName => kind map, not a single guessed string (spec §5.6, ruling F1 #1). */
|
|
public function testDetailExposesCompositePathKindsAsASubNameMap(): void
|
|
{
|
|
$header = $this->ability()->execute(['module' => 'divi/fullwidth-header'])['module'];
|
|
|
|
self::assertSame(
|
|
['text' => 'text', 'linkUrl' => 'url'],
|
|
$header['path_kinds']['buttonOne.innerContent']
|
|
);
|
|
self::assertSame(['src' => 'image'], $header['path_kinds']['image.innerContent']);
|
|
}
|
|
|
|
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());
|
|
}
|
|
}
|