tests/Support/AssertsToolErrors (used by TestCase): assertToolError($result, code)
checks the WP_Error code lit_<code> and the code of the client JSON and returns the
payload; clientError() decodes the payload; errorFields() returns the fields and
asserts they exist. Replaces the private clientError() decoders of
DiviWriteAbilitiesTest/DiviReplaceTextAbilityTest, 216 single-line
assertSame('lit_…', …->get_error_code()) assertions, 24 get_error_data()['fields']
digs and two json_decode(message) reads. ErrorsTest keeps json_decode: it tests
the format itself. Tests 1404 -> 1409 (AssertsToolErrorsTest); no test has fewer
assertions.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
45 lines
1.7 KiB
PHP
45 lines
1.7 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace LIT\MCP\Tests\Unit\Integrations\Divi\Design;
|
|
|
|
use Brain\Monkey\Functions;
|
|
use LIT\MCP\Integrations\Divi\Design\DesignSystemReader;
|
|
use LIT\MCP\Integrations\Divi\Design\DiviDesignSystemAbility;
|
|
use LIT\MCP\Tests\Support\DiviFixtures;
|
|
use LIT\MCP\Tests\Unit\TestCase;
|
|
use Mockery;
|
|
|
|
final class DiviDesignSystemAbilityTest extends TestCase
|
|
{
|
|
public function testReturnsDesignSystemWithPlaceholders(): void
|
|
{
|
|
$reader = Mockery::mock(DesignSystemReader::class);
|
|
$reader->allows('read')->andReturn(DiviFixtures::designSystem());
|
|
Functions\when('current_user_can')->justReturn(true);
|
|
$ability = new DiviDesignSystemAbility($reader);
|
|
|
|
self::assertTrue($ability->permission([]));
|
|
$result = $ability->execute([]);
|
|
|
|
self::assertSame('{{color:primary}}', $result['colors'][0]['placeholder']);
|
|
self::assertSame('{{color:Nachtblau}}', $result['colors'][2]['placeholder']);
|
|
self::assertSame('{{var:Telefon}}', $result['variables'][1]['placeholder']);
|
|
self::assertSame(['heading' => 'Open Sans', 'body' => 'Lato'], $result['fonts']);
|
|
self::assertSame('CTA primär', $result['presets'][1]['name']);
|
|
self::assertStringContainsString('{{font:heading}}', $result['notes'][0]);
|
|
self::assertTrue($ability->isDirect());
|
|
self::assertSame(['colors', 'variables', 'fonts', 'sizes', 'presets', 'notes'], $ability->outputSchema()['required']);
|
|
}
|
|
|
|
public function testNeedsEditPosts(): void
|
|
{
|
|
Functions\when('current_user_can')->justReturn(false);
|
|
|
|
$result = (new DiviDesignSystemAbility(Mockery::mock(DesignSystemReader::class)))->permission([]);
|
|
|
|
self::assertToolError($result, 'forbidden');
|
|
}
|
|
}
|