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,7 +50,7 @@ final class RevisionRestoreAbilityTest extends TestCase
|
||||
|
||||
public function testNonRevisionIdIsNotFound(): void
|
||||
{
|
||||
self::assertSame('lit_not_found', $this->ability(FakeChangeLog::forbidden())->permission(['revision_id' => 5])->get_error_code());
|
||||
self::assertToolError($this->ability(FakeChangeLog::forbidden())->permission(['revision_id' => 5]), 'not_found');
|
||||
}
|
||||
|
||||
public function testRequiresConfirmation(): void
|
||||
@@ -59,7 +59,7 @@ final class RevisionRestoreAbilityTest extends TestCase
|
||||
|
||||
$result = $this->ability(FakeChangeLog::forbidden())->execute(['revision_id' => 810]);
|
||||
|
||||
self::assertSame('lit_confirm_required', $result->get_error_code());
|
||||
self::assertToolError($result, 'confirm_required');
|
||||
}
|
||||
|
||||
public function testOrphanRevisionYieldsValidationErrorOnRevisionIdField(): void
|
||||
@@ -71,8 +71,8 @@ final class RevisionRestoreAbilityTest extends TestCase
|
||||
$error = $this->ability(FakeChangeLog::forbidden())
|
||||
->permission(['revision_id' => 810, 'rev' => 'irrelevant', 'confirm' => true]);
|
||||
|
||||
self::assertSame('lit_validation_failed', $error->get_error_code());
|
||||
self::assertArrayHasKey('revision_id', $error->get_error_data()['fields']);
|
||||
self::assertToolError($error, 'validation_failed');
|
||||
self::assertArrayHasKey('revision_id', self::errorFields($error));
|
||||
}
|
||||
|
||||
public function testATrashedEntryIsRefused(): void
|
||||
@@ -86,8 +86,8 @@ final class RevisionRestoreAbilityTest extends TestCase
|
||||
|
||||
$error = $this->ability(FakeChangeLog::forbidden())->execute(['revision_id' => 810, 'rev' => 'x', 'confirm' => true]);
|
||||
|
||||
self::assertSame('lit_validation_failed', $error->get_error_code());
|
||||
self::assertArrayHasKey('revision_id', $error->get_error_data()['fields']);
|
||||
self::assertToolError($error, 'validation_failed');
|
||||
self::assertArrayHasKey('revision_id', self::errorFields($error));
|
||||
}
|
||||
|
||||
public function testAMissedScheduleIsRefusedBecauseRestoringWouldPublish(): void
|
||||
@@ -110,7 +110,7 @@ final class RevisionRestoreAbilityTest extends TestCase
|
||||
'confirm' => true,
|
||||
]);
|
||||
|
||||
self::assertSame('lit_validation_failed', $error->get_error_code());
|
||||
self::assertToolError($error, 'validation_failed');
|
||||
self::assertStringContainsString('lit-post-publish', $error->get_error_data()['hint']);
|
||||
}
|
||||
|
||||
@@ -121,7 +121,7 @@ final class RevisionRestoreAbilityTest extends TestCase
|
||||
$result = $this->ability(FakeChangeLog::forbidden())
|
||||
->execute(['revision_id' => 810, 'confirm' => true, 'rev' => 'stale']);
|
||||
|
||||
self::assertSame('lit_rev_mismatch', $result->get_error_code());
|
||||
self::assertToolError($result, 'rev_mismatch');
|
||||
}
|
||||
|
||||
public function testSavesTheCurrentStateThenRestores(): void
|
||||
@@ -173,7 +173,7 @@ final class RevisionRestoreAbilityTest extends TestCase
|
||||
'rev' => $this->currentRev(),
|
||||
]);
|
||||
|
||||
self::assertSame('lit_write_failed', $result->get_error_code());
|
||||
self::assertToolError($result, 'write_failed');
|
||||
self::assertStringNotContainsString('Nichts wurde gespeichert', $result->get_error_message());
|
||||
self::assertStringContainsString(
|
||||
'Die Änderung wurde nicht gespeichert (Revision 813 bleibt erhalten).',
|
||||
|
||||
@@ -79,6 +79,6 @@ final class RevisionsListAbilityTest extends TestCase
|
||||
{
|
||||
$result = $this->ability()->execute(['post_id' => 5, 'cursor' => 'not-a-cursor']);
|
||||
|
||||
self::assertSame('lit_validation_failed', $result->get_error_code());
|
||||
self::assertToolError($result, 'validation_failed');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user