mirror of
https://github.com/BookStackApp/BookStack.git
synced 2025-03-04 03:37:58 +08:00
Updated attachment tests to align with front-end changes
This commit is contained in:
parent
d41452f39c
commit
9d6f574494
@ -36,7 +36,7 @@ class AttachmentTest extends TestCase
|
|||||||
protected function deleteUploads()
|
protected function deleteUploads()
|
||||||
{
|
{
|
||||||
$fileService = $this->app->make(\BookStack\Uploads\AttachmentService::class);
|
$fileService = $this->app->make(\BookStack\Uploads\AttachmentService::class);
|
||||||
foreach (\BookStack\Uploads\Attachment::all() as $file) {
|
foreach (Attachment::all() as $file) {
|
||||||
$fileService->deleteFile($file);
|
$fileService->deleteFile($file);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -110,12 +110,12 @@ class AttachmentTest extends TestCase
|
|||||||
$this->asAdmin();
|
$this->asAdmin();
|
||||||
|
|
||||||
$linkReq = $this->call('POST', 'attachments/link', [
|
$linkReq = $this->call('POST', 'attachments/link', [
|
||||||
'link' => 'https://example.com',
|
'attachment_link_url' => 'https://example.com',
|
||||||
'name' => 'Example Attachment Link',
|
'attachment_link_name' => 'Example Attachment Link',
|
||||||
'uploaded_to' => $page->id,
|
'attachment_link_uploaded_to' => $page->id,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$expectedResp = [
|
$expectedData = [
|
||||||
'path' => 'https://example.com',
|
'path' => 'https://example.com',
|
||||||
'name' => 'Example Attachment Link',
|
'name' => 'Example Attachment Link',
|
||||||
'uploaded_to' => $page->id,
|
'uploaded_to' => $page->id,
|
||||||
@ -127,8 +127,7 @@ class AttachmentTest extends TestCase
|
|||||||
];
|
];
|
||||||
|
|
||||||
$linkReq->assertStatus(200);
|
$linkReq->assertStatus(200);
|
||||||
$linkReq->assertJson($expectedResp);
|
$this->assertDatabaseHas('attachments', $expectedData);
|
||||||
$this->assertDatabaseHas('attachments', $expectedResp);
|
|
||||||
$attachment = Attachment::orderBy('id', 'desc')->take(1)->first();
|
$attachment = Attachment::orderBy('id', 'desc')->take(1)->first();
|
||||||
|
|
||||||
$pageGet = $this->get($page->getUrl());
|
$pageGet = $this->get($page->getUrl());
|
||||||
@ -147,28 +146,27 @@ class AttachmentTest extends TestCase
|
|||||||
$this->asAdmin();
|
$this->asAdmin();
|
||||||
|
|
||||||
$this->call('POST', 'attachments/link', [
|
$this->call('POST', 'attachments/link', [
|
||||||
'link' => 'https://example.com',
|
'attachment_link_url' => 'https://example.com',
|
||||||
'name' => 'Example Attachment Link',
|
'attachment_link_name' => 'Example Attachment Link',
|
||||||
'uploaded_to' => $page->id,
|
'attachment_link_uploaded_to' => $page->id,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$attachmentId = \BookStack\Uploads\Attachment::first()->id;
|
$attachmentId = Attachment::first()->id;
|
||||||
|
|
||||||
$update = $this->call('PUT', 'attachments/' . $attachmentId, [
|
$update = $this->call('PUT', 'attachments/' . $attachmentId, [
|
||||||
'uploaded_to' => $page->id,
|
'attachment_edit_name' => 'My new attachment name',
|
||||||
'name' => 'My new attachment name',
|
'attachment_edit_url' => 'https://test.example.com'
|
||||||
'link' => 'https://test.example.com'
|
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$expectedResp = [
|
$expectedData = [
|
||||||
|
'id' => $attachmentId,
|
||||||
'path' => 'https://test.example.com',
|
'path' => 'https://test.example.com',
|
||||||
'name' => 'My new attachment name',
|
'name' => 'My new attachment name',
|
||||||
'uploaded_to' => $page->id
|
'uploaded_to' => $page->id
|
||||||
];
|
];
|
||||||
|
|
||||||
$update->assertStatus(200);
|
$update->assertStatus(200);
|
||||||
$update->assertJson($expectedResp);
|
$this->assertDatabaseHas('attachments', $expectedData);
|
||||||
$this->assertDatabaseHas('attachments', $expectedResp);
|
|
||||||
|
|
||||||
$this->deleteUploads();
|
$this->deleteUploads();
|
||||||
}
|
}
|
||||||
@ -184,7 +182,7 @@ class AttachmentTest extends TestCase
|
|||||||
$filePath = storage_path($attachment->path);
|
$filePath = storage_path($attachment->path);
|
||||||
$this->assertTrue(file_exists($filePath), 'File at path ' . $filePath . ' does not exist');
|
$this->assertTrue(file_exists($filePath), 'File at path ' . $filePath . ' does not exist');
|
||||||
|
|
||||||
$attachment = \BookStack\Uploads\Attachment::first();
|
$attachment = Attachment::first();
|
||||||
$this->delete($attachment->getUrl());
|
$this->delete($attachment->getUrl());
|
||||||
|
|
||||||
$this->assertDatabaseMissing('attachments', [
|
$this->assertDatabaseMissing('attachments', [
|
||||||
|
Loading…
x
Reference in New Issue
Block a user