mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-28 06:08:52 +00:00
Merge remote-tracking branch 'Fyorl/ticket/11045' into develop-olympus
* Fyorl/ticket/11045: [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
This commit is contained in:
commit
888aa47b0e
11 changed files with 166 additions and 0 deletions
0
tests/compress/archive/.gitkeep
Normal file
0
tests/compress/archive/.gitkeep
Normal file
162
tests/compress/compress_test.php
Normal file
162
tests/compress/compress_test.php
Normal file
|
@ -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();
|
||||
}
|
||||
}
|
0
tests/compress/extract/.gitkeep
Normal file
0
tests/compress/extract/.gitkeep
Normal file
1
tests/compress/fixtures/1.txt
Normal file
1
tests/compress/fixtures/1.txt
Normal file
|
@ -0,0 +1 @@
|
|||
1
|
BIN
tests/compress/fixtures/archive.tar
Normal file
BIN
tests/compress/fixtures/archive.tar
Normal file
Binary file not shown.
BIN
tests/compress/fixtures/archive.tar.bz2
Normal file
BIN
tests/compress/fixtures/archive.tar.bz2
Normal file
Binary file not shown.
BIN
tests/compress/fixtures/archive.tar.gz
Normal file
BIN
tests/compress/fixtures/archive.tar.gz
Normal file
Binary file not shown.
BIN
tests/compress/fixtures/archive.zip
Normal file
BIN
tests/compress/fixtures/archive.zip
Normal file
Binary file not shown.
1
tests/compress/fixtures/dir/2.txt
Normal file
1
tests/compress/fixtures/dir/2.txt
Normal file
|
@ -0,0 +1 @@
|
|||
2
|
1
tests/compress/fixtures/dir/3.txt
Normal file
1
tests/compress/fixtures/dir/3.txt
Normal file
|
@ -0,0 +1 @@
|
|||
3
|
1
tests/compress/fixtures/dir/subdir/4.txt
Normal file
1
tests/compress/fixtures/dir/subdir/4.txt
Normal file
|
@ -0,0 +1 @@
|
|||
4
|
Loading…
Add table
Reference in a new issue