1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-05-05 23:25:30 +02:00

[ticket/10941] Finished filespec tests

PHPBB3-10941
This commit is contained in:
Fyorl 2012-06-21 14:27:39 +01:00
parent d6bd8928b5
commit fe4056c599
2 changed files with 91 additions and 0 deletions

View File

@ -20,4 +20,26 @@ class phpbb_mock_fileupload
{
return true;
}
public function image_types()
{
return array(
IMAGETYPE_GIF => array('gif'),
IMAGETYPE_JPEG => array('jpg', 'jpeg'),
IMAGETYPE_PNG => array('png'),
IMAGETYPE_SWF => array('swf'),
IMAGETYPE_PSD => array('psd'),
IMAGETYPE_BMP => array('bmp'),
IMAGETYPE_TIFF_II => array('tif', 'tiff'),
IMAGETYPE_TIFF_MM => array('tif', 'tiff'),
IMAGETYPE_JPC => array('jpg', 'jpeg'),
IMAGETYPE_JP2 => array('jpg', 'jpeg'),
IMAGETYPE_JPX => array('jpg', 'jpeg'),
IMAGETYPE_JB2 => array('jpg', 'jpeg'),
IMAGETYPE_SWC => array('swc'),
IMAGETYPE_IFF => array('iff'),
IMAGETYPE_WBMP => array('wbmp'),
IMAGETYPE_XBM => array('xbm'),
);
}
}

View File

@ -11,12 +11,14 @@ require_once __DIR__ . '/../../phpBB/includes/functions.php';
require_once __DIR__ . '/../../phpBB/includes/utf/utf_tools.php';
require_once __DIR__ . '/../../phpBB/includes/functions_upload.php';
require_once __DIR__ . '/../mock/fileupload.php';
require_once __DIR__ . '/../mock/request.php';
class phpbb_filespec_test extends phpbb_test_case
{
const TEST_COUNT = 100;
const PREFIX = 'phpbb_';
const MAX_STR_LEN = 50;
const UPLOAD_MAX_FILESIZE = 1000;
private $config;
private $filespec;
@ -38,6 +40,22 @@ class phpbb_filespec_test extends phpbb_test_case
$this->config = $config;
$this->path = __DIR__ . '/fixture/';
$this->init_filespec();
// Create copies of the files for use in testing move_file
$it = new DirectoryIterator($this->path);
foreach ($it as $fileinfo)
{
if ($fileinfo->isDot())
{
continue;
}
copy($fileinfo->getPathname(), $this->path . $fileinfo->getFilename() . '_copy');
if ($fileinfo->getFilename() === 'TXT')
{
copy($fileinfo->getPathname(), $this->path . $fileinfo->getFilename() . '_copy_2');
}
}
}
public function additional_checks_variables()
@ -97,6 +115,30 @@ class phpbb_filespec_test extends phpbb_test_case
);
}
public function move_file_variables()
{
return array(
array('GIF_copy', 'GIF_moved', 'image/gif', 'gif', false, true),
array('non_existant', 'still_non_existant', 'text/plain', 'txt', true, false),
array('TXT_copy', 'TXT_as_img', 'image/jpg', 'txt', true, true),
array('TXT_copy_2', 'TXT_moved', 'text/plain', 'txt', false, true),
array('JPG_copy', 'JPG_moved', 'image/png', 'jpg', false, true),
array('PNG_copy', 'PNG_moved', 'image/png', 'jpg', true, true),
);
}
protected function tearDown()
{
$it = new DirectoryIterator($this->path);
foreach ($it as $fileinfo)
{
if (strlen($fileinfo->getFilename()) > 3)
{
unlink($fileinfo->getPathname());
}
}
}
/**
* @dataProvider additional_checks_variables
*/
@ -182,4 +224,31 @@ class phpbb_filespec_test extends phpbb_test_case
$this->init_filespec(array('tmp_name' => $this->path . $filename, 'type' => $mimetype));
$this->assertEquals($expected, $this->filespec->is_image());
}
/**
* @dataProvider move_file_variables
*/
public function test_move_file($tmp_name, $realname, $mime_type, $extension, $error, $expected)
{
global $request, $phpbb_root_path, $phpEx;
$phpbb_root_path = '';
$phpEx = 'php';
$request = new phpbb_mock_request();
$upload = new phpbb_mock_fileupload();
$upload->max_filesize = self::UPLOAD_MAX_FILESIZE;
$this->init_filespec(array(
'tmp_name' => $this->path . $tmp_name,
'name' => $realname,
'type' => $mime_type,
));
$this->filespec->extension = $extension;
$this->filespec->upload = $upload;
$this->filespec->local = true;
$this->assertEquals($expected, $this->filespec->move_file($this->path));
$this->assertEquals($error, (bool) sizeof($this->filespec->error));
$this->assertEquals($this->filespec->file_moved, file_exists($this->path . $realname));
}
}