add extract all option to OC_Archive

This commit is contained in:
Robin Appelman 2012-03-28 22:31:45 +02:00
parent d8e9db207f
commit e57de98bbe
3 changed files with 29 additions and 2 deletions

View File

@ -77,6 +77,13 @@ abstract class OC_Archive{
* @return bool * @return bool
*/ */
abstract function extractFile($path,$dest); abstract function extractFile($path,$dest);
/**
* extract the archive
* @param string path
* @param string dest
* @return bool
*/
abstract function extract($dest);
/** /**
* check if a file or folder exists in the archive * check if a file or folder exists in the archive
* @param string path * @param string path

View File

@ -128,6 +128,15 @@ class OC_Archive_ZIP extends OC_Archive{
$fp = $this->zip->getStream($path); $fp = $this->zip->getStream($path);
file_put_contents($dest,$fp); file_put_contents($dest,$fp);
} }
/**
* extract the archive
* @param string path
* @param string dest
* @return bool
*/
function extract($dest){
return $this->zip->extractTo($dest);
}
/** /**
* check if a file or folder exists in the archive * check if a file or folder exists in the archive
* @param string path * @param string path

View File

@ -27,10 +27,10 @@ abstract class Test_Archive extends UnitTestCase {
$this->instance=$this->getExisting(); $this->instance=$this->getExisting();
$allFiles=$this->instance->getFiles(); $allFiles=$this->instance->getFiles();
$expected=array('lorem.txt','logo-wide.png','dir/','dir/lorem.txt'); $expected=array('lorem.txt','logo-wide.png','dir/','dir/lorem.txt');
$this->assertEqual(4,count($allFiles)); $this->assertEqual(4,count($allFiles),'only found '.count($allFiles).' out of 4 expected files');
foreach($expected as $file){ foreach($expected as $file){
$this->assertNotIdentical(false,array_search($file,$allFiles),'cant find '.$file.' in archive'); $this->assertNotIdentical(false,array_search($file,$allFiles),'cant find '.$file.' in archive');
$this->assertTrue($this->instance->fileExists($file)); $this->assertTrue($this->instance->fileExists($file),'file '.$file.' does not exist in archive');
} }
$this->assertFalse($this->instance->fileExists('non/existing/file')); $this->assertFalse($this->instance->fileExists('non/existing/file'));
@ -94,4 +94,15 @@ abstract class Test_Archive extends UnitTestCase {
$this->assertTrue($this->instance->fileExists('lorem.txt')); $this->assertTrue($this->instance->fileExists('lorem.txt'));
$this->assertEqual(file_get_contents($dir.'/lorem.txt'),$this->instance->getFile('lorem.txt')); $this->assertEqual(file_get_contents($dir.'/lorem.txt'),$this->instance->getFile('lorem.txt'));
} }
public function testExtract(){
$dir=OC::$SERVERROOT.'/apps/files_archive/tests/data';
$this->instance=$this->getExisting();
$tmpDir=OC_Helper::tmpFolder();
$this->instance->extract($tmpDir);
$this->assertEqual(true,file_exists($tmpDir.'lorem.txt'));
$this->assertEqual(true,file_exists($tmpDir.'dir/lorem.txt'));
$this->assertEqual(true,file_exists($tmpDir.'logo-wide.png'));
$this->assertEqual(file_get_contents($dir.'/lorem.txt'),file_get_contents($tmpDir.'lorem.txt'));
OC_Helper::rmdirr($tmpDir);
}
} }