1
0
mirror of https://github.com/e107inc/e107.git synced 2025-01-17 12:48:24 +01:00

User-extended cleanup

This commit is contained in:
Cameron 2021-01-10 14:37:42 -08:00
parent 4012ead989
commit 33b76590df
5 changed files with 518 additions and 226 deletions

View File

@ -483,7 +483,7 @@ class signup_shortcodes extends e_shortcode
// 'unallocated' entries are `user_extended_struct_parent` = 0
// Get a list of defined categories
$catList = $ue->getCategories(FALSE);
$catList = $ue->getCategories();
// Add in category zero - the 'no category' category
array_unshift($catList,array('user_extended_struct_parent' => 0, 'user_extended_struct_id' => '0'));

View File

@ -764,13 +764,11 @@ class user_shortcodes extends e_shortcode
";
*/
require_once(e_HANDLER."user_extended_class.php");
$ue = new e107_user_extended;
$ue = e107::getUserExt();
$ueCatList = $ue->user_extended_get_categories();
$ueFieldList = $ue->user_extended_get_fields();
$ueCatList[0][0] = array('user_extended_struct_name' => LAN_USER_44, 'user_extended_struct_text' => '');

View File

@ -14,31 +14,30 @@
function user_extended_shortcode($parm)
{
$currentUser = e107::user();
// $currentUser = e107::user();
$tp = e107::getParser();
$ue = e107::getUserExt();
global $loop_uid, $e107, $sc_style;
// include_lan(e_LANGUAGEDIR.e_LANGUAGE.'/lan_user_extended.php');
$parms = explode('.', $parm);
$tmp = explode('.', $parm);
$fieldname = $tmp[0];
$type = $tmp[1];
$user = varset($tmp[2], 0);
if(isset($loop_uid) && intval($loop_uid) == 0)
{
return '';
}
$key = $parms[0].".".$parms[1];
$key = $fieldname.".".$type;
$sc_style['USER_EXTENDED']['pre'] = (isset($sc_style['USER_EXTENDED'][$key]['pre']) ? $sc_style['USER_EXTENDED'][$key]['pre'] : '');
$sc_style['USER_EXTENDED']['post'] = (isset($sc_style['USER_EXTENDED'][$key]['post']) ? $sc_style['USER_EXTENDED'][$key]['post'] : '');
//include_once(e_HANDLER.'user_extended_class.php');
$ueStruct = e107::getUserExt()->user_extended_getStruct();
// $ueStruct = e107_user_extended::user_extended_getStruct();
$uid = (int) $user;
$uid = intval(varset($parms[2],0));
if($uid == 0)
if($uid === 0)
{
if(isset($loop_uid) && intval($loop_uid) > 0)
{
@ -57,7 +56,7 @@
if(!empty($udata['user_admin']))
{
$udata['user_class'].= ','.e_UC_ADMIN;
$udata['user_class'] .= ','.e_UC_ADMIN;
}
@ -66,167 +65,108 @@
/**
* @todo - must be a better way of picking up the 'Miscellaneous' category
*/
e107::includeLan(e_LANGUAGEDIR.e_LANGUAGE.'/lan_user.php');
// e107::coreLan('user');
if (($parms[1] != 'icon') && ($parms[0] != LAN_USER_44))
if(($type !== 'icon') && ($ue->getCategoryAttribute($fieldname, 'read') === false))
{
$fkeyApplic = varset($ueStruct["user_".$parms[0]]['user_extended_struct_applicable']);
$fkeyRead = varset($ueStruct["user_".$parms[0]]['user_extended_struct_read']);
$fkeyStruct = varset($ueStruct["user_".$parms[0]]['user_extended_struct_parms']);
$fkeyApplic = $ue->getFieldAttribute("user_" . $fieldname, 'applicable');
$fkeyRead = $ue->getFieldAttribute("user_" . $fieldname, 'read');
$fkeyStruct = $ue->getFieldAttribute("user_" . $fieldname, 'parms');
$ret_cause = 0;
if (!check_class($fkeyApplic, $udata['user_class'])) $ret_cause = 1;
if (!check_class($fkeyRead, $udata['user_class'])) $ret_cause = 2;
if (($ueStruct["user_".$parms[0]]['user_extended_struct_read'] == e_UC_READONLY && (!ADMIN && $udata['user_id'] != USERID))) $ret_cause = 3;
if ((!ADMIN && substr($fkeyStruct, -1) == 1
&& strpos($udata['user_hidden_fields'], "^user_".$parms[0]."^") !== FALSE && $uid != USERID)) $ret_cause = 4;
if ($ret_cause != 0)
if(!check_class($fkeyApplic, $udata['user_class']))
{
return FALSE;
$ret_cause = 1;
}
}
if($parms[1] == 'text_value')
{
// $_value = $tp->parseTemplate("{USER_EXTENDED={$parms[0]}.value}");
$_value = user_extended_shortcode($parms[0].".value");
//print_a($parms);
if($_value)
if(!check_class($fkeyRead, $udata['user_class']))
{
$__pre = (isset($sc_style['USER_EXTENDED'][$key]['pre']) ? $sc_style['USER_EXTENDED'][$key]['pre'] : '');
$__post = (isset($sc_style['USER_EXTENDED'][$key]['post']) ? $sc_style['USER_EXTENDED'][$key]['post'] : '');
// $_text = $tp->parseTemplate("{USER_EXTENDED={$parms[0]}.text}");
$_text = user_extended_shortcode($parms[0].".text");
$_mid = (isset($sc_style['USER_EXTENDED'][$key]['mid']) ? $sc_style['USER_EXTENDED'][$key]['mid'] : ': ');
return $__pre.$_text.$_mid.$_value.$__post;
$ret_cause = 2;
}
return false;
}
if ($parms[1] == 'text')
{
if(!isset($parms[0]) || !isset($ueStruct['user_'.$parms[0]]) || !isset($ueStruct['user_'.$parms[0]]['user_extended_struct_text']))
if(($fkeyRead == e_UC_READONLY && (!ADMIN && $udata['user_id'] != USERID)))
{
$ret_cause = 3;
}
if((!ADMIN && substr($fkeyStruct, -1) == 1 && strpos($udata['user_hidden_fields'], "^user_" . $fieldname . "^") !== false && $uid != USERID))
{
$ret_cause = 4;
}
if(!empty($ret_cause))
{
return false;
}
$text_val = $ueStruct['user_'.$parms[0]]['user_extended_struct_text'];
if($text_val)
{
return (defined($text_val) ? constant($text_val) : $text_val);
}
else
{
return FALSE;
}
}
if ($parms[1] == 'icon')
$ret = false;
switch($type)
{
if(defined(strtoupper($parms[0]).'_ICON'))
{
return constant(strtoupper($parms[0]).'_ICON');
}
elseif(is_readable(e_IMAGE."user_icons/user_{$parms[0]}.png"))
{
return "<img src='".e_IMAGE_ABS."user_icons/user_{$parms[0]}.png' style='width:16px; height:16px' alt='' />";
}
elseif(is_readable(e_IMAGE."user_icons/{$parms[0]}.png"))
{
return "<img src='".e_IMAGE_ABS."user_icons/{$parms[0]}.png' style='width:16px; height:16px' alt='' />";
}
//return '';
return FALSE;
}
case "text_value":
$_value = user_extended_shortcode($fieldname.".value.".$user);
if ($parms[1] === 'value')
{
$uVal = isset($parms[0]) && isset($udata['user_'.$parms[0]]) ? str_replace(chr(1), '', $udata['user_'.$parms[0]]) : '';
if(!isset($parms[0]) || !isset($ueStruct["user_".$parms[0]]) || !isset($ueStruct["user_".$parms[0]]['user_extended_struct_type']))
{
return null;
}
switch ($ueStruct["user_".$parms[0]]['user_extended_struct_type'])
{
case EUF_CHECKBOX:
$uVal = e107::unserialize($uVal);
if(!empty($uVal))
{
return implode(', ',$uVal);
/*
$text = '<ul>';
foreach($uVal as $v)
{
$text .= "<li>".$v."</li>";
}
$text .= "</ul>";
$ret_data = $text;*/
}
if($_value)
{
$__pre = (isset($sc_style['USER_EXTENDED'][$key]['pre']) ? $sc_style['USER_EXTENDED'][$key]['pre'] : '');
$__post = (isset($sc_style['USER_EXTENDED'][$key]['post']) ? $sc_style['USER_EXTENDED'][$key]['post'] : '');
$_text = $ue->getFieldLabel($fieldname); // user_extended_shortcode($fieldname.".text");
$_mid = (isset($sc_style['USER_EXTENDED'][$key]['mid']) ? $sc_style['USER_EXTENDED'][$key]['mid'] : ': ');
$ret = $__pre.$_text.$_mid.$_value.$__post;
}
break;
case EUF_COUNTRY:
if(!empty($uVal))
case "text":
if(isset($fieldname))
{
$ret = $ue->getFieldLabel($fieldname);
}
break;
case "icon":
if(defined(strtoupper($fieldname).'_ICON'))
{
$ret = constant(strtoupper($fieldname).'_ICON');
}
elseif(is_readable(e_IMAGE."user_icons/user_{$fieldname}.png"))
{
$ret = "<img src='".e_IMAGE_ABS."user_icons/user_{$fieldname}.png' style='width:16px; height:16px' alt='' />";
}
elseif(is_readable(e_IMAGE."user_icons/{$fieldname}.png"))
{
$ret = "<img src='".e_IMAGE_ABS."user_icons/{$fieldname}.png' style='width:16px; height:16px' alt='' />";
}
break;
case "value":
$uVal = isset($fieldname) && isset($udata['user_'.$fieldname]) ? str_replace(chr(1), '', $udata['user_'.$fieldname]) : '';
if(!empty($uVal))
{
$ret = $ue->renderValue($uVal, "user_".$fieldname);
if(!empty($ret))
{
return e107::getForm()->getCountry($uVal);
$ret = $tp->toHTML($ret, TRUE, 'no_make_clickable', "class:{$udata['user_class']}");
}
return false;
break;
case EUF_DB_FIELD : // check for db_lookup type
$tmp = explode(',',$ueStruct['user_'.$parms[0]]['user_extended_struct_values']);
}
break;
if(empty($tmp[1]) || empty($tmp[2]))
{
return null;
}
$sql_ue = new db; // Use our own DB object to avoid conflicts
if($sql_ue->select($tmp[0],"{$tmp[1]}, {$tmp[2]}","{$tmp[1]} = '{$uVal}'"))
{
$row = $sql_ue->fetch();
$ret_data = $row[$tmp[2]];
}
else
{
$ret_data = FALSE;
}
break;
case EUF_DATE : //check for 0000-00-00 in date field
if($uVal == '0000-00-00') { $uVal = ''; }
$ret_data = $uVal;
break;
case EUF_PREDEFINED : // Predefined field - have to look up display string in relevant file
$ret_data = e107::getUserExt()->user_extended_display_text($ueStruct['user_'.$parms[0]]['user_extended_struct_values'],$uVal);
break;
case EUF_RICHTEXTAREA :
$ret_data = e107::getParser()->toHTML($uVal);
break;
default :
$ret_data = $uVal;
}
if(!empty($ret_data))
{
return $tp->toHTML($ret_data, TRUE, 'no_make_clickable', "class:{$udata['user_class']}");
}
return FALSE;
// code to be executed if n is different from all labels;
}
// return TRUE;
return FALSE;
return $ret;
}

View File

@ -44,6 +44,7 @@ class e107_user_extended
public $systemCount = 0; // Count of system fields - always zero ATM
public $userCount = 0; // Count of non-system fields
private $fieldAttributes = array(); // Field Permissionss with field name as key.
private $catAttributes = array();
private $lastError;
public function __construct()
@ -139,20 +140,34 @@ class e107_user_extended
{
while($row = $sql->fetch())
{
if ($row['user_extended_struct_type'] == 0)
{ // Its a category
$id = $row['user_extended_struct_name'];
$this->catDefinitions[$row['user_extended_struct_id']] = $row;
$this->catAttributes[$id] = array(
'read' => (int) $row['user_extended_struct_read'],
'write' => (int) $row['user_extended_struct_write'],
'applicable' => (int) $row['user_extended_struct_applicable'],
);
}
else
{ // Its a field definition
$this->fieldDefinitions[$row['user_extended_struct_id']] = $row;
$id = 'user_' . $row['user_extended_struct_name'];
$this->fieldDefinitions[$row['user_extended_struct_id']] = $row;
$this->fieldAttributes[$id] = array(
'read' => $row['user_extended_struct_read'],
'write' => $row['user_extended_struct_write'],
'type' => $row['user_extended_struct_type']
'read' => (int) $row['user_extended_struct_read'],
'write' => (int) $row['user_extended_struct_write'],
'type' => $row['user_extended_struct_type'],
'values' => $row['user_extended_struct_values'],
'parms' => $row['user_extended_struct_parms'],
'applicable' => (int) $row['user_extended_struct_applicable'],
'required' => (int) $row['user_extended_struct_required'],
);
$this->nameIndex['user_' . $row['user_extended_struct_name']] = $row['user_extended_struct_id']; // Create name to ID index
if($row['user_extended_struct_text'] == '_system_')
@ -514,16 +529,18 @@ class e107_user_extended
*/
function getCategories($byID = TRUE)
{
return $this->user_extended_get_categories($byID);
return $this->catDefinitions;
}
/**
* BC Alias of getCategories()
* Return a list of the user-extended categories.
* @deprecated Use getCategories() instead.
* @param bool $byID
* @return array
*/
function user_extended_get_categories($byID = TRUE)
{
$ret = array();
$sql = e107::getDb('ue');
@ -679,7 +696,7 @@ class e107_user_extended
public function getFieldType($field)
{
if(!empty($this->fieldAttributes[$field]['type']))
if(isset($this->fieldAttributes[$field]['type']))
{
return (int) $this->fieldAttributes[$field]['type'];
}
@ -687,6 +704,53 @@ class e107_user_extended
return false;
}
/**
* Get the field attributes of a given field-name.
* @param string $field
* @param string read|write|type|values|parms|applicable
* @return bool|int|string
*/
public function getFieldAttribute($field, $att)
{
if(isset($this->fieldAttributes[$field][$att]))
{
return e107::getParser()->toHtml($this->fieldAttributes[$field][$att],false);
}
return false;
}
/**
* Get the category attributes of a given category-name.
* @param string $field
* @param string read|write|applicable
* @return bool|int
*/
public function getCategoryAttribute($field, $att)
{
if(isset($this->catAttributes[$field][$att]))
{
return (int) $this->catAttributes[$field][$att];
}
return false;
}
/**
* Get the field structure values of a given field-name.
* @param $field
* @return bool|string
*/
public function getFieldValues($field)
{
if(!empty($this->fieldAttributes[$field]['values']))
{
return e107::getParser()->toHTML($this->fieldAttributes[$field]['values'], false);
}
return false;
}
/**
* Return a list of all field types.
@ -1346,6 +1410,28 @@ class e107_user_extended
return $this->extended_xml;
}
/**
* @param string $field
* @return false|mixed|null
*/
public function getFieldLabel($field)
{
if(strpos($field, 'user_') !== 0)
{
$field = 'user_' . $field;
}
if(!isset($this->nameIndex[$field]) || !isset($this->fieldDefinitions[$this->nameIndex[$field]]['user_extended_struct_text']))
{
return null;
}
$text = $this->fieldDefinitions[$this->nameIndex[$field]]['user_extended_struct_text'];
return defset($text, $text);
}
/**
* Replacement Method for user_extended_getvalue(); Returns extended field data in the original posted format.
* @param int $uid
@ -1384,7 +1470,6 @@ class e107_user_extended
default:
$ret = $uinfo[$field_name];
// code to be executed if n is different from all labels;
}
return $ret;
@ -1537,65 +1622,126 @@ class e107_user_extended
/**
* Render Extended User Field Data in a read-only fashion.
* @param $value
* @param $type
* @param int|string $type field type number or field name.
* @return array|string
*/
public function renderValue($value, $type=null)
{
if(!empty($type) && !is_numeric($type))
{
$fieldname = $type;
$type = $this->getFieldType($type);
}
//TODO FIXME Add more types.
$ret = null;
switch($type)
{
case EUF_RADIO:
if(isset($fieldname))
{
$tmp = $this->getFieldAttribute($fieldname, 'values');
$choices = explode(',', $tmp);
foreach($choices as $choice)
{
$choice = trim($choice);
$choice = e107::getParser()->toHTML($choice);
if(strpos($choice,"|")!==FALSE)
{
list($val,$label) = explode("|",$choice);
}
elseif(strpos($choice," => ")!==FALSE) // new in v2.x
{
list($val,$label) = explode(" => ",$choice);
}
else
{
$val = $choice;
$label = $choice;
}
if($val == $value)
{
$ret = defset($label, $label);
break;
}
}
}
break;
case EUF_COUNTRY:
if(!empty($value))
{
return e107::getForm()->getCountry($value);
$ret = e107::getForm()->getCountry($value);
}
return null;
break;
case EUF_CHECKBOX:
$value = e107::unserialize($value);
if(!empty($value))
{
sort($value);
return implode('<br />',$value);
/*
$text = '<ul>';
foreach($uVal as $v)
{
$text .= "<li>".$v."</li>";
}
$text .= "</ul>";
$ret_data = $text;*/
}
break;
case EUF_DATE : //check for 0000-00-00 in date field
if($value == '0000-00-00') { $value = ''; }
return $value;
break;
case EUF_CHECKBOX:
$value = e107::unserialize($value);
if(!empty($value))
{
sort($value);
$ret = implode(', ', $value);
}
break;
case EUF_DATE : //check for 0000-00-00 in date field
if($value == '0000-00-00')
{
$value = '';
}
$ret = $value;
break;
case EUF_RICHTEXTAREA:
return e107::getParser()->toHTML($value, true);
$ret = e107::getParser()->toHTML($value, true);
break;
case EUF_DB_FIELD : // check for db_lookup type
if(!isset($fieldname))
{
return null;
}
$structValues = $this->getFieldValues($fieldname);
$tmp = explode(',', $structValues);
if(empty($tmp[1]) || empty($tmp[2]))
{
return null;
}
$sql_ue = e107::getDb('euf_db'); // Use our own DB object to avoid conflicts
if($sql_ue->select($tmp[0], "{$tmp[1]}, {$tmp[2]}", "{$tmp[1]} = '{$value}'"))
{
$row = $sql_ue->fetch();
$ret = varset($row[$tmp[2]]);
}
break;
case EUF_PREDEFINED : // Predefined field - have to look up display string in relevant file
if(isset($fieldname))
{
$structValues = $this->getFieldValues($fieldname);
$ret = $this->user_extended_display_text($structValues, $value);
}
break;
default:
return $value;
// code to be executed if n is different from all labels;
$ret = $value;
// code to be executed if n is different from all labels;
}
return null;
return $ret;
}
}

View File

@ -12,7 +12,8 @@
class e107_user_extendedTest extends \Codeception\Test\Unit
{
private $typeArray;
private $structTypes;
private $structLabels;
/** @var e107_user_extended */
protected $ue;
@ -31,7 +32,7 @@
$this->ue->__construct();
$this->typeArray = array(
$this->structTypes = array(
'text' => EUF_TEXT,
'homepage' => EUF_TEXT,
'radio' => EUF_RADIO,
@ -49,6 +50,24 @@
'richtextarea' => EUF_RICHTEXTAREA,
);
$this->structLabels = array (
'text' => 'Text',
'homepage' => 'UE_LAN_HOMEPAGE', // test constant use as well.
'radio' => 'Radio',
'dropdown' => 'Dropdown',
'dbfield' => 'Dbfield',
'textarea' => 'Textarea',
'integer' => 'Integer',
'date' => 'Date',
'language' => 'Language',
'list' => 'List',
'checkbox' => 'Checkbox',
'predefined' => 'Predefined',
'country' => 'Country',
'richtextarea' => 'Richtextarea',
'addon' => 'Addon'
);
$this->structValues = array(
'dropdown' => 'drop1,drop2,drop3',
'dbfield' => 'core_media_cat,media_cat_id,media_cat_title,media_cat_order',
@ -68,13 +87,13 @@
// Add a field of each type.
foreach($this->typeArray as $k=>$v)
foreach($this->structTypes as $k=> $v)
{
$value = (isset($this->structValues[$k])) ? $this->structValues[$k] : null;
$insert = array(
'name' => $k,
'text' => ucfirst($k),
'text' => $this->structLabels[$k],
'type' => $v,
'parms' => null,
'values' => (isset($this->structValues[$k])) ? $this->structValues[$k] : null,
@ -85,6 +104,30 @@
// $this->ue->user_extended_add($k, ucfirst($k), $v , null, $value);
}
// Insert a User-Extended Category
$insertCategory = array(
'name' => 'mycategory',
'text' => 'Category Name',
'type' => 0,
'read' => e_UC_PUBLIC,
'write' => e_UC_ADMIN,
'applicable' => e_UC_MEMBER
);
$this->ue->user_extended_add($insertCategory);
// Insert a User-Extended Category
$insertCategory2 = array(
'name' => 'mycategory2 ',
'text' => 'Category Name 2',
'type' => 0,
'read' => e_UC_ADMIN,
'write' => e_UC_ADMIN,
'applicable' => e_UC_MEMBER
);
$this->ue->user_extended_add($insertCategory2);
// As $_POSTED.
$this->userValues = array(
'text' => 'Some Text',
@ -143,7 +186,7 @@
$legacyExpectedValues = array (
'text' => 'Some Text',
'homepage' => 'https://e107.org',
'radio' => 'M',
'radio' => 'Male',
'dropdown' => 'drop3',
'dbfield' => 'News',
'textarea' => 'Text area value',
@ -168,36 +211,19 @@
}
$legacyExpectedLabels = array (
'text' => 'Text',
'homepage' => 'Homepage',
'radio' => 'Radio',
'dropdown' => 'Dropdown',
'dbfield' => 'Dbfield',
'textarea' => 'Textarea',
'integer' => 'Integer',
'date' => 'Date',
'language' => 'Language',
'list' => 'List',
'checkbox' => 'Checkbox',
'predefined' => 'Predefined',
'country' => 'Country',
'richtextarea' => 'Richtextarea',
);
foreach($this->userValues as $field => $value)
{
$parm = $field.'.text.1';
$result = $tp->parseTemplate('{USER_EXTENDED='.$parm.'}', true); // retrieve value for $field of user_id: 1.
$this->assertEquals($legacyExpectedLabels[$field], $result);
$expected = defset($this->structLabels[$field],$this->structLabels[$field]);
$this->assertEquals($expected, $result);
}
$legacyExpectedLabelValues = array (
'text' => 'Text: Some Text',
'homepage' => 'Homepage: https://e107.org',
'radio' => 'Radio: M',
'radio' => 'Radio: Male',
'dropdown' => 'Dropdown: drop3',
'dbfield' => 'Dbfield: News',
'textarea' => 'Textarea: Text area value',
@ -254,7 +280,7 @@
$result = $this->ue->getStructure();
foreach($this->typeArray as $k=>$v)
foreach($this->structTypes as $k=> $v)
{
$key = 'user_'.$k;
$this->assertArrayHasKey($key,$result);
@ -278,6 +304,36 @@
$this->assertEquals(EUF_RADIO,$result);
}
public function testGetFieldValues()
{
foreach($this->structValues as $key=>$value)
{
$result = $this->ue->getFieldValues('user_'.$key);
$this->assertEquals($value, $result);
}
}
public function testGetFieldLabel()
{
foreach($this->structLabels as $field => $label)
{
$result = $this->ue->getFieldLabel('user_'.$field);
$this->assertSame(defset($label, $label), $result);
}
}
function testGetFieldAttibute()
{
foreach($this->structValues as $field=>$val)
{
$result = $this->ue->getFieldAttribute('user_'.$field,'values');
$this->assertSame($val, $result);
}
}
/*
public function testUser_extended_getvalue()
{
@ -357,6 +413,78 @@
$this->assertEquals($expected, $result);
}
public function testGetCategoryAttribute()
{
$result = $this->ue->getCategoryAttribute('mycategory', 'read');
$this->assertSame(e_UC_PUBLIC, $result);
$result = $this->ue->getCategoryAttribute('mycategory', 'write');
$this->assertSame(e_UC_ADMIN, $result);
$result = $this->ue->getCategoryAttribute('user_text', 'read');
$this->assertSame(false, $result);
$result = $this->ue->getCategoryAttribute('not-a-category', 'read');
$this->assertSame(false, $result);
}
public function testGetCategories()
{
$expected = array (
0 =>
array (
// 'user_extended_struct_id' => '16',
'user_extended_struct_name' => 'mycategory',
'user_extended_struct_text' => 'Category Name',
'user_extended_struct_type' => '0',
'user_extended_struct_parms' => '',
'user_extended_struct_values' => '',
'user_extended_struct_default' => '',
'user_extended_struct_read' => '0',
'user_extended_struct_write' => '254',
'user_extended_struct_required' => '0',
'user_extended_struct_signup' => '0',
'user_extended_struct_applicable' => '253',
'user_extended_struct_order' => '0',
'user_extended_struct_parent' => '0',
),
1 =>
array (
// 'user_extended_struct_id' => '17',
'user_extended_struct_name' => 'mycategory2',
'user_extended_struct_text' => 'Category Name 2',
'user_extended_struct_type' => '0',
'user_extended_struct_parms' => '',
'user_extended_struct_values' => '',
'user_extended_struct_default' => '',
'user_extended_struct_read' => '254',
'user_extended_struct_write' => '254',
'user_extended_struct_required' => '0',
'user_extended_struct_signup' => '0',
'user_extended_struct_applicable' => '253',
'user_extended_struct_order' => '0',
'user_extended_struct_parent' => '0',
),
);
$result = $this->ue->getCategories(false);
$this->assertNotEmpty($result);
$id = 0;
foreach($result as $row)
{
unset($row['user_extended_struct_id']);
$this->assertSame($expected[$id], $row);
$id++;
}
}
/*
public function testUser_extended_edit()
{
@ -397,12 +525,92 @@
{
}
*/
public function testUser_extended_get_categories()
{
$expected = array (
'mycategory' =>
array (
'user_extended_struct_name' => 'mycategory',
'user_extended_struct_text' => 'Category Name',
'user_extended_struct_type' => '0',
'user_extended_struct_parms' => '',
'user_extended_struct_values' => '',
'user_extended_struct_default' => '',
'user_extended_struct_read' => '0',
'user_extended_struct_write' => '254',
'user_extended_struct_required' => '0',
'user_extended_struct_signup' => '0',
'user_extended_struct_applicable' => '253',
'user_extended_struct_order' => '0',
'user_extended_struct_parent' => '0',
),
'mycategory2' =>
array (
'user_extended_struct_name' => 'mycategory2',
'user_extended_struct_text' => 'Category Name 2',
'user_extended_struct_type' => '0',
'user_extended_struct_parms' => '',
'user_extended_struct_values' => '',
'user_extended_struct_default' => '',
'user_extended_struct_read' => '254',
'user_extended_struct_write' => '254',
'user_extended_struct_required' => '0',
'user_extended_struct_signup' => '0',
'user_extended_struct_applicable' => '253',
'user_extended_struct_order' => '0',
'user_extended_struct_parent' => '0',
),
);
// Test 1.
$result = $this->compileCategoryResult($this->ue->user_extended_get_categories());
$this->assertNotEmpty($result);
$this->assertEquals($expected, $result);
// Test 2
$result = $this->compileCategoryResult($this->ue->user_extended_get_categories(false), false);
$this->assertNotEmpty($result);
$this->assertEquals($expected, $result);
}
/**
* Remove ID since it could change during testing.
* @param array $result
*/
private function compileCategoryResult($result, $other=true)
{
if(empty($result))
{
return array();
}
$myresult = [];
if($other === false)
{
$result = array($result);
}
foreach($result as $row)
{
foreach($row as $arr)
{
unset($arr['user_extended_struct_id']);
$id = (string) $arr['user_extended_struct_name'];
foreach($arr as $field=>$val)
{
$myresult[$id][$field] = $val;
}
}
}
return $myresult;
}
/*
public function testAddDefaultFields()
{