From a83b50bb97ab662d7b10b2a37d07da3c09adfc14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julius=20H=C3=A4rtl?= Date: Sun, 17 Jun 2018 22:04:25 +0200 Subject: [PATCH] return empty result MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Julius Härtl --- .eslintrc.yml | 1 + js/controller/AttachmentController.js | 2 +- js/service/FileService.js | 12 ++++-------- lib/Service/FileService.php | 2 +- tests/unit/Service/FileServiceTest.php | 8 +++++++- 5 files changed, 14 insertions(+), 11 deletions(-) diff --git a/.eslintrc.yml b/.eslintrc.yml index 1200f3840..3e973a590 100644 --- a/.eslintrc.yml +++ b/.eslintrc.yml @@ -33,6 +33,7 @@ rules: no-fallthrough: error no-mixed-spaces-and-tabs: error no-unused-vars: warn + no-useless-escape: warn no-use-before-define: error semi: ["error", "always"] indent: diff --git a/js/controller/AttachmentController.js b/js/controller/AttachmentController.js index 892c2bedf..da8ce5292 100644 --- a/js/controller/AttachmentController.js +++ b/js/controller/AttachmentController.js @@ -53,7 +53,7 @@ class AttachmentListController { insertText = `![📎 ${filename}](${url})`; } return insertText; - }; + } select(attachment) { this.onSelect({attachment: this.getAttachmentMarkdown(attachment)}); diff --git a/js/service/FileService.js b/js/service/FileService.js index 89a219ea9..f1b6eb629 100644 --- a/js/service/FileService.js +++ b/js/service/FileService.js @@ -42,14 +42,10 @@ export default class FileService { { requesttoken: oc_requesttoken, type: 'deck_file', - } ]; } - fileItem.headers = - { - requesttoken: oc_requesttoken, - }; + fileItem.headers = {requesttoken: oc_requesttoken}; this.uploader.uploadItem(fileItem); } @@ -75,7 +71,7 @@ export default class FileService { return attachment.extendedData.info.extension === existingFile.extendedData.info.extension && attachment.extendedData.info.filename.startsWith(fileName); }); - let nextIndex = foundFilesMatching.length+1; + let nextIndex = foundFilesMatching.length + 1; fileItem.file.name = fileName + ' (' + nextIndex + ').' + existingFile.extendedData.info.extension; self.runUpload(fileItem); } @@ -90,14 +86,14 @@ export default class FileService { } - onSuccessItem(item, response) { + onSuccessItem (item, response) { let attachments = this.cardservice.get(item.cardId).attachments; let index = attachments.indexOf(attachments.find((attachment) => attachment.id === response.id)); if (~index) { attachments = attachments.splice(index, 1); } this.cardservice.get(item.cardId).attachments.push(response); - }; + } } diff --git a/lib/Service/FileService.php b/lib/Service/FileService.php index 5e4cb2326..adeaad4af 100644 --- a/lib/Service/FileService.php +++ b/lib/Service/FileService.php @@ -112,7 +112,7 @@ class FileService implements IAttachmentService { ]; if (empty($file)) { - $error = $this->l10n->t('No file uploaded'); + $error = $this->l10n->t('No file uploaded'); } if (!empty($file) && array_key_exists('error', $file) && $file['error'] !== UPLOAD_ERR_OK) { $error = $phpFileUploadErrors[$file['error']]; diff --git a/tests/unit/Service/FileServiceTest.php b/tests/unit/Service/FileServiceTest.php index 41c48914e..f0bf0e9e8 100644 --- a/tests/unit/Service/FileServiceTest.php +++ b/tests/unit/Service/FileServiceTest.php @@ -86,7 +86,7 @@ class FileServiceTest extends TestCase { private function mockGetUploadedFileEmpty() { $this->request->expects($this->once()) ->method('getUploadedFile') - ->willReturn(null); + ->willReturn([]); } private function mockGetUploadedFileError($error) { $this->request->expects($this->once()) @@ -107,6 +107,9 @@ class FileServiceTest extends TestCase { */ public function testCreateEmpty() { $attachment = $this->getAttachment(); + $this->l10n->expects($this->any()) + ->method('t') + ->willReturn('Error'); $this->mockGetUploadedFileEmpty(); $this->fileService->create($attachment); } @@ -117,6 +120,9 @@ class FileServiceTest extends TestCase { public function testCreateError() { $attachment = $this->getAttachment(); $this->mockGetUploadedFileError(UPLOAD_ERR_INI_SIZE); + $this->l10n->expects($this->any()) + ->method('t') + ->willReturn('Error'); $this->fileService->create($attachment); }