[ticket/13904] Remove phpbb_root_path global from upload class

PHPBB3-13904
This commit is contained in:
Marc Alexander 2015-06-02 15:29:32 +02:00
parent 47f8f2cc88
commit 52652ca182
3 changed files with 27 additions and 16 deletions

View file

@ -63,6 +63,9 @@ class upload
/** @var \phpbb\request\request_interface Request class */
protected $request;
/** @var string phpBB root path */
protected $phpbb_root_path;
/**
* Init file upload class.
*
@ -70,13 +73,15 @@ class upload
* @param \phpbb\files\factory $factory Files factory
* @param \phpbb\language\language $language Language class
* @param \phpbb\request\request_interface $request Request class
* @param string $phpbb_root_path phpBB root path
*/
public function __construct(filesystem_interface $filesystem, factory $factory, language $language, request_interface $request)
public function __construct(filesystem_interface $filesystem, factory $factory, language $language, request_interface $request, $phpbb_root_path)
{
$this->filesystem = $filesystem;
$this->factory = $factory;
$this->language = $language;
$this->request = $request;
$this->phpbb_root_path = $phpbb_root_path;
}
/**
@ -350,8 +355,6 @@ class upload
*/
function remote_upload($upload_url)
{
global $phpbb_root_path;
$upload_ary = array();
$upload_ary['local_mode'] = true;
@ -504,7 +507,7 @@ class upload
return $this->factory->get('filespec')->set_error($this->error_prefix . 'EMPTY_REMOTE_DATA');
}
$tmp_path = (!@ini_get('safe_mode') || strtolower(@ini_get('safe_mode')) == 'off') ? false : $phpbb_root_path . 'cache';
$tmp_path = (!@ini_get('safe_mode') || strtolower(@ini_get('safe_mode')) == 'off') ? false : $this->phpbb_root_path . 'cache';
$filename = tempnam($tmp_path, unique_id() . '-');
if (!($fp = @fopen($filename, 'wb')))

View file

@ -28,6 +28,9 @@ class phpbb_functional_fileupload_remote_test extends phpbb_functional_test_case
/** @var \phpbb\request\request_interface */
protected $request;
/** @var string phpBB root path */
protected $phpbb_root_path;
public function setUp()
{
parent::setUp();
@ -53,6 +56,7 @@ class phpbb_functional_fileupload_remote_test extends phpbb_functional_test_case
$container->set('files.filespec', new \phpbb\files\filespec($this->filesystem, $this->language));
$this->factory = new \phpbb\files\factory($container);
$container->set('files.factory', $this->factory);
$this->phpbb_root_path = $phpbb_root_path;
}
public function tearDown()
@ -65,7 +69,7 @@ class phpbb_functional_fileupload_remote_test extends phpbb_functional_test_case
public function test_invalid_extension()
{
/** @var \phpbb\files\upload $upload */
$upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language, $this->request);
$upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language, $this->request, $this->phpbb_root_path);
$upload->set_error_prefix('')
->set_allowed_extensions(array('jpg'))
->set_max_filesize(100);
@ -76,7 +80,7 @@ class phpbb_functional_fileupload_remote_test extends phpbb_functional_test_case
public function test_empty_file()
{
/** @var \phpbb\files\upload $upload */
$upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language, $this->request);
$upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language, $this->request, $this->phpbb_root_path);
$upload->set_error_prefix('')
->set_allowed_extensions(array('jpg'))
->set_max_filesize(100);
@ -87,7 +91,7 @@ class phpbb_functional_fileupload_remote_test extends phpbb_functional_test_case
public function test_successful_upload()
{
/** @var \phpbb\files\upload $upload */
$upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language, $this->request);
$upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language, $this->request, $this->phpbb_root_path);
$upload->set_error_prefix('')
->set_allowed_extensions(array('gif'))
->set_max_filesize(1000);
@ -99,7 +103,7 @@ class phpbb_functional_fileupload_remote_test extends phpbb_functional_test_case
public function test_too_large()
{
/** @var \phpbb\files\upload $upload */
$upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language, $this->request);
$upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language, $this->request, $this->phpbb_root_path);
$upload->set_error_prefix('')
->set_allowed_extensions(array('gif'))
->set_max_filesize(100);

View file

@ -33,6 +33,9 @@ class phpbb_fileupload_test extends phpbb_test_case
/** @var \phpbb\request\request_interface */
protected $request;
/** @var string phpBB root path */
protected $phpbb_root_path;
protected function setUp()
{
// Global $config required by unique_id
@ -61,6 +64,7 @@ class phpbb_fileupload_test extends phpbb_test_case
$this->factory = new \phpbb\files\factory($this->container);
$this->path = __DIR__ . '/fixture/';
$this->phpbb_root_path = $phpbb_root_path;
}
private function gen_valid_filespec()
@ -85,7 +89,7 @@ class phpbb_fileupload_test extends phpbb_test_case
public function test_common_checks_invalid_extension()
{
$upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language, $this->request);
$upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language, $this->request, $this->phpbb_root_path);
$upload->set_allowed_extensions(array('png'))
->set_max_filesize(100);
$file = $this->gen_valid_filespec();
@ -95,7 +99,7 @@ class phpbb_fileupload_test extends phpbb_test_case
public function test_common_checks_invalid_filename()
{
$upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language, $this->request);
$upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language, $this->request, $this->phpbb_root_path);
$upload->set_allowed_extensions(array('jpg'))
->set_max_filesize(100);
$file = $this->gen_valid_filespec();
@ -106,7 +110,7 @@ class phpbb_fileupload_test extends phpbb_test_case
public function test_common_checks_too_large()
{
$upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language, $this->request);
$upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language, $this->request, $this->phpbb_root_path);
$upload->set_allowed_extensions(array('jpg'))
->set_max_filesize(100);
$file = $this->gen_valid_filespec();
@ -117,7 +121,7 @@ class phpbb_fileupload_test extends phpbb_test_case
public function test_common_checks_valid_file()
{
$upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language, $this->request);
$upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language, $this->request, $this->phpbb_root_path);
$upload->set_allowed_extensions(array('jpg'))
->set_max_filesize(1000);
$file = $this->gen_valid_filespec();
@ -127,7 +131,7 @@ class phpbb_fileupload_test extends phpbb_test_case
public function test_local_upload()
{
$upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language, $this->request);
$upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language, $this->request, $this->phpbb_root_path);
$upload->set_allowed_extensions(array('jpg'))
->set_max_filesize(1000);
@ -139,7 +143,7 @@ class phpbb_fileupload_test extends phpbb_test_case
public function test_move_existent_file()
{
$upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language, $this->request);
$upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language, $this->request, $this->phpbb_root_path);
$upload->set_allowed_extensions(array('jpg'))
->set_max_filesize(1000);
@ -153,7 +157,7 @@ class phpbb_fileupload_test extends phpbb_test_case
public function test_move_existent_file_overwrite()
{
$upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language, $this->request);
$upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language, $this->request, $this->phpbb_root_path);
$upload->set_allowed_extensions(array('jpg'))
->set_max_filesize(1000);
@ -168,7 +172,7 @@ class phpbb_fileupload_test extends phpbb_test_case
public function test_valid_dimensions()
{
$upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language, $this->request);
$upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language, $this->request, $this->phpbb_root_path);
$upload->set_allowed_extensions(false)
->set_max_filesize(false)
->set_allowed_dimensions(1, 1, 100, 100);