mirror of
https://github.com/phpbb/phpbb.git
synced 2025-08-14 04:34:07 +02:00
[ticket/13697] Moving filesystem related functions to filesystem service
* Moving filesystem service to \phpbb\filesystem namespace * Wraping Symfony's Filesystem component * Moving filesystem related functions from includes/functions.php into \phpbb\filesystem\filesystem Functions moved (and deprecated): - phpbb_chmod - phpbb_is_writable - phpbb_is_absolute - phpbb_own_realpath - phpbb_realpath * Adding interface for filesystem service PHPBB3-13697
This commit is contained in:
@@ -23,6 +23,7 @@ class phpbb_filespec_test extends phpbb_test_case
|
||||
const UPLOAD_MAX_FILESIZE = 1000;
|
||||
|
||||
private $config;
|
||||
private $filesystem;
|
||||
public $path;
|
||||
|
||||
protected function setUp()
|
||||
@@ -30,7 +31,7 @@ class phpbb_filespec_test extends phpbb_test_case
|
||||
// Global $config required by unique_id
|
||||
// Global $user required by filespec::additional_checks and
|
||||
// filespec::move_file
|
||||
global $config, $user;
|
||||
global $config, $user, $phpbb_filesystem;
|
||||
|
||||
if (!is_array($config))
|
||||
{
|
||||
@@ -75,6 +76,8 @@ class phpbb_filespec_test extends phpbb_test_case
|
||||
$guessers[2]->set_priority(-2);
|
||||
$guessers[3]->set_priority(-2);
|
||||
$this->mimetype_guesser = new \phpbb\mimetype\guesser($guessers);
|
||||
|
||||
$this->filesystem = $phpbb_filesystem = new \phpbb\filesystem\filesystem();
|
||||
}
|
||||
|
||||
private function get_filespec($override = array())
|
||||
@@ -88,7 +91,7 @@ class phpbb_filespec_test extends phpbb_test_case
|
||||
'error' => '',
|
||||
);
|
||||
|
||||
return new filespec(array_merge($upload_ary, $override), null, $this->mimetype_guesser);
|
||||
return new filespec(array_merge($upload_ary, $override), null, $this->filesystem, $this->mimetype_guesser);
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
@@ -198,7 +201,7 @@ class phpbb_filespec_test extends phpbb_test_case
|
||||
$filespec = $this->get_filespec();
|
||||
$filespec->clean_filename('unique', self::PREFIX);
|
||||
$name = $filespec->realname;
|
||||
|
||||
|
||||
$this->assertEquals(strlen($name), 32 + strlen(self::PREFIX));
|
||||
$this->assertRegExp('#^[A-Za-z0-9]+$#', substr($name, strlen(self::PREFIX)));
|
||||
$this->assertFalse(isset($filenames[$name]));
|
||||
|
@@ -20,12 +20,14 @@ class phpbb_fileupload_test extends phpbb_test_case
|
||||
{
|
||||
private $path;
|
||||
|
||||
private $filesystem;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
// Global $config required by unique_id
|
||||
// Global $user required by several functions dealing with translations
|
||||
// Global $request required by form_upload, local_upload and is_valid
|
||||
global $config, $user, $request;
|
||||
global $config, $user, $request, $phpbb_filesystem;
|
||||
|
||||
if (!is_array($config))
|
||||
{
|
||||
@@ -40,6 +42,8 @@ class phpbb_fileupload_test extends phpbb_test_case
|
||||
|
||||
$request = new phpbb_mock_request();
|
||||
|
||||
$this->filesystem = $phpbb_filesystem = new \phpbb\filesystem\filesystem();
|
||||
|
||||
$this->path = __DIR__ . '/fixture/';
|
||||
}
|
||||
|
||||
@@ -65,7 +69,7 @@ class phpbb_fileupload_test extends phpbb_test_case
|
||||
|
||||
public function test_common_checks_invalid_extension()
|
||||
{
|
||||
$upload = new fileupload('', array('png'), 100);
|
||||
$upload = new fileupload($this->filesystem, '', array('png'), 100);
|
||||
$file = $this->gen_valid_filespec();
|
||||
$upload->common_checks($file);
|
||||
$this->assertEquals('DISALLOWED_EXTENSION', $file->error[0]);
|
||||
@@ -73,7 +77,7 @@ class phpbb_fileupload_test extends phpbb_test_case
|
||||
|
||||
public function test_common_checks_invalid_filename()
|
||||
{
|
||||
$upload = new fileupload('', array('jpg'), 100);
|
||||
$upload = new fileupload($this->filesystem, '', array('jpg'), 100);
|
||||
$file = $this->gen_valid_filespec();
|
||||
$file->realname = 'invalid?';
|
||||
$upload->common_checks($file);
|
||||
@@ -82,7 +86,7 @@ class phpbb_fileupload_test extends phpbb_test_case
|
||||
|
||||
public function test_common_checks_too_large()
|
||||
{
|
||||
$upload = new fileupload('', array('jpg'), 100);
|
||||
$upload = new fileupload($this->filesystem, '', array('jpg'), 100);
|
||||
$file = $this->gen_valid_filespec();
|
||||
$file->filesize = 1000;
|
||||
$upload->common_checks($file);
|
||||
@@ -91,7 +95,7 @@ class phpbb_fileupload_test extends phpbb_test_case
|
||||
|
||||
public function test_common_checks_valid_file()
|
||||
{
|
||||
$upload = new fileupload('', array('jpg'), 1000);
|
||||
$upload = new fileupload($this->filesystem, '', array('jpg'), 1000);
|
||||
$file = $this->gen_valid_filespec();
|
||||
$upload->common_checks($file);
|
||||
$this->assertEquals(0, sizeof($file->error));
|
||||
@@ -99,7 +103,7 @@ class phpbb_fileupload_test extends phpbb_test_case
|
||||
|
||||
public function test_local_upload()
|
||||
{
|
||||
$upload = new fileupload('', array('jpg'), 1000);
|
||||
$upload = new fileupload($this->filesystem, '', array('jpg'), 1000);
|
||||
|
||||
copy($this->path . 'jpg', $this->path . 'jpg.jpg');
|
||||
$file = $upload->local_upload($this->path . 'jpg.jpg');
|
||||
@@ -109,7 +113,7 @@ class phpbb_fileupload_test extends phpbb_test_case
|
||||
|
||||
public function test_move_existent_file()
|
||||
{
|
||||
$upload = new fileupload('', array('jpg'), 1000);
|
||||
$upload = new fileupload($this->filesystem, '', array('jpg'), 1000);
|
||||
|
||||
copy($this->path . 'jpg', $this->path . 'jpg.jpg');
|
||||
$file = $upload->local_upload($this->path . 'jpg.jpg');
|
||||
@@ -121,7 +125,7 @@ class phpbb_fileupload_test extends phpbb_test_case
|
||||
|
||||
public function test_move_existent_file_overwrite()
|
||||
{
|
||||
$upload = new fileupload('', array('jpg'), 1000);
|
||||
$upload = new fileupload($this->filesystem, '', array('jpg'), 1000);
|
||||
|
||||
copy($this->path . 'jpg', $this->path . 'jpg.jpg');
|
||||
copy($this->path . 'jpg', $this->path . 'copies/jpg.jpg');
|
||||
@@ -134,7 +138,7 @@ class phpbb_fileupload_test extends phpbb_test_case
|
||||
|
||||
public function test_valid_dimensions()
|
||||
{
|
||||
$upload = new fileupload('', false, false, 1, 1, 100, 100);
|
||||
$upload = new fileupload($this->filesystem, '', false, false, 1, 1, 100, 100);
|
||||
|
||||
$file1 = $this->gen_valid_filespec();
|
||||
$file2 = $this->gen_valid_filespec();
|
||||
|
Reference in New Issue
Block a user