Merge branch 'develop-ascraeus' into develop

* develop-ascraeus:
  [ticket/12334] Remove profile fields test group
  [ticket/12334] Add additional test for type_string
  [ticket/12334] Add string test for type_int
  [ticket/12334] Improve type_dropdown's test description
  [ticket/12334] Group profile fields test
  [ticket/12334] Change get_profile_value_raw_data to profile_value_raw_data
  [ticket/12334] Add get_profile_value_raw unit test for type_bool
  [ticket/12334] Add get_profile_value_raw unit test for type_date
  [ticket/12334] Add get_profile_value_raw unit tests for type_dropdown
  [ticket/12334] Add get_profile_value_raw unit test for type_string
  [ticket/12334] Add get_profile_value_raw unit test for type_url
  [ticket/12334] Add get_profile_value_raw unit tests for type_int
  [ticket/12334] Removed tests
  [ticket/12334] Dropdowns cannot be tested this way
  [ticket/12334] Added test get_profile_value_raw
  [ticket/12334] Changed from valueid to value_raw
  [ticket/12334] Implemented get_profile_valueid method
  [ticket/12334] Added field_novalue fall-back as requested
  [ticket/12334] Add PROFILE_FIELD_VALUEID template var
This commit is contained in:
Joas Schilling 2014-07-03 11:22:29 +02:00
commit db31866cbb
13 changed files with 380 additions and 18 deletions

View file

@ -389,6 +389,7 @@ class manager
{ {
$profile_field = $this->type_collection[$ident_ary['data']['field_type']]; $profile_field = $this->type_collection[$ident_ary['data']['field_type']];
$value = $profile_field->get_profile_value($ident_ary['value'], $ident_ary['data']); $value = $profile_field->get_profile_value($ident_ary['value'], $ident_ary['data']);
$value_raw = $profile_field->get_profile_value_raw($ident_ary['value'], $ident_ary['data']);
if ($value === null) if ($value === null)
{ {
@ -414,6 +415,7 @@ class manager
$tpl_fields['row'] += array( $tpl_fields['row'] += array(
'PROFILE_' . strtoupper($ident) . '_IDENT' => $ident, 'PROFILE_' . strtoupper($ident) . '_IDENT' => $ident,
'PROFILE_' . strtoupper($ident) . '_VALUE' => $value, 'PROFILE_' . strtoupper($ident) . '_VALUE' => $value,
'PROFILE_' . strtoupper($ident) . '_VALUE_RAW' => $value_raw,
'PROFILE_' . strtoupper($ident) . '_CONTACT' => $contact_url, 'PROFILE_' . strtoupper($ident) . '_CONTACT' => $contact_url,
'PROFILE_' . strtoupper($ident) . '_DESC' => $field_desc, 'PROFILE_' . strtoupper($ident) . '_DESC' => $field_desc,
'PROFILE_' . strtoupper($ident) . '_TYPE' => $ident_ary['data']['field_type'], 'PROFILE_' . strtoupper($ident) . '_TYPE' => $ident_ary['data']['field_type'],
@ -427,6 +429,7 @@ class manager
$tpl_fields['blockrow'][] = array( $tpl_fields['blockrow'][] = array(
'PROFILE_FIELD_IDENT' => $ident, 'PROFILE_FIELD_IDENT' => $ident,
'PROFILE_FIELD_VALUE' => $value, 'PROFILE_FIELD_VALUE' => $value,
'PROFILE_FIELD_VALUE_RAW' => $value_raw,
'PROFILE_FIELD_CONTACT' => $contact_url, 'PROFILE_FIELD_CONTACT' => $contact_url,
'PROFILE_FIELD_DESC' => $field_desc, 'PROFILE_FIELD_DESC' => $field_desc,
'PROFILE_FIELD_TYPE' => $ident_ary['data']['field_type'], 'PROFILE_FIELD_TYPE' => $ident_ary['data']['field_type'],

View file

@ -177,6 +177,24 @@ class type_bool extends type_base
} }
} }
/**
* {@inheritDoc}
*/
public function get_profile_value_raw($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} * {@inheritDoc}
*/ */

View file

@ -205,6 +205,19 @@ class type_date extends type_base
return $field_value; return $field_value;
} }
/**
* {@inheritDoc}
*/
public function get_profile_value_raw($field_value, $field_data)
{
if (($field_value === '' || $field_value === null) && !$field_data['field_show_novalue'])
{
return null;
}
return $field_value;
}
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */

View file

@ -186,6 +186,24 @@ class type_dropdown extends type_base
return $this->lang_helper->get($field_id, $lang_id, $field_value); return $this->lang_helper->get($field_id, $lang_id, $field_value);
} }
/**
* {@inheritDoc}
*/
public function get_profile_value_raw($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} * {@inheritDoc}
*/ */

View file

@ -151,6 +151,18 @@ class type_int extends type_base
return (int) $field_value; return (int) $field_value;
} }
/**
* {@inheritDoc}
*/
public function get_profile_value_raw($field_value, $field_data)
{
if (($field_value === '' || $field_value === null) && !$field_data['field_show_novalue'])
{
return null;
}
return (int) $field_value;
}
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */

View file

@ -93,6 +93,15 @@ interface type_interface
*/ */
public function get_profile_value($field_value, $field_data); 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_value_raw($field_value, $field_data);
/** /**
* Get Profile Value for display * Get Profile Value for display
* *

View file

@ -109,6 +109,19 @@ abstract class type_string_common extends type_base
return $field_value; return $field_value;
} }
/**
* {@inheritDoc}
*/
public function get_profile_value_raw($field_value, $field_data)
{
if (!$field_value && !$field_data['field_show_novalue'])
{
return null;
}
return $field_value;
}
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */

View file

@ -130,6 +130,54 @@ class phpbb_profilefield_type_bool_test extends phpbb_test_case
$this->assertSame($expected, $result, $description); $this->assertSame($expected, $result, $description);
} }
public function 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 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) public function is_set_callback($field_id, $lang_id, $field_value)
{ {
return isset($this->options[$field_value]); return isset($this->options[$field_value]);

View file

@ -179,6 +179,42 @@ class phpbb_profilefield_type_date_test extends phpbb_test_case
$this->assertSame($expected, $result, $description); $this->assertSame($expected, $result, $description);
} }
public function 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 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() public function return_callback_implode()
{ {
return implode('-', func_get_args()); return implode('-', func_get_args());

View file

@ -170,6 +170,54 @@ class phpbb_profilefield_type_dropdown_test extends phpbb_test_case
$this->assertSame($expected, $result, $description); $this->assertSame($expected, $result, $description);
} }
public function 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 null for empty value without show_novalue',
),
array(
'',
array('field_show_novalue' => true),
0,
'Field should return 0 for empty value with show_novalue',
),
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 0 for empty value with show_novalue',
),
);
}
/**
* @dataProvider 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) public function is_set_callback($field_id, $lang_id, $field_value)
{ {
return isset($this->dropdown_options[$field_value]); return isset($this->dropdown_options[$field_value]);

View file

@ -169,6 +169,66 @@ class phpbb_profilefield_type_int_test extends phpbb_test_case
$this->assertSame($expected, $result, $description); $this->assertSame($expected, $result, $description);
} }
public function 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',
),
array(
'string',
array('field_show_novalue' => false),
0,
'Field should return int cast of passed string'
),
);
}
/**
* @dataProvider 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() public function return_callback_implode()
{ {
return implode('-', func_get_args()); return implode('-', func_get_args());

View file

@ -225,6 +225,60 @@ class phpbb_profilefield_type_string_test extends phpbb_test_case
$this->assertSame($expected, $result, $description); $this->assertSame($expected, $result, $description);
} }
public function 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',
),
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',
),
);
}
/**
* @dataProvider 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() public function return_callback_implode()
{ {
return implode('-', func_get_args()); return implode('-', func_get_args());

View file

@ -104,6 +104,36 @@ class phpbb_profilefield_type_url_test extends phpbb_test_case
$this->assertSame($expected, $result, $description); $this->assertSame($expected, $result, $description);
} }
public function 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 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() public function return_callback_implode()
{ {
return implode('-', func_get_args()); return implode('-', func_get_args());