'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.',
$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.'],
]));
}
$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()
$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()
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);
$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()