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
@@ -106,7 +106,7 @@ final class MediaUploadAbilitiesTest extends TestCase
$result = (new MediaUploadAbility($importer, $this->uploads(), new Limits()))
->execute(['filename' => 'x.png', 'data' => 'AAAA']);
self::assertSame('lit_validation_failed', $result->get_error_code());
self::assertToolError($result, 'validation_failed');
}
public function testAPartialUploadIsLoggedAsPartialAndRethrown(): void
@@ -136,7 +136,7 @@ final class MediaUploadAbilitiesTest extends TestCase
$ability = new MediaUploadFromUrlAbility(Mockery::mock(MediaImporter::class), $this->uploads());
self::assertTrue($ability->permission(['url' => 'https://example.com/a.png']));
self::assertSame('lit_forbidden', $ability->permission(['url' => 'https://example.com/a.png', 'post_id' => 5])->get_error_code());
self::assertToolError($ability->permission(['url' => 'https://example.com/a.png', 'post_id' => 5]), 'forbidden');
}
public function testPermissionRefusesUsersWithoutUploadRights(): void
@@ -144,7 +144,7 @@ final class MediaUploadAbilitiesTest extends TestCase
Functions\when('current_user_can')->justReturn(false);
$ability = new MediaUploadAbility(Mockery::mock(MediaImporter::class), $this->uploads(), new Limits());
self::assertSame('lit_forbidden', $ability->permission(['filename' => 'a.png', 'data' => 'AAAA'])->get_error_code());
self::assertToolError($ability->permission(['filename' => 'a.png', 'data' => 'AAAA']), 'forbidden');
}
public function testUploadsForAParentThatDoesNotExistAreRefused(): void
@@ -153,7 +153,7 @@ final class MediaUploadAbilitiesTest extends TestCase
Functions\when('get_post')->justReturn(null);
$ability = new MediaUploadAbility(Mockery::mock(MediaImporter::class), $this->uploads(), new Limits());
self::assertSame('lit_not_found', $ability->permission(['filename' => 'a.png', 'data' => 'AAAA', 'post_id' => 9])->get_error_code());
self::assertToolError($ability->permission(['filename' => 'a.png', 'data' => 'AAAA', 'post_id' => 9]), 'not_found');
}
public function testDescriptionNamesTheConfiguredLimit(): void