/** * Remove a directory and its entries recursivly. * * @param string $dir Directory to delete. * @return bool Result of rmdir() call. */ public static function deleteDirectory($dir) { if (false === file_exists($dir)) { return true; } if (false === is_dir($dir)) { return unlink($dir); } foreach (scandir($dir) as $item) { if ($item == '.' || $item == '..') { continue; } if (false === Opus_Util_File::deleteDirectory($dir . DIRECTORY_SEPARATOR . $item)) { return false; } } return rmdir($dir); }
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); }
private function deleteTestFiles() { if (!is_null($this->testFiles)) { foreach ($this->testFiles as $key => $filepath) { try { Opus_Util_File::deleteDirectory(dirname($filepath)); } catch (Exception $e) { } } } }