feat: DynamicContentMap::loopFields() – loop_*-Optionen nach Art (X2); echte Loop-Optionen in DiviFixtures
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 5.5
parent
617ad2888d
commit
3d12043b4f
@@ -6,6 +6,7 @@ namespace LIT\MCP\Tests\Unit\Integrations\Divi\Pages;
|
||||
|
||||
use InvalidArgumentException;
|
||||
use LIT\MCP\Integrations\Divi\Compose\DynamicContentRules;
|
||||
use LIT\MCP\Integrations\Divi\Compose\LoopScope;
|
||||
use LIT\MCP\Integrations\Divi\Compose\Placeholders;
|
||||
use LIT\MCP\Integrations\Divi\Compose\VariableRef;
|
||||
use LIT\MCP\Integrations\Divi\Pages\DynamicContentMap;
|
||||
@@ -210,6 +211,88 @@ final class DynamicContentMapTest extends TestCase
|
||||
self::assertSame($before, json_encode($after));
|
||||
}
|
||||
|
||||
/** Ruling X2: loop_* options stay, grouped by kind – by group, the three meta options by name. */
|
||||
public function testLoopFieldsGroupTheLoopOptionsByKind(): void
|
||||
{
|
||||
$map = new DynamicContentMap(static fn (int $id): array => DiviFixtures::dynamicContentRegistry());
|
||||
|
||||
self::assertSame(
|
||||
[
|
||||
'loop_post_title', 'loop_post_date', 'loop_post_featured_image',
|
||||
'loop_post_meta_key_manual_custom_field', 'loop_product_title',
|
||||
],
|
||||
array_keys($map->loopFields(LoopScope::POST))
|
||||
);
|
||||
self::assertSame(
|
||||
['loop_term_name', 'loop_term_meta_key_manual_custom_field'],
|
||||
array_keys($map->loopFields(LoopScope::TERM))
|
||||
);
|
||||
self::assertSame(
|
||||
['loop_user_name', 'loop_user_meta_key_manual_custom_field'],
|
||||
array_keys($map->loopFields(LoopScope::USER))
|
||||
);
|
||||
self::assertSame(['loop_menu_text'], array_keys($map->loopFields(LoopScope::MENU)));
|
||||
// ACF repeater rows have no kind (X2/X7e); an unknown kind has no options.
|
||||
self::assertSame([], $map->loopFields('repeater_team'));
|
||||
self::assertSame([], $map->loopFields(''));
|
||||
}
|
||||
|
||||
public function testLoopFieldsHaveTheShapeOfTheAllowMap(): void
|
||||
{
|
||||
$map = new DynamicContentMap(static fn (int $id): array => DiviFixtures::dynamicContentRegistry());
|
||||
|
||||
$post = $map->loopFields(LoopScope::POST);
|
||||
|
||||
self::assertSame(
|
||||
[
|
||||
'before' => 'richtext', 'after' => 'richtext', 'loop_position' => 'text',
|
||||
'date_format' => 'select', 'custom_date_format' => 'text',
|
||||
],
|
||||
$post['loop_post_date']
|
||||
);
|
||||
self::assertSame(['loop_position' => 'text', 'thumbnail_size' => 'select'], $post['loop_post_featured_image']);
|
||||
self::assertSame(
|
||||
['select', 'text', 'yes_no_button'],
|
||||
[
|
||||
$post['loop_post_meta_key_manual_custom_field']['select_loop_meta_key'],
|
||||
$post['loop_post_meta_key_manual_custom_field']['loop_meta_key'],
|
||||
$post['loop_post_meta_key_manual_custom_field']['enable_html'],
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/** The custom field groups are translated ("Loop %s Custom Fields", esc_html__) – their name decides. */
|
||||
public function testTheMetaOptionsFollowTheirNameNotTheirGroup(): void
|
||||
{
|
||||
$registry = DiviFixtures::dynamicContentRegistry();
|
||||
$registry['loop_user_meta_key_manual_custom_field']['group'] = 'Schleife: Benutzer-Felder';
|
||||
$registry['loop_term_meta_key_manual_custom_field']['group'] = 'Loop';
|
||||
$registry['loop_post_meta_key_manual_custom_field']['group'] = 'Loop Users';
|
||||
$map = new DynamicContentMap(static fn (int $id): array => $registry);
|
||||
|
||||
self::assertArrayHasKey('loop_user_meta_key_manual_custom_field', $map->loopFields(LoopScope::USER));
|
||||
self::assertArrayHasKey('loop_term_meta_key_manual_custom_field', $map->loopFields(LoopScope::TERM));
|
||||
self::assertArrayHasKey('loop_post_meta_key_manual_custom_field', $map->loopFields(LoopScope::POST));
|
||||
self::assertArrayNotHasKey('loop_post_meta_key_manual_custom_field', $map->loopFields(LoopScope::USER));
|
||||
}
|
||||
|
||||
public function testLoopFieldsReadTheRegistryOfThePostAndAreEmptyWithoutIt(): void
|
||||
{
|
||||
$seen = [];
|
||||
$map = new DynamicContentMap(static function (int $postId) use (&$seen): array {
|
||||
$seen[] = $postId;
|
||||
|
||||
return DiviFixtures::dynamicContentRegistry();
|
||||
});
|
||||
|
||||
$map->loopFields(LoopScope::POST, 42);
|
||||
$map->loopFields(LoopScope::TERM);
|
||||
|
||||
self::assertSame([42, 0], $seen);
|
||||
self::assertSame([], (new DynamicContentMap(static fn (): array => []))->loopFields(LoopScope::POST));
|
||||
self::assertSame([], (new DynamicContentMap())->loopFields(LoopScope::POST), 'without Divi');
|
||||
}
|
||||
|
||||
private static function assertRejected(callable $call, string $fragment): void
|
||||
{
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user