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
58 lines
1.9 KiB
PHP
58 lines
1.9 KiB
PHP
<?php
|
||
|
||
/**
|
||
* Checks the curated short form against the live Divi catalog: every module exists, every
|
||
* field path is a known attribute path, every item type is an allowed child.
|
||
* Usage (DDEV, WordPress root): wp eval-file wp-content/plugins/WP-LIT-MCP/tests/Integration/divi-shortform-check.php
|
||
* No `declare(strict_types=1);` – wp eval-file runs the file through eval().
|
||
*/
|
||
|
||
defined('WP_CLI') && WP_CLI || exit;
|
||
|
||
use LIT\MCP\Integrations\Divi\Schema\DiviModules;
|
||
use LIT\MCP\Integrations\Divi\Schema\ModuleCatalog;
|
||
use LIT\MCP\Integrations\Divi\Schema\ShortformMap;
|
||
|
||
if (! DiviModules::isAvailable()) {
|
||
WP_CLI::error('Divi 5 is not active.');
|
||
}
|
||
|
||
$started = microtime(true);
|
||
$catalog = (new DiviModules())->catalog();
|
||
$problems = [];
|
||
foreach (ShortformMap::types() as $type) {
|
||
$name = ModuleCatalog::normalize($type);
|
||
if (! $catalog->has($name)) {
|
||
$problems[] = $name . ': unknown module';
|
||
continue;
|
||
}
|
||
|
||
foreach (ShortformMap::fields($type) as $field => $spec) {
|
||
if (! $catalog->isKnownPath($name, (string) $spec['path'])) {
|
||
$problems[] = sprintf(
|
||
'%s.%s: unknown path %s (closest: %s)',
|
||
$type,
|
||
$field,
|
||
$spec['path'],
|
||
implode(', ', $catalog->suggestions($name, (string) $spec['path']))
|
||
);
|
||
}
|
||
}
|
||
|
||
$child = ShortformMap::childType($type);
|
||
if ($child !== null && ! in_array(ModuleCatalog::normalize($child), $catalog->childrenOf($name), true)) {
|
||
$problems[] = sprintf('%s: %s is no allowed child (%s)', $type, $child, implode(', ', $catalog->childrenOf($name)));
|
||
}
|
||
}
|
||
|
||
if ($problems !== []) {
|
||
WP_CLI::error("Short form does not match the catalog:\n" . implode("\n", $problems));
|
||
}
|
||
|
||
WP_CLI::success(sprintf(
|
||
'%d short-form modules match the catalog of %d modules (%.0f ms).',
|
||
count(ShortformMap::types()),
|
||
count($catalog->names()),
|
||
(microtime(true) - $started) * 1000
|
||
));
|