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:
@@ -50,10 +50,10 @@ final class MenuAssignLocationAbilityTest extends TestCase
|
||||
$result = (new MenuAssignLocationAbility(FakeChangeLog::forbidden()))
|
||||
->execute(['location' => 'primary-menu', 'menu_id' => 0]);
|
||||
|
||||
self::assertSame('lit_confirm_required', $result->get_error_code());
|
||||
self::assertToolError($result, 'confirm_required');
|
||||
self::assertStringContainsString(
|
||||
'"Hauptmenü" (ID 3)',
|
||||
json_decode($result->get_error_message(), true)['message']
|
||||
self::clientError($result)['message']
|
||||
);
|
||||
}
|
||||
|
||||
@@ -104,7 +104,7 @@ final class MenuAssignLocationAbilityTest extends TestCase
|
||||
$result = (new MenuAssignLocationAbility(FakeChangeLog::forbidden()))
|
||||
->execute(['location' => 'primary-menu', 'menu_id' => 99]);
|
||||
|
||||
self::assertSame('lit_not_found', $result->get_error_code());
|
||||
self::assertToolError($result, 'not_found');
|
||||
}
|
||||
|
||||
public function testPermissionNeedsThemeOptionRights(): void
|
||||
@@ -114,7 +114,7 @@ final class MenuAssignLocationAbilityTest extends TestCase
|
||||
$ability = new MenuAssignLocationAbility(FakeChangeLog::forbidden());
|
||||
$input = ['location' => 'primary-menu', 'menu_id' => 8];
|
||||
|
||||
self::assertSame('lit_forbidden', $ability->permission($input)->get_error_code());
|
||||
self::assertToolError($ability->permission($input), 'forbidden');
|
||||
}
|
||||
|
||||
public function testIsDestructiveBecauseItReplacesTheMenuOfTheLocation(): void
|
||||
|
||||
Reference in New Issue
Block a user