]> source.dussan.org Git - nextcloud-server.git/commitdiff
add extract all option to OC_Archive
authorRobin Appelman <icewind@owncloud.com>
Wed, 28 Mar 2012 20:31:45 +0000 (22:31 +0200)
committerRobin Appelman <icewind@owncloud.com>
Wed, 28 Mar 2012 21:47:44 +0000 (23:47 +0200)
apps/files_archive/lib/archive.php
apps/files_archive/lib/zip.php
apps/files_archive/tests/archive.php

index be89f894fb7ff8c3fcab13a5a81ce9bb53d31100..3be3388a3b050f50227b225b8d1a4e4a83c054ef 100644 (file)
@@ -77,6 +77,13 @@ abstract class OC_Archive{
         * @return bool
         */
        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
         * @param string path
index eab101b3a5c0d7ae2bcff246d2527309201eff0e..16f2273f443294d43301e053e66c591ccf6c8fb1 100644 (file)
@@ -128,6 +128,15 @@ class OC_Archive_ZIP extends OC_Archive{
                $fp = $this->zip->getStream($path);
                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
         * @param string path
index 2e26b5e03b5c430456394f7e28f9a6030beb25d6..2619d91b3b887d3794596f52c538ce1c34e74fe3 100644 (file)
@@ -27,10 +27,10 @@ abstract class Test_Archive extends UnitTestCase {
                $this->instance=$this->getExisting();
                $allFiles=$this->instance->getFiles();
                $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){
                        $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'));
                
@@ -94,4 +94,15 @@ abstract class Test_Archive extends UnitTestCase {
                $this->assertTrue($this->instance->fileExists('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);
+       }
 }