From 56ecd4f4244ec276b92fb0d96ae23484463e6484 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elan=20Ruusam=C3=A4e?= Date: Mon, 14 Apr 2014 23:07:56 +0300 Subject: tar: test. skip instead of error if bz2 or zlib extension is missing --- _test/tests/inc/tar.test.php | 51 +++++++++++++++++++++++++++++++++++++------- 1 file changed, 43 insertions(+), 8 deletions(-) diff --git a/_test/tests/inc/tar.test.php b/_test/tests/inc/tar.test.php index 417f1a853..91e71632c 100644 --- a/_test/tests/inc/tar.test.php +++ b/_test/tests/inc/tar.test.php @@ -1,6 +1,32 @@ markTestSkipped('skipping all zlib tests. Need zlib extension'); + } + } + + /** + * dependency test to test available extensions + * fills $this->extensions array + */ + public function test_extensions() { + if (!extension_loaded('zlib')) { + $this->markTestSkipped('skipping all zlib tests. Need zlib extension'); + } + if (!extension_loaded('bz2')) { + $this->markTestSkipped('skipping all bz2 tests. Need bz2 extension'); + } + } /** * simple test that checks that the given filenames and contents can be grepped from @@ -58,8 +84,6 @@ class Tar_TestCase extends DokuWikiTest { $tar->addData('another/testdata3.txt', 'testcontent3'); $tar->close(); -copy ($tmp, '/tmp/test.tar'); - $this->assertTrue(filesize($tmp) > 30); //arbitrary non-zero number $data = file_get_contents($tmp); @@ -85,11 +109,12 @@ copy ($tmp, '/tmp/test.tar'); /** * List the contents of the prebuilt TAR files + * @depends test_extensions */ public function test_tarcontent() { $dir = dirname(__FILE__).'/tar'; - foreach(array('tar', 'tgz', 'tbz') as $ext) { + foreach($this->extensions as $ext) { $tar = new Tar(); $file = "$dir/test.$ext"; @@ -107,12 +132,13 @@ copy ($tmp, '/tmp/test.tar'); /** * Extract the prebuilt tar files + * @depends test_extensions */ public function test_tarextract() { $dir = dirname(__FILE__).'/tar'; $out = sys_get_temp_dir().'/dwtartest'.md5(time()); - foreach(array('tar', 'tgz', 'tbz') as $ext) { + foreach($this->extensions as $ext) { $tar = new Tar(); $file = "$dir/test.$ext"; @@ -133,12 +159,13 @@ copy ($tmp, '/tmp/test.tar'); /** * Extract the prebuilt tar files with component stripping + * @depends test_extensions */ public function test_compstripextract() { $dir = dirname(__FILE__).'/tar'; $out = sys_get_temp_dir().'/dwtartest'.md5(time()); - foreach(array('tar', 'tgz', 'tbz') as $ext) { + foreach($this->extensions as $ext) { $tar = new Tar(); $file = "$dir/test.$ext"; @@ -159,12 +186,13 @@ copy ($tmp, '/tmp/test.tar'); /** * Extract the prebuilt tar files with prefix stripping + * @depends test_extensions */ public function test_prefixstripextract() { $dir = dirname(__FILE__).'/tar'; $out = sys_get_temp_dir().'/dwtartest'.md5(time()); - foreach(array('tar', 'tgz', 'tbz') as $ext) { + foreach($this->extensions as $ext) { $tar = new Tar(); $file = "$dir/test.$ext"; @@ -185,12 +213,13 @@ copy ($tmp, '/tmp/test.tar'); /** * Extract the prebuilt tar files with include regex + * @depends test_extensions */ public function test_includeextract() { $dir = dirname(__FILE__).'/tar'; $out = sys_get_temp_dir().'/dwtartest'.md5(time()); - foreach(array('tar', 'tgz', 'tbz') as $ext) { + foreach($this->extensions as $ext) { $tar = new Tar(); $file = "$dir/test.$ext"; @@ -210,12 +239,13 @@ copy ($tmp, '/tmp/test.tar'); /** * Extract the prebuilt tar files with exclude regex + * @depends test_extensions */ public function test_excludeextract() { $dir = dirname(__FILE__).'/tar'; $out = sys_get_temp_dir().'/dwtartest'.md5(time()); - foreach(array('tar', 'tgz', 'tbz') as $ext) { + foreach($this->extensions as $ext) { $tar = new Tar(); $file = "$dir/test.$ext"; @@ -235,6 +265,7 @@ copy ($tmp, '/tmp/test.tar'); /** * Check the extension to compression guesser + * @depends test_extensions */ public function test_filetype() { $tar = new Tar(); @@ -249,6 +280,9 @@ copy ($tmp, '/tmp/test.tar'); $this->assertEquals(Tar::COMPRESS_BZIP, $tar->filetype('foo.tar.bz2')); } + /** + * @depends test_ext_zlib + */ public function test_longpathextract() { $dir = dirname(__FILE__).'/tar'; $out = sys_get_temp_dir().'/dwtartest'.md5(time()); @@ -338,6 +372,7 @@ copy ($tmp, '/tmp/test.tar'); /** * Extract a tarbomomb + * @depends test_ext_zlib */ public function test_tarbomb() { $dir = dirname(__FILE__).'/tar'; -- cgit v1.2.3 From 9efc0669141c20c5c3cf1c76384b8c85734788c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elan=20Ruusam=C3=A4e?= Date: Mon, 14 Apr 2014 23:16:49 +0300 Subject: run as much as possible (fill extensions conditionally), skip missing ext once --- _test/tests/inc/tar.test.php | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/_test/tests/inc/tar.test.php b/_test/tests/inc/tar.test.php index 91e71632c..76037d401 100644 --- a/_test/tests/inc/tar.test.php +++ b/_test/tests/inc/tar.test.php @@ -4,7 +4,16 @@ class Tar_TestCase extends DokuWikiTest { /** * file extensions that several tests use */ - protected $extensions = array('tar', 'tgz', 'tbz'); + protected $extensions = array('tar'); + + public function setUp() { + if (extension_loaded('zlib')) { + $this->extensions[] = 'tgz'; + } + if (extension_loaded('bz2')) { + $this->extensions[] = 'tbz'; + } + } /* * dependency for tests needing zlib extension to pass @@ -15,16 +24,12 @@ class Tar_TestCase extends DokuWikiTest { } } - /** - * dependency test to test available extensions - * fills $this->extensions array + /* + * dependency for tests needing zlib extension to pass */ - public function test_extensions() { - if (!extension_loaded('zlib')) { - $this->markTestSkipped('skipping all zlib tests. Need zlib extension'); - } + public function test_ext_bz2() { if (!extension_loaded('bz2')) { - $this->markTestSkipped('skipping all bz2 tests. Need bz2 extension'); + $this->markTestSkipped('skipping all bzip2 tests. Need bz2 extension'); } } @@ -109,7 +114,6 @@ class Tar_TestCase extends DokuWikiTest { /** * List the contents of the prebuilt TAR files - * @depends test_extensions */ public function test_tarcontent() { $dir = dirname(__FILE__).'/tar'; @@ -132,7 +136,6 @@ class Tar_TestCase extends DokuWikiTest { /** * Extract the prebuilt tar files - * @depends test_extensions */ public function test_tarextract() { $dir = dirname(__FILE__).'/tar'; @@ -159,7 +162,6 @@ class Tar_TestCase extends DokuWikiTest { /** * Extract the prebuilt tar files with component stripping - * @depends test_extensions */ public function test_compstripextract() { $dir = dirname(__FILE__).'/tar'; @@ -186,7 +188,6 @@ class Tar_TestCase extends DokuWikiTest { /** * Extract the prebuilt tar files with prefix stripping - * @depends test_extensions */ public function test_prefixstripextract() { $dir = dirname(__FILE__).'/tar'; @@ -213,7 +214,6 @@ class Tar_TestCase extends DokuWikiTest { /** * Extract the prebuilt tar files with include regex - * @depends test_extensions */ public function test_includeextract() { $dir = dirname(__FILE__).'/tar'; @@ -239,7 +239,6 @@ class Tar_TestCase extends DokuWikiTest { /** * Extract the prebuilt tar files with exclude regex - * @depends test_extensions */ public function test_excludeextract() { $dir = dirname(__FILE__).'/tar'; @@ -265,7 +264,6 @@ class Tar_TestCase extends DokuWikiTest { /** * Check the extension to compression guesser - * @depends test_extensions */ public function test_filetype() { $tar = new Tar(); -- cgit v1.2.3 From 64d063f11abb3946bad9d076a56b0fc51ccff127 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elan=20Ruusam=C3=A4e?= Date: Wed, 16 Apr 2014 11:22:46 +0300 Subject: call parent constructor as well --- _test/tests/inc/tar.test.php | 1 + 1 file changed, 1 insertion(+) diff --git a/_test/tests/inc/tar.test.php b/_test/tests/inc/tar.test.php index 76037d401..15453b16d 100644 --- a/_test/tests/inc/tar.test.php +++ b/_test/tests/inc/tar.test.php @@ -7,6 +7,7 @@ class Tar_TestCase extends DokuWikiTest { protected $extensions = array('tar'); public function setUp() { + parent::setUp(); if (extension_loaded('zlib')) { $this->extensions[] = 'tgz'; } -- cgit v1.2.3