aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorShitiz Garg <mail@dragooon.net>2014-06-11 02:33:35 +0530
committerShitiz Garg <mail@dragooon.net>2014-06-17 14:59:26 +0530
commit165d7c4b98bccb3142db4643329dabbd05cfc69a (patch)
tree37c59d3a414dad88059897a15988513a523eff2c
parent8be079bd66b3c51c2a36b5e5175765c2d41fc552 (diff)
downloadforums-165d7c4b98bccb3142db4643329dabbd05cfc69a.tar
forums-165d7c4b98bccb3142db4643329dabbd05cfc69a.tar.gz
forums-165d7c4b98bccb3142db4643329dabbd05cfc69a.tar.bz2
forums-165d7c4b98bccb3142db4643329dabbd05cfc69a.tar.xz
forums-165d7c4b98bccb3142db4643329dabbd05cfc69a.zip
[ticket/12514] Add unit test for type_url custom profile field
PHPBB3-12514
-rw-r--r--tests/profilefields/type_url_test.php106
1 files changed, 106 insertions, 0 deletions
diff --git a/tests/profilefields/type_url_test.php b/tests/profilefields/type_url_test.php
new file mode 100644
index 0000000000..08cb33e60f
--- /dev/null
+++ b/tests/profilefields/type_url_test.php
@@ -0,0 +1,106 @@
+<?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_profilefield_type_url_test extends phpbb_test_case
+{
+ protected $cp;
+ protected $field_options;
+
+ /**
+ * Sets up basic test objects
+ *
+ * @access public
+ * @return null
+ */
+ public function setUp()
+ {
+ $user = $this->getMock('\phpbb\user');
+ $user->expects($this->any())
+ ->method('lang')
+ ->will($this->returnCallback(array($this, 'return_callback_implode')));
+
+ $request = $this->getMock('\phpbb\request\request');
+ $template = $this->getMock('\phpbb\template\template');
+
+ $this->cp = new \phpbb\profilefields\type\type_url(
+ $request,
+ $template,
+ $user
+ );
+
+ $this->field_options = array(
+ 'field_type' => '\phpbb\profilefields\type\type_url',
+ 'field_name' => 'field',
+ 'field_id' => 1,
+ 'lang_id' => 1,
+ 'lang_name' => 'field',
+ 'field_required' => false,
+ );
+ }
+
+ public function get_validate_profile_field_data()
+ {
+ return array(
+ array(
+ '',
+ array('field_required' => true),
+ 'FIELD_INVALID_URL-field',
+ 'Field should reject empty field that is required',
+ ),
+ array(
+ 'invalidURL',
+ array(),
+ 'FIELD_INVALID_URL-field',
+ 'Field should reject invalid input',
+ ),
+ array(
+ 'http://onetwthree.aol.io',
+ array(),
+ false,
+ 'Field should accept valid URL',
+ ),
+ array(
+ 'http://example.com/index.html?param1=test&param2=awesome',
+ array(),
+ false,
+ 'Field should accept valid URL',
+ ),
+ array(
+ 'http://example.com/index.html/test/path?document=get',
+ array(),
+ false,
+ 'Field should accept valid URL',
+ ),
+ array(
+ 'http://example.com/index.html/test/path?document[]=DocType%20test&document[]=AnotherDoc',
+ array(),
+ false,
+ 'Field should accept valid URL having multi value parameters',
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider get_validate_profile_field_data
+ */
+ public function test_validate_profile_field($value, $field_options, $expected, $description)
+ {
+ $field_options = array_merge($this->field_options, $field_options);
+
+ $result = $this->cp->validate_profile_field($value, $field_options);
+
+ $this->assertSame($expected, $result, $description);
+ }
+
+ public function return_callback_implode()
+ {
+ return implode('-', func_get_args());
+ }
+}