From 08e2c07f0b7991d89a562e1a78da9462d830e134 Mon Sep 17 00:00:00 2001 From: PayBas Date: Mon, 31 Mar 2014 13:04:25 +0200 Subject: [PATCH 01/19] [ticket/12334] Add PROFILE_FIELD_VALUEID template var PHPBB3-12334 --- phpBB/phpbb/profilefields/manager.php | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/phpBB/phpbb/profilefields/manager.php b/phpBB/phpbb/profilefields/manager.php index 490db0419a..f075e38ded 100644 --- a/phpBB/phpbb/profilefields/manager.php +++ b/phpBB/phpbb/profilefields/manager.php @@ -412,13 +412,14 @@ class manager } $tpl_fields['row'] += array( - 'PROFILE_' . strtoupper($ident) . '_IDENT' => $ident, - 'PROFILE_' . strtoupper($ident) . '_VALUE' => $value, - 'PROFILE_' . strtoupper($ident) . '_CONTACT'=> $contact_url, - 'PROFILE_' . strtoupper($ident) . '_DESC' => $field_desc, - 'PROFILE_' . strtoupper($ident) . '_TYPE' => $ident_ary['data']['field_type'], - 'PROFILE_' . strtoupper($ident) . '_NAME' => $this->user->lang($ident_ary['data']['lang_name']), - 'PROFILE_' . strtoupper($ident) . '_EXPLAIN'=> $this->user->lang($ident_ary['data']['lang_explain']), + 'PROFILE_' . strtoupper($ident) . '_IDENT' => $ident, + 'PROFILE_' . strtoupper($ident) . '_VALUE' => $value, + 'PROFILE_' . strtoupper($ident) . '_VALUEID' => $ident_ary['value'], + 'PROFILE_' . strtoupper($ident) . '_CONTACT' => $contact_url, + 'PROFILE_' . strtoupper($ident) . '_DESC' => $field_desc, + 'PROFILE_' . strtoupper($ident) . '_TYPE' => $ident_ary['data']['field_type'], + 'PROFILE_' . strtoupper($ident) . '_NAME' => $this->user->lang($ident_ary['data']['lang_name']), + 'PROFILE_' . strtoupper($ident) . '_EXPLAIN' => $this->user->lang($ident_ary['data']['lang_explain']), 'S_PROFILE_' . strtoupper($ident) . '_CONTACT' => $ident_ary['data']['field_is_contact'], 'S_PROFILE_' . strtoupper($ident) => true, @@ -427,6 +428,7 @@ class manager $tpl_fields['blockrow'][] = array( 'PROFILE_FIELD_IDENT' => $ident, 'PROFILE_FIELD_VALUE' => $value, + 'PROFILE_FIELD_VALUEID' => $ident_ary['value'], 'PROFILE_FIELD_CONTACT' => $contact_url, 'PROFILE_FIELD_DESC' => $field_desc, 'PROFILE_FIELD_TYPE' => $ident_ary['data']['field_type'], From 4169fd65f07f67f99e64e7ab962d09c1e10f14dc Mon Sep 17 00:00:00 2001 From: PayBas Date: Sat, 5 Apr 2014 22:32:42 +0200 Subject: [PATCH 02/19] [ticket/12334] Added field_novalue fall-back as requested PHPBB3-12334 --- phpBB/phpbb/profilefields/manager.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/phpBB/phpbb/profilefields/manager.php b/phpBB/phpbb/profilefields/manager.php index f075e38ded..7602abf9aa 100644 --- a/phpBB/phpbb/profilefields/manager.php +++ b/phpBB/phpbb/profilefields/manager.php @@ -389,6 +389,7 @@ class manager { $profile_field = $this->type_collection[$ident_ary['data']['field_type']]; $value = $profile_field->get_profile_value($ident_ary['value'], $ident_ary['data']); + $valueid = (!$ident_ary['value'] && !$ident_ary['data']['field_show_novalue']) ? $ident_ary['data']['field_novalue'] : $ident_ary['value']; if ($value === null) { @@ -414,7 +415,7 @@ class manager $tpl_fields['row'] += array( 'PROFILE_' . strtoupper($ident) . '_IDENT' => $ident, 'PROFILE_' . strtoupper($ident) . '_VALUE' => $value, - 'PROFILE_' . strtoupper($ident) . '_VALUEID' => $ident_ary['value'], + 'PROFILE_' . strtoupper($ident) . '_VALUEID' => $valueid, 'PROFILE_' . strtoupper($ident) . '_CONTACT' => $contact_url, 'PROFILE_' . strtoupper($ident) . '_DESC' => $field_desc, 'PROFILE_' . strtoupper($ident) . '_TYPE' => $ident_ary['data']['field_type'], @@ -428,7 +429,7 @@ class manager $tpl_fields['blockrow'][] = array( 'PROFILE_FIELD_IDENT' => $ident, 'PROFILE_FIELD_VALUE' => $value, - 'PROFILE_FIELD_VALUEID' => $ident_ary['value'], + 'PROFILE_FIELD_VALUEID' => $valueid, 'PROFILE_FIELD_CONTACT' => $contact_url, 'PROFILE_FIELD_DESC' => $field_desc, 'PROFILE_FIELD_TYPE' => $ident_ary['data']['field_type'], From 507eca319d2bff9779d662a36b845017b7464e68 Mon Sep 17 00:00:00 2001 From: PayBas Date: Tue, 29 Apr 2014 16:16:19 +0200 Subject: [PATCH 03/19] [ticket/12334] Implemented get_profile_valueid method PHPBB3-12334 --- phpBB/phpbb/profilefields/manager.php | 2 +- phpBB/phpbb/profilefields/type/type_bool.php | 18 ++++++++++++++++++ phpBB/phpbb/profilefields/type/type_date.php | 13 +++++++++++++ .../phpbb/profilefields/type/type_dropdown.php | 18 ++++++++++++++++++ phpBB/phpbb/profilefields/type/type_int.php | 12 ++++++++++++ .../profilefields/type/type_interface.php | 9 +++++++++ .../profilefields/type/type_string_common.php | 13 +++++++++++++ 7 files changed, 84 insertions(+), 1 deletion(-) diff --git a/phpBB/phpbb/profilefields/manager.php b/phpBB/phpbb/profilefields/manager.php index 7602abf9aa..a2b931ce27 100644 --- a/phpBB/phpbb/profilefields/manager.php +++ b/phpBB/phpbb/profilefields/manager.php @@ -389,7 +389,7 @@ class manager { $profile_field = $this->type_collection[$ident_ary['data']['field_type']]; $value = $profile_field->get_profile_value($ident_ary['value'], $ident_ary['data']); - $valueid = (!$ident_ary['value'] && !$ident_ary['data']['field_show_novalue']) ? $ident_ary['data']['field_novalue'] : $ident_ary['value']; + $valueid = $profile_field->get_profile_valueid($ident_ary['value'], $ident_ary['data']); if ($value === null) { diff --git a/phpBB/phpbb/profilefields/type/type_bool.php b/phpBB/phpbb/profilefields/type/type_bool.php index eb8d3e47d6..64f4f8293f 100644 --- a/phpBB/phpbb/profilefields/type/type_bool.php +++ b/phpBB/phpbb/profilefields/type/type_bool.php @@ -177,6 +177,24 @@ class type_bool extends type_base } } + /** + * {@inheritDoc} + */ + public function get_profile_valueid($field_value, $field_data) + { + if ($field_value == $field_data['field_novalue'] && !$field_data['field_show_novalue']) + { + return null; + } + + if (!$field_value && $field_data['field_show_novalue']) + { + $field_value = $field_data['field_novalue']; + } + + return $field_value; + } + /** * {@inheritDoc} */ diff --git a/phpBB/phpbb/profilefields/type/type_date.php b/phpBB/phpbb/profilefields/type/type_date.php index 158eec6a0c..f59d74c33d 100644 --- a/phpBB/phpbb/profilefields/type/type_date.php +++ b/phpBB/phpbb/profilefields/type/type_date.php @@ -205,6 +205,19 @@ class type_date extends type_base return $field_value; } + /** + * {@inheritDoc} + */ + public function get_profile_valueid($field_value, $field_data) + { + if (($field_value === '' || $field_value === null) && !$field_data['field_show_novalue']) + { + return null; + } + + return $field_value; + } + /** * {@inheritDoc} */ diff --git a/phpBB/phpbb/profilefields/type/type_dropdown.php b/phpBB/phpbb/profilefields/type/type_dropdown.php index 52c9fcf86a..b201c4abbf 100644 --- a/phpBB/phpbb/profilefields/type/type_dropdown.php +++ b/phpBB/phpbb/profilefields/type/type_dropdown.php @@ -186,6 +186,24 @@ class type_dropdown extends type_base return $this->lang_helper->get($field_id, $lang_id, $field_value); } + /** + * {@inheritDoc} + */ + public function get_profile_valueid($field_value, $field_data) + { + if ($field_value == $field_data['field_novalue'] && !$field_data['field_show_novalue']) + { + return null; + } + + if (!$field_value && $field_data['field_show_novalue']) + { + $field_value = $field_data['field_novalue']; + } + + return $field_value; + } + /** * {@inheritDoc} */ diff --git a/phpBB/phpbb/profilefields/type/type_int.php b/phpBB/phpbb/profilefields/type/type_int.php index 78f1c7d2c9..8a803293d0 100644 --- a/phpBB/phpbb/profilefields/type/type_int.php +++ b/phpBB/phpbb/profilefields/type/type_int.php @@ -151,6 +151,18 @@ class type_int extends type_base return (int) $field_value; } + /** + * {@inheritDoc} + */ + public function get_profile_valueid($field_value, $field_data) + { + if (($field_value === '' || $field_value === null) && !$field_data['field_show_novalue']) + { + return null; + } + return (int) $field_value; + } + /** * {@inheritDoc} */ diff --git a/phpBB/phpbb/profilefields/type/type_interface.php b/phpBB/phpbb/profilefields/type/type_interface.php index 489e916fd5..8fe1bb2be5 100644 --- a/phpBB/phpbb/profilefields/type/type_interface.php +++ b/phpBB/phpbb/profilefields/type/type_interface.php @@ -93,6 +93,15 @@ interface type_interface */ public function get_profile_value($field_value, $field_data); + /** + * Get Profile Value ID for display (the raw, unprocessed user data) + * + * @param mixed $field_value Field value as stored in the database + * @param array $field_data Array with requirements of the field + * @return mixed Field value ID to display + */ + public function get_profile_valueid($field_value, $field_data); + /** * Get Profile Value for display * diff --git a/phpBB/phpbb/profilefields/type/type_string_common.php b/phpBB/phpbb/profilefields/type/type_string_common.php index b48e3c5add..1d26ba5d3a 100644 --- a/phpBB/phpbb/profilefields/type/type_string_common.php +++ b/phpBB/phpbb/profilefields/type/type_string_common.php @@ -109,6 +109,19 @@ abstract class type_string_common extends type_base return $field_value; } + /** + * {@inheritDoc} + */ + public function get_profile_valueid($field_value, $field_data) + { + if (!$field_value && !$field_data['field_show_novalue']) + { + return null; + } + + return $field_value; + } + /** * {@inheritDoc} */ From 2b451a174bc3cf253dacb3bfb313e9ff3f227de6 Mon Sep 17 00:00:00 2001 From: PayBas Date: Wed, 30 Apr 2014 10:08:21 +0200 Subject: [PATCH 04/19] [ticket/12334] Changed from valueid to value_raw PHPBB3-12334 --- phpBB/phpbb/profilefields/manager.php | 20 +++++++++---------- phpBB/phpbb/profilefields/type/type_bool.php | 2 +- phpBB/phpbb/profilefields/type/type_date.php | 2 +- .../profilefields/type/type_dropdown.php | 2 +- phpBB/phpbb/profilefields/type/type_int.php | 2 +- .../profilefields/type/type_interface.php | 2 +- .../profilefields/type/type_string_common.php | 2 +- 7 files changed, 16 insertions(+), 16 deletions(-) diff --git a/phpBB/phpbb/profilefields/manager.php b/phpBB/phpbb/profilefields/manager.php index a2b931ce27..26c11d9e22 100644 --- a/phpBB/phpbb/profilefields/manager.php +++ b/phpBB/phpbb/profilefields/manager.php @@ -389,7 +389,7 @@ class manager { $profile_field = $this->type_collection[$ident_ary['data']['field_type']]; $value = $profile_field->get_profile_value($ident_ary['value'], $ident_ary['data']); - $valueid = $profile_field->get_profile_valueid($ident_ary['value'], $ident_ary['data']); + $value_raw = $profile_field->get_profile_value_raw($ident_ary['value'], $ident_ary['data']); if ($value === null) { @@ -415,7 +415,7 @@ class manager $tpl_fields['row'] += array( 'PROFILE_' . strtoupper($ident) . '_IDENT' => $ident, 'PROFILE_' . strtoupper($ident) . '_VALUE' => $value, - 'PROFILE_' . strtoupper($ident) . '_VALUEID' => $valueid, + 'PROFILE_' . strtoupper($ident) . '_VALUE_RAW' => $value_raw, 'PROFILE_' . strtoupper($ident) . '_CONTACT' => $contact_url, 'PROFILE_' . strtoupper($ident) . '_DESC' => $field_desc, 'PROFILE_' . strtoupper($ident) . '_TYPE' => $ident_ary['data']['field_type'], @@ -427,14 +427,14 @@ class manager ); $tpl_fields['blockrow'][] = array( - 'PROFILE_FIELD_IDENT' => $ident, - 'PROFILE_FIELD_VALUE' => $value, - 'PROFILE_FIELD_VALUEID' => $valueid, - 'PROFILE_FIELD_CONTACT' => $contact_url, - 'PROFILE_FIELD_DESC' => $field_desc, - 'PROFILE_FIELD_TYPE' => $ident_ary['data']['field_type'], - 'PROFILE_FIELD_NAME' => $this->user->lang($ident_ary['data']['lang_name']), - 'PROFILE_FIELD_EXPLAIN' => $this->user->lang($ident_ary['data']['lang_explain']), + 'PROFILE_FIELD_IDENT' => $ident, + 'PROFILE_FIELD_VALUE' => $value, + 'PROFILE_FIELD_VALUE_RAW' => $value_raw, + 'PROFILE_FIELD_CONTACT' => $contact_url, + 'PROFILE_FIELD_DESC' => $field_desc, + 'PROFILE_FIELD_TYPE' => $ident_ary['data']['field_type'], + 'PROFILE_FIELD_NAME' => $this->user->lang($ident_ary['data']['lang_name']), + 'PROFILE_FIELD_EXPLAIN' => $this->user->lang($ident_ary['data']['lang_explain']), 'S_PROFILE_CONTACT' => $ident_ary['data']['field_is_contact'], 'S_PROFILE_' . strtoupper($ident) => true, diff --git a/phpBB/phpbb/profilefields/type/type_bool.php b/phpBB/phpbb/profilefields/type/type_bool.php index 64f4f8293f..c34dd9ce88 100644 --- a/phpBB/phpbb/profilefields/type/type_bool.php +++ b/phpBB/phpbb/profilefields/type/type_bool.php @@ -180,7 +180,7 @@ class type_bool extends type_base /** * {@inheritDoc} */ - public function get_profile_valueid($field_value, $field_data) + public function get_profile_value_raw($field_value, $field_data) { if ($field_value == $field_data['field_novalue'] && !$field_data['field_show_novalue']) { diff --git a/phpBB/phpbb/profilefields/type/type_date.php b/phpBB/phpbb/profilefields/type/type_date.php index f59d74c33d..90ac9a6703 100644 --- a/phpBB/phpbb/profilefields/type/type_date.php +++ b/phpBB/phpbb/profilefields/type/type_date.php @@ -208,7 +208,7 @@ class type_date extends type_base /** * {@inheritDoc} */ - public function get_profile_valueid($field_value, $field_data) + public function get_profile_value_raw($field_value, $field_data) { if (($field_value === '' || $field_value === null) && !$field_data['field_show_novalue']) { diff --git a/phpBB/phpbb/profilefields/type/type_dropdown.php b/phpBB/phpbb/profilefields/type/type_dropdown.php index b201c4abbf..f70693e294 100644 --- a/phpBB/phpbb/profilefields/type/type_dropdown.php +++ b/phpBB/phpbb/profilefields/type/type_dropdown.php @@ -189,7 +189,7 @@ class type_dropdown extends type_base /** * {@inheritDoc} */ - public function get_profile_valueid($field_value, $field_data) + public function get_profile_value_raw($field_value, $field_data) { if ($field_value == $field_data['field_novalue'] && !$field_data['field_show_novalue']) { diff --git a/phpBB/phpbb/profilefields/type/type_int.php b/phpBB/phpbb/profilefields/type/type_int.php index 8a803293d0..dd08df94c1 100644 --- a/phpBB/phpbb/profilefields/type/type_int.php +++ b/phpBB/phpbb/profilefields/type/type_int.php @@ -154,7 +154,7 @@ class type_int extends type_base /** * {@inheritDoc} */ - public function get_profile_valueid($field_value, $field_data) + public function get_profile_value_raw($field_value, $field_data) { if (($field_value === '' || $field_value === null) && !$field_data['field_show_novalue']) { diff --git a/phpBB/phpbb/profilefields/type/type_interface.php b/phpBB/phpbb/profilefields/type/type_interface.php index 8fe1bb2be5..2dd13fa480 100644 --- a/phpBB/phpbb/profilefields/type/type_interface.php +++ b/phpBB/phpbb/profilefields/type/type_interface.php @@ -100,7 +100,7 @@ interface type_interface * @param array $field_data Array with requirements of the field * @return mixed Field value ID to display */ - public function get_profile_valueid($field_value, $field_data); + public function get_profile_value_raw($field_value, $field_data); /** * Get Profile Value for display diff --git a/phpBB/phpbb/profilefields/type/type_string_common.php b/phpBB/phpbb/profilefields/type/type_string_common.php index 1d26ba5d3a..c2b951b6c9 100644 --- a/phpBB/phpbb/profilefields/type/type_string_common.php +++ b/phpBB/phpbb/profilefields/type/type_string_common.php @@ -112,7 +112,7 @@ abstract class type_string_common extends type_base /** * {@inheritDoc} */ - public function get_profile_valueid($field_value, $field_data) + public function get_profile_value_raw($field_value, $field_data) { if (!$field_value && !$field_data['field_show_novalue']) { From ac97497d9527082174e8581fdc8e16b454853fec Mon Sep 17 00:00:00 2001 From: PayBas Date: Mon, 5 May 2014 00:12:21 +0200 Subject: [PATCH 05/19] [ticket/12334] Added test get_profile_value_raw PHPBB3-12334 --- tests/profile/get_profile_value_raw_test.php | 52 ++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 tests/profile/get_profile_value_raw_test.php diff --git a/tests/profile/get_profile_value_raw_test.php b/tests/profile/get_profile_value_raw_test.php new file mode 100644 index 0000000000..a9950b1889 --- /dev/null +++ b/tests/profile/get_profile_value_raw_test.php @@ -0,0 +1,52 @@ +getMock('\phpbb\request\request'), + $this->getMock('\phpbb\template\template'), + $this->getMock('\phpbb\user') + ); + + $this->assertSame($expected, $cp->get_profile_value_raw($value, array( + 'field_type' => $type, + 'field_show_novalue' => $show_novalue, + ))); + } +} From 349fbabd2e686d828f683cb7df13ce38bbe6d645 Mon Sep 17 00:00:00 2001 From: PayBas Date: Mon, 5 May 2014 00:37:16 +0200 Subject: [PATCH 06/19] [ticket/12334] Dropdowns cannot be tested this way PHPBB3-12334 --- tests/profile/get_profile_value_raw_test.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/profile/get_profile_value_raw_test.php b/tests/profile/get_profile_value_raw_test.php index a9950b1889..20b61f062b 100644 --- a/tests/profile/get_profile_value_raw_test.php +++ b/tests/profile/get_profile_value_raw_test.php @@ -24,12 +24,12 @@ class phpbb_profile_get_profile_value_raw_test extends phpbb_test_case array('\phpbb\profilefields\type\type_url', 'http://www.test.com/', true, 'http://www.test.com/'), array('\phpbb\profilefields\type\type_text', '[b]bbcode test[/b]', false, '[b]bbcode test[/b]'), array('\phpbb\profilefields\type\type_text', '[b]bbcode test[/b]', true, '[b]bbcode test[/b]'), - array('\phpbb\profilefields\type\type_dropdown', '5', false, '5'), + /* array('\phpbb\profilefields\type\type_dropdown', '5', false, '5'), array('\phpbb\profilefields\type\type_dropdown', '5', true, '5'), array('\phpbb\profilefields\type\type_dropdown', '', false, ''), array('\phpbb\profilefields\type\type_dropdown', '', true, ''), array('\phpbb\profilefields\type\type_dropdown', null, false, null), - array('\phpbb\profilefields\type\type_dropdown', null, true, null), + array('\phpbb\profilefields\type\type_dropdown', null, true, null), */ ); } From 8cef0b69715e04cb39ab365e4bdb01a958e7126b Mon Sep 17 00:00:00 2001 From: PayBas Date: Thu, 22 May 2014 00:55:08 +0200 Subject: [PATCH 07/19] [ticket/12334] Removed tests Will be implemented in #2459 PHPBB3-12334 --- tests/profile/get_profile_value_raw_test.php | 52 -------------------- 1 file changed, 52 deletions(-) delete mode 100644 tests/profile/get_profile_value_raw_test.php diff --git a/tests/profile/get_profile_value_raw_test.php b/tests/profile/get_profile_value_raw_test.php deleted file mode 100644 index 20b61f062b..0000000000 --- a/tests/profile/get_profile_value_raw_test.php +++ /dev/null @@ -1,52 +0,0 @@ -getMock('\phpbb\request\request'), - $this->getMock('\phpbb\template\template'), - $this->getMock('\phpbb\user') - ); - - $this->assertSame($expected, $cp->get_profile_value_raw($value, array( - 'field_type' => $type, - 'field_show_novalue' => $show_novalue, - ))); - } -} From 7a5afdeb4c05c55d6759c5ccf49a301cda4aa14c Mon Sep 17 00:00:00 2001 From: Shitiz Garg Date: Tue, 24 Jun 2014 22:12:00 +0530 Subject: [PATCH 08/19] [ticket/12334] Add get_profile_value_raw unit tests for type_int PHPBB3-12334 --- tests/profilefields/type_int_test.php | 54 +++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/tests/profilefields/type_int_test.php b/tests/profilefields/type_int_test.php index 611edd32b9..312b3874b8 100644 --- a/tests/profilefields/type_int_test.php +++ b/tests/profilefields/type_int_test.php @@ -169,6 +169,60 @@ class phpbb_profilefield_type_int_test extends phpbb_test_case $this->assertSame($expected, $result, $description); } + public function get_profile_value_raw_data() + { + return array( + array( + '10', + array('field_show_novalue' => true), + 10, + 'Field should return the correct raw value', + ), + array( + '0', + array('field_show_novalue' => true), + 0, + 'Field should return correct raw value', + ), + array( + '', + array('field_show_novalue' => true), + 0, + 'Field should return correct raw value', + ), + array( + '10', + array('field_show_novalue' => false), + 10, + 'Field should return the correct raw value', + ), + array( + '0', + array('field_show_novalue' => false), + 0, + 'Field should return correct raw value', + ), + array( + '', + array('field_show_novalue' => false), + null, + 'Field should return correct raw value', + ), + ); + } + + /** + * @dataProvider get_profile_value_raw_data + */ + public function test_get_profile_value_raw($value, $field_options, $expected, $description) + { + $field_options = array_merge($this->field_options, $field_options); + + $result = $this->cp->get_profile_value_raw($value, $field_options); + + $this->assertSame($expected, $result, $description); + } + public function return_callback_implode() { return implode('-', func_get_args()); From e9fbaac2124f96a41ff6633f23fd195e15db0bc7 Mon Sep 17 00:00:00 2001 From: Shitiz Garg Date: Tue, 24 Jun 2014 22:15:20 +0530 Subject: [PATCH 09/19] [ticket/12334] Add get_profile_value_raw unit test for type_url PHPBB3-12334 --- tests/profilefields/type_url_test.php | 30 +++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/tests/profilefields/type_url_test.php b/tests/profilefields/type_url_test.php index 9957510d90..607cb7b9aa 100644 --- a/tests/profilefields/type_url_test.php +++ b/tests/profilefields/type_url_test.php @@ -104,6 +104,36 @@ class phpbb_profilefield_type_url_test extends phpbb_test_case $this->assertSame($expected, $result, $description); } + public function get_profile_value_raw_data() + { + return array( + array( + 'http://example.com', + array('field_show_novalue' => true), + 'http://example.com', + 'Field should return the correct raw value', + ), + array( + 'http://example.com', + array('field_show_novalue' => false), + 'http://example.com', + 'Field should return correct raw value', + ), + ); + } + + /** + * @dataProvider get_profile_value_raw_data + */ + public function test_get_profile_value_raw($value, $field_options, $expected, $description) + { + $field_options = array_merge($this->field_options, $field_options); + + $result = $this->cp->get_profile_value_raw($value, $field_options); + + $this->assertSame($expected, $result, $description); + } + public function return_callback_implode() { return implode('-', func_get_args()); From ab6d36dd576aadf37a36da2cd2f4ba1219540253 Mon Sep 17 00:00:00 2001 From: Shitiz Garg Date: Tue, 24 Jun 2014 22:22:10 +0530 Subject: [PATCH 10/19] [ticket/12334] Add get_profile_value_raw unit test for type_string PHPBB3-12334 --- tests/profilefields/type_string_test.php | 30 ++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/tests/profilefields/type_string_test.php b/tests/profilefields/type_string_test.php index cee8a1d863..2b3d239c3e 100644 --- a/tests/profilefields/type_string_test.php +++ b/tests/profilefields/type_string_test.php @@ -225,6 +225,36 @@ class phpbb_profilefield_type_string_test extends phpbb_test_case $this->assertSame($expected, $result, $description); } + public function get_profile_value_raw_data() + { + return array( + array( + '[b]bbcode test[/b]', + array('field_show_novalue' => true), + '[b]bbcode test[/b]', + 'Field should return the correct raw value', + ), + array( + '[b]bbcode test[/b]', + array('field_show_novalue' => false), + '[b]bbcode test[/b]', + 'Field should return correct raw value', + ), + ); + } + + /** + * @dataProvider get_profile_value_raw_data + */ + public function test_get_profile_value_raw($value, $field_options, $expected, $description) + { + $field_options = array_merge($this->field_options, $field_options); + + $result = $this->cp->get_profile_value_raw($value, $field_options); + + $this->assertSame($expected, $result, $description); + } + public function return_callback_implode() { return implode('-', func_get_args()); From 15929201b8cadc64f4a0fbcb49ddf5b6426f79a6 Mon Sep 17 00:00:00 2001 From: Shitiz Garg Date: Tue, 24 Jun 2014 22:27:30 +0530 Subject: [PATCH 11/19] [ticket/12334] Add get_profile_value_raw unit tests for type_dropdown PHPBB3-12334 --- tests/profilefields/type_dropdown_test.php | 48 ++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/tests/profilefields/type_dropdown_test.php b/tests/profilefields/type_dropdown_test.php index 0e92afd504..ae5402177a 100644 --- a/tests/profilefields/type_dropdown_test.php +++ b/tests/profilefields/type_dropdown_test.php @@ -170,6 +170,54 @@ class phpbb_profilefield_type_dropdown_test extends phpbb_test_case $this->assertSame($expected, $result, $description); } + public function get_profile_value_raw_data() + { + return array( + array( + '4', + array('field_show_novalue' => true), + '4', + 'Field should return the correct raw value', + ), + array( + '', + array('field_show_novalue' => false), + null, + 'Field should return correct raw value', + ), + array( + '', + array('field_show_novalue' => true), + 0, + 'Field should return correct raw value', + ), + array( + null, + array('field_show_novalue' => false), + null, + 'Field should return correct raw value', + ), + array( + null, + array('field_show_novalue' => true), + 0, + 'Field should return correct raw value', + ), + ); + } + + /** + * @dataProvider get_profile_value_raw_data + */ + public function test_get_profile_value_raw($value, $field_options, $expected, $description) + { + $field_options = array_merge($this->field_options, $field_options); + + $result = $this->cp->get_profile_value_raw($value, $field_options); + + $this->assertSame($expected, $result, $description); + } + public function is_set_callback($field_id, $lang_id, $field_value) { return isset($this->dropdown_options[$field_value]); From e406cc6fadfc753369c1118c49bddca6523ee2db Mon Sep 17 00:00:00 2001 From: Shitiz Garg Date: Tue, 24 Jun 2014 22:29:54 +0530 Subject: [PATCH 12/19] [ticket/12334] Add get_profile_value_raw unit test for type_date PHPBB3-12334 --- tests/profilefields/type_date_test.php | 36 ++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/tests/profilefields/type_date_test.php b/tests/profilefields/type_date_test.php index 39fe95b97f..7f719d0f03 100644 --- a/tests/profilefields/type_date_test.php +++ b/tests/profilefields/type_date_test.php @@ -179,6 +179,42 @@ class phpbb_profilefield_type_date_test extends phpbb_test_case $this->assertSame($expected, $result, $description); } + public function get_profile_value_raw_data() + { + return array( + array( + '', + array('field_show_novalue' => false), + null, + 'Field should return the correct raw value', + ), + array( + '', + array('field_show_novalue' => true), + '', + 'Field should return correct raw value', + ), + array( + '12/06/2014', + array('field_show_novalue' => true), + '12/06/2014', + 'Field should return correct raw value', + ), + ); + } + + /** + * @dataProvider get_profile_value_raw_data + */ + public function test_get_profile_value_raw($value, $field_options, $expected, $description) + { + $field_options = array_merge($this->field_options, $field_options); + + $result = $this->cp->get_profile_value_raw($value, $field_options); + + $this->assertSame($expected, $result, $description); + } + public function return_callback_implode() { return implode('-', func_get_args()); From 24eeab4883c9ced8ba12d99a7cbc14839ba19388 Mon Sep 17 00:00:00 2001 From: Shitiz Garg Date: Tue, 24 Jun 2014 22:34:59 +0530 Subject: [PATCH 13/19] [ticket/12334] Add get_profile_value_raw unit test for type_bool PHPBB3-12334 --- tests/profilefields/type_bool_test.php | 56 ++++++++++++++++++++++++-- 1 file changed, 52 insertions(+), 4 deletions(-) diff --git a/tests/profilefields/type_bool_test.php b/tests/profilefields/type_bool_test.php index 29c118d57d..ad9dd6514c 100644 --- a/tests/profilefields/type_bool_test.php +++ b/tests/profilefields/type_bool_test.php @@ -74,10 +74,10 @@ class phpbb_profilefield_type_bool_test extends phpbb_test_case { return array( array( - false, - array('field_required' => true), - 'FIELD_REQUIRED-field', - 'Field should not accept empty values for required fields', + false, + array('field_required' => true), + 'FIELD_REQUIRED-field', + 'Field should not accept empty values for required fields', ), ); } @@ -130,6 +130,54 @@ class phpbb_profilefield_type_bool_test extends phpbb_test_case $this->assertSame($expected, $result, $description); } + public function get_profile_value_raw_data() + { + return array( + array( + '4', + array('field_show_novalue' => true), + '4', + 'Field should return the correct raw value', + ), + array( + '', + array('field_show_novalue' => false), + null, + 'Field should return correct raw value', + ), + array( + '', + array('field_show_novalue' => true), + null, + 'Field should return correct raw value', + ), + array( + null, + array('field_show_novalue' => false), + null, + 'Field should return correct raw value', + ), + array( + null, + array('field_show_novalue' => true), + null, + 'Field should return correct raw value', + ), + ); + } + + /** + * @dataProvider get_profile_value_raw_data + */ + public function test_get_profile_value_raw($value, $field_options, $expected, $description) + { + $field_options = array_merge($this->field_options, $field_options); + + $result = $this->cp->get_profile_value_raw($value, $field_options); + + $this->assertSame($expected, $result, $description); + } + public function is_set_callback($field_id, $lang_id, $field_value) { return isset($this->options[$field_value]); From dbc223b4c374082d6385205e022664f38380366b Mon Sep 17 00:00:00 2001 From: Shitiz Garg Date: Fri, 27 Jun 2014 19:03:19 +0530 Subject: [PATCH 14/19] [ticket/12334] Change get_profile_value_raw_data to profile_value_raw_data PHPBB3-12334 --- tests/profilefields/type_bool_test.php | 4 ++-- tests/profilefields/type_date_test.php | 4 ++-- tests/profilefields/type_dropdown_test.php | 4 ++-- tests/profilefields/type_int_test.php | 4 ++-- tests/profilefields/type_string_test.php | 4 ++-- tests/profilefields/type_url_test.php | 4 ++-- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/tests/profilefields/type_bool_test.php b/tests/profilefields/type_bool_test.php index ad9dd6514c..bdab179c8c 100644 --- a/tests/profilefields/type_bool_test.php +++ b/tests/profilefields/type_bool_test.php @@ -130,7 +130,7 @@ class phpbb_profilefield_type_bool_test extends phpbb_test_case $this->assertSame($expected, $result, $description); } - public function get_profile_value_raw_data() + public function profile_value_raw_data() { return array( array( @@ -167,7 +167,7 @@ class phpbb_profilefield_type_bool_test extends phpbb_test_case } /** - * @dataProvider get_profile_value_raw_data + * @dataProvider profile_value_raw_data */ public function test_get_profile_value_raw($value, $field_options, $expected, $description) { diff --git a/tests/profilefields/type_date_test.php b/tests/profilefields/type_date_test.php index 7f719d0f03..0ad2cde9fe 100644 --- a/tests/profilefields/type_date_test.php +++ b/tests/profilefields/type_date_test.php @@ -179,7 +179,7 @@ class phpbb_profilefield_type_date_test extends phpbb_test_case $this->assertSame($expected, $result, $description); } - public function get_profile_value_raw_data() + public function profile_value_raw_data() { return array( array( @@ -204,7 +204,7 @@ class phpbb_profilefield_type_date_test extends phpbb_test_case } /** - * @dataProvider get_profile_value_raw_data + * @dataProvider profile_value_raw_data */ public function test_get_profile_value_raw($value, $field_options, $expected, $description) { diff --git a/tests/profilefields/type_dropdown_test.php b/tests/profilefields/type_dropdown_test.php index ae5402177a..1d20578fc1 100644 --- a/tests/profilefields/type_dropdown_test.php +++ b/tests/profilefields/type_dropdown_test.php @@ -170,7 +170,7 @@ class phpbb_profilefield_type_dropdown_test extends phpbb_test_case $this->assertSame($expected, $result, $description); } - public function get_profile_value_raw_data() + public function profile_value_raw_data() { return array( array( @@ -207,7 +207,7 @@ class phpbb_profilefield_type_dropdown_test extends phpbb_test_case } /** - * @dataProvider get_profile_value_raw_data + * @dataProvider profile_value_raw_data */ public function test_get_profile_value_raw($value, $field_options, $expected, $description) { diff --git a/tests/profilefields/type_int_test.php b/tests/profilefields/type_int_test.php index 312b3874b8..4b7bbc18c4 100644 --- a/tests/profilefields/type_int_test.php +++ b/tests/profilefields/type_int_test.php @@ -169,7 +169,7 @@ class phpbb_profilefield_type_int_test extends phpbb_test_case $this->assertSame($expected, $result, $description); } - public function get_profile_value_raw_data() + public function profile_value_raw_data() { return array( array( @@ -212,7 +212,7 @@ class phpbb_profilefield_type_int_test extends phpbb_test_case } /** - * @dataProvider get_profile_value_raw_data + * @dataProvider profile_value_raw_data */ public function test_get_profile_value_raw($value, $field_options, $expected, $description) { diff --git a/tests/profilefields/type_string_test.php b/tests/profilefields/type_string_test.php index 2b3d239c3e..0df42f388f 100644 --- a/tests/profilefields/type_string_test.php +++ b/tests/profilefields/type_string_test.php @@ -225,7 +225,7 @@ class phpbb_profilefield_type_string_test extends phpbb_test_case $this->assertSame($expected, $result, $description); } - public function get_profile_value_raw_data() + public function profile_value_raw_data() { return array( array( @@ -244,7 +244,7 @@ class phpbb_profilefield_type_string_test extends phpbb_test_case } /** - * @dataProvider get_profile_value_raw_data + * @dataProvider profile_value_raw_data */ public function test_get_profile_value_raw($value, $field_options, $expected, $description) { diff --git a/tests/profilefields/type_url_test.php b/tests/profilefields/type_url_test.php index 607cb7b9aa..a45a28e7c7 100644 --- a/tests/profilefields/type_url_test.php +++ b/tests/profilefields/type_url_test.php @@ -104,7 +104,7 @@ class phpbb_profilefield_type_url_test extends phpbb_test_case $this->assertSame($expected, $result, $description); } - public function get_profile_value_raw_data() + public function profile_value_raw_data() { return array( array( @@ -123,7 +123,7 @@ class phpbb_profilefield_type_url_test extends phpbb_test_case } /** - * @dataProvider get_profile_value_raw_data + * @dataProvider profile_value_raw_data */ public function test_get_profile_value_raw($value, $field_options, $expected, $description) { From 9051248e12f8d25f0632b3f3e89738a497a6619b Mon Sep 17 00:00:00 2001 From: Shitiz Garg Date: Fri, 27 Jun 2014 19:03:33 +0530 Subject: [PATCH 15/19] [ticket/12334] Group profile fields test PHPBB3-12334 --- tests/profilefields/type_bool_test.php | 3 +++ tests/profilefields/type_date_test.php | 3 +++ tests/profilefields/type_dropdown_test.php | 3 +++ tests/profilefields/type_googleplus_test.php | 3 +++ tests/profilefields/type_int_test.php | 3 +++ tests/profilefields/type_string_test.php | 3 +++ tests/profilefields/type_url_test.php | 3 +++ 7 files changed, 21 insertions(+) diff --git a/tests/profilefields/type_bool_test.php b/tests/profilefields/type_bool_test.php index bdab179c8c..9eccc7eb6d 100644 --- a/tests/profilefields/type_bool_test.php +++ b/tests/profilefields/type_bool_test.php @@ -11,6 +11,9 @@ * */ +/** +* @group profilefields +*/ class phpbb_profilefield_type_bool_test extends phpbb_test_case { protected $cp; diff --git a/tests/profilefields/type_date_test.php b/tests/profilefields/type_date_test.php index 0ad2cde9fe..8129f47de8 100644 --- a/tests/profilefields/type_date_test.php +++ b/tests/profilefields/type_date_test.php @@ -11,6 +11,9 @@ * */ +/** +* @group profilefields +*/ class phpbb_profilefield_type_date_test extends phpbb_test_case { protected $cp; diff --git a/tests/profilefields/type_dropdown_test.php b/tests/profilefields/type_dropdown_test.php index 1d20578fc1..5ba17ef120 100644 --- a/tests/profilefields/type_dropdown_test.php +++ b/tests/profilefields/type_dropdown_test.php @@ -11,6 +11,9 @@ * */ +/** +* @group profilefields +*/ class phpbb_profilefield_type_dropdown_test extends phpbb_test_case { protected $cp; diff --git a/tests/profilefields/type_googleplus_test.php b/tests/profilefields/type_googleplus_test.php index fdbdd86553..88387b5a99 100644 --- a/tests/profilefields/type_googleplus_test.php +++ b/tests/profilefields/type_googleplus_test.php @@ -11,6 +11,9 @@ * */ +/** +* @group profilefields +*/ class phpbb_profilefield_type_googleplus_test extends phpbb_test_case { public function get_profile_contact_value_data() diff --git a/tests/profilefields/type_int_test.php b/tests/profilefields/type_int_test.php index 4b7bbc18c4..9f432ad3c1 100644 --- a/tests/profilefields/type_int_test.php +++ b/tests/profilefields/type_int_test.php @@ -11,6 +11,9 @@ * */ +/** +* @group profilefields +*/ class phpbb_profilefield_type_int_test extends phpbb_test_case { protected $cp; diff --git a/tests/profilefields/type_string_test.php b/tests/profilefields/type_string_test.php index 0df42f388f..0ae91f1e8e 100644 --- a/tests/profilefields/type_string_test.php +++ b/tests/profilefields/type_string_test.php @@ -15,6 +15,9 @@ require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; require_once dirname(__FILE__) . '/../../phpBB/includes/functions_content.php'; require_once dirname(__FILE__) . '/../../phpBB/includes/utf/utf_tools.php'; +/** +* @group profilefields +*/ class phpbb_profilefield_type_string_test extends phpbb_test_case { protected $cp; diff --git a/tests/profilefields/type_url_test.php b/tests/profilefields/type_url_test.php index a45a28e7c7..3ed21b5fe5 100644 --- a/tests/profilefields/type_url_test.php +++ b/tests/profilefields/type_url_test.php @@ -13,6 +13,9 @@ require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; +/** +* @group profilefields +*/ class phpbb_profilefield_type_url_test extends phpbb_test_case { protected $cp; From 482a22351d08a31b3aa81008e67c994268f8fac5 Mon Sep 17 00:00:00 2001 From: Shitiz Garg Date: Fri, 27 Jun 2014 19:10:23 +0530 Subject: [PATCH 16/19] [ticket/12334] Improve type_dropdown's test description PHPBB3-12334 --- tests/profilefields/type_dropdown_test.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/profilefields/type_dropdown_test.php b/tests/profilefields/type_dropdown_test.php index 5ba17ef120..18d43a3b41 100644 --- a/tests/profilefields/type_dropdown_test.php +++ b/tests/profilefields/type_dropdown_test.php @@ -186,13 +186,13 @@ class phpbb_profilefield_type_dropdown_test extends phpbb_test_case '', array('field_show_novalue' => false), null, - 'Field should return correct raw value', + 'Field should null for empty value without show_novalue', ), array( '', array('field_show_novalue' => true), 0, - 'Field should return correct raw value', + 'Field should return 0 for empty value with show_novalue', ), array( null, @@ -204,7 +204,7 @@ class phpbb_profilefield_type_dropdown_test extends phpbb_test_case null, array('field_show_novalue' => true), 0, - 'Field should return correct raw value', + 'Field should return 0 for empty value with show_novalue', ), ); } From 8cb7afa503362a8e1725591d9619c8712b0b86c0 Mon Sep 17 00:00:00 2001 From: Shitiz Garg Date: Fri, 27 Jun 2014 19:10:48 +0530 Subject: [PATCH 17/19] [ticket/12334] Add string test for type_int PHPBB3-12334 --- tests/profilefields/type_int_test.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/profilefields/type_int_test.php b/tests/profilefields/type_int_test.php index 9f432ad3c1..78c3cee56e 100644 --- a/tests/profilefields/type_int_test.php +++ b/tests/profilefields/type_int_test.php @@ -211,6 +211,12 @@ class phpbb_profilefield_type_int_test extends phpbb_test_case null, 'Field should return correct raw value', ), + array( + 'string', + array('field_show_novalue' => false), + 0, + 'Field should return int cast of passed string' + ), ); } From e6f9b060dc5e7955ac42e947fbf850c958220277 Mon Sep 17 00:00:00 2001 From: Shitiz Garg Date: Fri, 27 Jun 2014 19:19:18 +0530 Subject: [PATCH 18/19] [ticket/12334] Add additional test for type_string PHPBB3-12334 --- tests/profilefields/type_string_test.php | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/tests/profilefields/type_string_test.php b/tests/profilefields/type_string_test.php index 0ae91f1e8e..9c483d7f5e 100644 --- a/tests/profilefields/type_string_test.php +++ b/tests/profilefields/type_string_test.php @@ -243,6 +243,30 @@ class phpbb_profilefield_type_string_test extends phpbb_test_case '[b]bbcode test[/b]', 'Field should return correct raw value', ), + array( + 125, + array('field_show_novalue' => false), + 125, + 'Field should return value of integer as is', + ), + array( + 0, + array('field_show_novalue' => false), + null, + 'Field should return null for empty integer without show_novalue', + ), + array( + 0, + array('field_show_novalue' => true), + 0, + 'Field should return 0 for empty integer with show_novalue', + ), + array( + null, + array('field_show_novalue' => true), + null, + 'field should return null value as is', + ), ); } From b48443969123b630deaec47ac70236fc13287067 Mon Sep 17 00:00:00 2001 From: Shitiz Garg Date: Fri, 27 Jun 2014 20:01:25 +0530 Subject: [PATCH 19/19] [ticket/12334] Remove profile fields test group PHPBB3-12334 --- tests/profilefields/type_bool_test.php | 3 --- tests/profilefields/type_date_test.php | 3 --- tests/profilefields/type_dropdown_test.php | 3 --- tests/profilefields/type_googleplus_test.php | 3 --- tests/profilefields/type_int_test.php | 3 --- tests/profilefields/type_string_test.php | 3 --- tests/profilefields/type_url_test.php | 3 --- 7 files changed, 21 deletions(-) diff --git a/tests/profilefields/type_bool_test.php b/tests/profilefields/type_bool_test.php index 9eccc7eb6d..bdab179c8c 100644 --- a/tests/profilefields/type_bool_test.php +++ b/tests/profilefields/type_bool_test.php @@ -11,9 +11,6 @@ * */ -/** -* @group profilefields -*/ class phpbb_profilefield_type_bool_test extends phpbb_test_case { protected $cp; diff --git a/tests/profilefields/type_date_test.php b/tests/profilefields/type_date_test.php index 8129f47de8..0ad2cde9fe 100644 --- a/tests/profilefields/type_date_test.php +++ b/tests/profilefields/type_date_test.php @@ -11,9 +11,6 @@ * */ -/** -* @group profilefields -*/ class phpbb_profilefield_type_date_test extends phpbb_test_case { protected $cp; diff --git a/tests/profilefields/type_dropdown_test.php b/tests/profilefields/type_dropdown_test.php index 18d43a3b41..ebecbf97f0 100644 --- a/tests/profilefields/type_dropdown_test.php +++ b/tests/profilefields/type_dropdown_test.php @@ -11,9 +11,6 @@ * */ -/** -* @group profilefields -*/ class phpbb_profilefield_type_dropdown_test extends phpbb_test_case { protected $cp; diff --git a/tests/profilefields/type_googleplus_test.php b/tests/profilefields/type_googleplus_test.php index 88387b5a99..fdbdd86553 100644 --- a/tests/profilefields/type_googleplus_test.php +++ b/tests/profilefields/type_googleplus_test.php @@ -11,9 +11,6 @@ * */ -/** -* @group profilefields -*/ class phpbb_profilefield_type_googleplus_test extends phpbb_test_case { public function get_profile_contact_value_data() diff --git a/tests/profilefields/type_int_test.php b/tests/profilefields/type_int_test.php index 78c3cee56e..ac48c10a84 100644 --- a/tests/profilefields/type_int_test.php +++ b/tests/profilefields/type_int_test.php @@ -11,9 +11,6 @@ * */ -/** -* @group profilefields -*/ class phpbb_profilefield_type_int_test extends phpbb_test_case { protected $cp; diff --git a/tests/profilefields/type_string_test.php b/tests/profilefields/type_string_test.php index 9c483d7f5e..f6c14ee38b 100644 --- a/tests/profilefields/type_string_test.php +++ b/tests/profilefields/type_string_test.php @@ -15,9 +15,6 @@ require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; require_once dirname(__FILE__) . '/../../phpBB/includes/functions_content.php'; require_once dirname(__FILE__) . '/../../phpBB/includes/utf/utf_tools.php'; -/** -* @group profilefields -*/ class phpbb_profilefield_type_string_test extends phpbb_test_case { protected $cp; diff --git a/tests/profilefields/type_url_test.php b/tests/profilefields/type_url_test.php index 3ed21b5fe5..a45a28e7c7 100644 --- a/tests/profilefields/type_url_test.php +++ b/tests/profilefields/type_url_test.php @@ -13,9 +13,6 @@ require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; -/** -* @group profilefields -*/ class phpbb_profilefield_type_url_test extends phpbb_test_case { protected $cp;