mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-07 20:08:53 +00:00
[ticket/13904] Improve code coverage
PHPBB3-13904
This commit is contained in:
parent
00e5ff9e2e
commit
e60c8a5a8b
3 changed files with 98 additions and 3 deletions
|
@ -235,10 +235,10 @@ class remote extends base
|
|||
{
|
||||
$max_file_size = $this->php_ini->getString('upload_max_filesize');
|
||||
|
||||
if (!empty($max_filesize))
|
||||
if (!empty($max_file_size))
|
||||
{
|
||||
$unit = strtolower(substr($max_file_size, -1, 1));
|
||||
$max_file_size = (int) $max_filesize;
|
||||
$max_file_size = (int) $max_file_size;
|
||||
|
||||
switch ($unit)
|
||||
{
|
||||
|
|
31
tests/files/type_foo.php
Normal file
31
tests/files/type_foo.php
Normal file
|
@ -0,0 +1,31 @@
|
|||
<?php
|
||||
/**
|
||||
*
|
||||
* This file is part of the phpBB Forum Software package.
|
||||
*
|
||||
* @copyright (c) phpBB Limited <https://www.phpbb.com>
|
||||
* @license GNU General Public License, version 2 (GPL-2.0)
|
||||
*
|
||||
* For full copyright and license information, please see
|
||||
* the docs/CREDITS.txt file.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace phpbb\files\types;
|
||||
|
||||
class foo extends \phpbb\files\types\remote
|
||||
{
|
||||
static public $tempnam_path;
|
||||
}
|
||||
|
||||
function tempnam($one, $two)
|
||||
{
|
||||
if (empty(foo::$tempnam_path))
|
||||
{
|
||||
return \tempnam($one, $two);
|
||||
}
|
||||
else
|
||||
{
|
||||
return foo::$tempnam_path;
|
||||
}
|
||||
}
|
|
@ -12,6 +12,7 @@
|
|||
*/
|
||||
|
||||
require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
|
||||
require_once dirname(__FILE__) . '/type_foo.php';
|
||||
|
||||
class phpbb_files_types_remote_test extends phpbb_test_case
|
||||
{
|
||||
|
@ -39,8 +40,9 @@ class phpbb_files_types_remote_test extends phpbb_test_case
|
|||
|
||||
protected function setUp()
|
||||
{
|
||||
global $phpbb_root_path, $phpEx;
|
||||
global $config, $phpbb_root_path, $phpEx;
|
||||
|
||||
$config = new \phpbb\config\config(array());
|
||||
$this->request = $this->getMock('\phpbb\request\request');
|
||||
|
||||
$this->filesystem = new \phpbb\filesystem\filesystem();
|
||||
|
@ -74,4 +76,66 @@ class phpbb_files_types_remote_test extends phpbb_test_case
|
|||
|
||||
$this->assertSame(array('NOT_UPLOADED'), $file->error);
|
||||
}
|
||||
|
||||
public function data_get_max_file_size()
|
||||
{
|
||||
return array(
|
||||
array('', 'http://example.com/foo/bar.png'),
|
||||
array('2k', 'http://example.com/foo/bar.png'),
|
||||
array('500k', 'http://example.com/foo/bar.png'),
|
||||
array('500M', 'http://example.com/foo/bar.png'),
|
||||
array('500m', 'http://example.com/foo/bar.png'),
|
||||
array('500k', 'http://google.com/.png', 'DISALLOWED_CONTENT'),
|
||||
array('1', 'http://google.com/.png', 'WRONG_FILESIZE'),
|
||||
array('500g', 'http://example.com/foo/bar.png'),
|
||||
array('foobar', 'http://example.com/foo/bar.png'),
|
||||
array('-5k', 'http://example.com/foo/bar.png'),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider data_get_max_file_size
|
||||
*/
|
||||
public function test_get_max_file_size($max_file_size, $link, $expected = 'URL_NOT_FOUND')
|
||||
{
|
||||
$php_ini = $this->getMock('\bantu\IniGetWrapper\IniGetWrapper', array('getString'));
|
||||
$php_ini->expects($this->any())
|
||||
->method('getString')
|
||||
->willReturn($max_file_size);
|
||||
$type_remote = new \phpbb\files\types\remote($this->factory, $this->language, $php_ini, $this->request, $this->phpbb_root_path);
|
||||
$upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language, $this->php_ini, $this->request, $this->phpbb_root_path);
|
||||
$upload->set_allowed_extensions(array('png'));
|
||||
$type_remote->set_upload($upload);
|
||||
|
||||
$file = $type_remote->upload($link);
|
||||
|
||||
$this->assertSame(array($expected), $file->error);
|
||||
}
|
||||
|
||||
public function test_upload_timeout()
|
||||
{
|
||||
$type_remote = new \phpbb\files\types\remote($this->factory, $this->language, $this->php_ini, $this->request, $this->phpbb_root_path);
|
||||
$upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language, $this->php_ini, $this->request, $this->phpbb_root_path);
|
||||
$upload->set_allowed_extensions(array('png'));
|
||||
$type_remote->set_upload($upload);
|
||||
$upload->upload_timeout = -5;
|
||||
|
||||
$file = $type_remote->upload('http://google.com/.png');
|
||||
|
||||
$this->assertSame(array('REMOTE_UPLOAD_TIMEOUT'), $file->error);
|
||||
}
|
||||
|
||||
public function test_upload_wrong_path()
|
||||
{
|
||||
$type_remote = new \phpbb\files\types\foo($this->factory, $this->language, $this->php_ini, $this->request, $this->phpbb_root_path);
|
||||
$upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language, $this->php_ini, $this->request, $this->phpbb_root_path);
|
||||
$upload->set_allowed_extensions(array('png'));
|
||||
$type_remote->set_upload($upload);
|
||||
$type_remote::$tempnam_path = $this->phpbb_root_path . 'cache/wrong/path';
|
||||
|
||||
$file = $type_remote->upload('http://google.com/.png');
|
||||
|
||||
$this->assertSame(array('NOT_UPLOADED'), $file->error);
|
||||
$type_remote::$tempnam_path = '';
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue