-<?php
+<?php namespace Tests;
-class AttachmentTest extends TestCase
+class AttachmentTest extends BrowserKitTest
{
/**
* Get a test file that can be uploaded
protected function uploadFile($name, $uploadedTo = 0)
{
$file = $this->getTestFile($name);
- return $this->call('POST', '/files/upload', ['uploaded_to' => $uploadedTo], [], ['file' => $file], []);
+ return $this->call('POST', '/attachments/upload', ['uploaded_to' => $uploadedTo], [], ['file' => $file], []);
}
/**
*/
protected function deleteUploads()
{
- $fileService = $this->app->make(\BookStack\Services\FileService::class);
- foreach (\BookStack\File::all() as $file) {
+ $fileService = $this->app->make(\BookStack\Services\AttachmentService::class);
+ foreach (\BookStack\Attachment::all() as $file) {
$fileService->deleteFile($file);
}
}
$this->uploadFile($fileName, $page->id);
$this->assertResponseOk();
$this->seeJsonContains($expectedResp);
- $this->seeInDatabase('files', $expectedResp);
+ $this->seeInDatabase('attachments', $expectedResp);
$this->deleteUploads();
}
{
$page = \BookStack\Page::first();
$this->asAdmin();
- $admin = $this->getAdmin();
$fileName = 'upload_test_file.txt';
$this->uploadFile($fileName, $page->id);
$admin = $this->getAdmin();
$this->asAdmin();
- $this->call('POST', 'files/link', [
+ $this->call('POST', 'attachments/link', [
'link' => 'https://example.com',
'name' => 'Example Attachment Link',
'uploaded_to' => $page->id,
$this->assertResponseOk();
$this->seeJsonContains($expectedResp);
- $this->seeInDatabase('files', $expectedResp);
+ $this->seeInDatabase('attachments', $expectedResp);
$this->visit($page->getUrl())->seeLink('Example Attachment Link')
->click('Example Attachment Link')->seePageIs('https://example.com');
$page = \BookStack\Page::first();
$this->asAdmin();
- $this->call('POST', 'files/link', [
+ $this->call('POST', 'attachments/link', [
'link' => 'https://example.com',
'name' => 'Example Attachment Link',
'uploaded_to' => $page->id,
]);
- $attachmentId = \BookStack\File::first()->id;
+ $attachmentId = \BookStack\Attachment::first()->id;
- $this->call('PUT', 'files/' . $attachmentId, [
+ $this->call('PUT', 'attachments/' . $attachmentId, [
'uploaded_to' => $page->id,
'name' => 'My new attachment name',
'link' => 'https://test.example.com'
$this->assertResponseOk();
$this->seeJsonContains($expectedResp);
- $this->seeInDatabase('files', $expectedResp);
+ $this->seeInDatabase('attachments', $expectedResp);
$this->deleteUploads();
}
$this->assertTrue(file_exists($filePath), 'File at path ' . $filePath . ' does not exist');
- $attachmentId = \BookStack\File::first()->id;
- $this->call('DELETE', 'files/' . $attachmentId);
+ $attachmentId = \BookStack\Attachment::first()->id;
+ $this->call('DELETE', 'attachments/' . $attachmentId);
- $this->dontSeeInDatabase('files', [
+ $this->dontSeeInDatabase('attachments', [
'name' => $fileName
]);
$this->assertFalse(file_exists($filePath), 'File at path ' . $filePath . ' was not deleted as expected');
$filePath = base_path('storage/' . $this->getUploadPath($fileName));
$this->assertTrue(file_exists($filePath), 'File at path ' . $filePath . ' does not exist');
- $this->seeInDatabase('files', [
+ $this->seeInDatabase('attachments', [
'name' => $fileName
]);
$this->call('DELETE', $page->getUrl());
- $this->dontSeeInDatabase('files', [
+ $this->dontSeeInDatabase('attachments', [
'name' => $fileName
]);
$this->assertFalse(file_exists($filePath), 'File at path ' . $filePath . ' was not deleted as expected');