1
0
mirror of https://github.com/e107inc/e107.git synced 2025-08-06 14:46:56 +02:00

Added more custom field tests.

This commit is contained in:
Cameron
2020-12-25 10:31:42 -08:00
parent 7dfac0dcfa
commit d890163836
3 changed files with 139 additions and 70 deletions

View File

@@ -29,10 +29,10 @@
private $_tab_default = 'additional'; private $_tab_default = 'additional';
function __construct() public function __construct()
{ {
asort($this->_fieldTypes); asort($this->_fieldTypes);
$this->_tab = array($this->_tab_default => "Additional"); $this->_tab = array($this->_tab_default => 'Additional');
} }
@@ -145,112 +145,125 @@
switch($fieldType) switch($fieldType)
{ {
case "dropdown": case 'dropdown':
case "checkboxes": case 'checkboxes':
case "radio": case 'radio':
return ($raw) ? $value : e107::getForm()->renderValue($key,$value,$this->_config[$key]); $ret = ($raw) ? $value : e107::getForm()->renderValue($key,$value,$this->_config[$key]);
break; break;
case "video": case 'video':
if(empty($value)) if(empty($value))
{ {
return null; $ret = null;
}
else
{
$ret = ($raw) ? 'https://www.youtube.com/watch?v='.str_replace('.youtube', '', $value) : $tp->toVideo($value);
} }
return ($raw) ? 'https://www.youtube.com/watch?v='.str_replace(".youtube", '', $value) : $tp->toVideo($value);
break; break;
case "image": case 'image':
return ($raw) ? $tp->thumbUrl($value,$parm) : $tp->toImage($value,$parm); $ret = ($raw) ? $tp->thumbUrl($value,$parm) : $tp->toImage($value,$parm);
break; break;
case "icon": case 'icon':
return ($raw) ? str_replace(".glyph", '', $value) : $tp->toIcon($value); $ret = ($raw) ? str_replace('.glyph', '', $value) : $tp->toIcon($value);
break; break;
case "country": case 'country':
return ($raw) ? $value : e107::getForm()->getCountry($value); $ret = ($raw) ? $value : e107::getForm()->getCountry($value);
break; break;
case "tags": case 'tags':
return ($raw) ? $value : $tp->toLabel($value,$type); $ret = ($raw) ? $value : $tp->toLabel($value,$type);
break; break;
case "lanlist": case 'lanlist':
case "language": case 'language':
return ($raw) ? $value : e107::getLanguage()->convert($value); $ret = ($raw) ? $value : e107::getLanguage()->convert($value);
break; break;
case "datestamp": case 'datestamp':
return ($raw) ? $value : $tp->toDate($value); $ret = ($raw) ? $value : $tp->toDate($value);
break; break;
case "file": case 'file':
if(empty($value)) if(empty($value))
{ {
return null; $ret = null;
}
else
{
$ret = ($raw) ? $tp->toFile($value, array('raw'=>1)) : $tp->toFile($value);
} }
return ($raw) ? $tp->toFile($value, array('raw'=>1)) : $tp->toFile($value);
break; break;
case "url": case 'url':
case "email": case 'email':
return ($raw) ? $value : $tp->toHTML($value); $ret = ($raw) ? $value : $tp->toHTML($value);
break; break;
case "user": case 'user':
return ($raw) ? $value : e107::getSystemUser($value,true)->getName(); $ret = ($raw) ? $value : e107::getSystemUser($value,true)->getName();
break; break;
case "userclass": case 'userclass':
return ($raw) ? $value : e107::getUserClass()->getName($value); $ret = ($raw) ? $value : e107::getUserClass()->getName($value);
break; break;
case "progressbar": case 'progressbar':
if($raw) if($raw)
{ {
return (strpos($value, '/') === false) ? $value.'%' : $value; $ret = (strpos($value, '/') === false) ? $value.'%' : $value;
}
else
{
$ret = e107::getForm()->progressBar($key,$value,$this->_config[$key]);
} }
return e107::getForm()->progressBar($key,$value,$this->_config[$key]);
break; break;
case "textarea": case 'textarea':
case "bbarea": case 'bbarea':
return $tp->toHTML($value, true, "BODY"); $ret = $tp->toHTML($value, true, 'BODY');
break; break;
case "boolean": case 'boolean':
if($raw) if($raw)
{ {
return $value; return $value;
} }
else
return empty($value) ? $tp->toGlyph('fa-times') : $tp->toGlyph('fa-check'); {
$ret = empty($value) ? $tp->toGlyph('fa-times') : $tp->toGlyph('fa-check');
}
break; break;
case "checkbox": case 'checkbox':
if($raw) if($raw)
{ {
return $value; $ret = $value;
} }
elseif(is_numeric($value))
if(is_numeric($value))
{ {
return empty($value) ? $tp->toGlyph('fa-times') : $tp->toGlyph('fa-check'); $ret = empty($value) ? $tp->toGlyph('fa-times') : $tp->toGlyph('fa-check');
}
else
{
$ret = $value;
} }
return $value;
break; break;
default: default:
return $tp->toHTML($value); $ret = $tp->toHTML($value);
} }
return $ret;
} }
@@ -263,10 +276,10 @@
foreach($this->_data as $ok=>$v) foreach($this->_data as $ok=>$v)
{ {
$text .= "<tr><td>".$ok."</td><td>".$this->getFieldTitle($ok)."</td><td>".$this->getFieldValue($ok)."</td><td>".$this->getFieldValue($ok, array('mode'=>'raw'))."</td></tr>"; $text .= '<tr><td>' .$ok. '</td><td>' .$this->getFieldTitle($ok). '</td><td>' .$this->getFieldValue($ok). '</td><td>' .$this->getFieldValue($ok, array('mode' =>'raw')). '</td></tr>';
} }
$text .= "</table>"; $text .= '</table>';
return $text; return $text;
@@ -310,7 +323,7 @@
$text = " $text = "
<div class='form-group'> <div class='form-group'>
".$frm->text('__e_customfields_tabs__', $this->_tab[$this->_tab_default], 30, array('placeholder'=>"Tab label",'size'=>'medium', 'required'=>1))." ".$frm->text('__e_customfields_tabs__', $this->_tab[$this->_tab_default], 30, array('placeholder' => 'Tab label', 'size' =>'medium', 'required' =>1))."
</div> </div>
<table class='table table-striped table-bordered'> <table class='table table-striped table-bordered'>
<colgroup> <colgroup>
@@ -320,8 +333,8 @@
<col style='width:40%' /> <col style='width:40%' />
</colgroup> </colgroup>
<tbody> <tbody>
<tr><th>".LAN_NAME."</th><th>".LAN_TITLE."</th><th>".LAN_TYPE."</th><th>Params</th><th>".LAN_TOOLTIP."</th></tr> <tr><th>".LAN_NAME. '</th><th>' .LAN_TITLE. '</th><th>' .LAN_TYPE. '</th><th>Params</th><th>' .LAN_TOOLTIP. '</th></tr>
"; ';
for($i = 0; $i <= $this->_field_limit; $i++) for($i = 0; $i <= $this->_field_limit; $i++)
{ {
@@ -343,10 +356,10 @@
$fieldType = $frm->select($name . '[' . $i . '][type]', $this->getFieldTypes(), varset($value[$i]['type']), $writeParms); $fieldType = $frm->select($name . '[' . $i . '][type]', $this->getFieldTypes(), varset($value[$i]['type']), $writeParms);
$fieldParms = $frm->text($name . '[' . $i . '][writeParms]', varset($value[$i]['writeParms']), 255, $parmsWriteParms); $fieldParms = $frm->text($name . '[' . $i . '][writeParms]', varset($value[$i]['writeParms']), 255, $parmsWriteParms);
$fieldHelp = $frm->text($name . '[' . $i . '][help]', varset($value[$i]['help']), 255, array('size' => 'block-level')); $fieldHelp = $frm->text($name . '[' . $i . '][help]', varset($value[$i]['help']), 255, array('size' => 'block-level'));
$text .= "<tr><td>" . $fieldName . "</td><td>" . $fieldTitle . "</td><td>" . $fieldType . "</td><td>" . $fieldParms . "</td><td>" . $fieldHelp . "</td></tr>"; $text .= '<tr><td>' . $fieldName . '</td><td>' . $fieldTitle . '</td><td>' . $fieldType . '</td><td>' . $fieldParms . '</td><td>' . $fieldHelp . '</td></tr>';
} }
$text .= "</tbody></table>"; $text .= '</tbody></table>';
return $text; return $text;
@@ -362,13 +375,13 @@
{ {
switch($type) switch($type)
{ {
case "radio": case 'radio':
case "dropdown": case 'dropdown':
case "checkboxes": case 'checkboxes':
return 'eg. { "optArray": { "blue": "Blue", "green": "Green", "red": "Red" }, "default": "blank" }'; return 'eg. { "optArray": { "blue": "Blue", "green": "Green", "red": "Red" }, "default": "blank" }';
break; break;
case "datestamp": case 'datestamp':
return 'eg. (Optional) { "format": "yyyy-mm-dd" }'; return 'eg. (Optional) { "format": "yyyy-mm-dd" }';
break; break;
@@ -405,7 +418,7 @@
if($fld['type'] === 'icon') if($fld['type'] === 'icon')
{ {
$fld['writeParms'] .= "&glyphs=1"; $fld['writeParms'] .= '&glyphs=1';
} }
if($fld['type'] === 'checkboxes') if($fld['type'] === 'checkboxes')
@@ -525,7 +538,7 @@
{ {
if(substr($k,0,$len) === $fieldname) if(substr($k,0,$len) === $fieldname)
{ {
list($tmp,$newkey) = explode("__",$k); list($tmp,$newkey) = explode('__',$k);
$new_data[$fieldname][$newkey] = $v; $new_data[$fieldname][$newkey] = $v;
unset($new_data[$k]); unset($new_data[$k]);

View File

@@ -32,7 +32,14 @@ function mimeFromFilename($fileName)
return "Content-type: image/".$mimeTypes[$fileExt]; return "Content-type: image/".$mimeTypes[$fileExt];
} }
/**
* @deprecated To be replaced with e107::getMedia()->resizeImage();
* @param string $source_file
* @param string $destination_file
* @param string $type
* @param string $model
* @return bool
*/
function resize_image($source_file, $destination_file, $type = "upload", $model = "") function resize_image($source_file, $destination_file, $type = "upload", $model = "")
{ {
// $destination_file - 'stdout' sends direct to browser. Otherwise treated as file name // $destination_file - 'stdout' sends direct to browser. Otherwise treated as file name

View File

@@ -225,6 +225,58 @@
20 => 'Progress Bar', 20 => 'Progress Bar',
); );
$expectedValues = array (
'image' => '<img class="img-responsive img-fluid"',
'video' => '<div class="embed-responsive embed-responsive-16by9',
'bbarea' => '<!-- bbcode-html-start --><p><b>Rich text.</b></p><!-- bbcode-html-end -->',
'boolean' => '<i class',
'checkboxes' => 'Boat, Plane',
'country' => 'Andorra',
'datestamp' => '<span>13 Jan 2017 : 00:35</span>',
'dropdown' => 'Red',
'email' => 'my@email.com',
'file' => '<a href=',
'icon' => '<i class=',
'language' => 'French',
'lanlist' => 'English',
'number' => '0',
'password' => 'a8f5f167f44f4964e6c998dee827110c',
'tags' => "<span class='label label-default'",
'textarea' => 'Plain text',
'url' => 'http://something.com',
'user' => 'e107',
'userclass' => 'Everyone (public)',
'progressbar' => "<div class='progress",
);
$expectedRawValues = array (
'image' => 'thumb.php?src=',
'video' => 'https://www.youtube.com/watch?v=WcuRPzB4RNc',
'bbarea' => '<!-- bbcode-html-start --><p><b>Rich text.</b></p><!-- bbcode-html-end -->',
'boolean' => '1',
'checkboxes' => 'boat,plane',
'country' => 'ad',
'datestamp' => '1484267751',
'dropdown' => 'red',
'email' => 'my@email.com',
'file' => 'e107_banners.zip',
'icon' => 'fa-check',
'language' => 'fr',
'lanlist' => 'en',
'number' => '0',
'password' => 'a8f5f167f44f4964e6c998dee827110c',
'tags' => 'tag1,tag2,tag3',
'textarea' => 'Plain text',
'url' => 'http://something.com',
'user' => '1',
'userclass' => '0',
'progressbar' => '75%',
);
$export = array();
foreach($data as $ok=>$v) foreach($data as $ok=>$v)
{ {
@@ -232,17 +284,14 @@
// echo ($title)."\n"; // echo ($title)."\n";
$value = $this->cf->getFieldValue($ok); $value = $this->cf->getFieldValue($ok);
$valueRaw = $this->cf->getFieldValue($ok, array('mode'=>'raw')); $valueRaw = $this->cf->getFieldValue($ok, array('mode'=>'raw'));
$this->assertStringStartsWith($expectedValues[$ok], $value);
$this->assertStringContainsString($expectedRawValues[$ok], $valueRaw);
} }
// check titles. // check titles.
$this->assertEquals($titlesExpected,$titles); $this->assertEquals($titlesExpected,$titles);
//@todo more tests for value and valueRaw.
} }