Media Endpoint improvements
For the code, media related stuff is now in its own controller Added support for querying the most recent file uploaded
This commit is contained in:
parent
2193e96274
commit
4f2d3b7c2b
6 changed files with 496 additions and 338 deletions
|
@ -655,148 +655,6 @@ class MicropubControllerTest extends TestCase
|
|||
]);
|
||||
}
|
||||
|
||||
public function test_media_endpoint_request_with_invalid_token_return_400_response()
|
||||
{
|
||||
$response = $this->post(
|
||||
'/api/media',
|
||||
[],
|
||||
['HTTP_Authorization' => 'Bearer abc123']
|
||||
);
|
||||
$response->assertStatus(400);
|
||||
$response->assertJsonFragment(['error_description' => 'The provided token did not pass validation']);
|
||||
}
|
||||
|
||||
public function test_media_endpoint_request_with_token_with_no_scope_returns_400_response()
|
||||
{
|
||||
$response = $this->post(
|
||||
'/api/media',
|
||||
[],
|
||||
['HTTP_Authorization' => 'Bearer ' . $this->getTokenWithNoScope()]
|
||||
);
|
||||
$response->assertStatus(400);
|
||||
$response->assertJsonFragment(['error_description' => 'The provided token has no scopes']);
|
||||
}
|
||||
|
||||
public function test_media_endpoint_request_with_insufficient_token_scopes_returns_401_response()
|
||||
{
|
||||
$response = $this->post(
|
||||
'/api/media',
|
||||
[],
|
||||
['HTTP_Authorization' => 'Bearer ' . $this->getTokenWithIncorrectScope()]
|
||||
);
|
||||
$response->assertStatus(401);
|
||||
$response->assertJsonFragment(['error_description' => 'The token’s scope does not have the necessary requirements.']);
|
||||
}
|
||||
|
||||
public function test_media_endpoint_upload_a_file()
|
||||
{
|
||||
Queue::fake();
|
||||
Storage::fake('s3');
|
||||
$file = __DIR__ . '/../aaron.png';
|
||||
|
||||
$response = $this->post(
|
||||
'/api/media',
|
||||
[
|
||||
'file' => new UploadedFile($file, 'aaron.png', 'image/png', null, true),
|
||||
],
|
||||
['HTTP_Authorization' => 'Bearer ' . $this->getToken()]
|
||||
);
|
||||
|
||||
$path = parse_url($response->getData()->location, PHP_URL_PATH);
|
||||
$filename = substr($path, 7);
|
||||
Queue::assertPushed(ProcessMedia::class);
|
||||
Storage::disk('local')->assertExists($filename);
|
||||
// now remove file
|
||||
unlink(storage_path('app/') . $filename);
|
||||
}
|
||||
|
||||
public function test_media_endpoint_upload_an_audio_file()
|
||||
{
|
||||
Queue::fake();
|
||||
Storage::fake('s3');
|
||||
$file = __DIR__ . '/../audio.mp3';
|
||||
|
||||
$response = $this->post(
|
||||
'/api/media',
|
||||
[
|
||||
'file' => new UploadedFile($file, 'audio.mp3', 'audio/mpeg', null, true),
|
||||
],
|
||||
['HTTP_Authorization' => 'Bearer ' . $this->getToken()]
|
||||
);
|
||||
|
||||
$path = parse_url($response->getData()->location, PHP_URL_PATH);
|
||||
$filename = substr($path, 7);
|
||||
Queue::assertPushed(ProcessMedia::class);
|
||||
Storage::disk('local')->assertExists($filename);
|
||||
// now remove file
|
||||
unlink(storage_path('app/') . $filename);
|
||||
}
|
||||
|
||||
public function test_media_endpoint_upload_a_video_file()
|
||||
{
|
||||
Queue::fake();
|
||||
Storage::fake('s3');
|
||||
$file = __DIR__ . '/../video.ogv';
|
||||
|
||||
$response = $this->post(
|
||||
'/api/media',
|
||||
[
|
||||
'file' => new UploadedFile($file, 'video.ogv', 'video/ogg', null, true),
|
||||
],
|
||||
['HTTP_Authorization' => 'Bearer ' . $this->getToken()]
|
||||
);
|
||||
|
||||
$path = parse_url($response->getData()->location, PHP_URL_PATH);
|
||||
$filename = substr($path, 7);
|
||||
Queue::assertPushed(ProcessMedia::class);
|
||||
Storage::disk('local')->assertExists($filename);
|
||||
// now remove file
|
||||
unlink(storage_path('app/') . $filename);
|
||||
}
|
||||
|
||||
public function test_media_endpoint_upload_a_document_file()
|
||||
{
|
||||
Queue::fake();
|
||||
Storage::fake('s3');
|
||||
|
||||
$response = $this->post(
|
||||
'/api/media',
|
||||
[
|
||||
'file' => UploadedFile::fake()->create('document.pdf', 100),
|
||||
],
|
||||
['HTTP_Authorization' => 'Bearer ' . $this->getToken()]
|
||||
);
|
||||
|
||||
$path = parse_url($response->getData()->location, PHP_URL_PATH);
|
||||
$filename = substr($path, 7);
|
||||
Queue::assertPushed(ProcessMedia::class);
|
||||
Storage::disk('local')->assertExists($filename);
|
||||
// now remove file
|
||||
unlink(storage_path('app/') . $filename);
|
||||
}
|
||||
|
||||
public function test_media_endpoint_upload_an_invalid_file_return_error()
|
||||
{
|
||||
Queue::fake();
|
||||
Storage::fake('local');
|
||||
|
||||
$response = $this->post(
|
||||
'/api/media',
|
||||
[
|
||||
'file' => new UploadedFile(
|
||||
__DIR__ . '/../aaron.png',
|
||||
'aaron.png',
|
||||
'image/png',
|
||||
UPLOAD_ERR_INI_SIZE,
|
||||
true
|
||||
),
|
||||
],
|
||||
['HTTP_Authorization' => 'Bearer ' . $this->getToken()]
|
||||
);
|
||||
$response->assertStatus(400);
|
||||
$response->assertJson(['error_description' => 'The uploaded file failed validation']);
|
||||
}
|
||||
|
||||
public function test_access_token_form_encoded()
|
||||
{
|
||||
$faker = \Faker\Factory::create();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue