aboutsummaryrefslogtreecommitdiffstats
path: root/tests/files
diff options
context:
space:
mode:
authorMarc Alexander <admin@m-a-styles.de>2015-09-07 22:52:20 +0200
committerMarc Alexander <admin@m-a-styles.de>2015-09-09 08:29:12 +0200
commite60c8a5a8bfa1aa500c096ea90cd32fda9465f9a (patch)
tree02f64e263e49e0dc61a267e45cf66143e4d6070a /tests/files
parent00e5ff9e2e9c0dd7325f33a22888d6888af4b197 (diff)
downloadforums-e60c8a5a8bfa1aa500c096ea90cd32fda9465f9a.tar
forums-e60c8a5a8bfa1aa500c096ea90cd32fda9465f9a.tar.gz
forums-e60c8a5a8bfa1aa500c096ea90cd32fda9465f9a.tar.bz2
forums-e60c8a5a8bfa1aa500c096ea90cd32fda9465f9a.tar.xz
forums-e60c8a5a8bfa1aa500c096ea90cd32fda9465f9a.zip
[ticket/13904] Improve code coverage
PHPBB3-13904
Diffstat (limited to 'tests/files')
-rw-r--r--tests/files/type_foo.php31
-rw-r--r--tests/files/types_remote_test.php66
2 files changed, 96 insertions, 1 deletions
diff --git a/tests/files/type_foo.php b/tests/files/type_foo.php
new file mode 100644
index 0000000000..20eddfcbc4
--- /dev/null
+++ b/tests/files/type_foo.php
@@ -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;
+ }
+}
diff --git a/tests/files/types_remote_test.php b/tests/files/types_remote_test.php
index 405a8c4104..6d513ac5c0 100644
--- a/tests/files/types_remote_test.php
+++ b/tests/files/types_remote_test.php
@@ -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 = '';
+ }
}