mirror of
https://github.com/phpbb/phpbb.git
synced 2025-08-11 03:04:09 +02:00
Merge remote-tracking branch 'Fyorl/ticket/10939' into develop
* Fyorl/ticket/10939: [ticket/10939] Added documentation for phpbb_request::file [ticket/10939] Added tests for phpbb_request::file [ticket/10939] Modified the default return for $request->file [ticket/10939] Modified fileupload tests to deal with new behaviour [ticket/10939] Modified mock request class to handle deactivated $_FILES [ticket/10939] Modified acp_groups.php to not use $_FILES [ticket/10939] Modified ucp_groups.php to not use $_FILES [ticket/10939] Modified functions_user.php to not use $_FILES [ticket/10939] Modified message_parser.php to not use $_FILES [ticket/10939] Modified functions_upload to not use $_FILES [ticket/10939] Modified request test slightly to include $_FILES [ticket/10939] Added $_FILES handling to phpbb_request
This commit is contained in:
@@ -11,13 +11,14 @@ class phpbb_mock_request implements phpbb_request_interface
|
||||
{
|
||||
protected $data;
|
||||
|
||||
public function __construct($get = array(), $post = array(), $cookie = array(), $server = array(), $request = false)
|
||||
public function __construct($get = array(), $post = array(), $cookie = array(), $server = array(), $request = false, $files = array())
|
||||
{
|
||||
$this->data[phpbb_request_interface::GET] = $get;
|
||||
$this->data[phpbb_request_interface::POST] = $post;
|
||||
$this->data[phpbb_request_interface::COOKIE] = $cookie;
|
||||
$this->data[phpbb_request_interface::REQUEST] = ($request === false) ? $post + $get : $request;
|
||||
$this->data[phpbb_request_interface::SERVER] = $server;
|
||||
$this->data[phpbb_request_interface::FILES] = $files;
|
||||
}
|
||||
|
||||
public function overwrite($var_name, $value, $super_global = phpbb_request_interface::REQUEST)
|
||||
@@ -42,6 +43,12 @@ class phpbb_mock_request implements phpbb_request_interface
|
||||
return $this->server($var_name, $default);
|
||||
}
|
||||
|
||||
public function file($form_name)
|
||||
{
|
||||
$super_global = phpbb_request_interface::FILES;
|
||||
return isset($this->data[$super_global][$form_name]) ? $this->data[$super_global][$form_name] : array();
|
||||
}
|
||||
|
||||
public function is_set_post($name)
|
||||
{
|
||||
return $this->is_set($name, phpbb_request_interface::POST);
|
||||
|
@@ -21,6 +21,13 @@ class phpbb_request_test extends phpbb_test_case
|
||||
$_COOKIE['test'] = 3;
|
||||
$_REQUEST['test'] = 3;
|
||||
$_GET['unset'] = '';
|
||||
$_FILES['test'] = array(
|
||||
'name' => 'file',
|
||||
'tmp_name' => 'tmp',
|
||||
'size' => 256,
|
||||
'type' => 'application/octet-stream',
|
||||
'error' => UPLOAD_ERR_OK,
|
||||
);
|
||||
|
||||
$_SERVER['HTTP_HOST'] = 'example.com';
|
||||
$_SERVER['HTTP_ACCEPT'] = 'application/json';
|
||||
@@ -42,6 +49,7 @@ class phpbb_request_test extends phpbb_test_case
|
||||
$this->assertEquals(2, $_GET['test'], 'Checking $_GET after enable_super_globals');
|
||||
$this->assertEquals(3, $_COOKIE['test'], 'Checking $_COOKIE after enable_super_globals');
|
||||
$this->assertEquals(3, $_REQUEST['test'], 'Checking $_REQUEST after enable_super_globals');
|
||||
$this->assertEquals(256, $_FILES['test']['size']);
|
||||
|
||||
$_POST['x'] = 2;
|
||||
$this->assertEquals($_POST, $GLOBALS['_POST'], 'Checking whether $_POST can still be accessed via $GLOBALS[\'_POST\']');
|
||||
@@ -85,6 +93,23 @@ class phpbb_request_test extends phpbb_test_case
|
||||
$this->request->header('SOMEVAR');
|
||||
}
|
||||
|
||||
public function test_file()
|
||||
{
|
||||
$file = $this->request->file('test');
|
||||
$this->assertEquals('file', $file['name']);
|
||||
$this->assertEquals('tmp', $file['tmp_name']);
|
||||
$this->assertEquals(256, $file['size']);
|
||||
$this->assertEquals('application/octet-stream', $file['type']);
|
||||
$this->assertEquals(UPLOAD_ERR_OK, $file['error']);
|
||||
}
|
||||
|
||||
public function test_file_not_exists()
|
||||
{
|
||||
$file = $this->request->file('404');
|
||||
$this->assertTrue(is_array($file));
|
||||
$this->assertTrue(empty($file));
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks that directly accessing $_POST will trigger
|
||||
* an error.
|
||||
|
@@ -19,7 +19,8 @@ class phpbb_fileupload_test extends phpbb_test_case
|
||||
{
|
||||
// Global $config required by unique_id
|
||||
// Global $user required by several functions dealing with translations
|
||||
global $config, $user;
|
||||
// Global $request required by form_upload, local_upload and is_valid
|
||||
global $config, $user, $request;
|
||||
|
||||
if (!is_array($config))
|
||||
{
|
||||
@@ -31,6 +32,9 @@ class phpbb_fileupload_test extends phpbb_test_case
|
||||
|
||||
$user = new phpbb_mock_user();
|
||||
$user->lang = new phpbb_mock_lang();
|
||||
|
||||
$request = new phpbb_mock_request();
|
||||
|
||||
$this->path = __DIR__ . '/fixture/';
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user