A contact-field item whose type is no allowed child now gets a hint that type is the node type, with the attrs path (fieldItem.advanced.type) and the lit-divi-update set alternative, instead of "unbekanntes Modul divi/email". The metadata fixture gains contact-form/contact-field (regenerated from Divi 5.2.1, additions only). Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01At3V6SjwbMe6eMzVGW3Hs7
57 lines
2.2 KiB
PHP
57 lines
2.2 KiB
PHP
<?php
|
||
|
||
/**
|
||
* Writes tests/Fixtures/divi/metadata-sample.json: Divi's own module metadata (name, title,
|
||
* category, children, attribute settings) and default attributes for the modules the unit
|
||
* tests use, so ModuleCatalog is tested against real Divi data without WordPress.
|
||
* Usage (DDEV, WordPress root): wp eval-file wp-content/plugins/WP-LIT-MCP/tests/Integration/divi-metadata-fixture.php
|
||
* No `declare(strict_types=1);` – wp eval-file runs the file through eval().
|
||
*/
|
||
|
||
defined('WP_CLI') && WP_CLI || exit;
|
||
|
||
use ET\Builder\Packages\ModuleLibrary\ModuleRegistration;
|
||
|
||
if (! class_exists(ModuleRegistration::class)) {
|
||
WP_CLI::error('Divi 5 is not active.');
|
||
}
|
||
|
||
$wanted = [
|
||
'section', 'row', 'column', 'text', 'heading', 'button', 'image', 'blurb', 'code', 'accordion',
|
||
'accordion-item', 'fullwidth-header', 'group', 'contact-form', 'contact-field',
|
||
];
|
||
$all = ModuleRegistration::get_all_core_modules_metadata();
|
||
$metadata = [];
|
||
$defaults = [];
|
||
foreach ($wanted as $key) {
|
||
$module = $all[$key] ?? null;
|
||
if (! is_array($module)) {
|
||
WP_CLI::error('Missing module ' . $key);
|
||
}
|
||
|
||
$attributes = [];
|
||
foreach ((array) ($module['attributes'] ?? []) as $attrName => $definition) {
|
||
$attributes[$attrName] = ['settings' => $definition['settings'] ?? []];
|
||
}
|
||
|
||
$metadata[] = array_filter([
|
||
'name' => $module['name'],
|
||
'title' => $module['title'] ?? '',
|
||
'category' => $module['category'] ?? '',
|
||
'childrenName' => $module['childrenName'] ?? null,
|
||
'childModuleName' => $module['childModuleName'] ?? null,
|
||
'attributes' => $attributes,
|
||
], static fn ($value): bool => $value !== null);
|
||
$defaults[$module['name']] = ModuleRegistration::get_default_attrs($module['name'], 'default');
|
||
}
|
||
|
||
$file = dirname(__DIR__) . '/Fixtures/divi/metadata-sample.json';
|
||
$json = wp_json_encode(
|
||
['divi' => ET_BUILDER_PRODUCT_VERSION, 'metadata' => $metadata, 'defaults' => $defaults],
|
||
JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE
|
||
);
|
||
if (! is_string($json) || file_put_contents($file, $json . "\n") === false) {
|
||
WP_CLI::error('Cannot write ' . $file);
|
||
}
|
||
WP_CLI::success(sprintf('metadata-sample.json: %d modules, %d bytes', count($metadata), strlen($json)));
|