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
@@ -92,7 +92,7 @@ final class MediaUpdateAbilityTest extends TestCase
]]);
self::assertInstanceOf(WP_Error::class, $result);
self::assertSame('lit_validation_failed', $result->get_error_code());
self::assertToolError($result, 'validation_failed');
self::assertStringContainsString('3 von 4', $result->get_error_message());
self::assertStringContainsString('nichts wurde gespeichert', $result->get_error_message());
$failures = $result->get_error_data()['failures'];
@@ -109,7 +109,7 @@ final class MediaUpdateAbilityTest extends TestCase
{
$result = (new MediaUpdateAbility($this->log()))->execute(['items' => [['id' => '99', 'alt' => 'x']]]);
self::assertSame('lit_not_found', $result->get_error_code());
self::assertToolError($result, 'not_found');
self::assertSame(99, $result->get_error_data()['failures'][0]['id']);
}
@@ -138,7 +138,7 @@ final class MediaUpdateAbilityTest extends TestCase
['id' => 34, 'alt' => 'neu', 'modified' => '2026-09-24 07:00:00'],
]]);
self::assertSame('lit_rev_mismatch', $result->get_error_code());
self::assertToolError($result, 'rev_mismatch');
self::assertSame(1, $result->get_error_data()['failures'][0]['index']);
self::assertStringContainsString('lit/media-get', $result->get_error_data()['hint']);
self::assertSame([], $this->altUpdates);
@@ -162,7 +162,7 @@ final class MediaUpdateAbilityTest extends TestCase
self::fail('WriteFailed expected');
} catch (WriteFailed $e) {
self::assertTrue($e->rolledBack);
self::assertSame('lit_write_failed', $e->toError()->get_error_code());
self::assertToolError($e->toError(), 'write_failed');
self::assertStringContainsString('neu lesen', $e->toError()->get_error_data()['hint']);
self::assertStringContainsString('Datenbankfehler', $e->getMessage());
}
@@ -232,7 +232,7 @@ final class MediaUpdateAbilityTest extends TestCase
self::fail('WriteFailed expected');
} catch (WriteFailed $e) {
$error = $e->toError();
self::assertSame('lit_partial_write', $error->get_error_code());
self::assertToolError($error, 'partial_write');
self::assertSame([33], $error->get_error_data()['changed_ids']);
self::assertStringContainsString('33', $error->get_error_message());
}