Added missing validation.file message

- Included test to cover
- Also applied StyleCI fixes

Closes #3248
This commit is contained in:
Dan Brown 2022-02-06 14:47:33 +00:00
parent d29a2a647a
commit 1df7497c09
No known key found for this signature in database
GPG Key ID: 46D9F943C24A2EF9
3 changed files with 30 additions and 26 deletions

View File

@ -32,6 +32,7 @@ return [
'digits_between' => 'The :attribute must be between :min and :max digits.',
'email' => 'The :attribute must be a valid email address.',
'ends_with' => 'The :attribute must end with one of the following: :values',
'file' => 'The :attribute must be provided as a valid file.',
'filled' => 'The :attribute field is required.',
'gt' => [
'numeric' => 'The :attribute must be greater than :value.',

View File

@ -122,7 +122,7 @@ class AttachmentsApiTest extends TestCase
$resp = $this->call('POST', $this->baseEndpoint, $details, [], ['file' => $file]);
$resp->assertStatus(422);
$resp->assertJson($this->validationResponse([
"file" => ["The file may not be greater than 1000 kilobytes."]
'file' => ['The file may not be greater than 1000 kilobytes.'],
]));
}
@ -139,15 +139,7 @@ class AttachmentsApiTest extends TestCase
$resp = $this->postJson($this->baseEndpoint, $details);
$resp->assertStatus(422);
$resp->assertJson([
'error' => [
'message' => 'The given data was invalid.',
'validation' => [
'name' => ['The name field is required.'],
],
'code' => 422,
],
]);
$resp->assertJson($this->validationResponse(['name' => ['The name field is required.']]));
}
public function test_link_or_file_needed_to_create()
@ -163,16 +155,27 @@ class AttachmentsApiTest extends TestCase
$resp = $this->postJson($this->baseEndpoint, $details);
$resp->assertStatus(422);
$resp->assertJson([
'error' => [
'message' => 'The given data was invalid.',
'validation' => [
'file' => ['The file field is required when link is not present.'],
'link' => ['The link field is required when file is not present.'],
],
'code' => 422,
],
]);
$resp->assertJson($this->validationResponse([
'file' => ['The file field is required when link is not present.'],
'link' => ['The link field is required when file is not present.'],
]));
}
public function test_message_shown_if_file_is_not_a_valid_file()
{
$this->actingAsApiAdmin();
/** @var Page $page */
$page = Page::query()->first();
$details = [
'name' => 'my attachment',
'uploaded_to' => $page->id,
'file' => 'cat',
];
$resp = $this->postJson($this->baseEndpoint, $details);
$resp->assertStatus(422);
$resp->assertJson($this->validationResponse(['file' => ['The file must be provided as a valid file.']]));
}
public function test_read_endpoint_for_link_attachment()

View File

@ -659,14 +659,14 @@ class PageContentTest extends TestCase
public function test_markdown_base64_extract_not_limited_by_pcre_limits()
{
$pcreBacktrackLimit = ini_get("pcre.backtrack_limit");
$pcreRecursionLimit = ini_get("pcre.recursion_limit");
$pcreBacktrackLimit = ini_get('pcre.backtrack_limit');
$pcreRecursionLimit = ini_get('pcre.recursion_limit');
$this->asEditor();
$page = Page::query()->first();
ini_set("pcre.backtrack_limit", "500");
ini_set("pcre.recursion_limit", "500");
ini_set('pcre.backtrack_limit', '500');
ini_set('pcre.recursion_limit', '500');
$content = str_repeat('a', 5000);
$base64Content = base64_encode($content);
@ -686,8 +686,8 @@ class PageContentTest extends TestCase
$this->assertEquals($content, file_get_contents($imageFile));
$this->deleteImage($imagePath);
ini_set("pcre.backtrack_limit", $pcreBacktrackLimit);
ini_set("pcre.recursion_limit", $pcreRecursionLimit);
ini_set('pcre.backtrack_limit', $pcreBacktrackLimit);
ini_set('pcre.recursion_limit', $pcreRecursionLimit);
}
public function test_base64_images_within_markdown_blanked_if_not_supported_extension_for_extract()