aboutsummaryrefslogtreecommitdiffstats
path: root/tests/functions
diff options
context:
space:
mode:
Diffstat (limited to 'tests/functions')
-rw-r--r--tests/functions/build_url_test.php5
-rw-r--r--tests/functions/insert_config_array_test.php142
-rw-r--r--tests/functions/make_clickable_test.php100
-rw-r--r--tests/functions/validate_username_test.php1
4 files changed, 106 insertions, 142 deletions
diff --git a/tests/functions/build_url_test.php b/tests/functions/build_url_test.php
index 06415a424e..a59b94c744 100644
--- a/tests/functions/build_url_test.php
+++ b/tests/functions/build_url_test.php
@@ -69,6 +69,11 @@ class phpbb_build_url_test extends phpbb_test_case
array('f', 'style', 't'),
'http://test.phpbb.com/viewtopic.php?',
),
+ array(
+ 'posting.php?f=2&mode=delete&p=20%22%3Cscript%3Ealert%281%29%3B%3C%2Fscript%3E',
+ false,
+ 'phpBB/posting.php?f=2&mode=delete&p=20%22%3Cscript%3Ealert%281%29%3B%3C%2Fscript%3E',
+ )
);
}
diff --git a/tests/functions/insert_config_array_test.php b/tests/functions/insert_config_array_test.php
deleted file mode 100644
index bfcb05862e..0000000000
--- a/tests/functions/insert_config_array_test.php
+++ /dev/null
@@ -1,142 +0,0 @@
-<?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.
-*
-*/
-
-class phpbb_functions_insert_config_array_test extends phpbb_test_case
-{
- public function config_display_vars()
- {
- return array(
- 'legend1' => '',
- 'acp_config_1' => array(),
- 'acp_config_2' => array(),
- 'acp_config_3' => array(),
- 'acp_config_4' => array(),
- 'acp_config_5' => array(),
- );
- }
-
- public function insert_config_array_data()
- {
- return array(
- array( // Add a new config after 1st array item
- array('new_config_1' => array()),
- array('after' => 'legend1'),
- array(
- 'legend1' => '',
- 'new_config_1' => array(),
- 'acp_config_1' => array(),
- 'acp_config_2' => array(),
- 'acp_config_3' => array(),
- 'acp_config_4' => array(),
- 'acp_config_5' => array(),
- ),
- ),
- array( // Add a new config after last array item
- array('new_config_1' => array()),
- array('after' => 'acp_config_5'),
- array(
- 'legend1' => '',
- 'acp_config_1' => array(),
- 'acp_config_2' => array(),
- 'acp_config_3' => array(),
- 'acp_config_4' => array(),
- 'acp_config_5' => array(),
- 'new_config_1' => array(),
- ),
- ),
- array( // Add a new config before 2nd array item
- array('new_config_1' => array()),
- array('before' => 'acp_config_1'),
- array(
- 'legend1' => '',
- 'new_config_1' => array(),
- 'acp_config_1' => array(),
- 'acp_config_2' => array(),
- 'acp_config_3' => array(),
- 'acp_config_4' => array(),
- 'acp_config_5' => array(),
- ),
- ),
- array( // Add a new config before last config item
- array('new_config_1' => array()),
- array('before' => 'acp_config_5'),
- array(
- 'legend1' => '',
- 'acp_config_1' => array(),
- 'acp_config_2' => array(),
- 'acp_config_3' => array(),
- 'acp_config_4' => array(),
- 'new_config_1' => array(),
- 'acp_config_5' => array(),
- ),
- ),
- array( // When an array key does not exist
- array('new_config_1' => array()),
- array('after' => 'foobar'),
- array(
- 'legend1' => '',
- 'acp_config_1' => array(),
- 'acp_config_2' => array(),
- 'acp_config_3' => array(),
- 'acp_config_4' => array(),
- 'acp_config_5' => array(),
- ),
- ),
- array( // When after|before is not used correctly (defaults to after)
- array('new_config_1' => array()),
- array('foobar' => 'acp_config_1'),
- array(
- 'legend1' => '',
- 'acp_config_1' => array(),
- 'new_config_1' => array(),
- 'acp_config_2' => array(),
- 'acp_config_3' => array(),
- 'acp_config_4' => array(),
- 'acp_config_5' => array(),
- ),
- ),
- array( // Add a new config set after the last array item
- array(
- 'legend2' => array(),
- 'new_config_1' => array(),
- 'new_config_2' => array(),
- 'new_config_3' => array(),
- ),
- array('after' => 'acp_config_5'),
- array(
- 'legend1' => '',
- 'acp_config_1' => array(),
- 'acp_config_2' => array(),
- 'acp_config_3' => array(),
- 'acp_config_4' => array(),
- 'acp_config_5' => array(),
- 'legend2' => array(),
- 'new_config_1' => array(),
- 'new_config_2' => array(),
- 'new_config_3' => array(),
- ),
- ),
- );
- }
-
- /**
- * @dataProvider insert_config_array_data
- */
- public function test_insert_config_array($new_config, $position, $expected)
- {
- $config_array = $this->config_display_vars();
- $new_config_array = phpbb_insert_config_array($config_array, $new_config, $position);
-
- $this->assertSame($expected, $new_config_array);
- }
-}
diff --git a/tests/functions/make_clickable_test.php b/tests/functions/make_clickable_test.php
new file mode 100644
index 0000000000..e61cb2c30e
--- /dev/null
+++ b/tests/functions/make_clickable_test.php
@@ -0,0 +1,100 @@
+<?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.
+*
+*/
+
+require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
+require_once dirname(__FILE__) . '/../../phpBB/includes/functions_content.php';
+
+class phpbb_functions_make_clickable_test extends phpbb_test_case
+{
+ /**
+ * Tags:
+ * 'm' - full URL like xxxx://aaaaa.bbb.cccc.
+ * 'l' - local relative board URL like http://domain.tld/path/to/board/index.php
+ * 'w' - URL without http/https protocol like www.xxxx.yyyy[/zzzz] aka 'lazy' URLs
+ * 'e' - email@domain type address
+ *
+ * Classes:
+ * "postlink-local" for 'l' URLs
+ * "postlink" for the rest of URLs
+ * empty for email addresses
+ **/
+ public function data_test_make_clickable_url_positive()
+ {
+ return array(
+ array(
+ 'http://www.phpbb.com/community/',
+ '<!-- m --><a class="postlink" href="http://www.phpbb.com/community/">http://www.phpbb.com/community/</a><!-- m -->'
+ ),
+ array(
+ 'http://www.phpbb.com/path/file.ext#section',
+ '<!-- m --><a class="postlink" href="http://www.phpbb.com/path/file.ext#section">http://www.phpbb.com/path/file.ext#section</a><!-- m -->'
+ ),
+ array(
+ 'ftp://ftp.phpbb.com/',
+ '<!-- m --><a class="postlink" href="ftp://ftp.phpbb.com/">ftp://ftp.phpbb.com/</a><!-- m -->'
+ ),
+ array(
+ 'sip://bantu@phpbb.com',
+ '<!-- m --><a class="postlink" href="sip://bantu@phpbb.com">sip://bantu@phpbb.com</a><!-- m -->'
+ ),
+ array(
+ 'www.phpbb.com/community/',
+ '<!-- w --><a class="postlink" href="http://www.phpbb.com/community/">www.phpbb.com/community/</a><!-- w -->'
+ ),
+ array(
+ 'http://testhost/viewtopic.php?t=1',
+ '<!-- l --><a class="postlink-local" href="http://testhost/viewtopic.php?t=1">viewtopic.php?t=1</a><!-- l -->'
+ ),
+ array(
+ 'email@domain.com',
+ '<!-- e --><a href="mailto:email@domain.com">email@domain.com</a><!-- e -->'
+ ),
+ // Test appending punctuation mark to the URL
+ array(
+ 'http://testhost/viewtopic.php?t=1!',
+ '<!-- l --><a class="postlink-local" href="http://testhost/viewtopic.php?t=1">viewtopic.php?t=1</a><!-- l -->!'
+ ),
+ array(
+ 'www.phpbb.com/community/?',
+ '<!-- w --><a class="postlink" href="http://www.phpbb.com/community/">www.phpbb.com/community/</a><!-- w -->?'
+ ),
+ // Test shortened text for URL > 55 characters long
+ // URL text should be turned into: first 39 chars + ' ... ' + last 10 chars
+ array(
+ 'http://www.phpbb.com/community/path/to/long/url/file.ext#section',
+ '<!-- m --><a class="postlink" href="http://www.phpbb.com/community/path/to/long/url/file.ext#section">http://www.phpbb.com/community/path/to/ ... xt#section</a><!-- m -->'
+ ),
+
+ // IDN is not parsed and returned as is
+ array('http://домен.рф', 'http://домен.рф'),
+ array('почта@домен.рф', 'почта@домен.рф'),
+ );
+ }
+
+ protected function setUp()
+ {
+ parent::setUp();
+
+ global $config, $user, $request;
+ $user = new phpbb_mock_user();
+ $request = new phpbb_mock_request();
+ }
+
+ /**
+ * @dataProvider data_test_make_clickable_url_positive
+ */
+ public function test_urls_matching_positive($url, $expected)
+ {
+ $this->assertSame($expected, make_clickable($url));
+ }
+}
diff --git a/tests/functions/validate_username_test.php b/tests/functions/validate_username_test.php
index dc9f685f04..4fa5af7ff3 100644
--- a/tests/functions/validate_username_test.php
+++ b/tests/functions/validate_username_test.php
@@ -11,6 +11,7 @@
*
*/
+require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
require_once dirname(__FILE__) . '/../../phpBB/includes/functions_user.php';
require_once dirname(__FILE__) . '/../../phpBB/includes/utf/utf_tools.php';
require_once dirname(__FILE__) . '/../mock/cache.php';