public function testUploadNdaFormHasCorrectInputFilter() { $uploadNdaForm = new UploadNda(); $inputFilter = $uploadNdaForm->getInputFilterSpecification(); $this->assertTrue(is_array($inputFilter)); $this->assertArrayHasKey('file', $inputFilter); }
/** * Action to replace an mis-uploaded DoA * * @return ViewModel * @throws \Zend\Form\Exception\InvalidArgumentException * @throws \InvalidArgumentException * @throws \Zend\Mvc\Exception\DomainException * @throws \Zend\Form\Exception\DomainException */ public function replaceAction() { $nda = $this->getProgramService()->findEntityById('Nda', $this->getEvent()->getRouteMatch()->getParam('id')); if (is_null($nda) || sizeof($nda->getObject()) === 0) { return $this->notFoundAction(); } $data = array_merge_recursive($this->getRequest()->getPost()->toArray(), $this->getRequest()->getFiles()->toArray()); $form = new UploadNda(); $form->setData($data); if ($this->getRequest()->isPost()) { if (!isset($data['cancel']) && $form->isValid()) { $fileData = $this->params()->fromFiles(); /** * Remove the current entity */ foreach ($nda->getObject() as $object) { $this->getProgramService()->removeEntity($object); } //Create a article object element $ndaObject = new NdaObject(); $ndaObject->setObject(file_get_contents($fileData['file']['tmp_name'])); $fileSizeValidator = new FilesSize(PHP_INT_MAX); $fileSizeValidator->isValid($fileData['file']); $nda->setSize($fileSizeValidator->size); $nda->setContentType($this->getGeneralService()->findContentTypeByContentTypeName($fileData['file']['type'])); $ndaObject->setNda($nda); $this->getProgramService()->newEntity($ndaObject); $this->flashMessenger()->setNamespace('success')->addMessage(sprintf(_("txt-nda-has-been-replaced-successfully"))); return $this->redirect()->toRoute('program/nda/view', ['id' => $nda->getId()]); } if (isset($data['cancel'])) { $this->flashMessenger()->setNamespace('info')->addMessage(sprintf(_("txt-action-has-been-cancelled"))); return $this->redirect()->toRoute('program/nda/view', ['id' => $nda->getId()]); } } return new ViewModel(['nda' => $nda, 'form' => $form]); }