From 165d7c4b98bccb3142db4643329dabbd05cfc69a Mon Sep 17 00:00:00 2001 From: Shitiz Garg Date: Wed, 11 Jun 2014 02:33:35 +0530 Subject: [ticket/12514] Add unit test for type_url custom profile field PHPBB3-12514 --- tests/profilefields/type_url_test.php | 106 ++++++++++++++++++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 tests/profilefields/type_url_test.php 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 @@ +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¶m2=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()); + } +} -- cgit v1.2.1