public function testFileLinkNoLabel() { $helper = new Application_View_Helper_FileLink(); $helper->setView(Zend_Registry::get('Opus_View')); $file = new Opus_File(126); $file->setLabel(null); $this->assertEquals('<a href="http:///files/146/test.pdf">test.pdf</a>' . '<input type="hidden" name="" value="126" id="" />', $helper->fileLink(null, $file, array('useFileLabel' => true))); }
public function getIst() { if ($this->_file->exists() && $this->getSignatureType() !== 'gpg' && $this->_file->canVerify()) { return $this->_file->getRealHash($this->getHashType()); } else { return null; } }
public function testGetLabel() { $this->useEnglish(); Zend_Registry::get('Zend_Translate')->loadModule('admin'); $element = new Application_Form_Element_FileHash('filehash'); $file = new Opus_File(116); $hashes = $file->getHashValue(); $hash = $hashes[0]; $this->assertEquals('MD5', $hash->getType()); $element->setValue($hash); $element->setFile($file); $this->assertEquals('Checksum - MD5', $element->getLabel()); }
public function setValue($file) { if (is_null($file)) { throw new Application_Exception(__METHOD__ . " Value must not be null."); } if (!$file instanceof Opus_File) { try { $file = new Opus_File($file); } catch (Opus_Model_NotFoundException $omnfe) { throw new Application_Exception("File with ID = {$file} not found."); } } if (!$file->exists()) { $this->addError('admin_filemanager_file_does_not_exist'); } parent::setValue($file); }
private function fetchFile($realm) { $targetFile = Opus_File::fetchByDocIdPathName($this->_doc->getId(), $this->_filename); if (is_null($targetFile)) { throw new Frontdoor_Model_FileNotFoundException(); } if (!$this->isFileAccessAllowed($targetFile, $realm)) { throw new Frontdoor_Model_FileAccessNotAllowedException(); } return $targetFile; }
public function testRequestPublishedDocWithAccessibleFile() { $this->markTestIncomplete('build breaks when running this test on ci system -- it seems that phpunit does not allow to test for file downloads'); // create test file test.pdf in file system $config = Zend_Registry::get('Zend_Config'); $path = $config->workspacePath . DIRECTORY_SEPARATOR . uniqid(); mkdir($path, 0777, true); $filepath = $path . DIRECTORY_SEPARATOR . 'test.pdf'; touch($filepath); $doc = $this->createTestDocument(); $doc->setServerState('published'); $file = new Opus_File(); $file->setVisibleInOai(true); $file->setPathName('test.pdf'); $file->setTempFile($filepath); $doc->addFile($file); $doc->store(); $this->dispatch('/oai/container/index/docId/' . $doc->getId()); // cleanup $file->delete(); Opus_Util_File::deleteDirectory($path); $this->assertResponseCode(200); }
/** * Regression Test for OPUSVIER-3072 (was Regression test for OPUSVIER-2509 and OPUSVIER-2510) */ public function testForDDCSubjectTypeForXMetaDiss() { $collection = new Opus_Collection(112); $doc = $this->createTestDocument(); $doc->setServerState('published'); $doc->setType('doctoralthesis'); // xMetaDiss liefert nur Doktorarbeiten und Habilitationen aus $doc->addCollection($collection); // fixing test for OPUSVIER-3142 $visibleFile = new Opus_File(); $visibleFile->setPathName('visible_file.txt'); $visibleFile->setVisibleInOai(true); $doc->addFile($visibleFile); $this->docIds[] = $doc->store(); $this->dispatch('/oai?verb=ListRecords&metadataPrefix=xMetaDiss&set=ddc:000'); $body = $this->getResponse()->getBody(); $this->assertNotContains('<dc:subject xsi:type="dcterms:DDC">000</dc:subject>', $body); $this->assertContains('<dc:subject xsi:type="xMetaDiss:DDC-SG">000</dc:subject>', $body); }
/** * Initialisierung des Formulars mit den Werten in einer Model-Instanz. * @param Opus_File $file */ public function populateFromModel($file) { $this->getElement(self::ELEMENT_ID)->setValue($file->getId()); $this->getElement(self::ELEMENT_FILE_LINK)->setValue($file); $this->getElement(self::ELEMENT_LABEL)->setValue($file->getLabel()); $this->getElement(self::ELEMENT_FILE_SIZE)->setValue($file->getFileSize()); $this->getElement(self::ELEMENT_LANGUAGE)->setValue($file->getLanguage()); $this->getElement(self::ELEMENT_COMMENT)->setValue($file->getComment()); $this->getElement(self::ELEMENT_SERVER_DATE_SUBMITTED)->setValue($this->getView()->formatValue()->formatDate($file->getServerDateSubmitted())); $this->getElement(self::ELEMENT_SORT_ORDER)->setValue($file->getSortOrder()); $visibility = array(); if ($file->getVisibleInFrontdoor()) { $visibility[] = 'frontdoor'; } if ($file->getVisibleInOai()) { $visibility[] = 'oai'; } $this->getElement(self::ELEMENT_VISIBILITY)->setValue($visibility); $this->getElement(self::ELEMENT_ROLES)->setValue($this->getRolesForFile($file->getId())); $this->getSubForm(self::SUBFORM_HASHES)->populateFromModel($file); }
/** * Dateien, die nicht sichtbar sind in Frontdoor dürfen nicht heruntergeladen werden. * * @expectedException Frontdoor_Model_FileAccessNotAllowedException */ public function testFileAccessDeniedIfNotVisibleInFrontdoorForGuest() { $model = new Frontdoor_Model_File(91, "frontdoor_invisible.txt"); $realm = new MockRealm(true, true); $opusFile = new Opus_File(128); $this->assertEquals(0, $opusFile->getVisibleInFrontdoor(), "Testdaten geändert."); $this->assertEquals("frontdoor_invisible.txt", $opusFile->getPathName(), "Testdaten geändert."); $model->getFileObject($realm); }
public function testDocumentWithNonExistentFile() { $doc = $this->createTestDocument(); $doc->setServerState('published'); $file = new Opus_File(); $file->setPathName('test.pdf'); $file->setVisibleInOai(true); $doc->addFile($file); $doc->store(); $model = new Oai_Model_Container($doc->getId()); $tarball = null; try { $tarball = $model->getFileHandle(); } catch (Oai_Model_Exception $e) { $this->assertEquals('requested document does not have any associated readable files', $e->getMessage()); } $this->assertTrue(is_null($tarball)); }
/** * * @param Opus_File $file * @return boolean Returns true if fulltext extraction for the file's MIME type * is supported. */ private function hasSupportedMimeType($file) { if ($file->getMimeType() === 'text/html' || $file->getMimeType() === 'text/plain' || $file->getMimeType() === 'application/pdf' || $file->getMimeType() === 'application/postscript' || $file->getMimeType() === 'application/xhtml+xml' || $file->getMimeType() === 'application/xml') { return true; } return false; }
protected function createTestFile($filename) { if (is_null($this->testFiles)) { $this->testFiles = array(); } $config = Zend_Registry::get('Zend_Config'); if (!isset($config->workspacePath)) { throw new Exception("config key 'workspacePath' not defined in config file"); } $path = $config->workspacePath . DIRECTORY_SEPARATOR . uniqid(); mkdir($path, 0777, true); $filepath = $path . DIRECTORY_SEPARATOR . $filename; touch($filepath); $this->assertTrue(is_readable($filepath)); $file = new Opus_File(); $file->setPathName(basename($filepath)); $file->setTempFile($filepath); if (array_key_exists($filename, $this->testFiles)) { throw Exception('filenames should be unique'); } $this->testFiles[$filename] = $filepath; return $file; }
public function testRenderWithFileTooBig() { $config = Zend_Registry::get('Zend_Config'); $config->merge(new Zend_Config(array('checksum' => array('maxVerificationSize' => '0')))); $element = new Application_Form_Element_FileHash('name'); $file = new Opus_File(116); $hashes = $file->getHashValue(); $hash = $hashes[0]; $element->setValue($hash); $element->setFile($file); $decorator = new Application_Form_Decorator_FileHash(); $decorator->setElement($element); $output = $decorator->render('content'); $this->assertEquals('content' . '<div class="textarea hashsoll"><span class="hash-label">Expected:</span>1ba50dc8abc619cea3ba39f77c75c0fe</div>' . '<input type="hidden" name="name[Soll]" value="1ba50dc8abc619cea3ba39f77c75c0fe" id="name-Soll" />' . '<div class="textarea hashist"><span class="hash-label">Actual:</span>' . Zend_Registry::get('Zend_Translate')->translate('frontdoor_file_too_big') . '</div>', $output); }