API begin and end fields for Admins (#5134)

This commit is contained in:
Kevin Papst
2024-10-25 10:47:58 +02:00
committed by GitHub
parent 31bae44f3c
commit dcc52f1a95
12 changed files with 161 additions and 47 deletions

View File

@@ -211,7 +211,7 @@ abstract class APIControllerBaseTest extends ControllerBaseTest
* @param bool $extraFields test for the error "This form should not contain extra fields"
* @param array<int, string>|array<string, mixed> $globalError
*/
protected function assertApiCallValidationError(Response $response, array $failedFields, bool $extraFields = false, array $globalError = []): void
protected function assertApiCallValidationError(Response $response, array $failedFields, bool $extraFields = false, array $globalError = [], array $expectedFields = [], array $missingFields = []): void
{
self::assertFalse($response->isSuccessful());
$result = json_decode($response->getContent(), true);
@@ -232,6 +232,18 @@ abstract class APIControllerBaseTest extends ControllerBaseTest
self::assertArrayHasKey('children', $result['errors']);
$data = $result['errors']['children'];
if (\count($expectedFields) > 0) {
foreach ($expectedFields as $expectedField) {
$this->assertArrayHasKey($expectedField, $data, 'Expected field is missing: ' . $expectedField);
}
}
if (\count($missingFields) > 0) {
foreach ($missingFields as $missingField) {
$this->assertArrayNotHasKey($missingField, $data, 'Expected missing field is available: ' . $missingField);
}
}
$foundErrors = [];
foreach ($failedFields as $key => $value) {