Example #1
0
 public function testKnownGoodZipArchiveEqualsGeneratedZipArchive()
 {
     $this->auth();
     $goodZip = new ZipArchiveModel(null, array('filename' => PROJECT_PATH . "/test/data/zip/test-archive.zip"));
     $xml = file_get_contents(PROJECT_PATH . "/test/data/xml/test1-questionnaire-definition.xml");
     QuestionnaireModel::importXML($xml);
     InstanceModel::importXML($xml, 'Test1 Company');
     $instance = new InstanceModel(array('questionnaireName' => 'Test1 Questionnaire', 'questionnaireVersion' => '3.00', 'revision' => 1, 'instanceName' => 'Test1 Company', 'depth' => 'question'));
     while ($page = $instance->nextPage()) {
         while ($section = $page->nextSection()) {
             while ($question = $section->nextQuestion()) {
                 $fileObj = new FileModel($question);
                 $fileObj->store(file_get_contents(PROJECT_PATH . '/test/data/zip/test-archive-attachment.txt'), array('filename' => 'test-archive-attachment.txt'));
                 break 3;
             }
         }
     }
     $zip = new ZipArchiveModel($instance, array('new' => '1'));
     $zip->addInstanceFullResponsesXMLDocument();
     $zip->addAttachments();
     $zip->close();
     $zip = new ZipArchiveModel($instance, array('filename' => $zip->getZipFileName()));
     $this->assertEquals($goodZip->getInstanceFullResponsesXMLDocument(), $zip->getInstanceFullResponsesXMLDocument());
     $this->assertEquals($goodZip->getFromName('files/4'), $zip->getFromName('files/4'));
     $zip->deleteZipFile();
 }
Example #2
0
 public function testEncryptedZipArchiveExportCanBeImported()
 {
     $this->auth();
     $crypto = CryptoModel::importRijndael256Key('testdupe', 'BqPwhnSskTFzxPUlljXG1zgG8cfgTSaGj8UyRWsKanA=');
     $instance = new InstanceModel(array('instanceID' => 1));
     $zip = new ZipArchiveModel($instance, array('new' => '1'));
     $zip->addInstanceFullResponsesXMLDocument();
     $zip->close();
     $encrypted = $crypto->encrypt($zip->getZipFileContents());
     $zip->deleteZipFile();
     $decrypted = $crypto->decrypt($encrypted);
     $tempfile = tempnam(PROJECT_PATH . DIRECTORY_SEPARATOR . 'tmp', 'zip');
     unlink($tempfile);
     file_put_contents($tempfile, $decrypted);
     $zip = new ZipArchiveModel(null, array('filename' => $tempfile));
     InstanceModel::importXML($zip, 'test encryption import');
     $zip->deleteZipFile();
 }
 public function ResponsesFullXMLArchiveAction()
 {
     $session = new Zend_Session_Namespace('login');
     $cryptoID = $this->_hasParam('cryptoID') ? $this->_getParam('cryptoID') : null;
     if ($this->_hasParam('download') && isset($session->tempFile)) {
         if (isset($cryptoID) && $cryptoID != 0) {
             $this->view->cryptoID = $cryptoID;
         }
         $this->view->archive = file_get_contents($session->tempFile);
         unlink($session->tempFile);
         unset($session->tempFile);
     } else {
         $instance = new InstanceModel(array('instanceID' => $session->dataInstanceID, 'depth' => 'instance'));
         $zip = new ZipArchiveModel($instance, array('new' => 1));
         $zip->addInstanceFullResponsesXMLDocument();
         $zip->addAttachments();
         $zip->close();
         $tempFile = tempnam(PROJECT_PATH . DIRECTORY_SEPARATOR . 'tmp', 'exp');
         $archive = '';
         if (isset($cryptoID) && $cryptoID != 0) {
             $crypto = new CryptoModel(array('cryptoID' => $cryptoID));
             $archive = $crypto->encrypt($zip->getZipFileContents());
             $this->view->cryptoID = $cryptoID;
         } else {
             $archive = $zip->getZipFileContents();
         }
         $zip->deleteZipFile();
         file_put_contents($tempFile, $archive);
         $session->tempFile = $tempFile;
     }
     $this->view->setRenderLayout(false);
 }