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:
@@ -71,7 +71,7 @@ final class ContentUpdateAbilityTest extends TestCase
|
||||
$result = $this->ability(Mockery::mock(PostWriter::class))
|
||||
->execute(['post_id' => 5, 'rev' => Rev::ofPost($this->post), 'title' => 'Neu']);
|
||||
|
||||
self::assertSame('lit_validation_failed', $result->get_error_code());
|
||||
self::assertToolError($result, 'validation_failed');
|
||||
}
|
||||
|
||||
public function testAMissedScheduleIsRefusedBecauseSavingWouldPublish(): void
|
||||
@@ -84,8 +84,8 @@ final class ContentUpdateAbilityTest extends TestCase
|
||||
$result = $this->ability(Mockery::mock(PostWriter::class))
|
||||
->execute(['post_id' => 5, 'rev' => Rev::ofPost($this->post), 'title' => 'Neu']);
|
||||
|
||||
self::assertSame('lit_validation_failed', $result->get_error_code());
|
||||
self::assertArrayHasKey('post_id', $result->get_error_data()['fields']);
|
||||
self::assertToolError($result, 'validation_failed');
|
||||
self::assertArrayHasKey('post_id', self::errorFields($result));
|
||||
self::assertStringContainsString('lit/post-schedule', $result->get_error_data()['hint']);
|
||||
}
|
||||
|
||||
@@ -96,7 +96,7 @@ final class ContentUpdateAbilityTest extends TestCase
|
||||
$result = $this->ability(Mockery::mock(PostWriter::class))
|
||||
->execute(['post_id' => 5, 'rev' => 'stale', 'title' => 'Neu']);
|
||||
|
||||
self::assertSame('lit_rev_mismatch', $result->get_error_code());
|
||||
self::assertToolError($result, 'rev_mismatch');
|
||||
self::assertStringContainsString('lit-content-get', $result->get_error_data()['hint']);
|
||||
}
|
||||
|
||||
@@ -105,7 +105,7 @@ final class ContentUpdateAbilityTest extends TestCase
|
||||
$result = $this->ability(Mockery::mock(PostWriter::class))
|
||||
->execute(['post_id' => 5, 'rev' => Rev::of('<p>Alt</p>'), 'title' => 'Neu']);
|
||||
|
||||
self::assertSame('lit_rev_mismatch', $result->get_error_code());
|
||||
self::assertToolError($result, 'rev_mismatch');
|
||||
}
|
||||
|
||||
public function testRawContentOnDiviPagesIsUnsupported(): void
|
||||
@@ -117,7 +117,7 @@ final class ContentUpdateAbilityTest extends TestCase
|
||||
$result = $this->ability($writer)
|
||||
->execute(['post_id' => 5, 'rev' => Rev::ofPost($this->post), 'content' => '<p>Neu</p>']);
|
||||
|
||||
self::assertSame('lit_unsupported', $result->get_error_code());
|
||||
self::assertToolError($result, 'unsupported');
|
||||
self::assertStringContainsString(PostPresenter::DIVI_INACTIVE_NOTE, $result->get_error_data()['hint']);
|
||||
}
|
||||
|
||||
@@ -129,7 +129,7 @@ final class ContentUpdateAbilityTest extends TestCase
|
||||
|
||||
$result = $this->ability($writer)->execute(['post_id' => 5, 'rev' => Rev::ofPost($this->post)]);
|
||||
|
||||
self::assertSame('lit_validation_failed', $result->get_error_code());
|
||||
self::assertToolError($result, 'validation_failed');
|
||||
}
|
||||
|
||||
public function testUpdateKeepsTheStatusAndCapturesARestorePointFirst(): void
|
||||
@@ -236,7 +236,7 @@ final class ContentUpdateAbilityTest extends TestCase
|
||||
$failure = $this->executeExpectingFailure($writer, $input);
|
||||
|
||||
self::assertTrue($failure->rolledBack);
|
||||
self::assertSame('lit_write_failed', $failure->toError()->get_error_code());
|
||||
self::assertToolError($failure->toError(), 'write_failed');
|
||||
$message = $failure->toError()->get_error_message();
|
||||
self::assertStringNotContainsString('Nichts wurde gespeichert', $message);
|
||||
self::assertStringContainsString('Die Änderung wurde nicht gespeichert (Revision 811 bleibt erhalten).', $message);
|
||||
@@ -326,7 +326,7 @@ final class ContentUpdateAbilityTest extends TestCase
|
||||
self::assertFalse($failure->rolledBack);
|
||||
self::assertStringContainsString('restore kaputt', $failure->getMessage());
|
||||
$error = $failure->toError();
|
||||
self::assertSame('lit_partial_write', $error->get_error_code());
|
||||
self::assertToolError($error, 'partial_write');
|
||||
self::assertSame(5, $error->get_error_data()['post_id']);
|
||||
self::assertSame(811, $error->get_error_data()['revision_id']);
|
||||
$log->assertPartials([
|
||||
|
||||
Reference in New Issue
Block a user