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:
@@ -41,7 +41,7 @@ final class MediaDeleteAbilityTest extends TestCase
|
||||
|
||||
$result = $this->ability(self::USAGE, FakeChangeLog::forbidden())->execute(['id' => 33]);
|
||||
|
||||
self::assertSame('lit_confirm_required', $result->get_error_code());
|
||||
self::assertToolError($result, 'confirm_required');
|
||||
self::assertStringContainsString('endgültig', $result->get_error_message());
|
||||
self::assertStringContainsString('1 Stelle', $result->get_error_message());
|
||||
self::assertSame(self::USAGE, $result->get_error_data()['usages']);
|
||||
@@ -51,7 +51,7 @@ final class MediaDeleteAbilityTest extends TestCase
|
||||
{
|
||||
$result = $this->ability([], FakeChangeLog::forbidden(), true)->execute(['id' => 33, 'confirm' => false]);
|
||||
|
||||
self::assertSame('lit_confirm_required', $result->get_error_code());
|
||||
self::assertToolError($result, 'confirm_required');
|
||||
self::assertStringContainsString('Papierkorb', $result->get_error_message());
|
||||
}
|
||||
|
||||
@@ -61,7 +61,7 @@ final class MediaDeleteAbilityTest extends TestCase
|
||||
|
||||
$result = $this->ability(self::USAGE, FakeChangeLog::forbidden())->execute(['id' => 33, 'confirm' => true]);
|
||||
|
||||
self::assertSame('lit_in_use', $result->get_error_code());
|
||||
self::assertToolError($result, 'in_use');
|
||||
self::assertSame(self::USAGE, $result->get_error_data()['usages']);
|
||||
}
|
||||
|
||||
@@ -71,7 +71,7 @@ final class MediaDeleteAbilityTest extends TestCase
|
||||
|
||||
$result = $this->ability(self::POSSIBLE, FakeChangeLog::forbidden())->execute(['id' => 33, 'confirm' => true]);
|
||||
|
||||
self::assertSame('lit_in_use', $result->get_error_code());
|
||||
self::assertToolError($result, 'in_use');
|
||||
}
|
||||
|
||||
public function testForceDeletesUsedMedia(): void
|
||||
@@ -115,7 +115,7 @@ final class MediaDeleteAbilityTest extends TestCase
|
||||
|
||||
$result = $this->ability([], FakeChangeLog::forbidden())->execute(['id' => 33, 'confirm' => true]);
|
||||
|
||||
self::assertSame('lit_write_failed', $result->get_error_code());
|
||||
self::assertToolError($result, 'write_failed');
|
||||
}
|
||||
|
||||
public function testRefusedDeleteThatRemovedDataIsAPartialWrite(): void
|
||||
@@ -133,7 +133,7 @@ final class MediaDeleteAbilityTest extends TestCase
|
||||
|
||||
$result = $this->ability([], $log)->execute(['id' => 33, 'confirm' => true]);
|
||||
|
||||
self::assertSame('lit_partial_write', $result->get_error_code());
|
||||
self::assertToolError($result, 'partial_write');
|
||||
self::assertSame(33, $result->get_error_data()['attachment_id']);
|
||||
$log->assertPartials(['ability' => 'lit/media-delete', 'object_type' => 'attachment', 'object_id' => '33']);
|
||||
}
|
||||
@@ -162,7 +162,7 @@ final class MediaDeleteAbilityTest extends TestCase
|
||||
unlink($file);
|
||||
}
|
||||
|
||||
self::assertSame('lit_in_use', $result->get_error_code());
|
||||
self::assertToolError($result, 'in_use');
|
||||
self::assertSame(MediaUsageFinder::FAILED_TITLE, $result->get_error_data()['usages'][0]['title']);
|
||||
}
|
||||
|
||||
@@ -193,8 +193,8 @@ final class MediaDeleteAbilityTest extends TestCase
|
||||
|
||||
$ability = $this->ability([], FakeChangeLog::forbidden());
|
||||
|
||||
self::assertSame('lit_validation_failed', $ability->permission(['id' => 33])->get_error_code());
|
||||
self::assertSame('lit_validation_failed', $ability->execute(['id' => 33, 'confirm' => true])->get_error_code());
|
||||
self::assertToolError($ability->permission(['id' => 33]), 'validation_failed');
|
||||
self::assertToolError($ability->execute(['id' => 33, 'confirm' => true]), 'validation_failed');
|
||||
}
|
||||
|
||||
public function testChecksDeletePostOnTheAttachment(): void
|
||||
@@ -203,7 +203,7 @@ final class MediaDeleteAbilityTest extends TestCase
|
||||
|
||||
$result = $this->ability([], FakeChangeLog::forbidden())->permission(['id' => 33]);
|
||||
|
||||
self::assertSame('lit_forbidden', $result->get_error_code());
|
||||
self::assertToolError($result, 'forbidden');
|
||||
}
|
||||
|
||||
public function testIsDestructiveAndDescribesWhatTheUsageCheckMisses(): void
|
||||
|
||||
Reference in New Issue
Block a user