aboutsummaryrefslogtreecommitdiffstats
path: root/tests/upload/fileupload_test.php
diff options
context:
space:
mode:
authorFyorl <gaelreth@gmail.com>2012-07-08 14:39:18 +0100
committerFyorl <gaelreth@gmail.com>2012-07-09 14:08:20 +0100
commit580cec619b399f710aedc1d3c2dd92c2287ebaff (patch)
tree1061387bc329050dff1d56e313d31196c0a830b2 /tests/upload/fileupload_test.php
parentd89af53f6311d9f4cec60d136cf017df9e1a36cd (diff)
downloadforums-580cec619b399f710aedc1d3c2dd92c2287ebaff.tar
forums-580cec619b399f710aedc1d3c2dd92c2287ebaff.tar.gz
forums-580cec619b399f710aedc1d3c2dd92c2287ebaff.tar.bz2
forums-580cec619b399f710aedc1d3c2dd92c2287ebaff.tar.xz
forums-580cec619b399f710aedc1d3c2dd92c2287ebaff.zip
[ticket/10941] Added subdirectory for file operations
Also removed common.php as it was unnecessary. PHPBB3-10941
Diffstat (limited to 'tests/upload/fileupload_test.php')
-rw-r--r--tests/upload/fileupload_test.php116
1 files changed, 116 insertions, 0 deletions
diff --git a/tests/upload/fileupload_test.php b/tests/upload/fileupload_test.php
new file mode 100644
index 0000000000..2b3c17b8e0
--- /dev/null
+++ b/tests/upload/fileupload_test.php
@@ -0,0 +1,116 @@
+<?php
+/**
+ *
+ * @package testing
+ * @copyright (c) 2012 phpBB Group
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+ *
+ */
+
+require_once __DIR__ . '/../../phpBB/includes/functions.php';
+require_once __DIR__ . '/../../phpBB/includes/utf/utf_tools.php';
+require_once __DIR__ . '/../../phpBB/includes/functions_upload.php';
+require_once __DIR__ . '/../mock/filespec.php';
+
+class phpbb_fileupload_test extends phpbb_test_case
+{
+ private $path;
+
+ protected function setUp()
+ {
+ // Global $config required by unique_id
+ // Global $user required by several functions dealing with translations
+ global $config, $user;
+
+ if (!is_array($config))
+ {
+ $config = array();
+ }
+
+ $config['rand_seed'] = '';
+ $config['rand_seed_last_update'] = time() + 600;
+
+ $user = new phpbb_mock_user();
+ $user->lang = new phpbb_mock_lang();
+ $this->path = __DIR__ . '/fixture/';
+ }
+
+ private function gen_valid_filespec()
+ {
+ $filespec = new phpbb_mock_filespec();
+ $filespec->filesize = 1;
+ $filespec->extension = 'jpg';
+ $filespec->realname = 'valid';
+ $filespec->width = 2;
+ $filespec->height = 2;
+
+ return $filespec;
+ }
+
+ protected function tearDown()
+ {
+ // Clear globals
+ global $config, $user;
+ $config = array();
+ $user = null;
+ }
+
+ public function test_common_checks_invalid_extension()
+ {
+ $upload = new fileupload('', array('png'), 100);
+ $file = $this->gen_valid_filespec();
+ $upload->common_checks($file);
+ $this->assertEquals('DISALLOWED_EXTENSION', $file->error[0]);
+ }
+
+ public function test_common_checks_invalid_filename()
+ {
+ $upload = new fileupload('', array('jpg'), 100);
+ $file = $this->gen_valid_filespec();
+ $file->realname = 'invalid?';
+ $upload->common_checks($file);
+ $this->assertEquals('INVALID_FILENAME', $file->error[0]);
+ }
+
+ public function test_common_checks_too_large()
+ {
+ $upload = new fileupload('', array('jpg'), 100);
+ $file = $this->gen_valid_filespec();
+ $file->filesize = 1000;
+ $upload->common_checks($file);
+ $this->assertEquals('WRONG_FILESIZE', $file->error[0]);
+ }
+
+ public function test_common_checks_valid_file()
+ {
+ $upload = new fileupload('', array('jpg'), 1000);
+ $file = $this->gen_valid_filespec();
+ $upload->common_checks($file);
+ $this->assertEquals(0, sizeof($file->error));
+ }
+
+ public function test_local_upload()
+ {
+ $upload = new fileupload('', array('jpg'), 1000);
+
+ copy($this->path . 'jpg', $this->path . 'jpg.jpg');
+ $file = $upload->local_upload($this->path . 'jpg.jpg');
+ $this->assertEquals(0, sizeof($file->error));
+ unlink($this->path . 'jpg.jpg');
+ }
+
+ public function test_valid_dimensions()
+ {
+ $upload = new fileupload('', false, false, 1, 1, 100, 100);
+
+ $file1 = $this->gen_valid_filespec();
+ $file2 = $this->gen_valid_filespec();
+ $file2->height = 101;
+ $file3 = $this->gen_valid_filespec();
+ $file3->width = 0;
+
+ $this->assertTrue($upload->valid_dimensions($file1));
+ $this->assertFalse($upload->valid_dimensions($file2));
+ $this->assertFalse($upload->valid_dimensions($file3));
+ }
+}