Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions tests/phpunit/base/frm_factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,21 @@ public function get_fields_from_form( $form_id ) {
* @return mixed
*/
public function set_field_value( $field ) {
if ( in_array( $field->type, array( 'checkbox', 'select', 'radio' ), true ) ) {
if ( ! $field->options ) {
return '';
}

// If checkbox, dropdown or radio field, return a random choice from the options.
$random_option = $field->options[ array_rand( $field->options ) ];

if ( FrmField::is_option_true( $field, 'separate_value' ) ) {
return $random_option['value'];
}

return $random_option;
}

$value = rand_str();
$field_values = array(
'email' => 'admin@example.org',
Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/base/testdata.xml
Original file line number Diff line number Diff line change
Expand Up @@ -791,7 +791,7 @@
<form_id>698</form_id>
<required></required>
<options><![CDATA[]]></options>
<field_options><![CDATA[{"size":"","max":"10","label":"","blank":"This field cannot be blank.","required_indicator":"*","invalid":"Date is invalid","separate_value":0,"clear_on_focus":0,"default_blank":0,"classes":"","custom_html":"<div id=\"frm_field_[id]_container\" class=\"frm_form_field form-field [required_class][error_class]\">\n <label for=\"field_[key]\" class=\"frm_primary_label\">[field_name]\n <span class=\"frm_required\">[required_label]<\/span>\n <\/label>\n [input]\n [if description]<div class=\"frm_description\">[description]<\/div>[\/if description]\n [if error]<div class=\"frm_error\">[error]<\/div>[\/if error]\n<\/div>","slide":0,"form_select":"","show_hide":"show","any_all":"any","align":"block","hide_field":[],"hide_field_cond":["=="],"hide_opt":[],"star":0,"ftypes":[],"data_type":"select","restrict":0,"start_year":"2000","end_year":"2020","read_only":0,"admin_only":"","locale":"","attach":false,"minnum":0,"maxnum":9999,"step":1,"clock":12,"start_time":"00:00","end_time":"23:59","unique":0,"use_calc":0,"calc":"","calc_dec":"","dyn_default_value":"","multiple":0,"unique_msg":"","autocom":0,"format":"","repeat":0,"add_label":"Add","remove_label":"Remove","conf_field":"","conf_input":"","conf_desc":"","conf_msg":"The entered values do not match","other":0}]]></field_options>
<field_options><![CDATA[{"size":"","max":"10","label":"","blank":"This field cannot be blank.","required_indicator":"*","invalid":"Date is invalid","separate_value":0,"clear_on_focus":0,"default_blank":0,"classes":"","custom_html":"<div id=\"frm_field_[id]_container\" class=\"frm_form_field form-field [required_class][error_class]\">\n <label for=\"field_[key]\" class=\"frm_primary_label\">[field_name]\n <span class=\"frm_required\">[required_label]<\/span>\n <\/label>\n [input]\n [if description]<div class=\"frm_description\">[description]<\/div>[\/if description]\n [if error]<div class=\"frm_error\">[error]<\/div>[\/if error]\n<\/div>","slide":0,"form_select":"","show_hide":"show","any_all":"any","align":"block","hide_field":[],"hide_field_cond":["=="],"hide_opt":[],"star":0,"ftypes":[],"data_type":"select","restrict":0,"start_year":"2000","end_year":"2050","read_only":0,"admin_only":"","locale":"","attach":false,"minnum":0,"maxnum":9999,"step":1,"clock":12,"start_time":"00:00","end_time":"23:59","unique":0,"use_calc":0,"calc":"","calc_dec":"","dyn_default_value":"","multiple":0,"unique_msg":"","autocom":0,"format":"","repeat":0,"add_label":"Add","remove_label":"Remove","conf_field":"","conf_input":"","conf_desc":"","conf_msg":"The entered values do not match","other":0}]]></field_options>
</field>
<field>
<id>8117</id>
Expand Down
Loading