/**
  * TODO Test sollte nur prüfen, ob Funktionen in Unterformular aufgerufen wird (verwende Mock-Objekt)
  */
 public function testUpdateModel()
 {
     $form = new Admin_Form_FileManager();
     $document = new Opus_Document(92);
     $form->populateFromModel($document);
     $filesForm = $form->getSubForm(Admin_Form_FileManager::SUBFORM_FILES);
     $files = $document->getFile();
     $this->assertEquals(2, count($files));
     $this->assertNull($files[0]->getComment());
     $fileForm = $filesForm->getSubForm('File0');
     $fileForm->getElement('Comment')->setValue('Testkommentar');
     $form->updateModel($document);
     $files = $document->getFile();
     $this->assertEquals(2, count($files));
     $this->assertEquals('Testkommentar', $files[0]->getComment());
 }
 /**
  * Zeigt Upload-Formular und Formulare fuer Dateien an.
  */
 public function indexAction()
 {
     $docId = $this->getRequest()->getParam(self::PARAM_DOCUMENT_ID);
     $document = $this->getHelper('documents')->getDocumentForId($docId);
     $form = null;
     if (isset($document)) {
         $editSession = new Admin_Model_DocumentEditSession($docId);
         if ($this->getRequest()->isPost()) {
             $post = $this->getRequest()->getPost();
             $form = new Admin_Form_FileManager();
             $data = $post[$form->getName()];
             // TODO
             $form->constructFromPost($data, $document);
             $form->populate($post);
             $result = $form->processPost($data, $data);
             if (is_array($result)) {
                 $target = $result['target'];
                 // TODO check if present
                 $result = $result['result'];
                 // TODO check if present
             }
             switch ($result) {
                 case Admin_Form_FileManager::RESULT_SAVE:
                     if ($form->isValid($post)) {
                         $form->updateModel($document);
                         try {
                             $document->store();
                         } catch (Opus_Mode_Exception $ome) {
                             $this->getLogger()->err(__METHOD__ . ' Error saving file metadata: ' . $ome->getMessage());
                             return $this->_redirectTo('index', 'admin_filemanager_save_failure', 'document', 'admin', array('id' => $docId));
                         }
                         return $this->_redirectTo('index', 'admin_filemanager_save_success', 'document', 'admin', array('id' => $docId));
                     } else {
                         $form->setMessage($this->view->translate('admin_filemanager_error_validation'));
                     }
                     break;
                 case Admin_Form_FileManager::RESULT_CANCEL:
                     // TODO Rücksprung zur Ursprungsseite
                     return $this->_redirectTo('index', null, 'document', 'admin', array('id' => $docId));
                     break;
                 case Admin_Form_Document::RESULT_SWITCH_TO:
                     $editSession->storePost($data, 'files');
                     // TODO Parameter in Unterarray 'params' => array() verlagern?
                     $target[self::PARAM_DOCUMENT_ID] = $docId;
                     $action = $target['action'];
                     unset($target['action']);
                     $controller = $target['controller'];
                     unset($target['controller']);
                     $module = $target['module'];
                     unset($target['module']);
                     return $this->_redirectTo($action, null, $controller, $module, $target);
                     break;
                 case Admin_Form_Document::RESULT_SHOW:
                 default:
                     // $form->populate($post);
                     break;
             }
         } else {
             // GET-Request; Neues Formular anzeigen bzw. Editieren fortsetzen
             $form = new Admin_Form_FileManager();
             $form->populateFromModel($document);
             $post = $editSession->retrievePost('files');
             if ($this->getRequest()->getParam('continue') && !is_null($post)) {
                 $form->continueEdit($this->getRequest(), $post);
             }
         }
     } else {
         // missing or bad parameter => go back to main page
         return $this->_redirectTo('index', array('failure' => 'admin_document_error_novalidid'), 'documents', 'admin');
     }
     // Set dynamic breadcrumb
     $this->_breadcrumbs->setDocumentBreadcrumb($document);
     $this->view->languageSelectorDisabled = true;
     $this->view->contentWrapperDisabled = true;
     // wrapper wird innerhalb des Formulars gerendert
     $form->setAction($this->view->url(array('module' => 'admin', 'controller' => 'filemanager', 'action' => 'index', self::PARAM_DOCUMENT_ID => $document->getId()), null, true));
     $this->renderForm($form);
 }