aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/mock/request.php9
-rw-r--r--tests/request/request_test.php25
-rw-r--r--tests/template/includephp_test.php12
-rw-r--r--tests/template/template_includejs_test.php7
-rw-r--r--tests/template/template_test.php7
-rw-r--r--tests/template/templates/include_variables.html1
-rw-r--r--tests/template/templates/includejs.html5
-rw-r--r--tests/template/templates/includephp_variables.html2
-rw-r--r--tests/template/templates/subdir/parent_only.js0
-rw-r--r--tests/template/templates/subdir/subsubdir/parent_only.js0
-rw-r--r--tests/template/templates/subdir/variable.html1
-rw-r--r--tests/test_framework/phpbb_functional_test_case.php4
-rw-r--r--tests/upload/fileupload_test.php6
13 files changed, 72 insertions, 7 deletions
diff --git a/tests/mock/request.php b/tests/mock/request.php
index 946dfdada9..2a272fc03b 100644
--- a/tests/mock/request.php
+++ b/tests/mock/request.php
@@ -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);
diff --git a/tests/request/request_test.php b/tests/request/request_test.php
index bca5125b7a..52c21abd2a 100644
--- a/tests/request/request_test.php
+++ b/tests/request/request_test.php
@@ -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.
diff --git a/tests/template/includephp_test.php b/tests/template/includephp_test.php
index f008a734eb..c93a53e2ad 100644
--- a/tests/template/includephp_test.php
+++ b/tests/template/includephp_test.php
@@ -23,6 +23,18 @@ class phpbb_template_includephp_test extends phpbb_template_template_test_case
$this->assertEquals("Path is relative to board root.\ntesting included php", $this->display('test'), "Testing INCLUDEPHP");
}
+ public function test_includephp_variables()
+ {
+ $this->setup_engine(array('tpl_allow_php' => true));
+
+ $cache_file = $this->template->cachepath . 'includephp_variables.html.php';
+
+ $this->run_template('includephp_variables.html', array('TEMPLATES' => 'templates'), array(), array(), "Path includes variables.\ntesting included php", $cache_file);
+
+ $this->template->set_filenames(array('test' => 'includephp_variables.html'));
+ $this->assertEquals("Path includes variables.\ntesting included php", $this->display('test'), "Testing INCLUDEPHP");
+ }
+
public function test_includephp_absolute()
{
$path_to_php = dirname(__FILE__) . '/templates/_dummy_include.php.inc';
diff --git a/tests/template/template_includejs_test.php b/tests/template/template_includejs_test.php
index a8f9a9037f..22b020208b 100644
--- a/tests/template/template_includejs_test.php
+++ b/tests/template/template_includejs_test.php
@@ -20,11 +20,14 @@ class phpbb_template_template_includejs_test extends phpbb_template_template_tes
$scripts = array(
'<script src="' . $this->test_path . '/templates/parent_and_child.js?assets_version=1"></script>',
'<script src="' . $this->test_path . '/parent_templates/parent_only.js?assets_version=1"></script>',
- '<script src="' . $this->test_path . '/templates/child_only.js?assets_version=1"></script>'
+ '<script src="' . $this->test_path . '/templates/child_only.js?assets_version=1"></script>',
+ '<script src="' . $this->test_path . '/templates/subdir/parent_only.js?assets_version=1"></script>',
+ '<script src="' . $this->test_path . '/templates/subdir/subsubdir/parent_only.js?assets_version=1"></script>',
+ '<script src="' . $this->test_path . '/templates/subdir/parent_only.js?assets_version=1"></script>',
);
// Run test
$cache_file = $this->template->cachepath . 'includejs.html.php';
- $this->run_template('includejs.html', array('PARENT' => 'parent_only.js'), array(), array(), implode('', $scripts), $cache_file);
+ $this->run_template('includejs.html', array('PARENT' => 'parent_only.js', 'SUBDIR' => 'subdir', 'EXT' => 'js'), array(), array(), implode('', $scripts), $cache_file);
}
}
diff --git a/tests/template/template_test.php b/tests/template/template_test.php
index f8677ed913..83995cb4ac 100644
--- a/tests/template/template_test.php
+++ b/tests/template/template_test.php
@@ -184,6 +184,13 @@ class phpbb_template_template_test extends phpbb_template_template_test_case
'value',
),
array(
+ 'include_variables.html',
+ array('SUBDIR' => 'subdir', 'VARIABLE' => 'value'),
+ array(),
+ array(),
+ 'value',
+ ),
+ array(
'loop_vars.html',
array(),
array('loop' => array(array('VARIABLE' => 'x'), array('VARIABLE' => 'y')), 'loop.inner' => array(array(), array())),
diff --git a/tests/template/templates/include_variables.html b/tests/template/templates/include_variables.html
new file mode 100644
index 0000000000..8371a061b5
--- /dev/null
+++ b/tests/template/templates/include_variables.html
@@ -0,0 +1 @@
+<!-- INCLUDE {SUBDIR}/variable.html -->
diff --git a/tests/template/templates/includejs.html b/tests/template/templates/includejs.html
index 8a2587d76b..ef73700eeb 100644
--- a/tests/template/templates/includejs.html
+++ b/tests/template/templates/includejs.html
@@ -2,4 +2,7 @@
<!-- INCLUDEJS {PARENT} -->
<!-- DEFINE $TEST = 'child_only.js' -->
<!-- INCLUDEJS {$TEST} -->
-{SCRIPTS} \ No newline at end of file
+<!-- INCLUDEJS subdir/{PARENT} -->
+<!-- INCLUDEJS {SUBDIR}/subsubdir/{PARENT} -->
+<!-- INCLUDEJS {SUBDIR}/parent_only.{EXT} -->
+{SCRIPTS}
diff --git a/tests/template/templates/includephp_variables.html b/tests/template/templates/includephp_variables.html
new file mode 100644
index 0000000000..6106efc86a
--- /dev/null
+++ b/tests/template/templates/includephp_variables.html
@@ -0,0 +1,2 @@
+Path includes variables.
+<!-- INCLUDEPHP ../tests/template/{TEMPLATES}/_dummy_include.php.inc -->
diff --git a/tests/template/templates/subdir/parent_only.js b/tests/template/templates/subdir/parent_only.js
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/tests/template/templates/subdir/parent_only.js
diff --git a/tests/template/templates/subdir/subsubdir/parent_only.js b/tests/template/templates/subdir/subsubdir/parent_only.js
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/tests/template/templates/subdir/subsubdir/parent_only.js
diff --git a/tests/template/templates/subdir/variable.html b/tests/template/templates/subdir/variable.html
new file mode 100644
index 0000000000..f68f91597c
--- /dev/null
+++ b/tests/template/templates/subdir/variable.html
@@ -0,0 +1 @@
+{VARIABLE}
diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php
index d002615e8c..41edb3e6af 100644
--- a/tests/test_framework/phpbb_functional_test_case.php
+++ b/tests/test_framework/phpbb_functional_test_case.php
@@ -125,7 +125,7 @@ class phpbb_functional_test_case extends phpbb_test_case
{
$this->extension_manager = new phpbb_extension_manager(
$this->get_db(),
- new phpbb_config(),
+ new phpbb_config(array()),
self::$config['table_prefix'] . 'ext',
$phpbb_root_path,
".$phpEx",
@@ -199,7 +199,7 @@ class phpbb_functional_test_case extends phpbb_test_case
$this->do_request('create_table', $data);
$this->do_request('config_file', $data);
- file_put_contents($phpbb_root_path . "config.$phpEx", phpbb_create_config_file_data($data, self::$config['dbms'], array(), true, true));
+ file_put_contents($phpbb_root_path . "config.$phpEx", phpbb_create_config_file_data($data, self::$config['dbms'], true, true));
$this->do_request('final', $data);
copy($phpbb_root_path . "config.$phpEx", $phpbb_root_path . "config_test.$phpEx");
diff --git a/tests/upload/fileupload_test.php b/tests/upload/fileupload_test.php
index 076855ab56..1665c493be 100644
--- a/tests/upload/fileupload_test.php
+++ b/tests/upload/fileupload_test.php
@@ -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/';
}