docs/test: S36-Hinweise abgelöst (X5); loopFields() in VariableRef gepinnt

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Jan-Niclas Loosen
2026-10-19 20:45:01 +02:00
co-authored by Claude Sonnet 5.5
parent f8912c255d
commit 5ee846e63d
2 changed files with 33 additions and 3 deletions
@@ -22,8 +22,8 @@ defined('ABSPATH') || exit;
/** /**
* lit/divi-dynamic-sources (spec §5.7, E12): Divi's dynamic content options for a post type * lit/divi-dynamic-sources (spec §5.7, E12): Divi's dynamic content options for a post type
* (DynamicContentOptions::get_options with a sample entry of the type the user may edit, else 0; * (DynamicContentOptions::get_options with a sample entry of the type the user may edit, else 0;
* no loop_* – S36; via DynamicContentMap::options()) with the placeholder that writes each, and * no loop_* – they need a node in a Divi loop, ruling X6; via DynamicContentMap::options()) with the
* the fields of the type usable as {{field:<key>}}. * placeholder that writes each, and the fields of the type usable as {{field:<key>}}.
* *
* Answer F4: only text-like fields are offered; relation/file fields show IDs in Divi (F26), Pods * Answer F4: only text-like fields are offered; relation/file fields show IDs in Divi (F26), Pods
* table storage is not post meta, protected keys never (S12), unknown types not (ruling P9) – each * table storage is not post meta, protected keys never (S12), unknown types not (ruling P9) – each
@@ -101,7 +101,7 @@ final class DynamicContentMapTest extends TestCase
// enable_html stays forbidden even though the registry lists it. // enable_html stays forbidden even though the registry lists it.
$html = $ref('post_meta_key', ['enable_html' => 'on']); $html = $ref('post_meta_key', ['enable_html' => 'on']);
self::assertRejected(static fn () => $references->canonical($html, $sanitizer), 'enable_html'); self::assertRejected(static fn () => $references->canonical($html, $sanitizer), 'enable_html');
// Loop content: Divi offers it only inside loops – never through the tools. // Loop content needs a Divi loop of its kind (ruling X5) – this VariableRef has none.
$loop = $ref('loop_post_title', []); $loop = $ref('loop_post_title', []);
self::assertRejected(static fn () => $references->canonical($loop, $sanitizer), 'Schleifen'); self::assertRejected(static fn () => $references->canonical($loop, $sanitizer), 'Schleifen');
} }
@@ -276,6 +276,36 @@ final class DynamicContentMapTest extends TestCase
self::assertArrayNotHasKey('loop_post_meta_key_manual_custom_field', $map->loopFields(LoopScope::USER)); self::assertArrayNotHasKey('loop_post_meta_key_manual_custom_field', $map->loopFields(LoopScope::USER));
} }
/** The map a loop composition builds (Task 4): forPost() + loopFields() of the loop's kind. */
public function testLoopFieldsWorkInVariableRefInsideALoopOfTheirKind(): void
{
$map = new DynamicContentMap(static fn (int $id): array => DiviFixtures::dynamicContentRegistry());
$terms = LoopScope::ofQueryType('post_taxonomies');
$references = new VariableRef(
DiviFixtures::designSystem(),
(array) $map->forPost(831) + $map->loopFields((string) $terms->kind(), 831),
$terms
);
$sanitizer = ComposeFixture::sanitizer();
$ref = static fn (string $name, array $settings): string => VariableRef::serialize('content', $name, $settings);
$name = $ref('loop_term_name', ['before' => 'Kategorie: ', 'after' => '', 'loop_position' => '']);
self::assertSame($name, $references->canonical($name, $sanitizer));
$title = $ref('post_title', ['before' => '', 'after' => '']);
self::assertSame($title, $references->canonical($title, $sanitizer));
self::assertRejected(
static fn () => $references->canonical($ref('loop_post_title', []), $sanitizer),
'passt nicht zur Schleife dieses Elements (Typ: Terme)'
);
self::assertRejected(
static fn () => $references->canonical(
$ref('loop_term_meta_key_manual_custom_field', ['enable_html' => 'on']),
$sanitizer
),
'enable_html'
);
}
public function testLoopFieldsReadTheRegistryOfThePostAndAreEmptyWithoutIt(): void public function testLoopFieldsReadTheRegistryOfThePostAndAreEmptyWithoutIt(): void
{ {
$seen = []; $seen = [];