From f960a5b92019befa4da7b0d46a85cd41699ae556 Mon Sep 17 00:00:00 2001 From: wadedvsa <155439365+wadedvsa@users.noreply.github.com> Date: Fri, 23 Feb 2024 13:20:32 +0000 Subject: [PATCH 1/9] feat: Upload/remove files from conversation --- .../Controller/ConversationsController.php | 72 +++++++++++++++---- .../ConversationsControllerFactory.php | 3 + .../src/Form/Model/Fieldset/Message/Reply.php | 19 +++-- .../src/Form/Model/Form/Message/Reply.php | 1 + 4 files changed, 78 insertions(+), 17 deletions(-) diff --git a/module/Olcs/src/Controller/ConversationsController.php b/module/Olcs/src/Controller/ConversationsController.php index 9ea7e4665..b2de7cdaa 100644 --- a/module/Olcs/src/Controller/ConversationsController.php +++ b/module/Olcs/src/Controller/ConversationsController.php @@ -4,15 +4,18 @@ namespace Olcs\Controller; +use Common\Category; use Common\Controller\Interfaces\ToggleAwareInterface; use Common\Controller\Lva\AbstractController; use Common\FeatureToggle; use Common\Form\Form; +use Common\Service\Helper\FileUploadHelperService; use Common\Service\Helper\FlashMessengerHelperService; use Common\Service\Helper\FormHelperService; use Common\Service\Table\TableFactory; use Dvsa\Olcs\Transfer\Command\Messaging\Conversation\Create; use Dvsa\Olcs\Transfer\Command\Messaging\Message\Create as CreateMessageCommand; +use Dvsa\Olcs\Transfer\Query\Messaging\Documents; use Dvsa\Olcs\Transfer\Query\Messaging\Messages\ByConversation as ByConversationQuery; use Dvsa\Olcs\Transfer\Query\Messaging\Conversations\ByOrganisation as ByOrganisationQuery; use Dvsa\Olcs\Utils\Translation\NiTextTranslation; @@ -22,6 +25,7 @@ use Olcs\Form\Model\Form\Message\Reply as ReplyForm; use Olcs\Form\Model\Form\Message\Create as CreateForm; use Olcs\Service\Data\MessagingAppOrLicNo; +use Olcs\Service\Data\SubCategory; class ConversationsController extends AbstractController implements ToggleAwareInterface { @@ -34,17 +38,20 @@ class ConversationsController extends AbstractController implements ToggleAwareI protected FlashMessengerHelperService $flashMessengerHelper; protected TableFactory $tableFactory; protected FormHelperService $formHelperService; + protected FileUploadHelperService $uploadHelper; public function __construct( NiTextTranslation $niTextTranslationUtil, AuthorizationService $authService, FlashMessengerHelperService $flashMessengerHelper, TableFactory $tableFactory, - FormHelperService $formHelperService + FormHelperService $formHelperService, + FileUploadHelperService $uploadHelper ) { $this->flashMessengerHelper = $flashMessengerHelper; $this->tableFactory = $tableFactory; $this->formHelperService = $formHelperService; + $this->uploadHelper = $uploadHelper; parent::__construct($niTextTranslationUtil, $authService); } @@ -106,13 +113,17 @@ private function submitConversation(\Laminas\Form\Form $form) { $response = $this->handleCommand($this->mapFormDataToCommand($form)); if (!$response->isOk()) { - $this->flashMessengerHelper->addErrorMessage('There was an server error when submitting your conversation; please try later'); + $this->flashMessengerHelper->addErrorMessage( + 'There was an server error when submitting your conversation; please try later', + ); return $this->addAction(); } $conversationId = $response->getResult()['id']['conversation'] ?? null; if (empty($conversationId)) { - $this->flashMessengerHelper->addErrorMessage('There was an server error when submitting your conversation; please try later'); + $this->flashMessengerHelper->addErrorMessage( + 'There was an server error when submitting your conversation; please try later', + ); return $this->addAction(); } @@ -133,7 +144,7 @@ private function mapFormDataToCommand(\Laminas\Form\Form $form): Create $appOrLicNoPrefix = substr($data['form-actions']['appOrLicNo'], 0, 1); $appOrLicNoSuffix = substr($data['form-actions']['appOrLicNo'], 1); - switch($appOrLicNoPrefix) { + switch ($appOrLicNoPrefix) { case MessagingAppOrLicNo::PREFIX_LICENCE: $processedData['licence'] = $appOrLicNoSuffix; break; @@ -172,19 +183,21 @@ public function viewAction() $form = $this->formHelperService->createForm(ReplyForm::class, true, false); $this->formHelperService->setFormActionFromRequest($form, $this->getRequest()); - $table = $this->tableFactory - ->buildTable('messages-view', $messages, $params); + $table = $this->tableFactory->buildTable('messages-view', $messages, $params); + + $canUploadFiles = $this->getCurrentOrganisation()['isMessagingFileUploadEnabled']; $view = new ViewModel( [ - 'table' => $table, - 'form' => $form, - 'canReply' => $canReply, + 'table' => $table, + 'form' => $form, + 'canReply' => $canReply, + 'canUploadFiles' => $canUploadFiles, ], ); $view->setTemplate('messages-view'); - if ($this->getRequest()->isPost() && $this->params()->fromPost('action') === 'reply') { + if ($this->getRequest()->isPost()) { return $this->parseReply($view, $form); } @@ -194,10 +207,19 @@ public function viewAction() /** @return Response|ViewModel */ protected function parseReply(ViewModel $view, Form $form) { - $form->setData((array)$this->params()->fromPost()); + $form->setData((array)$this->getRequest()->getPost()); $form->get('id')->setValue($this->params()->fromRoute('conversation')); - if (!$form->isValid()) { + $hasProcessedFiles = $this->processFiles( + $form, + 'form-actions->file', + [$this, 'processFileUpload'], + [$this, 'deleteFile'], + [$this, 'getUploadedFiles'], + 'form-actions->file->fileCount' + ); + + if ($hasProcessedFiles || $this->params()->fromPost('action') !== 'reply' || !$form->isValid()) { return $view; } @@ -219,4 +241,30 @@ protected function parseReply(ViewModel $view, Form $form) return parent::indexAction(); } + + public function processFileUpload($file) + { + $dtoData = [ + 'category' => Category::CATEGORY_LICENSING, + 'subCategory' => Category::DOC_SUB_CATEGORY_MESSAGING, + 'description' => $file['name'], + 'isExternal' => true, + 'conversation' => $this->params()->fromRoute('conversationId'), + ]; + + $this->uploadFile($file, $dtoData); + } + + public function getUploadedFiles() + { + $params = [ + 'category' => Category::CATEGORY_LICENSING, + 'subCategory' => Category::DOC_SUB_CATEGORY_MESSAGING, + 'conversation' => $this->params()->fromRoute('conversationId'), + ]; + + $response = $this->handleQuery(Documents::create($params)); + + return $response->getResult(); + } } diff --git a/module/Olcs/src/Controller/Factory/ConversationsControllerFactory.php b/module/Olcs/src/Controller/Factory/ConversationsControllerFactory.php index c4f4a45b3..3a47c47d0 100644 --- a/module/Olcs/src/Controller/Factory/ConversationsControllerFactory.php +++ b/module/Olcs/src/Controller/Factory/ConversationsControllerFactory.php @@ -4,6 +4,7 @@ namespace Olcs\Controller\Factory; +use Common\Service\Helper\FileUploadHelperService; use Common\Service\Helper\FlashMessengerHelperService; use Common\Service\Helper\FormHelperService; use Common\Service\Table\TableFactory; @@ -25,6 +26,7 @@ public function __invoke( $flashMessengerHelper = $container->get(FlashMessengerHelperService::class); $tableFactory = $container->get(TableFactory::class); $formHelperService = $container->get(FormHelperService::class); + $uploadHolder = $container->get(FileUploadHelperService::class); return new ConversationsController( $niTextTranslationUtil, @@ -32,6 +34,7 @@ public function __invoke( $flashMessengerHelper, $tableFactory, $formHelperService, + $uploadHolder, ); } } diff --git a/module/Olcs/src/Form/Model/Fieldset/Message/Reply.php b/module/Olcs/src/Form/Model/Fieldset/Message/Reply.php index 3f432d797..fbbeb00e3 100644 --- a/module/Olcs/src/Form/Model/Fieldset/Message/Reply.php +++ b/module/Olcs/src/Form/Model/Fieldset/Message/Reply.php @@ -5,9 +5,11 @@ namespace Olcs\Form\Model\Fieldset\Message; use Common\Form\Elements\InputFilters\ActionButton; +use Common\Form\Model\Fieldset\MultipleFileUpload; use Laminas\Form\Annotation as Form; -use Laminas\Form\Element\File; use Laminas\Form\Element\Textarea; +use Laminas\Filter\StringTrim; +use Laminas\Validator\StringLength; class Reply { @@ -18,12 +20,19 @@ class Reply * }) * @Form\Options({"label": "You can enter up to 1000 characters"}) * @Form\Required(true) - * @Form\Type(\Laminas\Form\Element\Textarea::class) - * @Form\Filter(\Laminas\Filter\StringTrim::class) - * @Form\Validator(\Laminas\Validator\StringLength::class, options={"min": 5, "max": 1000}) + * @Form\Type(Textarea::class) + * @Form\Filter(StringTrim::class) + * @Form\Validator(StringLength::class, options={"min": 5, "max": 1000}) */ public ?TextArea $reply = null; + /** + * @Form\Name("file") + * @Form\Attributes({"id": "file"}) + * @Form\ComposedObject(MultipleFileUpload::class) + */ + public ?MultipleFileUpload $file = null; + /** * @Form\Attributes({ * "type": "submit", @@ -34,7 +43,7 @@ class Reply * @Form\Options({ * "label": "Send message" * }) - * @Form\Type(\Common\Form\Elements\InputFilters\ActionButton::class) + * @Form\Type(ActionButton::class) */ public ?ActionButton $send = null; } diff --git a/module/Olcs/src/Form/Model/Form/Message/Reply.php b/module/Olcs/src/Form/Model/Form/Message/Reply.php index a4f6a83bc..5356d58c7 100644 --- a/module/Olcs/src/Form/Model/Form/Message/Reply.php +++ b/module/Olcs/src/Form/Model/Form/Message/Reply.php @@ -4,6 +4,7 @@ namespace Olcs\Form\Model\Form\Message; +use Common\Form\Model\Fieldset\MultipleFileUpload; use Laminas\Form\Annotation as Form; use Laminas\Form\Element\Hidden; use Olcs\Form\Model\Fieldset\Message\Reply as ReplyFieldset; From 1fbab1bca5bed853c7628e23e861b6f6647ec738 Mon Sep 17 00:00:00 2001 From: wadedvsa <155439365+wadedvsa@users.noreply.github.com> Date: Fri, 23 Feb 2024 16:59:19 +0000 Subject: [PATCH 2/9] fix: Message document link --- .../Olcs/src/Controller/ConversationsController.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/module/Olcs/src/Controller/ConversationsController.php b/module/Olcs/src/Controller/ConversationsController.php index b2de7cdaa..59cedd6fa 100644 --- a/module/Olcs/src/Controller/ConversationsController.php +++ b/module/Olcs/src/Controller/ConversationsController.php @@ -216,7 +216,7 @@ protected function parseReply(ViewModel $view, Form $form) [$this, 'processFileUpload'], [$this, 'deleteFile'], [$this, 'getUploadedFiles'], - 'form-actions->file->fileCount' + 'form-actions->file->fileCount', ); if ($hasProcessedFiles || $this->params()->fromPost('action') !== 'reply' || !$form->isValid()) { @@ -245,11 +245,11 @@ protected function parseReply(ViewModel $view, Form $form) public function processFileUpload($file) { $dtoData = [ - 'category' => Category::CATEGORY_LICENSING, - 'subCategory' => Category::DOC_SUB_CATEGORY_MESSAGING, - 'description' => $file['name'], - 'isExternal' => true, - 'conversation' => $this->params()->fromRoute('conversationId'), + 'category' => Category::CATEGORY_LICENSING, + 'subCategory' => Category::DOC_SUB_CATEGORY_MESSAGING, + 'description' => $file['name'], + 'isExternal' => true, + 'messagingConversation' => $this->params()->fromRoute('conversationId'), ]; $this->uploadFile($file, $dtoData); From 1e655751e9ac2b03f9386d0c03ae5acf2697f098 Mon Sep 17 00:00:00 2001 From: wadedvsa <155439365+wadedvsa@users.noreply.github.com> Date: Mon, 26 Feb 2024 12:27:44 +0000 Subject: [PATCH 3/9] fix: Keep reply open on file remove --- module/Olcs/src/Controller/ConversationsController.php | 3 +++ module/Olcs/view/messages-view.phtml | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/module/Olcs/src/Controller/ConversationsController.php b/module/Olcs/src/Controller/ConversationsController.php index 59cedd6fa..cc8426c37 100644 --- a/module/Olcs/src/Controller/ConversationsController.php +++ b/module/Olcs/src/Controller/ConversationsController.php @@ -192,6 +192,7 @@ public function viewAction() 'table' => $table, 'form' => $form, 'canReply' => $canReply, + 'openReply' => false, 'canUploadFiles' => $canUploadFiles, ], ); @@ -219,6 +220,8 @@ protected function parseReply(ViewModel $view, Form $form) 'form-actions->file->fileCount', ); + $view->setVariable('openReply', $hasProcessedFiles); + if ($hasProcessedFiles || $this->params()->fromPost('action') !== 'reply' || !$form->isValid()) { return $view; } diff --git a/module/Olcs/view/messages-view.phtml b/module/Olcs/view/messages-view.phtml index 62ceeac4c..fe5a60f5d 100644 --- a/module/Olcs/view/messages-view.phtml +++ b/module/Olcs/view/messages-view.phtml @@ -21,7 +21,7 @@ echo $this->partial( ?> canReply): ?> -
+
openReply): ?>open> Send a reply From 502963e4db2f56763e2ab4cef1088206ca93f547 Mon Sep 17 00:00:00 2001 From: wadedvsa <155439365+wadedvsa@users.noreply.github.com> Date: Mon, 26 Feb 2024 17:03:05 +0000 Subject: [PATCH 4/9] feat: Correlation ID for handling documents --- module/Olcs/src/Controller/ConversationsController.php | 10 ++++++---- module/Olcs/src/Form/Model/Form/Message/Reply.php | 6 ++++++ 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/module/Olcs/src/Controller/ConversationsController.php b/module/Olcs/src/Controller/ConversationsController.php index cc8426c37..91a164a71 100644 --- a/module/Olcs/src/Controller/ConversationsController.php +++ b/module/Olcs/src/Controller/ConversationsController.php @@ -25,7 +25,6 @@ use Olcs\Form\Model\Form\Message\Reply as ReplyForm; use Olcs\Form\Model\Form\Message\Create as CreateForm; use Olcs\Service\Data\MessagingAppOrLicNo; -use Olcs\Service\Data\SubCategory; class ConversationsController extends AbstractController implements ToggleAwareInterface { @@ -181,6 +180,7 @@ public function viewAction() } $form = $this->formHelperService->createForm(ReplyForm::class, true, false); + $form->get('correlationId')->setValue(sha1(microtime())); $this->formHelperService->setFormActionFromRequest($form, $this->getRequest()); $table = $this->tableFactory->buildTable('messages-view', $messages, $params); @@ -230,6 +230,7 @@ protected function parseReply(ViewModel $view, Form $form) CreateMessageCommand::create( [ 'conversation' => $this->params()->fromRoute('conversationId'), + 'correlationId' => $this->getRequest()->getPost('correlationId'), 'messageContent' => $form->get('form-actions')->get('reply')->getValue(), ], ), @@ -253,6 +254,7 @@ public function processFileUpload($file) 'description' => $file['name'], 'isExternal' => true, 'messagingConversation' => $this->params()->fromRoute('conversationId'), + 'correlationId' => $this->getRequest()->getPost('correlationId'), ]; $this->uploadFile($file, $dtoData); @@ -261,9 +263,9 @@ public function processFileUpload($file) public function getUploadedFiles() { $params = [ - 'category' => Category::CATEGORY_LICENSING, - 'subCategory' => Category::DOC_SUB_CATEGORY_MESSAGING, - 'conversation' => $this->params()->fromRoute('conversationId'), + 'category' => Category::CATEGORY_LICENSING, + 'subCategory' => Category::DOC_SUB_CATEGORY_MESSAGING, + 'correlationId' => $this->getRequest()->getPost('correlationId'), ]; $response = $this->handleQuery(Documents::create($params)); diff --git a/module/Olcs/src/Form/Model/Form/Message/Reply.php b/module/Olcs/src/Form/Model/Form/Message/Reply.php index 5356d58c7..ad9b7d488 100644 --- a/module/Olcs/src/Form/Model/Form/Message/Reply.php +++ b/module/Olcs/src/Form/Model/Form/Message/Reply.php @@ -24,6 +24,12 @@ class Reply */ public ?Hidden $id = null; + /** + * @Form\Attributes({"value": ""}) + * @Form\Type(\Laminas\Form\Element\Hidden::class) + */ + public ?Hidden $correlationId = null; + /** * @Form\Attributes({"value": "reply"}) * @Form\Type(\Laminas\Form\Element\Hidden::class) From 62d0ad89a2023c87c45d87f5a44055ff6a4df711 Mon Sep 17 00:00:00 2001 From: wadedvsa <155439365+wadedvsa@users.noreply.github.com> Date: Wed, 28 Feb 2024 10:38:54 +0000 Subject: [PATCH 5/9] chore: olcs-transfer bump --- composer.lock | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/composer.lock b/composer.lock index 29fc9f4dd..fc5675667 100644 --- a/composer.lock +++ b/composer.lock @@ -4108,16 +4108,16 @@ }, { "name": "olcs/olcs-transfer", - "version": "v6.0.1", + "version": "v6.2.0", "source": { "type": "git", "url": "https://github.com/dvsa/olcs-transfer.git", - "reference": "43132a1630e82c8c2231c37b03178ebb1aa2663f" + "reference": "788ab4ba4db697820a45922c06dfaf8fdd462bea" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/dvsa/olcs-transfer/zipball/43132a1630e82c8c2231c37b03178ebb1aa2663f", - "reference": "43132a1630e82c8c2231c37b03178ebb1aa2663f", + "url": "https://api.github.com/repos/dvsa/olcs-transfer/zipball/788ab4ba4db697820a45922c06dfaf8fdd462bea", + "reference": "788ab4ba4db697820a45922c06dfaf8fdd462bea", "shasum": "" }, "require": { @@ -4158,9 +4158,9 @@ "notification-url": "https://packagist.org/downloads/", "description": "OLCS Transfer", "support": { - "source": "https://github.com/dvsa/olcs-transfer/tree/v6.0.1" + "source": "https://github.com/dvsa/olcs-transfer/tree/v6.2.0" }, - "time": "2024-02-22T14:58:13+00:00" + "time": "2024-02-28T10:34:35+00:00" }, { "name": "olcs/olcs-utils", From f25bf2f086dd30d79743f32b495e76ce5e1c55bc Mon Sep 17 00:00:00 2001 From: wadedvsa <155439365+wadedvsa@users.noreply.github.com> Date: Wed, 28 Feb 2024 11:41:59 +0000 Subject: [PATCH 6/9] chore: olcs-transfer bump --- composer.lock | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/composer.lock b/composer.lock index 6b26b3396..fc5675667 100644 --- a/composer.lock +++ b/composer.lock @@ -4108,16 +4108,16 @@ }, { "name": "olcs/olcs-transfer", - "version": "v6.1.0", + "version": "v6.2.0", "source": { "type": "git", "url": "https://github.com/dvsa/olcs-transfer.git", - "reference": "ff4249e741de87991c0b999513e754e96de1446b" + "reference": "788ab4ba4db697820a45922c06dfaf8fdd462bea" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/dvsa/olcs-transfer/zipball/ff4249e741de87991c0b999513e754e96de1446b", - "reference": "ff4249e741de87991c0b999513e754e96de1446b", + "url": "https://api.github.com/repos/dvsa/olcs-transfer/zipball/788ab4ba4db697820a45922c06dfaf8fdd462bea", + "reference": "788ab4ba4db697820a45922c06dfaf8fdd462bea", "shasum": "" }, "require": { @@ -4158,9 +4158,9 @@ "notification-url": "https://packagist.org/downloads/", "description": "OLCS Transfer", "support": { - "source": "https://github.com/dvsa/olcs-transfer/tree/v6.1.0" + "source": "https://github.com/dvsa/olcs-transfer/tree/v6.2.0" }, - "time": "2024-02-22T15:22:13+00:00" + "time": "2024-02-28T10:34:35+00:00" }, { "name": "olcs/olcs-utils", From 4b07b8e23613afcf8eaf0ebff1a698707e3eb2e9 Mon Sep 17 00:00:00 2001 From: wadedvsa <155439365+wadedvsa@users.noreply.github.com> Date: Wed, 28 Feb 2024 12:43:45 +0000 Subject: [PATCH 7/9] chore: olcs-common bump --- composer.lock | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/composer.lock b/composer.lock index fc5675667..74587fef6 100644 --- a/composer.lock +++ b/composer.lock @@ -3982,16 +3982,16 @@ }, { "name": "olcs/olcs-common", - "version": "v6.0.0", + "version": "v6.1.0", "source": { "type": "git", "url": "https://github.com/dvsa/olcs-common.git", - "reference": "3f4192f5df14a23a77797c7acd0454856500a483" + "reference": "f0c888c687e4680d82c7d44986c153e2212c51aa" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/dvsa/olcs-common/zipball/3f4192f5df14a23a77797c7acd0454856500a483", - "reference": "3f4192f5df14a23a77797c7acd0454856500a483", + "url": "https://api.github.com/repos/dvsa/olcs-common/zipball/f0c888c687e4680d82c7d44986c153e2212c51aa", + "reference": "f0c888c687e4680d82c7d44986c153e2212c51aa", "shasum": "" }, "require": { @@ -4049,9 +4049,9 @@ "notification-url": "https://packagist.org/downloads/", "description": "Common library for the OLCS Project", "support": { - "source": "https://github.com/dvsa/olcs-common/tree/v6.0.0" + "source": "https://github.com/dvsa/olcs-common/tree/v6.1.0" }, - "time": "2024-02-20T12:08:06+00:00" + "time": "2024-02-28T12:41:58+00:00" }, { "name": "olcs/olcs-logging", From 552fa4fda3f23f07fc3e8ce1cd91c422aa4778c4 Mon Sep 17 00:00:00 2001 From: wadedvsa <155439365+wadedvsa@users.noreply.github.com> Date: Thu, 29 Feb 2024 09:52:48 +0000 Subject: [PATCH 8/9] chore: olcs-transfer and olcs-common bump --- composer.lock | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/composer.lock b/composer.lock index 9b75d0351..65570a58d 100644 --- a/composer.lock +++ b/composer.lock @@ -3982,16 +3982,16 @@ }, { "name": "olcs/olcs-common", - "version": "v6.0.0", + "version": "v6.1.0", "source": { "type": "git", "url": "https://github.com/dvsa/olcs-common.git", - "reference": "3f4192f5df14a23a77797c7acd0454856500a483" + "reference": "f0c888c687e4680d82c7d44986c153e2212c51aa" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/dvsa/olcs-common/zipball/3f4192f5df14a23a77797c7acd0454856500a483", - "reference": "3f4192f5df14a23a77797c7acd0454856500a483", + "url": "https://api.github.com/repos/dvsa/olcs-common/zipball/f0c888c687e4680d82c7d44986c153e2212c51aa", + "reference": "f0c888c687e4680d82c7d44986c153e2212c51aa", "shasum": "" }, "require": { @@ -4049,9 +4049,9 @@ "notification-url": "https://packagist.org/downloads/", "description": "Common library for the OLCS Project", "support": { - "source": "https://github.com/dvsa/olcs-common/tree/v6.0.0" + "source": "https://github.com/dvsa/olcs-common/tree/v6.1.0" }, - "time": "2024-02-20T12:08:06+00:00" + "time": "2024-02-28T12:41:58+00:00" }, { "name": "olcs/olcs-logging", @@ -8024,5 +8024,5 @@ "platform-overrides": { "ext-redis": "4.3" }, - "plugin-api-version": "2.3.0" + "plugin-api-version": "2.6.0" } From c5bf614f5e6bf19297d43411cd0fd9a768d47525 Mon Sep 17 00:00:00 2001 From: wadedvsa <155439365+wadedvsa@users.noreply.github.com> Date: Fri, 1 Mar 2024 10:05:31 +0000 Subject: [PATCH 9/9] fix: Controller test --- .../ConversationsControllerTest.php | 106 +++++++++++++++--- 1 file changed, 92 insertions(+), 14 deletions(-) diff --git a/test/Olcs/src/Controller/ConversationsControllerTest.php b/test/Olcs/src/Controller/ConversationsControllerTest.php index 87bc2d90f..fe27fc987 100644 --- a/test/Olcs/src/Controller/ConversationsControllerTest.php +++ b/test/Olcs/src/Controller/ConversationsControllerTest.php @@ -6,11 +6,14 @@ use Common\Controller\Plugin\HandleQuery; use Common\Controller\Plugin\Redirect; use Common\Form\Form; +use Common\Rbac\User; use Common\Service\Cqrs\Response; +use Common\Service\Helper\FileUploadHelperService; use Common\Service\Helper\FlashMessengerHelperService; use Common\Service\Helper\FormHelperService; use Common\Service\Table\TableFactory; use Dvsa\Olcs\Utils\Translation\NiTextTranslation; +use Laminas\Form\Element\Hidden; use Laminas\Form\Element\Text; use Laminas\Form\Fieldset; use Laminas\Http\Request; @@ -40,6 +43,7 @@ public function setUp(): void $this->mockNavigation = m::mock(Navigation::class)->shouldIgnoreMissing(); $this->mockForm = m::mock(Form::class); $this->mockParams = m::mock(Params::class); + $this->mockUploadHelper = m::mock(FileUploadHelperService::class); $this->sut = m::mock(Sut::class) ->makePartial() @@ -52,6 +56,7 @@ public function setUp(): void $this->setMockedProperties($reflectionClass, 'tableFactory', $this->mockTableFactory); $this->setMockedProperties($reflectionClass, 'formHelperService', $this->mockFormHelperService); $this->setMockedProperties($reflectionClass, 'navigationService', $this->mockNavigation); + $this->setMockedProperties($reflectionClass, 'uploadHelper', $this->mockUploadHelper); $this->mockFormHelperService->shouldReceive('createForm') ->once() @@ -81,13 +86,15 @@ public function testViewAction(): void $mockResponse->shouldReceive('isOk') ->andReturn(true); $mockResponse->shouldReceive('getResult') - ->andReturn([ - 'extra' => [ - 'conversation' => [ - 'isClosed' => true, + ->andReturn( + [ + 'extra' => [ + 'conversation' => [ + 'isClosed' => true, + ], ], ], - ]); + ); $mockHandleQuery = m::mock(HandleQuery::class) ->makePartial(); @@ -107,11 +114,29 @@ public function testViewAction(): void ->with('conversationId') ->andReturn(1); + $mockUser = m::mock(User::class); + $mockUser->shouldReceive('getUserData') + ->once() + ->andReturn( + [ + 'organisationUsers' => [ + [ + 'organisation' => [ + 'isMessagingFileUploadEnabled' => true, + ], + ], + ], + ], + ); + $this->sut->shouldReceive('params') ->andReturn($this->mockParams); $this->sut->shouldReceive('plugin') ->with('handleQuery') ->andReturn($mockHandleQuery); + $this->sut->shouldReceive('plugin') + ->with('currentUser') + ->andReturn($mockUser); $table = ''; @@ -127,6 +152,15 @@ public function testViewAction(): void ->shouldReceive('findBy->setActive') ->once(); + $mockFormElement = m::mock(Hidden::class); + $mockFormElement->shouldReceive('setValue') + ->once(); + + $this->mockForm->shouldReceive('get') + ->once() + ->with('correlationId') + ->andReturn($mockFormElement); + $view = $this->sut->viewAction(); $this->assertInstanceOf(ViewModel::class, $view); $this->assertEquals($table, $view->getVariable('table')); @@ -138,15 +172,23 @@ public function testReply(): void $mockRequest->shouldReceive('isPost') ->once() ->andReturn(true); + $mockRequest->shouldReceive('getPost') + ->once() + ->withNoArgs() + ->andReturn([]); + $mockRequest->shouldReceive('getPost') + ->with('correlationId') + ->once() + ->andReturn('123'); + + $this->mockForm->shouldReceive('setData') + ->once() + ->with([]); $this->mockParams->shouldReceive('fromPost') ->once() ->with('action') ->andReturn('reply'); - $this->mockParams->shouldReceive('fromPost') - ->once() - ->withNoArgs() - ->andReturn(['a' => 'b']); $this->mockParams->shouldReceive('fromRoute') ->once() ->with('conversation') @@ -157,7 +199,7 @@ public function testReply(): void ->andReturn(['a' => 'b']); $this->sut->shouldReceive('getRequest') - ->twice() + ->times(5) ->andReturn($mockRequest); $mockCommandReturn = m::mock(Response::class); @@ -181,10 +223,6 @@ function ($command) { ->with('handleCommand') ->andReturn($mockCommandHandler); - $this->mockForm->shouldReceive('setData') - ->once() - ->with(['a' => 'b']); - $mockFormElement = m::mock(Text::class); $mockFormElement->shouldReceive('setValue') ->once() @@ -229,6 +267,46 @@ function ($command) { ->with('conversations/view', ['a' => 'b']) ->andReturn($mockViewModel); + $this->mockUploadHelper + ->shouldReceive('setForm') + ->once() + ->andReturn($this->mockUploadHelper); + + $this->mockUploadHelper + ->shouldReceive('setSelector') + ->once() + ->andReturn($this->mockUploadHelper); + + $this->mockUploadHelper + ->shouldReceive('setUploadCallback') + ->once() + ->andReturn($this->mockUploadHelper); + + $this->mockUploadHelper + ->shouldReceive('setDeleteCallback') + ->once() + ->andReturn($this->mockUploadHelper); + + $this->mockUploadHelper + ->shouldReceive('setLoadCallback') + ->once() + ->andReturn($this->mockUploadHelper); + + $this->mockUploadHelper + ->shouldReceive('setRequest') + ->once() + ->andReturn($this->mockUploadHelper); + + $this->mockUploadHelper + ->shouldReceive('setCountSelector') + ->once() + ->andReturn($this->mockUploadHelper); + + $this->mockUploadHelper + ->shouldReceive('process') + ->once() + ->andReturn(false); + $this->sut->shouldReceive('plugin') ->once() ->with('redirect')