aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCesar G <prototech91@gmail.com>2014-02-27 23:33:39 -0800
committerCesar G <prototech91@gmail.com>2014-04-22 15:21:02 -0700
commit47f8a6375f12d9ca18b88432a8d2e51d168909fe (patch)
treeffd6620ee8873bd06d6f5cb04c10c4401816094b
parentf05e0ec9eb30bdfdc4cf4b0355c8da7c40d6a6f1 (diff)
downloadforums-47f8a6375f12d9ca18b88432a8d2e51d168909fe.tar
forums-47f8a6375f12d9ca18b88432a8d2e51d168909fe.tar.gz
forums-47f8a6375f12d9ca18b88432a8d2e51d168909fe.tar.bz2
forums-47f8a6375f12d9ca18b88432a8d2e51d168909fe.tar.xz
forums-47f8a6375f12d9ca18b88432a8d2e51d168909fe.zip
[ticket/11508] Add tests.
PHPBB3-11508
-rw-r--r--tests/functions/build_url_test.php77
-rw-r--r--tests/path_helper/path_helper_test.php (renamed from tests/path_helper/web_root_path_test.php)138
2 files changed, 214 insertions, 1 deletions
diff --git a/tests/functions/build_url_test.php b/tests/functions/build_url_test.php
new file mode 100644
index 0000000000..8d0aa76317
--- /dev/null
+++ b/tests/functions/build_url_test.php
@@ -0,0 +1,77 @@
+<?php
+/**
+*
+* @package testing
+* @copyright (c) 2014 phpBB Group
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+*
+*/
+
+require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
+
+class phpbb_build_url_test extends phpbb_test_case
+{
+ protected function setUp()
+ {
+ global $user, $phpbb_dispatcher, $phpbb_container, $phpbb_root_path;
+
+ parent::setUp();
+
+ $phpbb_container = new phpbb_mock_container_builder();
+ $user = new phpbb_mock_user();
+ $phpbb_dispatcher = new phpbb_mock_event_dispatcher();
+
+ $this->path_helper = new \phpbb\path_helper(
+ new \phpbb\symfony_request(
+ new phpbb_mock_request()
+ ),
+ new \phpbb\filesystem(),
+ $phpbb_root_path,
+ 'php'
+ );
+ $phpbb_container->set('path_helper', $path_helper);
+ }
+ public function build_url_test_data()
+ {
+ return array(
+ array(
+ 'index.php',
+ false,
+ 'phpBB/index.php?',
+ ),
+ array(
+ 'index.php',
+ 't',
+ 'phpBB/index.php?',
+ ),
+ array(
+ 'viewtopic.php?f=2&style=1&t=6',
+ 'f',
+ 'phpBB/viewtopic.php?style=1&amp;t=6',
+ ),
+ array(
+ 'viewtopic.php?f=2&style=1&t=6',
+ array('f', 'style', 't'),
+ 'phpBB/viewtopic.php',
+ ),
+ array(
+ 'http://test.phpbb.com/viewtopic.php?f=2&style=1&t=6',
+ array('f', 'style', 't'),
+ 'http://test.phpbb.com/viewtopic.php',
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider build_url_test_data
+ */
+ public function test_build_url($page, $strip_vars, $expected)
+ {
+ global $user, $phpbb_root_path;
+
+ $user->page['page'] = $page;
+ $output = build_url($strip_vars);
+
+ $this->assertEquals($expected, $output);
+ }
+}
diff --git a/tests/path_helper/web_root_path_test.php b/tests/path_helper/path_helper_test.php
index ec04135997..e77ad6d343 100644
--- a/tests/path_helper/web_root_path_test.php
+++ b/tests/path_helper/path_helper_test.php
@@ -7,7 +7,7 @@
*
*/
-class phpbb_path_helper_web_root_path_test extends phpbb_test_case
+class phpbb_path_helper_test extends phpbb_test_case
{
protected $path_helper;
protected $phpbb_root_path = '';
@@ -176,4 +176,140 @@ class phpbb_path_helper_web_root_path_test extends phpbb_test_case
{
$this->assertEquals($expected, $this->path_helper->clean_url($input));
}
+
+ public function glue_url_params_data()
+ {
+ return array(
+ array(
+ array(),
+ '',
+ ),
+ array(
+ array('test' => 'xyz'),
+ 'test=xyz',
+ ),
+ array(
+ array('test' => 'xyz', 'var' => 'value'),
+ 'test=xyz&amp;var=value',
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider glue_url_params_data
+ */
+ public function test_glue_url_params($params, $expected)
+ {
+ $this->assertEquals($expected, $this->path_helper->glue_url_params($params));
+ }
+
+ public function get_url_parts_data()
+ {
+ return array(
+ array(
+ 'viewtopic.php',
+ true,
+ array('base' => 'viewtopic.php', 'params' => array()),
+ ),
+ array(
+ './viewtopic.php?t=5&amp;f=6',
+ true,
+ array('base' => './viewtopic.php', 'params' => array('t' => '5', 'f' => '6')),
+ ),
+ array(
+ 'viewtopic.php?t=5&f=6',
+ false,
+ array('base' => 'viewtopic.php', 'params' => array('t' => '5', 'f' => '6')),
+ ),
+ array(
+ 'https://phpbb.com/community/viewtopic.php?t=5&amp;f=6',
+ true,
+ array('base' => 'https://phpbb.com/community/viewtopic.php', 'params' => array('t' => '5', 'f' => '6')),
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider get_url_parts_data
+ */
+ public function test_get_url_parts($url, $is_amp, $expected)
+ {
+ $this->assertEquals($expected, $this->path_helper->get_url_parts($url, $is_amp));
+ }
+
+ public function strip_url_params_data()
+ {
+ return array(
+ array(
+ 'viewtopic.php',
+ 'sid',
+ false,
+ 'viewtopic.php',
+ ),
+ array(
+ './viewtopic.php?t=5&amp;f=6',
+ 'f',
+ true,
+ './viewtopic.php?t=5',
+ ),
+ array(
+ 'viewtopic.php?t=5&f=6&sid=19adc288814103cbb4625e74e77455aa',
+ array('t'),
+ false,
+ 'viewtopic.php?f=6&amp;sid=19adc288814103cbb4625e74e77455aa',
+ ),
+ array(
+ 'https://phpbb.com/community/viewtopic.php?t=5&amp;f=6',
+ array('t', 'f'),
+ true,
+ 'https://phpbb.com/community/viewtopic.php',
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider strip_url_params_data
+ */
+ public function test_strip_url_params($url, $strip, $is_amp, $expected)
+ {
+ $this->assertEquals($expected, $this->path_helper->strip_url_params($url, $strip, $is_amp));
+ }
+
+ public function append_url_params_data()
+ {
+ return array(
+ array(
+ 'viewtopic.php',
+ array(),
+ false,
+ 'viewtopic.php',
+ ),
+ array(
+ './viewtopic.php?t=5&amp;f=6',
+ array('t' => '7'),
+ true,
+ './viewtopic.php?t=7&amp;f=6',
+ ),
+ array(
+ 'viewtopic.php?t=5&f=6&sid=19adc288814103cbb4625e74e77455aa',
+ array('p' => '5'),
+ false,
+ 'viewtopic.php?t=5&amp;f=6&amp;p=5&amp;sid=19adc288814103cbb4625e74e77455aa',
+ ),
+ array(
+ 'https://phpbb.com/community/viewtopic.php',
+ array('t' => '7', 'f' => '8'),
+ true,
+ 'https://phpbb.com/community/viewtopic.php?t=7&amp;f=8',
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider append_url_params_data
+ */
+ public function test_append_url_params($url, $params, $is_amp, $expected)
+ {
+ $this->assertEquals($expected, $this->path_helper->append_url_params($url, $params, $is_amp));
+ }
}