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:
@@ -44,7 +44,7 @@ final class PostTrashAbilityTest extends TestCase
|
||||
|
||||
$result = $this->ability(FakeChangeLog::forbidden())->execute(['post_id' => 5]);
|
||||
|
||||
self::assertSame('lit_confirm_required', $result->get_error_code());
|
||||
self::assertToolError($result, 'confirm_required');
|
||||
}
|
||||
|
||||
public function testMovesToTrashNeverDeletes(): void
|
||||
@@ -76,7 +76,7 @@ final class PostTrashAbilityTest extends TestCase
|
||||
|
||||
$result = $ability->execute(['post_id' => 5, 'confirm' => true]);
|
||||
|
||||
self::assertSame('lit_unsupported', $result->get_error_code());
|
||||
self::assertToolError($result, 'unsupported');
|
||||
}
|
||||
|
||||
public function testAHookThrowingDuringTheWriteIsAPartialWrite(): void
|
||||
@@ -93,7 +93,7 @@ final class PostTrashAbilityTest extends TestCase
|
||||
self::assertFalse($e->rolledBack);
|
||||
self::assertSame(5, $e->postId);
|
||||
self::assertStringContainsString('save_post-Hook kaputt', $e->getMessage());
|
||||
self::assertSame('lit_partial_write', $e->toError()->get_error_code());
|
||||
self::assertToolError($e->toError(), 'partial_write');
|
||||
}
|
||||
$log->assertPartials(['ability' => 'lit/post-trash', 'object_type' => 'page', 'object_id' => '5']);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user