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:
@@ -96,7 +96,7 @@ final class ContentQueryAbilityTest extends TestCase
|
||||
{
|
||||
$result = $this->ability()->execute(['post_type' => 'page', 'cursor' => '???']);
|
||||
|
||||
self::assertSame('lit_validation_failed', $result->get_error_code());
|
||||
self::assertToolError($result, 'validation_failed');
|
||||
}
|
||||
|
||||
public function testQueryIsRestrictedToOwnPostsWithoutEditOthersPosts(): void
|
||||
@@ -193,7 +193,7 @@ final class ContentQueryAbilityTest extends TestCase
|
||||
|
||||
$result = $this->ability($schema)->execute(['post_type' => 'page', 'field' => ['key' => 'ghost']]);
|
||||
|
||||
self::assertSame('lit_validation_failed', $result->get_error_code());
|
||||
self::assertToolError($result, 'validation_failed');
|
||||
self::assertStringContainsString('role', $result->get_error_message());
|
||||
}
|
||||
|
||||
@@ -209,9 +209,9 @@ final class ContentQueryAbilityTest extends TestCase
|
||||
$password = $this->ability($schema)->execute(['post_type' => 'page', 'field' => ['key' => 'secret']]);
|
||||
$protected = $this->ability($schema)->execute(['post_type' => 'page', 'field' => ['key' => '_internal']]);
|
||||
|
||||
self::assertSame('lit_validation_failed', $password->get_error_code());
|
||||
self::assertToolError($password, 'validation_failed');
|
||||
self::assertSame('Verfügbare Felder: role.', $password->get_error_data()['hint']);
|
||||
self::assertSame('lit_validation_failed', $protected->get_error_code());
|
||||
self::assertToolError($protected, 'validation_failed');
|
||||
self::assertSame('Verfügbare Felder: role.', $protected->get_error_data()['hint']);
|
||||
}
|
||||
|
||||
@@ -225,7 +225,7 @@ final class ContentQueryAbilityTest extends TestCase
|
||||
'taxonomy' => ['taxonomy' => 'ghost', 'terms' => [1]],
|
||||
]);
|
||||
|
||||
self::assertSame('lit_validation_failed', $result->get_error_code());
|
||||
self::assertToolError($result, 'validation_failed');
|
||||
self::assertStringContainsString('category', $result->get_error_message());
|
||||
}
|
||||
|
||||
@@ -235,7 +235,7 @@ final class ContentQueryAbilityTest extends TestCase
|
||||
$schema->allows('isManaged')->andReturn(false);
|
||||
$ability = new ContentQueryAbility($schema, Mockery::mock(PostPresenter::class));
|
||||
|
||||
self::assertSame('lit_not_found', $ability->permission(['post_type' => 'secret'])->get_error_code());
|
||||
self::assertToolError($ability->permission(['post_type' => 'secret']), 'not_found');
|
||||
}
|
||||
|
||||
public function testPermissionIsForbiddenWithoutEditRights(): void
|
||||
@@ -245,7 +245,7 @@ final class ContentQueryAbilityTest extends TestCase
|
||||
$schema = SchemaFixture::managed();
|
||||
$ability = new ContentQueryAbility($schema, Mockery::mock(PostPresenter::class));
|
||||
|
||||
self::assertSame('lit_forbidden', $ability->permission(['post_type' => 'page'])->get_error_code());
|
||||
self::assertToolError($ability->permission(['post_type' => 'page']), 'forbidden');
|
||||
}
|
||||
|
||||
public function testInputSchemaLimitsSearchLengthAndTaxonomyTermsCount(): void
|
||||
|
||||
Reference in New Issue
Block a user