feat: lit/divi-dynamic-sources with text-like fields only (E12, F4)
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -143,6 +143,73 @@ final class DynamicContentMapTest extends TestCase
|
||||
self::assertNull((new DynamicContentMap())->forPost(7));
|
||||
}
|
||||
|
||||
public function testOptionsCarryLabelGroupAndSettingTypesWithoutLoops(): void
|
||||
{
|
||||
$map = new DynamicContentMap(static fn (int $id): array => DiviFixtures::dynamicContentRegistry());
|
||||
|
||||
$options = $map->options(831);
|
||||
|
||||
self::assertSame(['post_id' => 'select_post'], $options['post_link_url_page']['settings']);
|
||||
self::assertSame('post_meta_key', $options['post_meta_key']['label']);
|
||||
self::assertSame('Standard', $options['post_meta_key']['group']);
|
||||
self::assertArrayNotHasKey('loop_post_title', $options);
|
||||
self::assertNull((new DynamicContentMap(static fn (int $id): array => []))->options(831));
|
||||
}
|
||||
|
||||
public function testOptionsUseTheSameNamesAndTypesAsTheAllowMap(): void
|
||||
{
|
||||
$map = new DynamicContentMap(static fn (int $id): array => DiviFixtures::dynamicContentRegistry());
|
||||
|
||||
$options = $map->options(831);
|
||||
|
||||
self::assertSame(array_keys((array) $map->forPost(831)), array_keys((array) $options));
|
||||
$settings = array_map(static fn (array $option): array => $option['settings'], (array) $options);
|
||||
self::assertSame($map->forPost(831), $settings);
|
||||
// Placeholder options the registry lacks: name as label, no group.
|
||||
self::assertSame(['label' => 'post_tags', 'group' => ''], array_slice($options['post_tags'], 0, 2));
|
||||
}
|
||||
|
||||
public function testOptionsNeverNameProtectedMetaKeys(): void
|
||||
{
|
||||
// A third-party filter may register per-key options (D4 style custom_meta_<key>).
|
||||
$registry = DiviFixtures::dynamicContentRegistry() + [
|
||||
'custom_meta__edit_lock' => ['label' => '_edit_lock', 'group' => 'Custom', 'fields' => []],
|
||||
'custom_meta_custom_meta__secret' => ['label' => 'x', 'group' => 'Custom', 'fields' => []],
|
||||
'custom_meta_telefon' => ['label' => 'Telefon', 'group' => 'Custom', 'fields' => []],
|
||||
];
|
||||
$map = new DynamicContentMap(static fn (int $id): array => $registry);
|
||||
|
||||
$options = (array) $map->options(831);
|
||||
|
||||
self::assertArrayNotHasKey('custom_meta__edit_lock', $options);
|
||||
self::assertArrayNotHasKey('custom_meta_custom_meta__secret', $options);
|
||||
self::assertSame('Telefon', $options['custom_meta_telefon']['label']);
|
||||
// The allow map itself is unchanged: VariableRef refuses those names by its own rules (S12/S30).
|
||||
self::assertArrayHasKey('custom_meta__edit_lock', (array) $map->forPost(831));
|
||||
}
|
||||
|
||||
public function testTheAllowMapIsUnchangedByTheRawLookupRefactor(): void
|
||||
{
|
||||
// Snapshot of forPost() for the live-like registry, taken before forPost() moved onto raw()
|
||||
// (Task 15): the security allow map must stay exactly the same (rulings S22/S29/S30/S37).
|
||||
$before = '{"post_title":{"before":"richtext","after":"richtext"},"post_excerpt":{"before":"richtext",'
|
||||
. '"after":"richtext","words":"text","read_more_label":"text"},"post_date":{"before":"richtext",'
|
||||
. '"after":"richtext","date_format":"select","custom_date_format":"text"},"post_author":{"before":'
|
||||
. '"richtext","after":"richtext","name_format":"select","link":"yes_no_button"},"site_title":{"before":'
|
||||
. '"richtext","after":"richtext"},"post_link_url":[],"post_link_url_page":{"post_id":"select_post"},'
|
||||
. '"post_featured_image":[],"post_meta_key":{"before":"richtext","after":"richtext","select_meta_key":'
|
||||
. '"select","meta_key":"text","enable_html":"yes_no_button"},"broken_fields":{"a":"","b":""},'
|
||||
. '"no_fields":[],"post_modified_date":{"before":"richtext","after":"richtext","date_format":"select",'
|
||||
. '"custom_date_format":"text"},"post_categories":{"before":"richtext","after":"richtext"},'
|
||||
. '"post_tags":{"before":"richtext","after":"richtext"}}';
|
||||
|
||||
$map = new DynamicContentMap(static fn (int $id): array => DiviFixtures::dynamicContentRegistry());
|
||||
$after = $map->forPost(831);
|
||||
|
||||
self::assertSame(json_decode($before, true), $after);
|
||||
self::assertSame($before, json_encode($after));
|
||||
}
|
||||
|
||||
private static function assertRejected(callable $call, string $fragment): void
|
||||
{
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user