aboutsummaryrefslogtreecommitdiffstats
path: root/tests/compress
diff options
context:
space:
mode:
authorAndreas Fischer <bantu@phpbb.com>2012-09-14 00:49:48 +0200
committerAndreas Fischer <bantu@phpbb.com>2012-09-14 00:49:48 +0200
commit91423880da4af4f92cd6634f8b1934b896ac8026 (patch)
tree0b23033ee63ab2acc9898a26e6ba84f293da6d76 /tests/compress
parent8a91598b14e0c638a7674294790a3f4079c58758 (diff)
parent888aa47b0e165528b2344a060d65ccd4d2a33ae6 (diff)
downloadforums-91423880da4af4f92cd6634f8b1934b896ac8026.tar
forums-91423880da4af4f92cd6634f8b1934b896ac8026.tar.gz
forums-91423880da4af4f92cd6634f8b1934b896ac8026.tar.bz2
forums-91423880da4af4f92cd6634f8b1934b896ac8026.tar.xz
forums-91423880da4af4f92cd6634f8b1934b896ac8026.zip
Merge branch 'develop-olympus' into develop
* develop-olympus: [ticket/11045] Removed file conflict tests for compress class [ticket/11045] Replaced __DIR__ with dirname(__FILE__) [ticket/11045] Opening brace on its own line [ticket/11045] Explicitely check for zlib and bz2 [ticket/11045] Added tests for file conflicts [ticket/11045] Added unit tests for the compress class
Diffstat (limited to 'tests/compress')
-rw-r--r--tests/compress/archive/.gitkeep0
-rw-r--r--tests/compress/compress_test.php162
-rw-r--r--tests/compress/extract/.gitkeep0
-rw-r--r--tests/compress/fixtures/1.txt1
-rw-r--r--tests/compress/fixtures/archive.tarbin0 -> 10240 bytes
-rw-r--r--tests/compress/fixtures/archive.tar.bz2bin0 -> 224 bytes
-rw-r--r--tests/compress/fixtures/archive.tar.gzbin0 -> 239 bytes
-rw-r--r--tests/compress/fixtures/archive.zipbin0 -> 412 bytes
-rw-r--r--tests/compress/fixtures/dir/2.txt1
-rw-r--r--tests/compress/fixtures/dir/3.txt1
-rw-r--r--tests/compress/fixtures/dir/subdir/4.txt1
11 files changed, 166 insertions, 0 deletions
diff --git a/tests/compress/archive/.gitkeep b/tests/compress/archive/.gitkeep
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/tests/compress/archive/.gitkeep
diff --git a/tests/compress/compress_test.php b/tests/compress/compress_test.php
new file mode 100644
index 0000000000..65094671e3
--- /dev/null
+++ b/tests/compress/compress_test.php
@@ -0,0 +1,162 @@
+<?php
+/**
+ *
+ * @package testing
+ * @copyright (c) 2012 phpBB Group
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+ *
+ */
+
+require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
+require_once dirname(__FILE__) . '/../../phpBB/includes/functions_admin.php';
+require_once dirname(__FILE__) . '/../../phpBB/includes/functions_compress.php';
+
+class phpbb_compress_test extends phpbb_test_case
+{
+ const EXTRACT_DIR = '/extract/';
+ const ARCHIVE_DIR = '/archive/';
+
+ private $path;
+
+ protected $filelist = array(
+ '1.txt',
+ 'dir/2.txt',
+ 'dir/3.txt',
+ 'dir/subdir/4.txt',
+ );
+
+ protected function setUp()
+ {
+ // Required for compress::add_file
+ global $phpbb_root_path;
+ $phpbb_root_path = '';
+
+ $this->path = dirname(__FILE__) . '/fixtures/';
+
+ if (!@extension_loaded('zlib') || !@extension_loaded('bz2'))
+ {
+ $this->markTestSkipped('PHP needs to be compiled with --with-zlib and --with-bz2 in order to run these tests');
+ }
+ }
+
+ protected function tearDown()
+ {
+ foreach (array(dirname(__FILE__) . self::EXTRACT_DIR, dirname(__FILE__) . self::ARCHIVE_DIR) as $dir)
+ {
+ $this->clear_dir($dir);
+ }
+ }
+
+ protected function clear_dir($dir)
+ {
+ $iterator = new DirectoryIterator($dir);
+ foreach ($iterator as $fileinfo)
+ {
+ $name = $fileinfo->getFilename();
+ $path = $fileinfo->getPathname();
+
+ if ($name[0] !== '.')
+ {
+ if ($fileinfo->isDir())
+ {
+ $this->clear_dir($path);
+ rmdir($path);
+ }
+ else
+ {
+ unlink($path);
+ }
+ }
+ }
+ }
+
+ protected function archive_files($compress)
+ {
+ $compress->add_file($this->path . '1.txt', $this->path);
+ $compress->add_file(
+ 'tests/compress/fixtures/dir/',
+ 'tests/compress/fixtures/',
+ '',
+ // The comma here is not an error, this is a comma-separated list
+ 'subdir/4.txt,3.txt'
+ );
+ $compress->add_custom_file($this->path . 'dir/3.txt', 'dir/3.txt');
+ $compress->add_data(file_get_contents($this->path . 'dir/subdir/4.txt'), 'dir/subdir/4.txt');
+ }
+
+ protected function valid_extraction($extra = array())
+ {
+ $filelist = array_merge($this->filelist, $extra);
+
+ foreach ($filelist as $filename)
+ {
+ $path = dirname(__FILE__) . self::EXTRACT_DIR . $filename;
+ $this->assertTrue(file_exists($path));
+
+ // Check the file's contents is correct
+ $contents = explode('_', basename($filename, '.txt'));
+ $contents = $contents[0];
+ $this->assertEquals($contents . "\n", file_get_contents($path));
+ }
+ }
+
+ public function tar_archive_list()
+ {
+ return array(
+ array('archive.tar', '.tar'),
+ array('archive.tar.gz', '.tar.gz'),
+ array('archive.tar.bz2', '.tar.bz2'),
+ );
+ }
+
+ /**
+ * @dataProvider tar_archive_list
+ */
+ public function test_extract_tar($filename, $type)
+ {
+ $compress = new compress_tar('r', $this->path . $filename);
+ $compress->extract('tests/compress/' . self::EXTRACT_DIR);
+ $this->valid_extraction();
+ }
+
+ public function test_extract_zip()
+ {
+ $compress = new compress_zip('r', $this->path . 'archive.zip');
+ $compress->extract('tests/compress/' . self::EXTRACT_DIR);
+ $this->valid_extraction();
+ }
+
+ /**
+ * @depends test_extract_tar
+ * @dataProvider tar_archive_list
+ */
+ public function test_compress_tar($filename, $type)
+ {
+ $tar = dirname(__FILE__) . self::ARCHIVE_DIR . $filename;
+ $compress = new compress_tar('w', $tar);
+ $this->archive_files($compress);
+ $compress->close();
+ $this->assertTrue(file_exists($tar));
+
+ $compress->mode = 'r';
+ $compress->open();
+ $compress->extract('tests/compress/' . self::EXTRACT_DIR);
+ $this->valid_extraction();
+ }
+
+ /**
+ * @depends test_extract_zip
+ */
+ public function test_compress_zip()
+ {
+ $zip = dirname(__FILE__) . self::ARCHIVE_DIR . 'archive.zip';
+ $compress = new compress_zip('w', $zip);
+ $this->archive_files($compress);
+ $compress->close();
+ $this->assertTrue(file_exists($zip));
+
+ $compress = new compress_zip('r', $zip);
+ $compress->extract('tests/compress/' . self::EXTRACT_DIR);
+ $this->valid_extraction();
+ }
+}
diff --git a/tests/compress/extract/.gitkeep b/tests/compress/extract/.gitkeep
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/tests/compress/extract/.gitkeep
diff --git a/tests/compress/fixtures/1.txt b/tests/compress/fixtures/1.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/tests/compress/fixtures/1.txt
@@ -0,0 +1 @@
+1
diff --git a/tests/compress/fixtures/archive.tar b/tests/compress/fixtures/archive.tar
new file mode 100644
index 0000000000..54ed56084e
--- /dev/null
+++ b/tests/compress/fixtures/archive.tar
Binary files differ
diff --git a/tests/compress/fixtures/archive.tar.bz2 b/tests/compress/fixtures/archive.tar.bz2
new file mode 100644
index 0000000000..04c0eccd74
--- /dev/null
+++ b/tests/compress/fixtures/archive.tar.bz2
Binary files differ
diff --git a/tests/compress/fixtures/archive.tar.gz b/tests/compress/fixtures/archive.tar.gz
new file mode 100644
index 0000000000..195e7a060a
--- /dev/null
+++ b/tests/compress/fixtures/archive.tar.gz
Binary files differ
diff --git a/tests/compress/fixtures/archive.zip b/tests/compress/fixtures/archive.zip
new file mode 100644
index 0000000000..bdb618fc26
--- /dev/null
+++ b/tests/compress/fixtures/archive.zip
Binary files differ
diff --git a/tests/compress/fixtures/dir/2.txt b/tests/compress/fixtures/dir/2.txt
new file mode 100644
index 0000000000..0cfbf08886
--- /dev/null
+++ b/tests/compress/fixtures/dir/2.txt
@@ -0,0 +1 @@
+2
diff --git a/tests/compress/fixtures/dir/3.txt b/tests/compress/fixtures/dir/3.txt
new file mode 100644
index 0000000000..00750edc07
--- /dev/null
+++ b/tests/compress/fixtures/dir/3.txt
@@ -0,0 +1 @@
+3
diff --git a/tests/compress/fixtures/dir/subdir/4.txt b/tests/compress/fixtures/dir/subdir/4.txt
new file mode 100644
index 0000000000..b8626c4cff
--- /dev/null
+++ b/tests/compress/fixtures/dir/subdir/4.txt
@@ -0,0 +1 @@
+4