test: AssertsToolErrors helper for tool error assertions (T3)

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>
This commit is contained in:
2026-09-26 17:55:35 +02:00
co-authored by Claude Opus 5.5
parent 72eeaa46ad
commit 60290c85a5
50 changed files with 337 additions and 256 deletions
@@ -97,16 +97,16 @@ final class DiviContentComposerTest extends TestCase
{
$disabled = $this->composer(false)->check('post', [['type' => 'section']]);
self::assertInstanceOf(WP_Error::class, $disabled);
self::assertSame('lit_validation_failed', $disabled->get_error_code());
self::assertArrayHasKey('divi', $disabled->get_error_data()['fields']);
self::assertToolError($disabled, 'validation_failed');
self::assertArrayHasKey('divi', self::errorFields($disabled));
$invalid = $this->composer()->check('page', [
['type' => 'section', 'modules' => [['type' => 'button', 'attrs' => ['x.y' => ['desktop' => 1]]]]],
['type' => 'section', 'modules' => [['type' => 'button', 'url' => 'javascript:alert(1)', 'text' => 'x']]],
]);
self::assertInstanceOf(WP_Error::class, $invalid);
self::assertSame('lit_invalid_attr_path', $invalid->get_error_code());
$fields = $invalid->get_error_data()['fields'];
self::assertToolError($invalid, 'invalid_attr_path');
$fields = self::errorFields($invalid);
self::assertArrayHasKey('divi[0].modules[0].modules[0][0].attrs.x.y', $fields);
self::assertGreaterThanOrEqual(2, count($fields), 'every error of every section comes back');
self::assertSame([], $this->saved);
@@ -130,7 +130,7 @@ final class DiviContentComposerTest extends TestCase
$written = $this->composer(true, $registry)->write(42, 'page', $sections);
self::assertInstanceOf(WP_Error::class, $written);
self::assertSame('lit_validation_failed', $written->get_error_code());
self::assertToolError($written, 'validation_failed');
self::assertSame([], $this->saved);
}