mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-12 06:18:52 +00:00
[ticket/10941] Refactored init_filespec to return new object.
Removed $filespec as a property of the filespec test and instead just instantiate new objects. PHPBB3-10941
This commit is contained in:
parent
61d74007a4
commit
ff7e5d73f7
1 changed files with 26 additions and 27 deletions
|
@ -21,7 +21,6 @@ class phpbb_filespec_test extends phpbb_test_case
|
||||||
const UPLOAD_MAX_FILESIZE = 1000;
|
const UPLOAD_MAX_FILESIZE = 1000;
|
||||||
|
|
||||||
private $config;
|
private $config;
|
||||||
private $filespec;
|
|
||||||
public $path;
|
public $path;
|
||||||
|
|
||||||
protected function setUp()
|
protected function setUp()
|
||||||
|
@ -45,7 +44,6 @@ class phpbb_filespec_test extends phpbb_test_case
|
||||||
|
|
||||||
$this->config = &$config;
|
$this->config = &$config;
|
||||||
$this->path = __DIR__ . '/fixture/';
|
$this->path = __DIR__ . '/fixture/';
|
||||||
$this->init_filespec();
|
|
||||||
|
|
||||||
// Create copies of the files for use in testing move_file
|
// Create copies of the files for use in testing move_file
|
||||||
$iterator = new DirectoryIterator($this->path);
|
$iterator = new DirectoryIterator($this->path);
|
||||||
|
@ -64,7 +62,7 @@ class phpbb_filespec_test extends phpbb_test_case
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function init_filespec($override = array())
|
private function get_filespec($override = array())
|
||||||
{
|
{
|
||||||
// Initialise a blank filespec object for use with trivial methods
|
// Initialise a blank filespec object for use with trivial methods
|
||||||
$upload_ary = array(
|
$upload_ary = array(
|
||||||
|
@ -75,7 +73,7 @@ class phpbb_filespec_test extends phpbb_test_case
|
||||||
'error' => '',
|
'error' => '',
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->filespec = new filespec(array_merge($upload_ary, $override), null);
|
return new filespec(array_merge($upload_ary, $override), null);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function tearDown()
|
protected function tearDown()
|
||||||
|
@ -126,12 +124,12 @@ class phpbb_filespec_test extends phpbb_test_case
|
||||||
public function test_additional_checks($filename, $expected)
|
public function test_additional_checks($filename, $expected)
|
||||||
{
|
{
|
||||||
$upload = new phpbb_mock_fileupload();
|
$upload = new phpbb_mock_fileupload();
|
||||||
$this->init_filespec(array('tmp_name', $this->path . $filename));
|
$filespec = $this->get_filespec(array('tmp_name', $this->path . $filename));
|
||||||
$this->filespec->upload = $upload;
|
$filespec->upload = $upload;
|
||||||
$this->filespec->file_moved = true;
|
$filespec->file_moved = true;
|
||||||
$this->filespec->filesize = $this->filespec->get_filesize($this->path . $filename);
|
$filespec->filesize = $filespec->get_filesize($this->path . $filename);
|
||||||
|
|
||||||
$this->assertEquals($expected, $this->filespec->additional_checks());
|
$this->assertEquals($expected, $filespec->additional_checks());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function check_content_variables()
|
public function check_content_variables()
|
||||||
|
@ -151,8 +149,8 @@ class phpbb_filespec_test extends phpbb_test_case
|
||||||
public function test_check_content($filename, $expected)
|
public function test_check_content($filename, $expected)
|
||||||
{
|
{
|
||||||
$disallowed_content = explode('|', $this->config['mime_triggers']);
|
$disallowed_content = explode('|', $this->config['mime_triggers']);
|
||||||
$this->init_filespec(array('tmp_name' => $this->path . $filename));
|
$filespec = $this->get_filespec(array('tmp_name' => $this->path . $filename));
|
||||||
$this->assertEquals($expected, $this->filespec->check_content($disallowed_content));
|
$this->assertEquals($expected, $filespec->check_content($disallowed_content));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function clean_filename_variables()
|
public function clean_filename_variables()
|
||||||
|
@ -173,9 +171,9 @@ class phpbb_filespec_test extends phpbb_test_case
|
||||||
public function test_clean_filename_real($filename)
|
public function test_clean_filename_real($filename)
|
||||||
{
|
{
|
||||||
$bad_chars = array("'", "\\", ' ', '/', ':', '*', '?', '"', '<', '>', '|');
|
$bad_chars = array("'", "\\", ' ', '/', ':', '*', '?', '"', '<', '>', '|');
|
||||||
$this->init_filespec(array('name' => $filename));
|
$filespec = $this->get_filespec(array('name' => $filename));
|
||||||
$this->filespec->clean_filename('real', self::PREFIX);
|
$filespec->clean_filename('real', self::PREFIX);
|
||||||
$name = $this->filespec->realname;
|
$name = $filespec->realname;
|
||||||
|
|
||||||
$this->assertEquals(0, preg_match('/%(\w{2})/', $name));
|
$this->assertEquals(0, preg_match('/%(\w{2})/', $name));
|
||||||
foreach ($bad_chars as $char)
|
foreach ($bad_chars as $char)
|
||||||
|
@ -189,9 +187,9 @@ class phpbb_filespec_test extends phpbb_test_case
|
||||||
$filenames = array();
|
$filenames = array();
|
||||||
for ($tests = 0; $tests < self::TEST_COUNT; $tests++)
|
for ($tests = 0; $tests < self::TEST_COUNT; $tests++)
|
||||||
{
|
{
|
||||||
$this->init_filespec();
|
$filespec = $this->get_filespec();
|
||||||
$this->filespec->clean_filename('unique', self::PREFIX);
|
$filespec->clean_filename('unique', self::PREFIX);
|
||||||
$name = $this->filespec->realname;
|
$name = $filespec->realname;
|
||||||
|
|
||||||
$this->assertEquals(strlen($name), 32 + strlen(self::PREFIX));
|
$this->assertEquals(strlen($name), 32 + strlen(self::PREFIX));
|
||||||
$this->assertRegExp('#^[A-Za-z0-9]+$#', substr($name, strlen(self::PREFIX)));
|
$this->assertRegExp('#^[A-Za-z0-9]+$#', substr($name, strlen(self::PREFIX)));
|
||||||
|
@ -215,7 +213,8 @@ class phpbb_filespec_test extends phpbb_test_case
|
||||||
*/
|
*/
|
||||||
public function test_get_extension($filename, $expected)
|
public function test_get_extension($filename, $expected)
|
||||||
{
|
{
|
||||||
$this->assertEquals($expected, $this->filespec->get_extension($filename));
|
$filespec = $this->get_filespec();
|
||||||
|
$this->assertEquals($expected, $filespec->get_extension($filename));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function is_image_variables()
|
public function is_image_variables()
|
||||||
|
@ -234,8 +233,8 @@ class phpbb_filespec_test extends phpbb_test_case
|
||||||
*/
|
*/
|
||||||
public function test_is_image($filename, $mimetype, $expected)
|
public function test_is_image($filename, $mimetype, $expected)
|
||||||
{
|
{
|
||||||
$this->init_filespec(array('tmp_name' => $this->path . $filename, 'type' => $mimetype));
|
$filespec = $this->get_filespec(array('tmp_name' => $this->path . $filename, 'type' => $mimetype));
|
||||||
$this->assertEquals($expected, $this->filespec->is_image());
|
$this->assertEquals($expected, $filespec->is_image());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function move_file_variables()
|
public function move_file_variables()
|
||||||
|
@ -263,20 +262,20 @@ class phpbb_filespec_test extends phpbb_test_case
|
||||||
$upload = new phpbb_mock_fileupload();
|
$upload = new phpbb_mock_fileupload();
|
||||||
$upload->max_filesize = self::UPLOAD_MAX_FILESIZE;
|
$upload->max_filesize = self::UPLOAD_MAX_FILESIZE;
|
||||||
|
|
||||||
$this->init_filespec(array(
|
$filespec = $this->get_filespec(array(
|
||||||
'tmp_name' => $this->path . $tmp_name,
|
'tmp_name' => $this->path . $tmp_name,
|
||||||
'name' => $realname,
|
'name' => $realname,
|
||||||
'type' => $mime_type,
|
'type' => $mime_type,
|
||||||
));
|
));
|
||||||
$this->filespec->extension = $extension;
|
$filespec->extension = $extension;
|
||||||
$this->filespec->upload = $upload;
|
$filespec->upload = $upload;
|
||||||
$this->filespec->local = true;
|
$filespec->local = true;
|
||||||
|
|
||||||
$this->assertEquals($expected, $this->filespec->move_file($this->path));
|
$this->assertEquals($expected, $filespec->move_file($this->path));
|
||||||
$this->assertEquals($this->filespec->file_moved, file_exists($this->path . $realname));
|
$this->assertEquals($filespec->file_moved, file_exists($this->path . $realname));
|
||||||
if ($error)
|
if ($error)
|
||||||
{
|
{
|
||||||
$this->assertEquals($error, $this->filespec->error[0]);
|
$this->assertEquals($error, $filespec->error[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
$phpEx = '';
|
$phpEx = '';
|
||||||
|
|
Loading…
Add table
Reference in a new issue