Files

49 lines
1.7 KiB
PHP

<?php
declare(strict_types=1);
namespace LIT\MCP\Tests\Unit\Integrations\Divi\Design;
use InvalidArgumentException;
use LIT\MCP\Integrations\Divi\Design\PresetScope;
use PHPUnit\Framework\TestCase;
final class PresetScopeTest extends TestCase
{
public function testShortAndFullNames(): void
{
self::assertSame('divi/button', PresetScope::fromInput(['module' => 'button'], 'items[0]')->name);
self::assertSame('module', PresetScope::fromInput(['module' => 'divi/button'], 'items[0]')->kind);
$group = PresetScope::fromInput(['group' => 'font-body'], 'items[0]');
self::assertSame(['group', 'divi/font-body'], [$group->kind, $group->name]);
self::assertSame('Gruppen-Preset divi/font-body', $group->label());
self::assertTrue($group->equals(new PresetScope('group', 'divi/font-body')));
}
/** @return array<string, array{array<string, mixed>, string}> */
public static function invalid(): array
{
return [
'nothing' => [[], 'items[0]'],
'both' => [['module' => 'button', 'group' => 'font'], 'items[0]'],
'not a name' => [['module' => 'Button 1'], 'items[0].module'],
'not a string' => [['group' => 5], 'items[0].group'],
'two slashes' => [['module' => 'divi/a/b'], 'items[0].module'],
];
}
/**
* @dataProvider invalid
* @param array<string, mixed> $item
*/
public function testInvalidInputNamesTheField(array $item, string $field): void
{
try {
PresetScope::fromInput($item, 'items[0]');
self::fail('expected an exception');
} catch (InvalidArgumentException $e) {
self::assertStringStartsWith($field . ':', $e->getMessage());
}
}
}