feat: Kurzform {{loop:<option>}} in Placeholders – Tabelle LOOP, before/after aus den Loop-Feldern der Komposition (X4)
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 5.5
parent
5ee846e63d
commit
6da2c0090f
@@ -5,6 +5,7 @@ declare(strict_types=1);
|
||||
namespace LIT\MCP\Tests\Unit\Integrations\Divi\Compose;
|
||||
|
||||
use InvalidArgumentException;
|
||||
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\Design\DesignSystem;
|
||||
@@ -15,6 +16,15 @@ use PHPUnit\Framework\TestCase;
|
||||
|
||||
final class PlaceholdersTest extends TestCase
|
||||
{
|
||||
/** Loop fields of a post loop as DynamicContentMap::loopFields() gives them (Divi 5.15.1 shapes). */
|
||||
private const POST_LOOP_FIELDS = [
|
||||
'loop_post_date' => [
|
||||
'before' => 'richtext', 'after' => 'richtext', 'loop_position' => 'text',
|
||||
'date_format' => 'select', 'custom_date_format' => 'text',
|
||||
],
|
||||
'loop_post_featured_image' => ['loop_position' => 'text', 'thumbnail_size' => 'select'],
|
||||
];
|
||||
|
||||
/**
|
||||
* Rows with a third value true go into a URL field (ruling P4: only the link row – URL mode
|
||||
* refuses colour references by design).
|
||||
@@ -78,6 +88,10 @@ final class PlaceholdersTest extends TestCase
|
||||
'bad field key' => ['{{field:a b}}', 'Ungültiger Feldschlüssel'],
|
||||
'protected field key' => ['{{field:_edit_lock}}', 'Ungültiger Feldschlüssel'],
|
||||
'embedded' => ['Seite: {{post:title}}', 'allein im Wert'],
|
||||
'embedded loop value' => ['Am {{loop:post_date}}', 'post, field, link, loop'],
|
||||
'unknown loop value' => ['{{loop:views}}', 'Unbekannter Schleifen-Inhalt "views". Vorhanden: post_title,'],
|
||||
'loop value with its prefix' => ['{{loop:loop_post_date}}', 'ohne "loop_"'],
|
||||
'loop meta key option' => ['{{loop:post_meta_key_manual_custom_field}}', 'nur in der Vollform'],
|
||||
'link without id' => ['{{link:start}}', 'Ungültige Beitrags-ID'],
|
||||
'link to a missing post' => ['{{link:999}}', 'Eintrag 999'],
|
||||
'link without link targets' => ['{{link:0}}', 'Ungültige Beitrags-ID'],
|
||||
@@ -168,4 +182,44 @@ final class PlaceholdersTest extends TestCase
|
||||
|
||||
(new Placeholders(DiviFixtures::designSystem()))->resolve('{{link:839}}');
|
||||
}
|
||||
|
||||
/**
|
||||
* Ruling X4: {{loop:<option>}} names the loop option without its prefix; before/after only where the loop
|
||||
* fields of the composition's scope give the option those settings (Divi has none on image options).
|
||||
*/
|
||||
public function testLoopPlaceholdersNameTheLoopOption(): void
|
||||
{
|
||||
$placeholders = new Placeholders(DiviFixtures::designSystem(), null, self::POST_LOOP_FIELDS);
|
||||
|
||||
$date = $placeholders->resolve('{{ loop : Post_Date }}');
|
||||
self::assertSame(
|
||||
'$variable({"type":"content","value":{"name":"loop_post_date","settings":{"before":"","after":""}}})$',
|
||||
$date
|
||||
);
|
||||
self::assertSame(
|
||||
'$variable({"type":"content","value":{"name":"loop_post_featured_image","settings":{}}})$',
|
||||
$placeholders->resolve('{{loop:post_featured_image}}')
|
||||
);
|
||||
// Not in the scope's fields (no loop, another kind): no settings – VariableRef names the loop problem.
|
||||
self::assertSame(
|
||||
'$variable({"type":"content","value":{"name":"loop_term_name","settings":{}}})$',
|
||||
$placeholders->resolve('{{loop:term_name}}')
|
||||
);
|
||||
|
||||
// What the placeholder writes passes the checker of a post loop unchanged.
|
||||
$references = new VariableRef(
|
||||
DiviFixtures::designSystem(),
|
||||
DynamicContentMap::fromOptions(DiviFixtures::dynamicContentRegistry()) + self::POST_LOOP_FIELDS,
|
||||
LoopScope::ofQueryType('post_types')
|
||||
);
|
||||
self::assertSame($date, $references->canonical($date, ComposeFixture::sanitizer()));
|
||||
}
|
||||
|
||||
public function testEveryLoopPlaceholderNamesALoopOption(): void
|
||||
{
|
||||
foreach (Placeholders::LOOP as $short => $option) {
|
||||
self::assertSame('loop_' . $short, $option);
|
||||
self::assertStringNotContainsString('meta_key', $option, 'meta key options need settings (full form)');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user