public function testUpdate()
 {
     $form = $this->buildForm();
     $formValidator = new UsersSettoriFormInputFilter();
     $form->setInputFilter($formValidator->getInputFilter());
     if ($form->isValid()) {
         $formValidator->exchangeArray($form->getData());
         $this->helper->setConnection($this->getConnectionMock());
         $this->assertEquals($this->helper->update($formValidator), 1);
     }
 }
 public function indexAction()
 {
     /**
      * @var \Doctrine\ORM\EntityManager $em
      */
     $em = $this->getServiceLocator()->get('doctrine.entitymanager.orm_default');
     /**
      * @var \Doctrine\DBAL\Connection $connection
      */
     $connection = $em->getConnection();
     $request = $this->getRequest();
     $post = array_merge_recursive($request->getPost()->toArray(), $request->getFiles()->toArray());
     if (!($request->isXmlHttpRequest() or $request->isPost())) {
         return $this->redirect()->toRoute('main');
     }
     $inputFilter = new UsersSettoriFormInputFilter();
     $form = new UsersSettoriForm();
     $form->setBindOnValidate(false);
     $form->setInputFilter($inputFilter->getInputFilter());
     $form->setData($post);
     $this->initializeAdminArea();
     $userDetails = $this->recoverUserDetails();
     $helper = new SettoriControllerHelper();
     $helper->setEntityManager($em);
     $helper->setConnection($connection);
     $helper->getConnection()->beginTransaction();
     try {
         if (!$form->isValid()) {
             throw new NullException("The form is not valid");
         }
         $inputFilter->exchangeArray($form->getData());
         $helper->setLoggedUser($userDetails);
         $lastInsertId = $helper->insert($inputFilter);
         $helper->getConnection()->commit();
         $logWriter = new LogWriter($connection);
         $logWriter->writeLog(array('user_id' => $userDetails->id, 'module_id' => ModulesContainer::contenuti_id, 'message' => "Inserito nuovo settore utente " . $inputFilter->nome, 'type' => 'info', 'reference_id' => $lastInsertId, 'backend' => 1));
         $this->layout()->setVariables(array('messageType' => 'success', 'messageTitle' => 'Settore utente inserito correttamente', 'messageText' => 'I dati sono stati processati correttamente dal sistema', 'showLinkResetFormAndShowIt' => 1, 'backToSummaryLink' => $this->url()->fromRoute('admin/users-settori-summary', array('lang' => $this->params()->fromRoute('lang'))), 'backToSummaryText' => "Elenco settori", 'insertAgainLabel' => "Inserisci un altro settore"));
     } catch (\Exception $e) {
         $helper->getConnection()->rollBack();
         $logWriter = new LogWriter($connection);
         $logWriter->writeLog(array('user_id' => $userDetails->id, 'module_id' => ModulesContainer::contenuti_id, 'message' => "Errore inserimento nuovo settore: " . $inputFilter->nome, 'type' => 'error', 'backend' => 1));
         $this->layout()->setVariables(array('messageType' => 'danger', 'messageTitle' => 'Errore inserimento nuovo settore', 'messageText' => 'Messaggio generato: ' . $e->getMessage(), 'form' => $form, 'formInputFilter' => $inputFilter->getInputFilter(), 'messageShowFormLink' => 1, 'messageShowForm' => 'Torna al form di inserimento dati'));
     }
     $this->layout()->setTemplate($this->layout()->getVariable('templateDir') . 'message.phtml');
 }