mirror of
https://github.com/phpbb/phpbb.git
synced 2025-05-29 10:39:19 +02:00
[ticket/10941] Now actually checks for the value of errors.
Uses phpbb_mock_lang to return the key used when setting errors to allow that key to be checked for during tests rather than just checking if any error was set. PHPBB3-10941
This commit is contained in:
parent
943af957e6
commit
19405a7f47
@ -57,15 +57,12 @@ class phpbb_functional_fileupload_test extends phpbb_functional_test_case
|
||||
|
||||
public function test_remote_upload()
|
||||
{
|
||||
// Note: we cannot check for the actual value of the error messages
|
||||
// since they are passed through the translator which will result in
|
||||
// blank strings within this test framework.
|
||||
|
||||
// Only doing this within the functional framework because we need a
|
||||
// URL
|
||||
|
||||
// Global $config required by unique_id
|
||||
global $config;
|
||||
// Global $user required by fileupload::remote_upload
|
||||
global $config, $user;
|
||||
|
||||
if (!is_array($config))
|
||||
{
|
||||
@ -75,20 +72,23 @@ class phpbb_functional_fileupload_test extends phpbb_functional_test_case
|
||||
$config['rand_seed'] = '';
|
||||
$config['rand_seed_last_update'] = time() + 600;
|
||||
|
||||
$user = new phpbb_mock_user();
|
||||
$user->lang = new phpbb_mock_lang();
|
||||
|
||||
// Test 1: Invalid extension
|
||||
$upload = new fileupload('', array('jpg'), 100);
|
||||
$file = $upload->remote_upload('http://example.com/image.gif');
|
||||
$this->assertEquals(1, sizeof($file->error));
|
||||
$this->assertEquals('URL_INVALID',$file->error[0]);
|
||||
|
||||
// Test 2: Non-existant file
|
||||
$upload = new fileupload('', array('jpg'), 100);
|
||||
$file = $upload->remote_upload('http://example.com/image.jpg');
|
||||
$this->assertEquals(1, sizeof($file->error));
|
||||
$this->assertEquals('EMPTY_REMOTE_DATA', $file->error[0]);
|
||||
|
||||
// Test 3: File too large
|
||||
$upload = new fileupload('', array('gif'), 100);
|
||||
$file = $upload->remote_upload($this->root_url . 'styles/prosilver/theme/images/forum_read.gif');
|
||||
$this->assertEquals(1, sizeof($file->error));
|
||||
$this->assertEquals('WRONG_FILESIZE', $file->error[0]);
|
||||
|
||||
// Test 4: Successful upload
|
||||
$upload = new fileupload('', array('gif'), 1000);
|
||||
@ -97,5 +97,6 @@ class phpbb_functional_fileupload_test extends phpbb_functional_test_case
|
||||
$this->assertTrue(file_exists($file->filename));
|
||||
|
||||
$config = array();
|
||||
$user = null;
|
||||
}
|
||||
}
|
||||
|
@ -27,7 +27,9 @@ class phpbb_filespec_test extends phpbb_test_case
|
||||
protected function setUp()
|
||||
{
|
||||
// Global $config required by unique_id
|
||||
global $config;
|
||||
// Global $user required by filespec::additional_checks and
|
||||
// filespec::move_file
|
||||
global $config, $user;
|
||||
|
||||
if (!is_array($config))
|
||||
{
|
||||
@ -38,6 +40,9 @@ class phpbb_filespec_test extends phpbb_test_case
|
||||
$config['rand_seed_last_update'] = time() + 600;
|
||||
$config['mime_triggers'] = 'body|head|html|img|plaintext|a href|pre|script|table|title';
|
||||
|
||||
$user = new phpbb_mock_user();
|
||||
$user->lang = new phpbb_mock_lang();
|
||||
|
||||
$this->config = &$config;
|
||||
$this->path = __DIR__ . '/fixture/';
|
||||
$this->init_filespec();
|
||||
@ -75,6 +80,8 @@ class phpbb_filespec_test extends phpbb_test_case
|
||||
|
||||
protected function tearDown()
|
||||
{
|
||||
global $user;
|
||||
|
||||
$files = array(
|
||||
'gif_copy' => 1,
|
||||
'jpg_copy' => 1,
|
||||
@ -99,6 +106,7 @@ class phpbb_filespec_test extends phpbb_test_case
|
||||
}
|
||||
|
||||
$this->config = array();
|
||||
$user = null;
|
||||
}
|
||||
|
||||
public function additional_checks_variables()
|
||||
@ -117,10 +125,6 @@ class phpbb_filespec_test extends phpbb_test_case
|
||||
*/
|
||||
public function test_additional_checks($filename, $expected)
|
||||
{
|
||||
// Global $user required by filespec::additional_checks
|
||||
global $user;
|
||||
$user = new phpbb_mock_user();
|
||||
|
||||
$upload = new phpbb_mock_fileupload();
|
||||
$this->init_filespec(array('tmp_name', $this->path . $filename));
|
||||
$this->filespec->upload = $upload;
|
||||
@ -170,7 +174,6 @@ class phpbb_filespec_test extends phpbb_test_case
|
||||
*/
|
||||
public function test_clean_filename_real($filename)
|
||||
{
|
||||
|
||||
$bad_chars = array("'", "\\", ' ', '/', ':', '*', '?', '"', '<', '>', '|');
|
||||
$this->init_filespec(array('name' => $filename));
|
||||
$this->filespec->clean_filename('real', self::PREFIX);
|
||||
@ -241,11 +244,11 @@ class phpbb_filespec_test extends phpbb_test_case
|
||||
{
|
||||
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('non_existant', 'still_non_existant', 'text/plain', 'txt', 'GENERAL_UPLOAD_ERROR', false),
|
||||
array('txt_copy', 'txt_as_img', 'image/jpg', 'txt', 'UNABLE_GET_IMAGE_SIZE', 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),
|
||||
array('png_copy', 'png_moved', 'image/png', 'jpg', 'IMAGE_FILETYPE_MISMATCH', true),
|
||||
);
|
||||
}
|
||||
|
||||
@ -272,8 +275,11 @@ class phpbb_filespec_test extends phpbb_test_case
|
||||
$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));
|
||||
if ($error)
|
||||
{
|
||||
$this->assertEquals($error, $this->filespec->error[0]);
|
||||
}
|
||||
|
||||
$phpEx = '';
|
||||
}
|
||||
|
@ -31,6 +31,7 @@ class phpbb_fileupload_test extends phpbb_test_case
|
||||
$config['rand_seed_last_update'] = time() + 600;
|
||||
|
||||
$user = new phpbb_mock_user();
|
||||
$user->lang = new phpbb_mock_lang();
|
||||
$this->path = __DIR__ . '/fixture/';
|
||||
}
|
||||
|
||||
@ -56,10 +57,6 @@ class phpbb_fileupload_test extends phpbb_test_case
|
||||
|
||||
public function test_common_checks()
|
||||
{
|
||||
// Note: we cannot check for the actual value of the error messages
|
||||
// since they are passed through the translator which will result in
|
||||
// blank strings within this test framework.
|
||||
|
||||
// Test 1: Valid file
|
||||
$upload = new fileupload('', array('jpg'), 1000);
|
||||
$file = $this->gen_valid_filespec();
|
||||
@ -71,20 +68,20 @@ class phpbb_fileupload_test extends phpbb_test_case
|
||||
$file = $this->gen_valid_filespec();
|
||||
$file->filesize = 1000;
|
||||
$upload->common_checks($file);
|
||||
$this->assertEquals(1, sizeof($file->error));
|
||||
$this->assertEquals('WRONG_FILESIZE', $file->error[0]);
|
||||
|
||||
// Test 3: Invalid filename
|
||||
$upload = new fileupload('', array('jpg'), 100);
|
||||
$file = $this->gen_valid_filespec();
|
||||
$file->realname = 'invalid?';
|
||||
$upload->common_checks($file);
|
||||
$this->assertEquals(1, sizeof($file->error));
|
||||
$this->assertEquals('INVALID_FILENAME', $file->error[0]);
|
||||
|
||||
// Test 4: Invalid extension
|
||||
$upload = new fileupload('', array('png'), 100);
|
||||
$file = $this->gen_valid_filespec();
|
||||
$upload->common_checks($file);
|
||||
$this->assertEquals(1, sizeof($file->error));
|
||||
$this->assertEquals('DISALLOWED_EXTENSION', $file->error[0]);
|
||||
}
|
||||
|
||||
public function test_local_upload()
|
||||
|
Loading…
x
Reference in New Issue
Block a user