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:
2026-09-26 17:55:35 +02:00
co-authored by Claude Opus 5.5
parent 72eeaa46ad
commit 60290c85a5
50 changed files with 337 additions and 256 deletions
@@ -34,7 +34,7 @@ final class DiviPageLoaderTest extends TestCase
$result = (new DiviPageLoader(DiviFixtures::schema()))->load(7, false);
self::assertInstanceOf(WP_Error::class, $result);
self::assertSame('lit_unsupported', $result->get_error_code());
self::assertToolError($result, 'unsupported');
self::assertStringContainsString('Divi-4', $result->get_error_message());
}
@@ -50,7 +50,7 @@ final class DiviPageLoaderTest extends TestCase
ini_set('error_log', (string) $previous);
}
self::assertSame('lit_unsupported', $result->get_error_code());
self::assertToolError($result, 'unsupported');
self::assertStringContainsString('kein gültiges Block-Markup', $result->get_error_message());
self::assertStringContainsString('divi parse of post 7 failed', (string) file_get_contents($log));
unlink($log);
@@ -62,7 +62,7 @@ final class DiviPageLoaderTest extends TestCase
$loader = new DiviPageLoader(DiviFixtures::schema());
self::assertInstanceOf(DiviPage::class, $loader->load(7, false));
self::assertSame('lit_validation_failed', $loader->load(7, true)->get_error_code());
self::assertToolError($loader->load(7, true), 'validation_failed');
}
public function testWritableChecks(): void
@@ -70,7 +70,7 @@ final class DiviPageLoaderTest extends TestCase
$loader = new DiviPageLoader(DiviFixtures::schema(false));
DiviFixtures::givenPost('');
$empty = $loader->load(7, true);
self::assertSame('lit_unsupported', $loader->writable($empty)->get_error_code());
self::assertToolError($loader->writable($empty), 'unsupported');
$loader = new DiviPageLoader(DiviFixtures::schema());
DiviFixtures::givenPost("<!-- wp:paragraph -->\n<p>Gutenberg</p>\n<!-- /wp:paragraph -->");
@@ -81,6 +81,6 @@ final class DiviPageLoaderTest extends TestCase
DiviFixtures::givenPost('', ['post_status' => 'future', 'post_date_gmt' => '2020-01-01 00:00:00']);
$missed = $loader->load(7, true);
self::assertTrue($missed->isDiviLayout());
self::assertSame('lit_validation_failed', $loader->writable($missed)->get_error_code());
self::assertToolError($loader->writable($missed), 'validation_failed');
}
}