Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
66 lines
2.8 KiB
PHP
66 lines
2.8 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace LIT\MCP\Tests\Unit\Integrations\Divi\Design;
|
|
|
|
use LIT\MCP\Integrations\Divi\Design\PresetScope;
|
|
use LIT\MCP\Integrations\Divi\Design\PresetUsageMatcher;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
final class PresetUsageMatcherTest extends TestCase
|
|
{
|
|
private const BUTTON = '<!-- wp:divi/section --><!-- wp:divi/row --><!-- wp:divi/column -->'
|
|
. '<!-- wp:divi/button %s /--><!-- /wp:divi/column --><!-- /wp:divi/row --><!-- /wp:divi/section -->';
|
|
|
|
private static function page(string $buttonAttrs): string
|
|
{
|
|
return sprintf(self::BUTTON, $buttonAttrs);
|
|
}
|
|
|
|
public function testModulePresetInTheStack(): void
|
|
{
|
|
$matcher = new PresetUsageMatcher();
|
|
$button = new PresetScope('module', 'divi/button');
|
|
|
|
self::assertTrue($matcher->uses(self::page('{"modulePreset":["aaaaaaaaaa"]}'), $button, 'aaaaaaaaaa', false));
|
|
self::assertTrue($matcher->uses(self::page('{"modulePreset":["x","aaaaaaaaaa"]}'), $button, 'aaaaaaaaaa', false));
|
|
self::assertTrue($matcher->uses(self::page('{"modulePreset":"aaaaaaaaaa"}'), $button, 'aaaaaaaaaa', false));
|
|
self::assertFalse($matcher->uses(self::page('{"modulePreset":["bbbbbbbbbb"]}'), $button, 'aaaaaaaaaa', false));
|
|
self::assertFalse(
|
|
$matcher->uses(self::page('{"modulePreset":["aaaaaaaaaa"]}'), new PresetScope('module', 'divi/text'), 'aaaaaaaaaa', false),
|
|
'an ID of another module does not count'
|
|
);
|
|
}
|
|
|
|
public function testDefaultModulePresetReachesModulesWithoutOwnPreset(): void
|
|
{
|
|
$matcher = new PresetUsageMatcher();
|
|
$button = new PresetScope('module', 'divi/button');
|
|
|
|
self::assertTrue($matcher->uses(self::page('{}'), $button, 'dddddddddd', true));
|
|
self::assertTrue($matcher->uses(self::page('{"modulePreset":["default"]}'), $button, 'dddddddddd', true));
|
|
self::assertFalse($matcher->uses(self::page('{"modulePreset":["aaaaaaaaaa"]}'), $button, 'dddddddddd', true));
|
|
}
|
|
|
|
public function testGroupPresetById(): void
|
|
{
|
|
$matcher = new PresetUsageMatcher();
|
|
$group = new PresetScope('group', 'divi/font-body');
|
|
$attrs = '{"groupPreset":{"content.decoration.bodyFont":{"presetId":["gggggggggg"],"groupName":"divi/font-body"}}}';
|
|
|
|
self::assertTrue($matcher->uses(self::page($attrs), $group, 'gggggggggg', false));
|
|
self::assertFalse($matcher->uses(self::page($attrs), new PresetScope('group', 'divi/spacing'), 'gggggggggg', false));
|
|
}
|
|
|
|
public function testBrokenMarkupCountsAsUse(): void
|
|
{
|
|
self::assertTrue((new PresetUsageMatcher())->uses(
|
|
'<!-- wp:divi/section {"a": --><!-- /wp:divi/row -->',
|
|
new PresetScope('module', 'divi/button'),
|
|
'aaaaaaaaaa',
|
|
false
|
|
));
|
|
}
|
|
}
|