From 7252880f21c842017c334eb15c6a7a174f950798 Mon Sep 17 00:00:00 2001
From: Andreas Gohr <andi@splitbrain.org>
Date: Sat, 3 Nov 2012 18:30:52 +0100
Subject: [PATCH] added test cases for Tar::extract parameters

---
 _test/tests/inc/tar.test.php | 103 +++++++++++++++++++++++++++++++++++
 1 file changed, 103 insertions(+)

diff --git a/_test/tests/inc/tar.test.php b/_test/tests/inc/tar.test.php
index 706516d9e..4de9e668d 100644
--- a/_test/tests/inc/tar.test.php
+++ b/_test/tests/inc/tar.test.php
@@ -113,9 +113,112 @@ class Tar_TestCase extends DokuWikiTest {
 
             TestUtils::rdelete($out);
         }
+    }
+
+    /**
+     * Extract the prebuilt tar files with component stripping
+     */
+    public function test_compstripextract(){
+        $dir = dirname(__FILE__).'/tar';
+        $out = sys_get_temp_dir().'/dwtartest'.md5(time());
+
+        foreach(array('tar', 'tgz', 'tbz') as $ext){
+            $tar  = new Tar();
+            $file = "$dir/test.$ext";
+
+            $tar->open($file);
+            $tar->extract($out,1);
+
+            clearstatcache();
+
+            $this->assertFileExists($out.'/testdata1.txt', "Extracted $file");
+            $this->assertEquals(13, filesize($out.'/testdata1.txt'), "Extracted $file");
+
+            $this->assertFileExists($out.'/foobar/testdata2.txt', "Extracted $file");
+            $this->assertEquals(13, filesize($out.'/foobar/testdata2.txt'), "Extracted $file");
+
+            TestUtils::rdelete($out);
+        }
+    }
+
+    /**
+     * Extract the prebuilt tar files with prefix stripping
+     */
+    public function test_prefixstripextract(){
+        $dir = dirname(__FILE__).'/tar';
+        $out = sys_get_temp_dir().'/dwtartest'.md5(time());
 
+        foreach(array('tar', 'tgz', 'tbz') as $ext){
+            $tar  = new Tar();
+            $file = "$dir/test.$ext";
+
+            $tar->open($file);
+            $tar->extract($out,'tar/foobar/');
+
+            clearstatcache();
+
+            $this->assertFileExists($out.'/tar/testdata1.txt', "Extracted $file");
+            $this->assertEquals(13, filesize($out.'/tar/testdata1.txt'), "Extracted $file");
+
+            $this->assertFileExists($out.'/testdata2.txt', "Extracted $file");
+            $this->assertEquals(13, filesize($out.'/testdata2.txt'), "Extracted $file");
+
+            TestUtils::rdelete($out);
+        }
     }
 
+    /**
+     * Extract the prebuilt tar files with include regex
+     */
+    public function test_includeextract(){
+        $dir = dirname(__FILE__).'/tar';
+        $out = sys_get_temp_dir().'/dwtartest'.md5(time());
+
+        foreach(array('tar', 'tgz', 'tbz') as $ext){
+            $tar  = new Tar();
+            $file = "$dir/test.$ext";
+
+            $tar->open($file);
+            $tar->extract($out,'','','/\/foobar\//');
+
+            clearstatcache();
+
+            $this->assertFileNotExists($out.'/tar/testdata1.txt', "Extracted $file");
+
+
+            $this->assertFileExists($out.'/tar/foobar/testdata2.txt', "Extracted $file");
+            $this->assertEquals(13, filesize($out.'/tar/foobar/testdata2.txt'), "Extracted $file");
+
+            TestUtils::rdelete($out);
+        }
+    }
+
+    /**
+     * Extract the prebuilt tar files with exclude regex
+     */
+    public function test_excludeextract(){
+        $dir = dirname(__FILE__).'/tar';
+        $out = sys_get_temp_dir().'/dwtartest'.md5(time());
+
+        foreach(array('tar', 'tgz', 'tbz') as $ext){
+            $tar  = new Tar();
+            $file = "$dir/test.$ext";
+
+            $tar->open($file);
+            $tar->extract($out,'','/\/foobar\//');
+
+            clearstatcache();
+
+            $this->assertFileExists($out.'/tar/testdata1.txt', "Extracted $file");
+            $this->assertEquals(13, filesize($out.'/tar/testdata1.txt'), "Extracted $file");
+
+            $this->assertFileNotExists($out.'/tar/foobar/testdata2.txt', "Extracted $file");
+
+            TestUtils::rdelete($out);
+        }
+    }
+
+
     /**
      * Check the extension to compression guesser
      */
-- 
GitLab