HTML-FormFu-2.07/0000775000175100017520000000000013404751171012036 5ustar carlcarlHTML-FormFu-2.07/dist.ini0000644000175100017520000000636513404751171013512 0ustar carlcarlname = HTML-FormFu author = Carl Franks license = Perl_5 copyright_holder = Carl Franks copyright_year = 2018 main_module = lib/HTML/FormFu.pm [Prereqs] ;;; Although we believe this will work on perl 5.8 versions, other dependancies ;;; such as Number::Format have been forcing a minimum version of 5.10 since ;;; 2011. Testing new versions against 5.8.x is getting impractical ;;perl = 5.008001 perl = 5.010 ; this is the lowest version of Exporter I can identify that exports import() ; it's bundled with perl 5.83 ; version 5.567 that ships with perl 5.82 is no good Exporter = 5.57 Carp = 0 Class::MOP::Method = 0 Clone = 0.31 Config::Any = 0.18 ; 0.10 - supports multi-doc config files ; 0.18 - prefers YAML::XS for YAML Cwd = 0 Data::Visitor = 0.26 ; when it dumped Any::Moose for Moose Data::Visitor::Callback = 0 DateTime = 0.54 ; required for string overloading DateTime::Format::Strptime = 1.2000 DateTime::Format::Builder = 0.7901 ; fixes memory leaks DateTime::Format::Natural = 0 DateTime::Locale = 0.45 Email::Valid = 0 Encode = 0 Fatal = 0 File::Copy = 0 File::Find = 0 File::ShareDir = 0 File::Spec = 0 File::Temp = 0 Hash::Flatten = 0 HTML::Scrubber = 0 HTML::TokeParser::Simple = 3.14 HTTP::Headers = 1.64 IO::File = 0 JSON::MaybeXS = 0 List::MoreUtils = 0 List::Util = 1.45 Locale::Maketext = 0 Module::Pluggable = 0 Moose = 1.00 ; Reasonable default until we get test results Moose::Role = 0 Moose::Util = 0 MooseX::Aliases = 0 MooseX::Attribute::Chained = 1.0.2 Number::Format = 0 Readonly = 0 Regexp::Common = 0 Path::Class::File = 0 Scalar::Util = 0 Storable = 0 Task::Weaken = 0 ; to ensure Scalar::Util was built with weaken() YAML::XS = 0.32 [Prereqs / TestRequires] CGI = 3.37 ; for file POST tests POSIX = 0 Regexp::Assemble = 0 Test::More = 0.92 Test::Exception = 0 Test::Memory::Cycle = 0 ; for the xt/circular_reference.t Test::RequiresInternet = 0 ;; -- ;; -- Sets of additional tests we want to do as part of release [Test::Perl::Critic] [MetaTests] ;; [PodCoverageTests] ; Currently we comprehensively fail these [PkgVersion] ; [PodVersion] ; PodWeaver does this and more [PodWeaver] [Test::Kwalitee] [Test::EOL] finder = :InstallModules ; prevents test inputs being flagged [Test::PAUSE::Permissions] ; if doing a release make sure we have PAUSE perms ;; -- Additional information [GithubMeta] ; Grab the repo metadata [NextRelease] ; Mark up the next release in changes ;; -- Additional git [Git::GatherDir] [Git::NextVersion] ; Get the next version tag from git [Git::CheckFor::CorrectBranch] ; ensure on master branch for release [Git::Remote::Check] ; ensure our branch is ahead of remote ;; -- We base the release stuff on the starter module, and tweak a bit [@Starter] -remove = GatherDir ; this is replaced by [Git::GatherDir] ReadmeAnyFromPod.source_filename = lib/HTML/FormFu.pm [ReadmeAnyFromPod / Pod_Readme] type = pod location = root ; do not include pod readmes in the build! [@Git] changelog = Changes allow_dirty = dist.ini allow_dirty = README.pod allow_dirty = Changes commit_msg = v%v%t - %d%n%n%c tag_format = v%v%t ; see Git::Tag tag_message = v%v%t - %d ; see Git::Tag HTML-FormFu-2.07/MANIFEST0000644000175100017520000006672313404751171013203 0ustar carlcarl# This file was automatically generated by Dist::Zilla::Plugin::Manifest v6.011. Changes LICENSE MANIFEST MANIFEST.SKIP META.json META.yml Makefile.PL README bin/html_formfu_deploy.pl bin/html_formfu_dumpconf.pl dist.ini examples/unicode/Changes examples/unicode/Makefile.PL examples/unicode/README examples/unicode/database.sql examples/unicode/lib/unicode.pm examples/unicode/lib/unicode/Controller/Root.pm examples/unicode/lib/unicode/Model/DB.pm examples/unicode/lib/unicode/Schema.pm examples/unicode/lib/unicode/Schema/Unicode.pm examples/unicode/lib/unicode/View/TT.pm examples/unicode/lib/unicode/View/TT/Alloy.pm examples/unicode/root/favicon.ico examples/unicode/root/formfu/block examples/unicode/root/formfu/checkboxgroup examples/unicode/root/formfu/checkboxgroup_tag examples/unicode/root/formfu/content_button examples/unicode/root/formfu/end_block examples/unicode/root/formfu/end_form examples/unicode/root/formfu/field examples/unicode/root/formfu/form examples/unicode/root/formfu/input examples/unicode/root/formfu/input_tag examples/unicode/root/formfu/label examples/unicode/root/formfu/multi examples/unicode/root/formfu/non_block examples/unicode/root/formfu/recaptcha examples/unicode/root/formfu/repeatable examples/unicode/root/formfu/select_tag examples/unicode/root/formfu/start_block examples/unicode/root/formfu/start_form examples/unicode/root/formfu/textarea_tag examples/unicode/root/forms/index.yml examples/unicode/root/forms/view.conf examples/unicode/root/forms/view.yml examples/unicode/root/index.tt examples/unicode/root/static/images/btn_120x50_built.png examples/unicode/root/static/images/btn_120x50_built_shadow.png examples/unicode/root/static/images/btn_120x50_powered.png examples/unicode/root/static/images/btn_120x50_powered_shadow.png examples/unicode/root/static/images/btn_88x31_built.png examples/unicode/root/static/images/btn_88x31_built_shadow.png examples/unicode/root/static/images/btn_88x31_powered.png examples/unicode/root/static/images/btn_88x31_powered_shadow.png examples/unicode/root/static/images/catalyst_logo.png examples/unicode/root/vertically-aligned.css examples/unicode/root/view.tt examples/unicode/script/unicode_cgi.pl examples/unicode/script/unicode_create.pl examples/unicode/script/unicode_fastcgi.pl examples/unicode/script/unicode_server.pl examples/unicode/script/unicode_test.pl examples/unicode/t/01app.t examples/unicode/t/02pod.t examples/unicode/t/03podcoverage.t examples/unicode/t/model_DB.t examples/unicode/t/view_TT-Alloy.t examples/unicode/t/view_TT.t examples/unicode/unicode.db examples/unicode/unicode.yml examples/vertically-aligned-css/test.jpg examples/vertically-aligned-css/vertically-aligned-ie.css examples/vertically-aligned-css/vertically-aligned.css examples/vertically-aligned-css/vertically-aligned.html examples/vertically-aligned-css/vertically-aligned.pl examples/vertically-aligned-css/vertically-aligned.tt examples/vertically-aligned-css/vertically-aligned.yml lib/HTML/FormFu.pm lib/HTML/FormFu/Attribute.pm lib/HTML/FormFu/Constants.pm lib/HTML/FormFu/Constraint.pm lib/HTML/FormFu/Constraint/ASCII.pm lib/HTML/FormFu/Constraint/AllOrNone.pm lib/HTML/FormFu/Constraint/AutoSet.pm lib/HTML/FormFu/Constraint/Bool.pm lib/HTML/FormFu/Constraint/Callback.pm lib/HTML/FormFu/Constraint/CallbackOnce.pm lib/HTML/FormFu/Constraint/DateTime.pm lib/HTML/FormFu/Constraint/DependOn.pm lib/HTML/FormFu/Constraint/Email.pm lib/HTML/FormFu/Constraint/Equal.pm lib/HTML/FormFu/Constraint/File.pm lib/HTML/FormFu/Constraint/File/MIME.pm lib/HTML/FormFu/Constraint/File/MaxSize.pm lib/HTML/FormFu/Constraint/File/MinSize.pm lib/HTML/FormFu/Constraint/File/Size.pm lib/HTML/FormFu/Constraint/Integer.pm lib/HTML/FormFu/Constraint/JSON.pm lib/HTML/FormFu/Constraint/Length.pm lib/HTML/FormFu/Constraint/MaxLength.pm lib/HTML/FormFu/Constraint/MaxRange.pm lib/HTML/FormFu/Constraint/MinLength.pm lib/HTML/FormFu/Constraint/MinMaxFields.pm lib/HTML/FormFu/Constraint/MinRange.pm lib/HTML/FormFu/Constraint/Number.pm lib/HTML/FormFu/Constraint/Printable.pm lib/HTML/FormFu/Constraint/Range.pm lib/HTML/FormFu/Constraint/Regex.pm lib/HTML/FormFu/Constraint/Repeatable/Any.pm lib/HTML/FormFu/Constraint/Required.pm lib/HTML/FormFu/Constraint/Set.pm lib/HTML/FormFu/Constraint/SingleValue.pm lib/HTML/FormFu/Constraint/Word.pm lib/HTML/FormFu/Deflator.pm lib/HTML/FormFu/Deflator/Callback.pm lib/HTML/FormFu/Deflator/CompoundDateTime.pm lib/HTML/FormFu/Deflator/CompoundSplit.pm lib/HTML/FormFu/Deflator/FormatNumber.pm lib/HTML/FormFu/Deflator/PathClassFile.pm lib/HTML/FormFu/Deflator/Strftime.pm lib/HTML/FormFu/Deploy.pm lib/HTML/FormFu/Element.pm lib/HTML/FormFu/Element/Blank.pm lib/HTML/FormFu/Element/Block.pm lib/HTML/FormFu/Element/Button.pm lib/HTML/FormFu/Element/Checkbox.pm lib/HTML/FormFu/Element/Checkboxgroup.pm lib/HTML/FormFu/Element/ComboBox.pm lib/HTML/FormFu/Element/ContentButton.pm lib/HTML/FormFu/Element/Date.pm lib/HTML/FormFu/Element/DateTime.pm lib/HTML/FormFu/Element/Email.pm lib/HTML/FormFu/Element/Fieldset.pm lib/HTML/FormFu/Element/File.pm lib/HTML/FormFu/Element/Hidden.pm lib/HTML/FormFu/Element/Hr.pm lib/HTML/FormFu/Element/Image.pm lib/HTML/FormFu/Element/Label.pm lib/HTML/FormFu/Element/Multi.pm lib/HTML/FormFu/Element/Number.pm lib/HTML/FormFu/Element/Password.pm lib/HTML/FormFu/Element/Radio.pm lib/HTML/FormFu/Element/Radiogroup.pm lib/HTML/FormFu/Element/Repeatable.pm lib/HTML/FormFu/Element/Reset.pm lib/HTML/FormFu/Element/Select.pm lib/HTML/FormFu/Element/SimpleTable.pm lib/HTML/FormFu/Element/Src.pm lib/HTML/FormFu/Element/Submit.pm lib/HTML/FormFu/Element/Text.pm lib/HTML/FormFu/Element/Textarea.pm lib/HTML/FormFu/Element/URL.pm lib/HTML/FormFu/Exception.pm lib/HTML/FormFu/Exception/Constraint.pm lib/HTML/FormFu/Exception/Inflator.pm lib/HTML/FormFu/Exception/Input.pm lib/HTML/FormFu/Exception/Transformer.pm lib/HTML/FormFu/Exception/Validator.pm lib/HTML/FormFu/FakeQuery.pm lib/HTML/FormFu/Filter.pm lib/HTML/FormFu/Filter/Callback.pm lib/HTML/FormFu/Filter/CompoundJoin.pm lib/HTML/FormFu/Filter/CompoundSprintf.pm lib/HTML/FormFu/Filter/CopyValue.pm lib/HTML/FormFu/Filter/Encode.pm lib/HTML/FormFu/Filter/ForceListValue.pm lib/HTML/FormFu/Filter/FormatNumber.pm lib/HTML/FormFu/Filter/HTMLEscape.pm lib/HTML/FormFu/Filter/HTMLScrubber.pm lib/HTML/FormFu/Filter/LowerCase.pm lib/HTML/FormFu/Filter/NonNumeric.pm lib/HTML/FormFu/Filter/Regex.pm lib/HTML/FormFu/Filter/Split.pm lib/HTML/FormFu/Filter/TrimEdges.pm lib/HTML/FormFu/Filter/UpperCase.pm lib/HTML/FormFu/Filter/Whitespace.pm lib/HTML/FormFu/I18N.pm lib/HTML/FormFu/I18N/bg.pm lib/HTML/FormFu/I18N/cs.pm lib/HTML/FormFu/I18N/da.pm lib/HTML/FormFu/I18N/de.pm lib/HTML/FormFu/I18N/en.pm lib/HTML/FormFu/I18N/es.pm lib/HTML/FormFu/I18N/fr.pm lib/HTML/FormFu/I18N/hu.pm lib/HTML/FormFu/I18N/it.pm lib/HTML/FormFu/I18N/ja.pm lib/HTML/FormFu/I18N/no.pm lib/HTML/FormFu/I18N/pt_br.pm lib/HTML/FormFu/I18N/pt_pt.pm lib/HTML/FormFu/I18N/ro.pm lib/HTML/FormFu/I18N/ru.pm lib/HTML/FormFu/I18N/tr.pm lib/HTML/FormFu/I18N/ua.pm lib/HTML/FormFu/I18N/zh_cn.pm lib/HTML/FormFu/Inflator.pm lib/HTML/FormFu/Inflator/Callback.pm lib/HTML/FormFu/Inflator/CompoundDateTime.pm lib/HTML/FormFu/Inflator/DateTime.pm lib/HTML/FormFu/Literal.pm lib/HTML/FormFu/Localize.pm lib/HTML/FormFu/Manual/Cookbook.pod lib/HTML/FormFu/Manual/Unicode.pod lib/HTML/FormFu/Model.pm lib/HTML/FormFu/Model/HashRef.pm lib/HTML/FormFu/ObjectUtil.pm lib/HTML/FormFu/OutputProcessor.pm lib/HTML/FormFu/OutputProcessor/Indent.pm lib/HTML/FormFu/OutputProcessor/StripWhitespace.pm lib/HTML/FormFu/Plugin.pm lib/HTML/FormFu/Plugin/StashValid.pm lib/HTML/FormFu/Preload.pm lib/HTML/FormFu/Processor.pm lib/HTML/FormFu/QueryType/CGI.pm lib/HTML/FormFu/QueryType/CGI/Simple.pm lib/HTML/FormFu/QueryType/Catalyst.pm lib/HTML/FormFu/Role/Constraint/Others.pm lib/HTML/FormFu/Role/ContainsElements.pm lib/HTML/FormFu/Role/ContainsElementsSharedWithField.pm lib/HTML/FormFu/Role/CreateChildren.pm lib/HTML/FormFu/Role/CustomRoles.pm lib/HTML/FormFu/Role/Element/Coercible.pm lib/HTML/FormFu/Role/Element/Field.pm lib/HTML/FormFu/Role/Element/FieldMethods.pm lib/HTML/FormFu/Role/Element/Group.pm lib/HTML/FormFu/Role/Element/Input.pm lib/HTML/FormFu/Role/Element/Layout.pm lib/HTML/FormFu/Role/Element/MultiElement.pm lib/HTML/FormFu/Role/Element/NonBlock.pm lib/HTML/FormFu/Role/Element/ProcessOptionsFromModel.pm lib/HTML/FormFu/Role/Element/SingleValueField.pm lib/HTML/FormFu/Role/Filter/Compound.pm lib/HTML/FormFu/Role/FormAndBlockMethods.pm lib/HTML/FormFu/Role/FormAndElementMethods.pm lib/HTML/FormFu/Role/FormBlockAndFieldMethods.pm lib/HTML/FormFu/Role/GetProcessors.pm lib/HTML/FormFu/Role/HasParent.pm lib/HTML/FormFu/Role/NestedHashUtils.pm lib/HTML/FormFu/Role/Populate.pm lib/HTML/FormFu/Role/Render.pm lib/HTML/FormFu/Transformer.pm lib/HTML/FormFu/Transformer/Callback.pm lib/HTML/FormFu/Upload.pm lib/HTML/FormFu/UploadParam.pm lib/HTML/FormFu/Util.pm lib/HTML/FormFu/Validator.pm lib/HTML/FormFu/Validator/Callback.pm share/templates/tt/xhtml/block share/templates/tt/xhtml/end_block share/templates/tt/xhtml/end_form share/templates/tt/xhtml/field share/templates/tt/xhtml/field_layout share/templates/tt/xhtml/field_layout_block share/templates/tt/xhtml/field_layout_checkboxgroup_field share/templates/tt/xhtml/field_layout_comment share/templates/tt/xhtml/field_layout_contentbutton_field share/templates/tt/xhtml/field_layout_errors share/templates/tt/xhtml/field_layout_field share/templates/tt/xhtml/field_layout_javascript share/templates/tt/xhtml/field_layout_label share/templates/tt/xhtml/field_layout_label_field share/templates/tt/xhtml/field_layout_label_text share/templates/tt/xhtml/field_layout_multi_field share/templates/tt/xhtml/field_layout_parser share/templates/tt/xhtml/field_layout_select_field share/templates/tt/xhtml/field_layout_textarea_field share/templates/tt/xhtml/form share/templates/tt/xhtml/non_block share/templates/tt/xhtml/recaptcha share/templates/tt/xhtml/repeatable share/templates/tt/xhtml/start_block share/templates/tt/xhtml/start_form t/00-report-prereqs.dd t/00-report-prereqs.t t/01use.t t/04basic.t t/04basic.yml t/05_repeated_render.t t/block_insert_after.t t/block_insert_before.t t/bugs/constructor_arg_overwrites_default.t t/bugs/date_element_deflator.t t/bugs/date_element_empty_input.t t/bugs/datetime_hour_lt_10.t t/bugs/disabled_select_default_value.yml t/bugs/element_class.t t/bugs/element_parent.t t/bugs/empty_block_with_nested_name.t t/bugs/empty_block_with_nested_name.yml t/bugs/error_msg.t t/bugs/error_multiple_fields_same_name.t t/bugs/error_multiple_fields_same_name.yml t/bugs/field_no_name.t t/bugs/filter_run_once.t t/bugs/multiple_checkbox_same_name.t t/bugs/multiple_checkbox_same_name.yml t/bugs/name_regex_chars.t t/bugs/not_nested.t t/bugs/populate_element_coderef.t t/bugs/pre_1_00_compat.t t/bugs/pre_1_00_compat.yml t/bugs/render_processed_value_retain_default.t t/bugs/render_processed_value_retain_default.yml t/bugs/repeatable_increase_rep.t t/bugs/repeatable_increase_rep.yml t/bugs/result_params_multiple.t t/bugs/select_empty_options.t t/bugs/submit_no_value.t t/bugs/submit_retain_default.t t/bugs/value_empty_string.t t/bugs/value_no_default.t t/bugs/yaml_utf8.t t/bugs/yaml_utf8.txt t/bugs/yaml_utf8.yml t/constraints/allornone.t t/constraints/allornone_attach_errors_to_base.t t/constraints/allornone_attach_errors_to_base.yml t/constraints/allornone_attach_errors_to_others.t t/constraints/allornone_attach_errors_to_others.yml t/constraints/ascii.t t/constraints/autoset.t t/constraints/autoset_group.t t/constraints/bool.t t/constraints/callback.t t/constraints/callbackonce.t t/constraints/constraint.t t/constraints/constraint_other_siblings.t t/constraints/constraint_other_siblings.yml t/constraints/constraint_other_siblings_not.t t/constraints/constraint_other_siblings_not.yml t/constraints/constraint_when.t t/constraints/constraint_when.yml t/constraints/constraint_when_any_field.t t/constraints/constraint_when_any_field.yml t/constraints/constraint_when_any_true_value.t t/constraints/constraint_when_any_true_value.yml t/constraints/constraint_when_default_empty_value.t t/constraints/constraint_when_default_empty_value.yml t/constraints/constraint_when_fields.t t/constraints/constraint_when_fields.yml t/constraints/datetime_parser.t t/constraints/dependon.t t/constraints/dependon_attach_errors_to_base.t t/constraints/dependon_attach_errors_to_base.yml t/constraints/dependon_attach_errors_to_others.t t/constraints/dependon_attach_errors_to_others.yml t/constraints/email-mx.t t/constraints/email.t t/constraints/equal.t t/constraints/equal_internals.t t/constraints/equal_not.t t/constraints/file.t t/constraints/file.yml t/constraints/file_maxsize.t t/constraints/file_maxsize.yml t/constraints/file_mime.t t/constraints/file_mime.yml t/constraints/file_minsize.t t/constraints/file_minsize.yml t/constraints/file_size.t t/constraints/file_size.yml t/constraints/integer.t t/constraints/json.t t/constraints/length.t t/constraints/localize.t t/constraints/maxlength.t t/constraints/maxrange.t t/constraints/minlength.t t/constraints/minmaxfields.t t/constraints/minmaxfields_with_filter_split.t t/constraints/minmaxfields_with_filter_split.yml t/constraints/minrange.t t/constraints/not_equal.t t/constraints/not_word.t t/constraints/number.t t/constraints/printable.t t/constraints/range.t t/constraints/regex.t t/constraints/regex_anchored.t t/constraints/regex_common.t t/constraints/repeatable_any.t t/constraints/repeatable_any.yml t/constraints/repeatable_any_not_increment_field_names.t t/constraints/repeatable_any_not_increment_field_names.yml t/constraints/required.t t/constraints/required_file.t t/constraints/required_file.yml t/constraints/required_only_on_reps.t t/constraints/required_only_on_reps.yml t/constraints/set.t t/constraints/singlevalue.t t/constraints/word.t t/constraints/xml.t t/deflators/callback.t t/deflators/compounddatetime.t t/deflators/compounddatetime.yml t/deflators/compounddatetime_field_order.t t/deflators/compounddatetime_field_order.yml t/deflators/compoundsplit.t t/deflators/compoundsplit.yml t/deflators/compoundsplit_after_submit.t t/deflators/compoundsplit_after_submit.yml t/deflators/compoundsplit_field_order.t t/deflators/compoundsplit_field_order.yml t/deflators/compoundsplit_split.t t/deflators/compoundsplit_split.yml t/deflators/formatnumber.t t/deflators/formatnumber.yml t/deflators/pathclassfile.t t/elements-file_post.t t/elements-file_post.txt t/elements/blank.t t/elements/block.t t/elements/block_auto_block_id.t t/elements/block_auto_block_id.yml t/elements/block_repeatable.t t/elements/block_repeatable.yml t/elements/block_repeatable_attrs.t t/elements/block_repeatable_attrs.yml t/elements/block_repeatable_auto_block_id.t t/elements/block_repeatable_auto_block_id.yml t/elements/block_repeatable_auto_id.t t/elements/block_repeatable_auto_id.yml t/elements/block_repeatable_date.t t/elements/block_repeatable_date.yml t/elements/block_repeatable_inc.t t/elements/block_repeatable_inc.yml t/elements/block_repeatable_multi.t t/elements/block_repeatable_tag.t t/elements/block_repeatable_tag.yml t/elements/button.t t/elements/button_no_name.t t/elements/checkbox.t t/elements/checkbox_force_default.t t/elements/checkbox_retain_default.t t/elements/checkbox_reverse.t t/elements/checkbox_reverse.yml t/elements/checkboxgroup.t t/elements/checkboxgroup_attributes_escaped.t t/elements/checkboxgroup_attributes_escaped.yml t/elements/combobox.t t/elements/combobox.yml t/elements/combobox_repeatable.t t/elements/combobox_repeatable.yml t/elements/combobox_required.t t/elements/combobox_required.yml t/elements/content_button.t t/elements/date.t t/elements/date_default.t t/elements/date_default_datetime_args.t t/elements/date_default_datetime_args.yml t/elements/date_default_empty.t t/elements/date_month_year.t t/elements/date_natural.t t/elements/date_order.t t/elements/date_order_error.t t/elements/date_rename.t t/elements/date_undef.t t/elements/date_year_reverse.t t/elements/date_year_reverse.yml t/elements/datetime.t t/elements/datetime.yml t/elements/datetime_interval.t t/elements/datetime_interval.yml t/elements/datetime_seconds.t t/elements/datetime_seconds.yml t/elements/element_setup.t t/elements/email.t t/elements/error_attributes_failing_test.select-with-attrs.yml t/elements/error_attributes_failing_test.select.yml t/elements/error_attributes_failing_test.t t/elements/error_attributes_failing_test.text-with-attrs.yml t/elements/error_attributes_failing_test.text.yml t/elements/escaping.t t/elements/field_default_empty_value.t t/elements/field_default_empty_value.yml t/elements/field_non_param.t t/elements/fieldset.t t/elements/fieldset_legend_attrs.t t/elements/fieldset_legend_attrs.yml t/elements/file.t t/elements/file_post.txt t/elements/file_post_cgi_simple.t t/elements/hidden.t t/elements/hr.t t/elements/image.t t/elements/label.t t/elements/label.yml t/elements/label_value_submission.t t/elements/label_value_submission.yml t/elements/multi.t t/elements/multi_errors.t t/elements/multiple_submit_buttons.t t/elements/no_block_tag.t t/elements/no_block_tag.yml t/elements/no_container_tag.t t/elements/no_container_tag.yml t/elements/number.t t/elements/number.yml t/elements/object.t t/elements/object/field_layout_field_custom t/elements/password.t t/elements/password_render_value.t t/elements/password_retain_default.t t/elements/radio.t t/elements/radio_force_default.t t/elements/radio_retain_default.t t/elements/radiogroup.t t/elements/radiogroup_attributes_escaped.t t/elements/radiogroup_attributes_escaped.yml t/elements/radiogroup_attrs_xml.t t/elements/radiogroup_dup_opt.t t/elements/radiogroup_errors.t t/elements/radiogroup_force_default.t t/elements/radiogroup_id.t t/elements/radiogroup_id_value.t t/elements/radiogroup_retain_default.t t/elements/radiogroup_subgroup.t t/elements/radiogroup_unknown_opt.t t/elements/radiogroup_xml.t t/elements/render_method.t t/elements/repeatable_counter_name.t t/elements/repeatable_counter_name.yml t/elements/repeatable_repeatable.t t/elements/repeatable_repeatable.yml t/elements/reset.t t/elements/reverse.t t/elements/select.t t/elements/select_attributes_escaped.t t/elements/select_attributes_escaped.yml t/elements/select_deflator_default.t t/elements/select_empty_first.t t/elements/select_empty_first.yml t/elements/select_empty_first_label.t t/elements/select_force_default.t t/elements/select_label_loc.t t/elements/select_multi_default_values.t t/elements/select_multi_value.t t/elements/select_optgroup.t t/elements/select_options.t t/elements/select_retain_default.t t/elements/select_same_name.t t/elements/select_same_name.yml t/elements/select_value_range.t t/elements/simple_table.t t/elements/simple_table.yml t/elements/simple_table_class.t t/elements/simple_table_class.yml t/elements/simple_table_multiple.t t/elements/simple_table_multiple.yml t/elements/src.t t/elements/submit.t t/elements/text.t t/elements/text_attributes.t t/elements/text_auto_comment_class.t t/elements/text_auto_comment_class.yml t/elements/text_auto_container_class.t t/elements/text_auto_container_class.yml t/elements/text_auto_container_comment_class.t t/elements/text_auto_container_comment_class.yml t/elements/text_auto_container_error_class.t t/elements/text_auto_container_error_class.yml t/elements/text_auto_container_label_class.t t/elements/text_auto_container_label_class.yml t/elements/text_auto_label_class.t t/elements/text_auto_label_class.yml t/elements/text_datalist_options.t t/elements/text_datalist_options.yml t/elements/text_datalist_values.t t/elements/text_datalist_values.yml t/elements/text_errors.t t/elements/text_force_default.t t/elements/text_layout.t t/elements/text_layout.yml t/elements/text_retain_default.t t/elements/text_title.t t/elements/textarea.t t/elements/url.t t/elements/url.yml t/examples/custom_label.t t/examples/custom_label2.t t/examples/field_as.t t/examples/fields_as_list_items.t t/field_accessor_loc.t t/field_accessor_loc_arrayref.t t/field_accessor_loc_arrayref.yml t/field_change_name.t t/field_id.t t/filters/all_by_default.t t/filters/callback.t t/filters/compoundjoin.t t/filters/compoundjoin.yml t/filters/compoundjoin_field_order.t t/filters/compoundjoin_field_order.yml t/filters/compoundjoin_join.t t/filters/compoundjoin_join.yml t/filters/compoundsprintf.t t/filters/compoundsprintf.yml t/filters/compoundsprintf_field_order.t t/filters/compoundsprintf_field_order.yml t/filters/copyvalue.t t/filters/encode.t t/filters/filter.t t/filters/formatnumber.t t/filters/formatnumber.yml t/filters/htmlescape.t t/filters/htmlscrubber.t t/filters/lowercase.t t/filters/nonnumeric.t t/filters/regex.t t/filters/regex.yml t/filters/regex_eval.t t/filters/regex_eval.yml t/filters/split.t t/filters/split.yml t/filters/trimedges.t t/filters/uppercase.t t/filters/whitespace.t t/force_errors/allornone.t t/force_errors/callbackonce.t t/force_errors/dependon.t t/force_errors/equal.t t/force_errors/force_errors.t t/force_errors/integer.t t/force_errors/minmaxfields.t t/form/add_render_class_args.t t/form/add_valid.t t/form/add_valid_unknown.t t/form/attributes.t t/form/auto_constraint_class.t t/form/auto_error_class.t t/form/auto_error_field_class.t t/form/auto_error_message.t t/form/auto_fieldset.t t/form/auto_label.t t/form/clone.t t/form/config_callback.t t/form/config_callback.yml t/form/constraints_from_dbic.t t/form/constraints_from_dbic.yml t/form/constraints_from_dbic_rs.t t/form/default_args.t t/form/default_args_alt.t t/form/default_args_alt.yml t/form/default_args_isa.t t/form/default_args_isa.yml t/form/default_args_not_inheriting.t t/form/default_values.t t/form/end.t t/form/error_message.t t/form/force_error_message.t t/form/form_error_message_class.t t/form/get_all_elements.t t/form/get_constraint.t t/form/get_constraints.t t/form/get_deflator.t t/form/get_deflators.t t/form/get_element.t t/form/get_elements.t t/form/get_errors.t t/form/get_field.t t/form/get_fields.t t/form/get_filter.t t/form/get_filters.t t/form/get_inflator.t t/form/get_inflators.t t/form/get_parent.t t/form/get_parent.yml t/form/has_errors.t t/form/hidden_fields.t t/form/init_arg.t t/form/insert_after.t t/form/insert_before.t t/form/javascript.t t/form/javascript_src.t t/form/languages.t t/form/languages.yml t/form/model.t t/form/multiple_same_named_fields.t t/form/object.t t/form/object/form t/form/param.t t/form/param_array.t t/form/param_list.t t/form/param_value.t t/form/params.t t/form/params_ignore_underscore.t t/form/query.t t/form/render_processed_value.t t/form/render_processed_value.yml t/form/start.t t/form/stash.t t/form/submitted.t t/form/submitted_and_valid.t t/form/title_xml.t t/form/valid.t t/i18n/add_localize_object.t t/i18n/add_localize_object_from_class.t t/i18n/add_localize_object_from_class.yml t/inflators/array.t t/inflators/callback.t t/inflators/compounddatetime.t t/inflators/compounddatetime.yml t/inflators/compounddatetime_field_order.t t/inflators/compounddatetime_field_order.yml t/inflators/datetime_optional.t t/inflators/datetime_parser.t t/inflators/datetime_regex.t t/inflators/datetime_regex_string.t t/inflators/datetime_strptime.t t/inflators/datetime_timezone.t t/inflators/datetime_with_constraint.t t/inflators/datetime_with_constraint.yml t/internals/default_args-types.t t/internals/default_args-types.yml t/lib/HTMLFormFu/DBICUniqueFake.pm t/lib/HTMLFormFu/ElementSetup.pm t/lib/HTMLFormFu/I18N.pm t/lib/HTMLFormFu/I18N/en.pm t/lib/HTMLFormFu/MyBlockRole.pm t/lib/HTMLFormFu/MyDeflator.pm t/lib/HTMLFormFu/MyFieldRole.pm t/lib/HTMLFormFu/MyFormRole.pm t/lib/HTMLFormFu/MyModel.pm t/lib/HTMLFormFu/MyObject.pm t/lib/HTMLFormFu/MyValidator.pm t/lib/HTMLFormFu/RegressLocalization.pm t/lib/HTMLFormFu/RegressLocalization/en.pm t/lib/HTMLFormFu/TestLib.pm t/lib/MyApp/Schema.pm t/lib/MyApp/Schema/Dongle.pm t/lib/MyApp/Schema/Person.pm t/load_config/config_file_path.t t/load_config/config_file_path/form.yml t/load_config/config_file_path2/form.yml t/load_config/load_config_file.t t/load_config/load_config_file_constraint_regex.t t/load_config/load_config_file_constraint_regex.yml t/load_config/load_config_file_fieldset.yml t/load_config/load_config_file_form.yml t/load_config/load_config_file_multi_stream.t t/load_config/load_config_file_multi_stream.yml t/load_config/load_config_file_multiple.t t/load_config/load_config_file_multiple.yml t/load_config/load_config_file_multiple1.yml t/load_config/load_config_file_multiple2.yml t/load_config/load_config_filestem.t t/model/hashref_create.t t/model/hashref_create_repeatable_without_nestedname.t t/model/hashref_create_repeatable_without_nestedname.yml t/model/hashref_default_values.t t/model/hashref_escaping.t t/model/hashref_multi_within_rep.t t/model/hashref_multi_within_rep.yml t/model/hashref_process.t t/multiple_select_fields.t t/multiple_text_fields.t t/nested-elements-file_post.t t/nested/constraints/allornone.t t/nested/constraints/callbackonce.t t/nested/constraints/constraint_when.t t/nested/constraints/constraint_when.yml t/nested/constraints/dependon.t t/nested/constraints/equal.t t/nested/constraints/minmaxfields.t t/nested/constraints/required.t t/nested/element_name.t t/nested/element_name.yml t/nested/elements/block_repeatable_multi_named.t t/nested/elements/block_repeatable_multi_named.yml t/nested/elements/block_repeatable_multi_named_filter.t t/nested/elements/block_repeatable_multi_named_filter.yml t/nested/elements/block_without_name.t t/nested/elements/block_without_name.yml t/nested/elements/checkbox_force_default.t t/nested/elements/checkbox_retain_default.t t/nested/elements/combobox.t t/nested/elements/date.t t/nested/elements/multi.t t/nested/elements/multi_named.t t/nested/elements/radio.t t/nested/elements/radio_force_default.t t/nested/elements/radio_retain_default.t t/nested/elements/radiogroup.t t/nested/elements/radiogroup_force_default.t t/nested/elements/radiogroup_retain_default.t t/nested/elements/repeatable_repeatable.t t/nested/elements/repeatable_repeatable.yml t/nested/elements/select.t t/nested/elements/select_force_default.t t/nested/elements/select_retain_default.t t/nested/elements/select_same_name.t t/nested/elements/select_same_name.yml t/nested/elements/text.t t/nested/filters/regex.t t/nested/form/render_processed_value.t t/nested/form/render_processed_value.yml t/nested/form_input.t t/nested/illegal_name.t t/nested/inflators/datetime_strptime.t t/nested/internals/form_processed_params.t t/nested/internals/hash_keys.t t/nested/param.t t/nested/params.t t/nested/pre_expanded.t t/nested/transformers/callback.t t/nested/valid.t t/nested/validators/callback.t t/output_processors/indent.t t/output_processors/indent_internals.t t/output_processors/strip_whitespace.t t/output_processors/strip_whitespace.yml t/plugins/stashvalid.t t/plugins/stashvalid.yml t/plugins/stashvalid_on_field.t t/plugins/stashvalid_on_field.yml t/repeatable/clone.t t/repeatable/clone.yml t/repeatable/constraints/attach_errors_to.t t/repeatable/constraints/attach_errors_to.yml t/repeatable/constraints/equal.t t/repeatable/constraints/equal.yml t/repeatable/constraints/required.t t/repeatable/constraints/required.yml t/repeatable/constraints/required_not_increment_field_names.t t/repeatable/constraints/required_not_increment_field_names.yml t/repeatable/constraints/required_not_nested.t t/repeatable/constraints/required_not_nested.yml t/repeatable/constraints/when.t t/repeatable/constraints/when.yml t/repeatable/repeatable/constraints/repeatable_any.t t/repeatable/repeatable/constraints/repeatable_any.yml t/roles/block.t t/roles/block.yml t/roles/field.t t/roles/field.yml t/roles/form.t t/roles/form.yml t/templates/field_layout t/transformers/callback.t t/utils/append_xml_attribute.t t/utils/has_xml_attribute.t t/utils/remove_xml_attribute.t t/validators/callback.t t/validators/validator.t xt/author/00-compile.t xt/author/critic.t xt/author/eol.t xt/author/pod-syntax.t xt/circular_reference.t xt/circular_reference.yml xt/release/distmeta.t xt/release/kwalitee.t xt/release/pause-permissions.t HTML-FormFu-2.07/t/0000775000175100017520000000000013404751171012301 5ustar carlcarlHTML-FormFu-2.07/t/multiple_select_fields.t0000644000175100017520000000166513404751171017214 0ustar carlcarluse strict; use warnings; use Test::More tests => 2; use HTML::FormFu; my $form = HTML::FormFu->new( { tt_args => { INCLUDE_PATH => 'share/templates/tt/xhtml' } } ); $form->element('Select')->name('foo')->values( [qw/ one two three /] ) ->default('two')->multiple(1); $form->process( { foo => [qw/ one three /], } ); my $xhtml = <
EOF is( "$form", $xhtml ); $form = HTML::FormFu->new( { tt_args => { INCLUDE_PATH => 'share/templates/tt/xhtml' } } ); $form->element('Select')->name('foo')->values( [qw/ one two three /] ) ->default('two')->multiple(1); my $select_field = $form->get_element( { name => 'foo' } ); $select_field->default( [qw/ one three /] ); is( "$form", $xhtml ); HTML-FormFu-2.07/t/repeatable/0000775000175100017520000000000013404751171014405 5ustar carlcarlHTML-FormFu-2.07/t/repeatable/repeatable/0000775000175100017520000000000013404751171016511 5ustar carlcarlHTML-FormFu-2.07/t/repeatable/repeatable/constraints/0000775000175100017520000000000013404751171021060 5ustar carlcarlHTML-FormFu-2.07/t/repeatable/repeatable/constraints/repeatable_any.yml0000644000175100017520000000061513404751171024556 0ustar carlcarl--- elements: - type: Hidden name: outer_count - type: Repeatable counter_name: outer_count elements: - name: foo constraints: - 'Repeatable::Any' - type: Hidden name: inner_count - type: Repeatable counter_name: inner_count elements: - name: foo constraints: - 'Repeatable::Any' HTML-FormFu-2.07/t/repeatable/repeatable/constraints/repeatable_any.t0000644000175100017520000000254713404751171024226 0ustar carlcarluse strict; use warnings; use Test::More tests => 3; use HTML::FormFu; use lib 't/lib'; use HTMLFormFu::TestLib; my $form = HTML::FormFu->new; $form->load_config_file( 't/repeatable/repeatable/constraints/repeatable_any.yml'); # Valid { $form->process( { outer_count => 3, foo_1 => 'a', foo_2 => '', foo_3 => '', inner_count_1 => 2, foo_1_1 => '', foo_1_2 => 'b', inner_count_2 => 3, foo_2_1 => '', foo_2_2 => '', foo_2_3 => 'c', inner_count_3 => 1, foo_3_1 => 'd', } ); ok( $form->submitted_and_valid ); } # Missing - Invalid { $form->process( { outer_count => 3, foo_1 => '', foo_2 => '', foo_3 => '', inner_count_1 => 2, foo_1_1 => '', foo_1_2 => 'b', inner_count_2 => 3, foo_2_1 => '', foo_2_2 => '', foo_2_3 => 'c', inner_count_3 => 1, foo_3_1 => '', } ); ok( !$form->submitted_and_valid ); # error is only attached to first rep is_deeply( [ $form->has_errors ], [ 'foo_1', 'foo_3_1' ] ); } HTML-FormFu-2.07/t/repeatable/constraints/0000775000175100017520000000000013404751171016754 5ustar carlcarlHTML-FormFu-2.07/t/repeatable/constraints/required_not_increment_field_names.yml0000644000175100017520000000031613404751171026567 0ustar carlcarl--- elements: - type: Hidden name: count - type: Repeatable increment_field_names: 0 counter_name: count elements: - name: foo - name: bar constraints: - Required HTML-FormFu-2.07/t/repeatable/constraints/required.t0000644000175100017520000000312313404751171020756 0ustar carlcarluse strict; use warnings; use Test::More tests => 11; use HTML::FormFu; use lib 't/lib'; use HTMLFormFu::TestLib; my $form = HTML::FormFu->new( { tt_args => { INCLUDE_PATH => 'share/templates/tt/xhtml' } } ); $form->load_config_file('t/repeatable/constraints/required.yml'); $form->get_element( { type => 'Repeatable' } )->repeat(2); # Valid { $form->process( { 'rep_1.foo' => 'a', 'rep_1.bar' => 'b', 'rep_2.foo' => 'c', 'rep_2.bar' => 'd', count => 2, } ); ok( $form->submitted_and_valid ); is_deeply( $form->params, { rep_1 => { foo => 'a', bar => 'b', }, rep_2 => { foo => 'c', bar => 'd', }, count => 2, } ); } # Missing - Invalid { $form->process( { 'rep_1.bar' => 'b', 'rep_2.foo' => 'c', count => 2, } ); ok( !$form->submitted_and_valid ); ok( $form->has_errors('rep_1.foo') ); ok( !$form->has_errors('rep_1.bar') ); ok( !$form->has_errors('rep_2.foo') ); ok( $form->has_errors('rep_2.bar') ); like( $form->get_field( { nested_name => 'rep_1.foo' } ), qr/This field is required/ ); unlike( $form->get_field( { nested_name => 'rep_1.bar' } ), qr/This field is required/ ); unlike( $form->get_field( { nested_name => 'rep_2.foo' } ), qr/This field is required/ ); like( $form->get_field( { nested_name => 'rep_2.bar' } ), qr/This field is required/ ); } HTML-FormFu-2.07/t/repeatable/constraints/required_not_nested.yml0000644000175100017520000000031613404751171023537 0ustar carlcarl--- elements: - type: Hidden name: count - type: Repeatable increment_field_names: 1 counter_name: count elements: - name: foo - name: bar constraints: - Required HTML-FormFu-2.07/t/repeatable/constraints/attach_errors_to.t0000644000175100017520000000141413404751171022501 0ustar carlcarluse strict; use warnings; use Test::More tests => 5; use HTML::FormFu; use lib 't/lib'; use HTMLFormFu::TestLib; my $form = HTML::FormFu->new( { tt_args => { INCLUDE_PATH => 'share/templates/tt/xhtml' } } ); $form->load_config_file('t/repeatable/constraints/attach_errors_to.yml'); $form->get_element( { type => 'Repeatable' } )->repeat(2); # Missing - Invalid { $form->process( { 'rep_1.foo' => 'AAA', 'rep_1.bar' => '', count => 1, } ); ok( !$form->submitted_and_valid ); ok( $form->has_errors('rep_1.foo') ); ok( $form->has_errors('rep_1.bar') ); like( $form->get_field( { nested_name => 'rep_1.foo' } ), qr/Error/ ); like( $form->get_field( { nested_name => 'rep_1.bar' } ), qr/Error/ ); } HTML-FormFu-2.07/t/repeatable/constraints/when.yml0000644000175100017520000000045213404751171020437 0ustar carlcarl--- elements: - type: Hidden name: count - type: Repeatable nested_name: rep increment_field_names: 1 counter_name: count elements: - name: foo - name: bar constraints: - type: Required when: field: 'rep.foo' HTML-FormFu-2.07/t/repeatable/constraints/equal.t0000644000175100017520000000367413404751171020260 0ustar carlcarluse strict; use warnings; use Test::More tests => 16; use HTML::FormFu; use lib 't/lib'; use HTMLFormFu::TestLib; my $form = HTML::FormFu->new; $form->load_config_file('t/repeatable/constraints/equal.yml'); $form->get_element( { type => 'Repeatable' } )->repeat(2); # Valid { $form->process( { 'rep_1.foo' => 'a', 'rep_1.bar' => 'a', 'rep_1.baz' => 'a', 'rep_2.foo' => 'c', 'rep_2.bar' => 'c', 'rep_2.baz' => 'c', count => 2, } ); ok( $form->submitted_and_valid ); is_deeply( $form->params, { rep_1 => { foo => 'a', bar => 'a', baz => 'a', }, rep_2 => { foo => 'c', bar => 'c', baz => 'c', }, count => 2, } ); } # Invalid { $form->process( { 'rep_1.foo' => 'a', 'rep_1.bar' => 'a', 'rep_1.baz' => 'a', 'rep_2.foo' => 'c', 'rep_2.bar' => 'd', 'rep_2.baz' => 'c', count => 2, } ); ok( !$form->submitted_and_valid ); ok( !$form->has_errors('rep_1.foo') ); ok( !$form->has_errors('rep_1.bar') ); ok( !$form->has_errors('rep_1.baz') ); ok( !$form->has_errors('rep_2.foo') ); ok( $form->has_errors('rep_2.bar') ); ok( !$form->has_errors('rep_2.baz') ); } # Missing - Invalid { $form->process( { 'rep_1.foo' => 'a', 'rep_1.bar' => 'a', 'rep_1.baz' => 'a', 'rep_2.foo' => 'c', count => 2, } ); ok( !$form->submitted_and_valid ); ok( !$form->has_errors('rep_1.foo') ); ok( !$form->has_errors('rep_1.bar') ); ok( !$form->has_errors('rep_1.baz') ); ok( !$form->has_errors('rep_2.foo') ); ok( $form->has_errors('rep_2.bar') ); ok( $form->has_errors('rep_2.baz') ); } HTML-FormFu-2.07/t/repeatable/constraints/required_not_increment_field_names.t0000644000175100017520000000317513404751171026237 0ustar carlcarluse strict; use warnings; use Test::More tests => 13; use HTML::FormFu; use lib 't/lib'; use HTMLFormFu::TestLib; my $form = HTML::FormFu->new( { tt_args => { INCLUDE_PATH => 'share/templates/tt/xhtml' } } ); $form->load_config_file( 't/repeatable/constraints/required_not_increment_field_names.yml'); $form->get_element( { type => 'Repeatable' } )->repeat(2); # Valid { $form->process( { foo => [ 'a', 'b' ], bar => [ 'c', 'd' ], count => 2, } ); ok( $form->submitted_and_valid ); is_deeply( $form->params, { foo => [ 'a', 'b' ], bar => [ 'c', 'd' ], count => 2, } ); } # Missing - Invalid { $form->process( { foo => [ '', 'b' ], bar => [ 'c', '' ], count => 2, } ); ok( !$form->submitted_and_valid ); # $form->has_errors() doesn't really make sense for multiple fields with the same name # - an error on any of those fields will return true ok( $form->has_errors('foo') ); ok( $form->has_errors('bar') ); my $foo1 = $form->get_fields('foo')->[0]; my $foo2 = $form->get_fields('foo')->[1]; my $bar1 = $form->get_fields('bar')->[0]; my $bar2 = $form->get_fields('bar')->[1]; is( scalar @{ $foo1->get_errors }, 1 ); is( scalar @{ $foo2->get_errors }, 0 ); is( scalar @{ $bar1->get_errors }, 0 ); is( scalar @{ $bar2->get_errors }, 1 ); like( $foo1, qr/This field is required/ ); unlike( $foo2, qr/This field is required/ ); unlike( $bar1, qr/This field is required/ ); like( $bar2, qr/This field is required/ ); } HTML-FormFu-2.07/t/repeatable/constraints/required.yml0000644000175100017520000000034313404751171021315 0ustar carlcarl--- elements: - type: Hidden name: count - type: Repeatable nested_name: rep increment_field_names: 1 counter_name: count elements: - name: foo - name: bar constraints: - Required HTML-FormFu-2.07/t/repeatable/constraints/attach_errors_to.yml0000644000175100017520000000051513404751171023040 0ustar carlcarl--- elements: - type: Hidden name: count - type: Repeatable nested_name: rep counter_name: count elements: - name: foo constraints: - type: AllOrNone others: rep.bar attach_errors_to: - rep.foo - rep.bar - name: bar HTML-FormFu-2.07/t/repeatable/constraints/when.t0000644000175100017520000000130213404751171020074 0ustar carlcarluse strict; use warnings; use Test::More tests => 4; use HTML::FormFu; use lib 't/lib'; use HTMLFormFu::TestLib; my $form = HTML::FormFu->new; $form->load_config_file('t/repeatable/constraints/when.yml'); $form->get_element( { type => 'Repeatable' } )->repeat(1); # Valid { $form->process( { 'rep_1.foo' => 'a', 'rep_1.bar' => 'b', count => 1, } ); ok( $form->submitted_and_valid ); } # Missing - Invalid { $form->process( { 'rep_1.foo' => 'a', 'rep_1.bar' => '', count => 1, } ); ok( $form->has_errors ); ok( $form->valid('rep_1.foo') ); ok( !$form->valid('rep_1.bar') ); } HTML-FormFu-2.07/t/repeatable/constraints/equal.yml0000644000175100017520000000050713404751171020606 0ustar carlcarl--- elements: - type: Hidden name: count - type: Repeatable nested_name: rep increment_field_names: 1 counter_name: count elements: - name: foo constraints: - type: Equal others: - bar - 'rep.baz' - name: bar - name: baz HTML-FormFu-2.07/t/repeatable/constraints/required_not_nested.t0000644000175100017520000000250613404751171023204 0ustar carlcarluse strict; use warnings; use Test::More tests => 11; use HTML::FormFu; use lib 't/lib'; use HTMLFormFu::TestLib; my $form = HTML::FormFu->new( { tt_args => { INCLUDE_PATH => 'share/templates/tt/xhtml' } } ); $form->load_config_file('t/repeatable/constraints/required_not_nested.yml'); $form->get_element( { type => 'Repeatable' } )->repeat(2); # Valid { $form->process( { foo_1 => 'a', bar_1 => 'b', foo_2 => 'c', bar_2 => 'd', count => 2, } ); ok( $form->submitted_and_valid ); is_deeply( $form->params, { foo_1 => 'a', bar_1 => 'b', foo_2 => 'c', bar_2 => 'd', count => 2, } ); } # Missing - Invalid { $form->process( { bar_1 => 'b', foo_2 => 'c', count => 2, } ); ok( !$form->submitted_and_valid ); ok( $form->has_errors('foo_1') ); ok( !$form->has_errors('bar_1') ); ok( !$form->has_errors('foo_2') ); ok( $form->has_errors('bar_2') ); like( $form->get_field('foo_1'), qr/This field is required/ ); unlike( $form->get_field('bar_1'), qr/This field is required/ ); unlike( $form->get_field('foo_2'), qr/This field is required/ ); like( $form->get_field('bar_2'), qr/This field is required/ ); } HTML-FormFu-2.07/t/repeatable/clone.yml0000644000175100017520000000036513404751171016232 0ustar carlcarl--- auto_fieldset: 1 elements: - type: Hidden name: count - type: Repeatable nested_name: rep increment_field_names: 1 counter_name: count elements: - name: foo - name: bar constraints: - Required HTML-FormFu-2.07/t/repeatable/clone.t0000644000175100017520000000351513404751171015674 0ustar carlcarluse strict; use warnings; use Scalar::Util qw/ refaddr /; use Test::More tests => 19; use HTML::FormFu; my $form = HTML::FormFu->new; $form->load_config_file('t/repeatable/clone.yml'); $form->get_all_element( { type => 'Repeatable' } )->repeat(2); $form->process( { 'rep_1.foo' => 'a', 'rep_1.bar' => '', 'rep_2.foo' => '', 'rep_2.bar' => 'd', count => 2, } ); isa_ok( $form, 'HTML::FormFu' ); # fieldset my $fs = $form->get_element; isa_ok( $fs, 'HTML::FormFu::Element::Fieldset' ); is( refaddr( $fs->parent ), refaddr($form), ); # hidden field my $hidden = $form->get_field('count'); isa_ok( $hidden, 'HTML::FormFu::Element::Hidden' ); is( refaddr( $hidden->parent ), refaddr($fs), ); # repeatable my $rep = $fs->get_element( { type => 'Repeatable' } ); isa_ok( $rep, 'HTML::FormFu::Element::Repeatable' ); is( refaddr( $rep->parent ), refaddr($fs), ); # block 1 { my $block = $rep->get_elements->[0]; my $foo = $block->get_fields->[0]; is( refaddr( $foo->parent ), refaddr($block), ); is( refaddr( $foo->get_constraint->parent ), refaddr($foo), ); ok( !$foo->get_error ); my $bar = $block->get_fields->[1]; is( refaddr( $bar->parent ), refaddr($block), ); is( refaddr( $bar->get_constraint->parent ), refaddr($bar), ); is( refaddr( $bar->get_error->parent ), refaddr($bar), ); } # block 2 { my $block = $rep->get_elements->[1]; my $foo = $block->get_fields->[0]; is( refaddr( $foo->parent ), refaddr($block), ); is( refaddr( $foo->get_constraint->parent ), refaddr($foo), ); is( refaddr( $foo->get_error->parent ), refaddr($foo), ); my $bar = $block->get_fields->[1]; is( refaddr( $bar->parent ), refaddr($block), ); is( refaddr( $bar->get_constraint->parent ), refaddr($bar), ); ok( !$bar->get_error ); } HTML-FormFu-2.07/t/elements-file_post.t0000644000175100017520000000631513404751171016267 0ustar carlcarluse strict; use warnings; use Test::More; use HTML::FormFu; use IO::File; eval "use CGI"; if ($@) { plan skip_all => 'CGI required'; die $!; } plan tests => 25; # Copied from CGI.pm - http://search.cpan.org/perldoc?CGI %ENV = ( %ENV, 'SCRIPT_NAME' => '/test.cgi', 'SERVER_NAME' => 'perl.org', 'HTTP_CONNECTION' => 'TE, close', 'REQUEST_METHOD' => 'POST', 'SCRIPT_URI' => 'http://www.perl.org/test.cgi', 'SCRIPT_FILENAME' => '/home/usr/test.cgi', 'SERVER_SOFTWARE' => 'Apache/1.3.27 (Unix) ', 'HTTP_TE' => 'deflate,gzip;q=0.3', 'QUERY_STRING' => '', 'REMOTE_PORT' => '1855', 'HTTP_USER_AGENT' => 'Mozilla/5.0 (compatible; Konqueror/2.1.1; X11)', 'SERVER_PORT' => '80', 'REMOTE_ADDR' => '127.0.0.1', 'CONTENT_TYPE' => 'multipart/form-data; boundary=xYzZY', 'SERVER_PROTOCOL' => 'HTTP/1.1', 'PATH' => '/usr/local/bin:/usr/bin:/bin', 'REQUEST_URI' => '/test.cgi', 'GATEWAY_INTERFACE' => 'CGI/1.1', 'SCRIPT_URL' => '/test.cgi', 'SERVER_ADDR' => '127.0.0.1', 'DOCUMENT_ROOT' => '/home/develop', 'HTTP_HOST' => 'www.perl.org' ); my $io = new IO::File 't/elements-file_post.txt'; $io->binmode; local *STDIN = $io; my $q = CGI->new(); my $form = HTML::FormFu->new( { action => 'http://www.perl.org/test.cgi', elements => [ { type => 'Text', name => 'multiple' }, { type => 'File', name => 'multiple' }, { type => 'File', name => 'multiple' }, { type => 'File', name => 'hello_world' }, { type => 'File', name => 'does_not_exist_gif' }, { type => 'File', name => '100x100_gif' }, { type => 'File', name => '300x300_gif' }, ], } ); $form->process($q); { my $multiple = $form->params->{multiple}; is( @$multiple, 3 ); my ( $m1, $m2, $m3 ) = @$multiple; ok( !ref $m1 ); is( $m1, 'foo' ); isa_ok( $m2, 'HTML::FormFu::Upload' ); is( $m2->filename, 'one.txt' ); is( $m2->headers->content_length, 4 ); is( $m2->headers->content_type, 'text/plain' ); is( $m2->slurp, "One\n" ); # new Cat-compatable methods is( $m2->size, 4 ); is( $m2->type, 'text/plain' ); isa_ok( $m3, 'HTML::FormFu::Upload' ); is( $m3->filename, 'two.txt' ); is( $m3->headers->content_length, 5 ); is( $m3->headers->content_type, 'text/plain' ); is( $m3->slurp, "Two!\n" ); } { my $value = $form->params->{hello_world}; isa_ok( $value, 'HTML::FormFu::Upload' ); is( $value->filename, 'hello_world.txt' ); is( $value->headers->content_length, 13 ); is( $value->headers->content_type, 'text/plain' ); is( $value->slurp, "Hello World!\n" ); } { my $value = $form->params->{does_not_exist_gif}; isa_ok( $value, 'HTML::FormFu::Upload' ); is( $value->filename, 'does_not_exist.gif' ); is( $value->headers->content_length, undef ); is( $value->headers->content_type, 'application/octet-stream' ); is( $value->slurp, '' ); } HTML-FormFu-2.07/t/force_errors/0000775000175100017520000000000013404751171014773 5ustar carlcarlHTML-FormFu-2.07/t/force_errors/integer.t0000644000175100017520000000132113404751171016610 0ustar carlcarluse strict; use warnings; use Test::More tests => 6; use HTML::FormFu; my $form = HTML::FormFu->new; $form->element('Text')->name('foo')->constraint('Integer')->force_errors(1); $form->element('Text')->name('bar')->constraint('Integer')->force_errors(1); { $form->process( { foo => '12', bar => "12\n", } ); ok( !$form->has_errors('foo') ); ok( $form->has_errors('bar') ); ok( @{ $form->get_errors( { name => 'foo', forced => 1 } ) } ); } { $form->process( { foo => 0, bar => "0\n", } ); ok( !$form->has_errors('foo') ); ok( $form->has_errors('bar') ); ok( @{ $form->get_errors( { name => 'foo', forced => 1 } ) } ); } HTML-FormFu-2.07/t/force_errors/equal.t0000644000175100017520000000462113404751171016270 0ustar carlcarluse strict; use warnings; use Test::More tests => 31; use HTML::FormFu; my $form = HTML::FormFu->new->force_errors(1); $form->element('Text')->name('foo')->constraint('Equal') ->others( [ 'bar', 'baz' ] ); $form->element('Text')->name('bar'); $form->element('Text')->name('baz'); # valid { $form->process( { foo => 'yada', bar => 'yada', baz => 'yada', } ); ok( $form->submitted_and_valid ); ok( !$form->has_errors('foo') ); ok( !$form->has_errors('bar') ); ok( !$form->has_errors('baz') ); ok( @{ $form->get_errors( { name => 'foo', forced => 1 } ) } ); ok( @{ $form->get_errors( { name => 'bar', forced => 1 } ) } ); ok( @{ $form->get_errors( { name => 'baz', forced => 1 } ) } ); } # valid { $form->process( { foo => '', bar => '', baz => '', } ); ok( $form->submitted_and_valid ); ok( !$form->has_errors('foo') ); ok( !$form->has_errors('bar') ); ok( !$form->has_errors('baz') ); ok( @{ $form->get_errors( { name => 'foo', forced => 1 } ) } ); ok( @{ $form->get_errors( { name => 'bar', forced => 1 } ) } ); ok( @{ $form->get_errors( { name => 'baz', forced => 1 } ) } ); } # valid { $form->process( { foo => [ 'a', 'b' ], bar => [ 'a', 'b' ], baz => [ 'b', 'a' ], } ); ok( $form->submitted_and_valid ); ok( !$form->has_errors('foo') ); ok( !$form->has_errors('bar') ); ok( !$form->has_errors('baz') ); ok( @{ $form->get_errors( { name => 'foo', forced => 1 } ) } ); ok( @{ $form->get_errors( { name => 'bar', forced => 1 } ) } ); ok( @{ $form->get_errors( { name => 'baz', forced => 1 } ) } ); } # invalid { $form->process( { foo => 'yada', bar => 'yada', baz => 'x', } ); ok( !$form->submitted_and_valid ); ok( !$form->has_errors('foo') ); ok( !$form->has_errors('bar') ); ok( $form->has_errors('baz') ); ok( @{ $form->get_errors( { name => 'baz', forced => 1 } ) } ); } # invalid { $form->process( { foo => [ 'a', 'b' ], bar => [ 'a', 'b' ], baz => ['a'], } ); ok( !$form->submitted_and_valid ); ok( !$form->has_errors('foo') ); ok( !$form->has_errors('bar') ); ok( $form->has_errors('baz') ); ok( @{ $form->get_errors( { name => 'baz', forced => 1 } ) } ); } HTML-FormFu-2.07/t/force_errors/callbackonce.t0000644000175100017520000000177413404751171017570 0ustar carlcarluse strict; use warnings; use Test::More tests => 9; use HTML::FormFu; my $form = HTML::FormFu->new; $form->element('Text')->name('foo')->constraint('CallbackOnce') ->force_errors(1)->callback( sub { return $_[0] eq 'a'; } ); $form->element('Text')->name('bar')->constraint('CallbackOnce') ->force_errors(1)->callback( sub { return $_[0] eq 'b'; } ); # valid { $form->process( { foo => 'a', bar => 'b', } ); ok( $form->submitted_and_valid ); ok( !$form->has_errors('foo') ); ok( !$form->has_errors('bar') ); ok( @{ $form->get_errors( { name => 'foo', forced => 1 } ) } ); ok( @{ $form->get_errors( { name => 'bar', forced => 1 } ) } ); } # invalid { $form->process( { foo => 'a', bar => 'c', } ); ok( !$form->submitted_and_valid ); ok( !$form->has_errors('foo') ); ok( $form->has_errors('bar') ); ok( @{ $form->get_errors( { name => 'foo', forced => 1 } ) } ); } HTML-FormFu-2.07/t/force_errors/dependon.t0000644000175100017520000000221513404751171016752 0ustar carlcarluse strict; use warnings; use Test::More tests => 13; use HTML::FormFu; my $form = HTML::FormFu->new; $form->element('Text')->name('foo')->constraint('DependOn') ->others( [qw/ bar baz /] )->force_errors(1); $form->element('Text')->name('bar'); $form->element('Text')->name('baz'); # valid { $form->process( { foo => 1, bar => 'a', baz => [2], } ); ok( $form->submitted_and_valid ); ok( !$form->has_errors('foo') ); ok( !$form->has_errors('bar') ); ok( !$form->has_errors('baz') ); ok( @{ $form->get_errors( { name => 'foo', forced => 1 } ) } ); ok( @{ $form->get_errors( { name => 'bar', forced => 1 } ) } ); ok( @{ $form->get_errors( { name => 'baz', forced => 1 } ) } ); } # invalid { $form->process( { foo => 1, bar => '', baz => 2, } ); ok( !$form->submitted_and_valid ); ok( !$form->has_errors('foo') ); ok( $form->has_errors('bar') ); ok( !$form->has_errors('baz') ); ok( @{ $form->get_errors( { name => 'foo', forced => 1 } ) } ); ok( @{ $form->get_errors( { name => 'baz', forced => 1 } ) } ); } HTML-FormFu-2.07/t/force_errors/allornone.t0000644000175100017520000000351013404751171017146 0ustar carlcarluse strict; use warnings; use Test::More tests => 24; use HTML::FormFu; my $form = HTML::FormFu->new->indicator( sub {1} ); $form->element('Text')->name('foo')->constraint('AllOrNone') ->others( [qw/ bar baz bif /] )->force_errors(1); $form->element('Text')->name('bar'); $form->element('Text')->name('baz'); $form->element('Text')->name('bif'); # Valid { $form->process( { foo => 1, bar => 'a', baz => [2], bif => [ 3, 4 ], } ); ok( $form->submitted_and_valid ); ok( !$form->has_errors('foo') ); ok( !$form->has_errors('bar') ); ok( !$form->has_errors('baz') ); ok( !$form->has_errors('bif') ); ok( @{ $form->get_errors( { name => 'foo', forced => 1 } ) } ); ok( @{ $form->get_errors( { name => 'bar', forced => 1 } ) } ); ok( @{ $form->get_errors( { name => 'baz', forced => 1 } ) } ); ok( @{ $form->get_errors( { name => 'bif', forced => 1 } ) } ); } # Valid { $form->process( {} ); ok( $form->submitted_and_valid ); ok( !$form->has_errors('foo') ); ok( !$form->has_errors('bar') ); ok( !$form->has_errors('baz') ); ok( !$form->has_errors('bif') ); ok( @{ $form->get_errors( { name => 'foo', forced => 1 } ) } ); ok( @{ $form->get_errors( { name => 'bar', forced => 1 } ) } ); ok( @{ $form->get_errors( { name => 'baz', forced => 1 } ) } ); ok( @{ $form->get_errors( { name => 'bif', forced => 1 } ) } ); } # Invalid { $form->process( { foo => 1, bar => '', baz => [2], bif => [ 3, 4 ], } ); ok( !$form->submitted_and_valid ); ok( !$form->has_errors('foo') ); ok( $form->has_errors('bar') ); ok( !$form->has_errors('baz') ); ok( !$form->has_errors('bif') ); ok( @{ $form->get_errors( { name => 'bar', forced => 1 } ) } ); } HTML-FormFu-2.07/t/force_errors/minmaxfields.t0000644000175100017520000000406313404751171017641 0ustar carlcarluse strict; use warnings; use Test::More tests => 26; use HTML::FormFu; my $form = HTML::FormFu->new; $form->element('Text')->name('foo')->constraint('MinMaxFields') ->others( [qw/ bar baz boz/] )->min(1)->max(2)->force_errors(1); $form->element('Text')->name('bar'); $form->element('Text')->name('baz'); $form->element('Text')->name('boz'); # valid { $form->process( { foo => 1, bar => '', baz => [2], boz => '', } ); ok( !$form->has_errors, 'no real errors' ); ok( !$form->has_errors('foo') ); ok( !$form->has_errors('bar') ); ok( !$form->has_errors('baz') ); ok( !$form->has_errors('boz') ); ok( @{ $form->get_errors( { name => 'foo', forced => 1 } ) } ); ok( !@{ $form->get_errors( { name => 'bar', forced => 1 } ) } ); ok( !@{ $form->get_errors( { name => 'baz', forced => 1 } ) } ); ok( !@{ $form->get_errors( { name => 'boz', forced => 1 } ) } ); } # valid { $form->process( { foo => 1, bar => '', baz => '', boz => '', } ); ok( !$form->has_errors, 'no real errors' ); ok( !$form->has_errors('foo') ); ok( !$form->has_errors('bar') ); ok( !$form->has_errors('baz') ); ok( !$form->has_errors('boz') ); ok( @{ $form->get_errors( { name => 'foo', forced => 1 } ) } ); ok( !@{ $form->get_errors( { name => 'bar', forced => 1 } ) } ); ok( !@{ $form->get_errors( { name => 'baz', forced => 1 } ) } ); ok( !@{ $form->get_errors( { name => 'boz', forced => 1 } ) } ); } # invalid { $form->process( { foo => 1, bar => '', baz => 2, boz => '22', } ); ok( $form->has_errors ); ok( $form->has_errors('foo') ); ok( !$form->has_errors('bar') ); ok( !$form->has_errors('baz') ); ok( !$form->has_errors('boz') ); ok( !@{ $form->get_errors( { name => 'bar', forced => 1 } ) } ); ok( !@{ $form->get_errors( { name => 'baz', forced => 1 } ) } ); ok( !@{ $form->get_errors( { name => 'boz', forced => 1 } ) } ); } HTML-FormFu-2.07/t/force_errors/force_errors.t0000644000175100017520000000204313404751171017647 0ustar carlcarluse strict; use warnings; use Test::More tests => 15; use HTML::FormFu; my $form = HTML::FormFu->new->force_errors(1); $form->element('Text')->name('foo')->constraint('Integer'); $form->element('Text')->name('bar')->constraint('Integer'); { $form->process( { foo => '1', bar => '0', } ); ok( !$form->has_errors, 'has no real errors' ); ok( !$form->has_errors('foo') ); ok( !$form->has_errors('bar') ); ok( @{ $form->get_errors( { name => 'foo', forced => 1 } ) } ); ok( @{ $form->get_errors( { name => 'bar', forced => 1 } ) } ); ok( $form->valid('foo') ); ok( $form->valid('bar') ); ok( $form->submitted_and_valid ); } { $form->process( { foo => 0, bar => "0\n", } ); ok( $form->has_errors ); ok( !$form->has_errors('foo') ); ok( $form->has_errors('bar') ); ok( @{ $form->get_errors( { name => 'foo', forced => 1 } ) } ); ok( $form->valid('foo') ); ok( !$form->valid('bar') ); ok( !$form->submitted_and_valid ); } HTML-FormFu-2.07/t/05_repeated_render.t0000644000175100017520000000071513404751171016123 0ustar carlcarluse strict; use warnings; use Test::More tests => 2; use HTML::FormFu; my $form = HTML::FormFu->new( { tt_args => { INCLUDE_PATH => 'share/templates/tt/xhtml' } } ); $form->load_config_file('t/04basic.yml'); # check output is still exactly the same after rendering again { my $html = "$form"; is( $html, "$form" ); } # and after submitted form { $form->process( { age => 'abc', } ); my $html = "$form"; is( $html, "$form" ); } HTML-FormFu-2.07/t/constraints/0000775000175100017520000000000013404751171014650 5ustar carlcarlHTML-FormFu-2.07/t/constraints/regex.t0000644000175100017520000000137713404751171016155 0ustar carlcarluse strict; use warnings; use Test::More tests => 8; use HTML::FormFu; my $form = HTML::FormFu->new; $form->element('Text')->name('foo'); $form->element('Text')->name('bar'); $form->constraint('Regex'); # Valid { $form->process( { foo => 'aaa', bar => 'bbbbbbb', } ); ok( $form->valid('foo'), 'foo valid' ); ok( $form->valid('bar'), 'bar valid' ); ok( grep { $_ eq 'foo' } $form->valid ); ok( grep { $_ eq 'bar' } $form->valid ); } # "0" is valid { $form->process( { foo => 0, bar => 2, } ); ok( $form->valid('foo'), 'foo valid' ); ok( $form->valid('bar'), 'foo valid' ); ok( grep { $_ eq 'foo' } $form->valid ); ok( grep { $_ eq 'bar' } $form->valid ); } HTML-FormFu-2.07/t/constraints/constraint_when_default_empty_value.t0000644000175100017520000000163113404751171024357 0ustar carlcarluse strict; use warnings; use Test::More tests => 8; use HTML::FormFu; my $form = HTML::FormFu->new; $form->load_config_file( 't/constraints/constraint_when_default_empty_value.yml'); # valid - foo Checkbox missing - bar is required { $form->process( { bar => '42', } ); ok( $form->submitted_and_valid ); is( $form->param_value('bar'), 42 ); } # valid - foo Checkbox present - bar optional { $form->process( { foo => '1', } ); ok( $form->submitted_and_valid ); is( $form->param_value('foo'), 1 ); } # valid - foo Checkbox present - bar optional { $form->process( { foo => '1', bar => '42', } ); ok( $form->submitted_and_valid ); is( $form->param_value('foo'), 1 ); is( $form->param_value('bar'), 42 ); } # invalid - foo Checkbox missing - bar required { $form->process( { bar => '', } ); ok( !$form->submitted_and_valid ); } HTML-FormFu-2.07/t/constraints/file_size.yml0000644000175100017520000000043213404751171017341 0ustar carlcarl--- action: 'http://www.perl.org/test.cgi' elements: - type: File name: hello_world constraints: - type: File::Size min: 1 max: 15 - type: File name: does_not_exist_gif constraints: - type: File::Size min: 1 max: 15 HTML-FormFu-2.07/t/constraints/constraint_other_siblings_not.t0000644000175100017520000000442413404751171023176 0ustar carlcarluse strict; use warnings; use Test::More tests => 24; use HTML::FormFu; my $form = HTML::FormFu->new( { tt_args => { INCLUDE_PATH => 'share/templates/tt/xhtml' } } ); $form->load_config_file('t/constraints/constraint_other_siblings_not.yml'); # Valid { $form->process( { foo => 'yada', bar => 'boba', baz => 'sith', } ); ok( $form->valid('foo'), 'foo valid' ); ok( $form->valid('bar'), 'bar valid' ); ok( $form->valid('bar'), 'baz valid' ); } # Valid { $form->process( { foo => '', bar => '', baz => '', } ); ok( $form->valid('foo'), 'foo valid' ); ok( $form->valid('bar'), 'bar valid' ); ok( $form->valid('baz'), 'baz valid' ); } # Valid { $form->process( { foo => '', bar => 'yada', baz => 'boba', } ); ok( $form->valid('foo'), 'foo valid' ); ok( $form->valid('bar'), 'bar valid' ); ok( $form->valid('baz'), 'baz valid' ); } # Valid { $form->process( { foo => 'yada', bar => '', baz => '', } ); ok( $form->valid('foo'), 'foo valid' ); ok( $form->valid('bar'), 'bar valid' ); ok( $form->valid('baz'), 'baz valid' ); } # Valid { $form->process( { foo => '', bar => 'yada', baz => '', } ); ok( $form->valid('foo'), 'foo valid' ); ok( $form->valid('bar'), 'bar valid' ); ok( $form->valid('baz'), 'baz valid' ); } # Invalid { $form->process( { foo => 'yada', bar => 'yada', baz => 'x', } ); ok( $form->valid('foo'), 'foo valid' ); ok( !$form->valid('bar'), 'bar not valid' ); ok( $form->valid('baz'), 'baz valid' ); } # Invalid { $form->process( { foo => 'yada', bar => 'x', baz => 'yada', } ); ok( $form->valid('foo'), 'foo valid' ); ok( $form->valid('bar'), 'bar valid' ); ok( !$form->valid('baz'), 'baz not valid' ); } # Invalid { $form->process( { foo => 'yada', bar => 'yada', baz => 'yada', } ); ok( $form->valid('foo'), 'foo valid' ); ok( !$form->valid('bar'), 'bar not valid' ); ok( !$form->valid('baz'), 'baz not valid' ); } HTML-FormFu-2.07/t/constraints/file_maxsize.yml0000644000175100017520000000023013404751171020043 0ustar carlcarl--- action: 'http://www.perl.org/test.cgi' elements: - type: File name: hello_world constraints: - type: File::MaxSize max: 15 HTML-FormFu-2.07/t/constraints/minmaxfields_with_filter_split.t0000644000175100017520000000151013404751171023323 0ustar carlcarluse strict; use warnings; use Test::More tests => 7; use HTML::FormFu; my $form = HTML::FormFu->new; $form->load_config_file('t/constraints/minmaxfields_with_filter_split.yml'); # Valid { $form->process( { foo => '', bar => '', baz => '', } ); ok( !$form->has_errors ); $form->process( { foo => '1', bar => '', baz => '', } ); ok( !$form->has_errors ); $form->process( { foo => '1,2', bar => '', baz => '', } ); ok( !$form->has_errors ); } # Invalid { $form->process( { foo => 1, bar => '', baz => 2, } ); ok( $form->has_errors ); ok( !$form->valid('foo') ); ok( $form->valid('bar') ); ok( $form->valid('baz') ); } HTML-FormFu-2.07/t/constraints/equal_not.t0000644000175100017520000000303213404751171017020 0ustar carlcarluse strict; use warnings; use Test::More tests => 15; use HTML::FormFu; my $form = HTML::FormFu->new; $form->element('Text')->name('foo')->constraint('Equal') ->others( [ 'bar', 'baz' ] )->not(1); $form->element('Text')->name('bar'); $form->element('Text')->name('baz'); # Valid { $form->process( { foo => 'yada', bar => 'boba', baz => 'sith', } ); ok( $form->valid('foo'), 'foo valid' ); ok( $form->valid('bar'), 'bar valid' ); ok( $form->valid('bar'), 'baz valid' ); } # Valid { $form->process( { foo => '', bar => '', baz => '', } ); ok( $form->valid('foo'), 'foo valid' ); ok( $form->valid('bar'), 'bar valid' ); ok( $form->valid('baz'), 'baz valid' ); } # Valid { $form->process( { foo => '', bar => 'yada', baz => 'boba', } ); ok( $form->valid('foo'), 'foo valid' ); ok( $form->valid('bar'), 'bar valid' ); ok( $form->valid('baz'), 'baz valid' ); } # Valid { $form->process( { foo => '', bar => 'yada', baz => '', } ); ok( $form->valid('foo'), 'foo valid' ); ok( $form->valid('bar'), 'bar valid' ); ok( $form->valid('baz'), 'baz valid' ); } # Invalid { $form->process( { foo => 'yada', bar => 'yada', baz => 'x', } ); ok( $form->valid('foo'), 'foo valid' ); ok( !$form->valid('bar'), 'bar not valid' ); ok( $form->valid('baz'), 'baz valid' ); } HTML-FormFu-2.07/t/constraints/integer.t0000644000175100017520000000146513404751171016476 0ustar carlcarluse strict; use warnings; use Test::More tests => 8; use HTML::FormFu; my $form = HTML::FormFu->new; $form->element('Text')->name('foo'); $form->element('Text')->name('bar'); $form->constraint('Integer'); # Valid # linebreak not valid { $form->process( { foo => '12', bar => "12\n", } ); ok( $form->valid('foo'), 'foo valid' ); ok( !$form->valid('bar'), 'bar valid' ); ok( grep { $_ eq 'foo' } $form->valid ); ok( !grep { $_ eq 'bar' } $form->valid ); } # "0" is valid # linebreak not valid { $form->process( { foo => 0, bar => "0\n", } ); ok( $form->valid('foo'), 'foo valid' ); ok( !$form->valid('bar'), 'foo valid' ); ok( grep { $_ eq 'foo' } $form->valid ); ok( !grep { $_ eq 'bar' } $form->valid ); } HTML-FormFu-2.07/t/constraints/required_only_on_reps.t0000644000175100017520000000322013404751171021436 0ustar carlcarluse strict; use warnings; use Test::More tests => 4; use HTML::FormFu; use lib 't/lib'; use HTMLFormFu::TestLib; my $form = HTML::FormFu->new; $form->load_config_file('t/constraints/required_only_on_reps.yml'); # Valid { $form->process( { foo_1 => 'a', bar_1 => '', buz_1 => 'g', moo_1 => 'j', foo_2 => '', bar_2 => 'e', buz_2 => '', moo_2 => 'k', foo_3 => '', bar_3 => '', buz_3 => 'i', moo_3 => 'l', count => 3, } ); ok( $form->submitted_and_valid ); } # Valid { $form->process( { foo_1 => 'a', bar_1 => 'd', buz_1 => 'g', moo_1 => 'j', foo_2 => 'b', bar_2 => 'e', buz_2 => 'h', moo_2 => 'k', foo_3 => 'c', bar_3 => 'f', buz_3 => 'i', moo_3 => 'l', count => 3, } ); ok( $form->submitted_and_valid ); } # Missing - Invalid { $form->process( { foo_1 => '', bar_1 => '', buz_1 => '', moo_1 => '', foo_2 => '', bar_2 => '', buz_2 => '', moo_2 => 'k', foo_3 => '', bar_3 => '', buz_3 => 'i', moo_3 => '', count => 3, } ); ok( !$form->submitted_and_valid ); is_deeply( [ $form->has_errors ], [ qw/ foo_1 buz_1 moo_1 bar_2 moo_3 / ] ); } HTML-FormFu-2.07/t/constraints/required_file.t0000644000175100017520000000315113404751171017652 0ustar carlcarluse strict; use warnings; use Test::More; use HTML::FormFu; eval "use CGI"; if ($@) { plan skip_all => 'CGI required'; die $!; } plan tests => 4; # Copied from CGI.pm - http://search.cpan.org/perldoc?CGI %ENV = ( %ENV, 'SCRIPT_NAME' => '/test.cgi', 'SERVER_NAME' => 'perl.org', 'HTTP_CONNECTION' => 'TE, close', 'REQUEST_METHOD' => 'POST', 'SCRIPT_URI' => 'http://www.perl.org/test.cgi', 'SCRIPT_FILENAME' => '/home/usr/test.cgi', 'SERVER_SOFTWARE' => 'Apache/1.3.27 (Unix) ', 'HTTP_TE' => 'deflate,gzip;q=0.3', 'QUERY_STRING' => '', 'REMOTE_PORT' => '1855', 'HTTP_USER_AGENT' => 'Mozilla/5.0 (compatible; Konqueror/2.1.1; X11)', 'SERVER_PORT' => '80', 'REMOTE_ADDR' => '127.0.0.1', 'CONTENT_TYPE' => 'multipart/form-data; boundary=xYzZY', 'SERVER_PROTOCOL' => 'HTTP/1.1', 'PATH' => '/usr/local/bin:/usr/bin:/bin', 'REQUEST_URI' => '/test.cgi', 'GATEWAY_INTERFACE' => 'CGI/1.1', 'SCRIPT_URL' => '/test.cgi', 'SERVER_ADDR' => '127.0.0.1', 'DOCUMENT_ROOT' => '/home/develop', 'HTTP_HOST' => 'www.perl.org' ); my $q; { my $file = 't/elements/file_post.txt'; local *STDIN; open STDIN, "<", $file or die "missing test file $file"; binmode STDIN; $q = CGI->new; } my $form = HTML::FormFu->new; $form->load_config_file('t/constraints/required_file.yml'); $form->process($q); ok( $form->submitted ); ok( !$form->has_errors ); ok( $form->valid('multiple') ); ok( $form->valid('hello_world') ); HTML-FormFu-2.07/t/constraints/required.t0000644000175100017520000000252213404751171016654 0ustar carlcarluse strict; use warnings; use Test::More tests => 16; use HTML::FormFu; use lib 't/lib'; use HTMLFormFu::TestLib; my $form = HTML::FormFu->new; $form->element('Text')->name('foo'); $form->element('Text')->name('bar'); $form->constraint('Required'); # Valid { $form->process( { foo => 'yada', bar => 'nada', } ); ok( $form->valid('foo'), 'foo valid' ); ok( $form->valid('bar'), 'bar valid' ); ok( grep { $_ eq 'foo' } $form->valid ); ok( grep { $_ eq 'bar' } $form->valid ); } # Missing - Invalid { $form->process( { foo => 'yada', } ); ok( $form->valid('foo'), 'foo value' ); ok( !$form->valid('bar'), 'bar not valid' ); ok( grep { $_ eq 'foo' } $form->valid ); ok( !grep { $_ eq 'bar' } $form->valid ); } # Empty string - Invalid { $form->process( { foo => '', bar => 2, } ); ok( !$form->valid('foo'), 'foo not valid' ); ok( $form->valid('bar'), 'bar valid' ); ok( !grep { $_ eq 'foo' } $form->valid ); ok( grep { $_ eq 'bar' } $form->valid ); } # "0" is valid { $form->process( { foo => 0, bar => 2, } ); ok( $form->valid('foo'), 'foo valid' ); ok( $form->valid('bar'), 'foo valid' ); ok( grep { $_ eq 'foo' } $form->valid ); ok( grep { $_ eq 'bar' } $form->valid ); } HTML-FormFu-2.07/t/constraints/singlevalue.t0000644000175100017520000000074013404751171017352 0ustar carlcarluse strict; use warnings; use Test::More tests => 1; use HTML::FormFu; my $form = HTML::FormFu->new; $form->element('Text')->name('foo'); $form->element('Text')->name('bar'); $form->element('Text')->name('baz'); $form->element('Text')->name('bif'); $form->element('Text')->name('bom'); $form->constraint('SingleValue'); $form->process( { foo => 1, bar => '', baz => [2], bif => [ 3, 4 ], } ); is_deeply( [ $form->has_errors ], ['bif'] ); HTML-FormFu-2.07/t/constraints/minrange.t0000644000175100017520000000114513404751171016634 0ustar carlcarluse strict; use warnings; use Test::More tests => 4; use HTML::FormFu; my $form = HTML::FormFu->new; $form->element('Text')->name('foo')->constraint('MinRange')->min(3); $form->element('Text')->name('bar')->constraint('MinRange')->min(3); # Valid { $form->process( { foo => 3, bar => 4, } ); ok( $form->valid('foo'), 'foo valid' ); ok( $form->valid('bar'), 'bar valid' ); } # Invalid { $form->process( { foo => 1, bar => 6, } ); ok( !$form->valid('foo'), 'foo not valid' ); ok( $form->valid('bar'), 'bar not valid' ); } HTML-FormFu-2.07/t/constraints/constraint_when_any_true_value.yml0000644000175100017520000000020213404751171023672 0ustar carlcarl--- elements: - name: foo - name: bar constraints: - type: Required when: field: foo HTML-FormFu-2.07/t/constraints/maxlength.t0000644000175100017520000000133213404751171017021 0ustar carlcarluse strict; use warnings; use Test::More tests => 5; use HTML::FormFu; my $form = HTML::FormFu->new; $form->element('Text')->name('foo')->constraint('MaxLength')->max(5); $form->element('Text')->name('bar')->constraint('MaxLength')->max(5); # Valid { $form->process( { foo => 'abc', bar => 'abcde', } ); ok( $form->valid('foo'), 'foo valid' ); ok( $form->valid('bar'), 'bar valid' ); } # Invalid { $form->process( { foo => 'ab', bar => 'abcdef', } ); ok( $form->valid('foo'), 'foo valid' ); ok( !$form->valid('bar'), 'bar not valid' ); is( $form->get_error('bar')->message, 'Must not be longer than 5 characters long' ); } HTML-FormFu-2.07/t/constraints/constraint_when_any_field.yml0000644000175100017520000000053213404751171022610 0ustar carlcarl--- elements: - name: a constraints: - type: MinMaxFields min: 1 max: 2 others: - 'b' - 'c' - 'd' when: any_field: - 'a' - 'b' - 'c' - 'd' - name: b - name: c - name: d HTML-FormFu-2.07/t/constraints/number.t0000644000175100017520000000136413404751171016327 0ustar carlcarluse strict; use warnings; use Test::More tests => 8; use HTML::FormFu; my $form = HTML::FormFu->new; $form->element('Text')->name('foo'); $form->element('Text')->name('bar'); $form->constraint('Number'); # Valid { $form->process( { foo => 1, bar => 2, } ); ok( $form->valid('foo'), 'foo valid' ); ok( $form->valid('bar'), 'bar valid' ); ok( grep { $_ eq 'foo' } $form->valid ); ok( grep { $_ eq 'bar' } $form->valid ); } # "0" is valid { $form->process( { foo => 0, bar => 2, } ); ok( $form->valid('foo'), 'foo valid' ); ok( $form->valid('bar'), 'foo valid' ); ok( grep { $_ eq 'foo' } $form->valid ); ok( grep { $_ eq 'bar' } $form->valid ); } HTML-FormFu-2.07/t/constraints/callback.t0000644000175100017520000000136213404751171016571 0ustar carlcarluse strict; use warnings; # base the package name on the test file path # to stop 'redefined' warnings under Test::Aggregate::Nested package My::Constraints::Callback; use HTML::FormFu; my $form = HTML::FormFu->new; $form->element('Text')->name('foo')->constraint('Callback')->callback( \&cb ); $form->element('Text')->name('bar')->constraint('Callback') ->callback("My::Constraints::Callback::cb"); sub cb { my $value = shift; ::ok(1) if grep { $value eq $_ ? 1 : 0 } qw/ 1 0 a /; return 1; } package main; use Test::More tests => 5; # Valid { $form->process( { foo => 1, bar => [ 0, 'a', 'b' ], } ); ::ok( $form->valid('foo'), 'foo valid' ); ::ok( $form->valid('bar'), 'bar valid' ); } HTML-FormFu-2.07/t/constraints/equal.t0000644000175100017520000000413113404751171016141 0ustar carlcarluse strict; use warnings; use Test::More tests => 21; use HTML::FormFu; my $form = HTML::FormFu->new; $form->element('Text')->name('foo')->constraint('Equal') ->others( [ 'bar', 'baz' ] ); $form->element('Text')->name('bar'); $form->element('Text')->name('baz'); # Valid { $form->process( { foo => 'yada', bar => 'yada', baz => 'yada', } ); ok( $form->valid('foo'), 'foo valid' ); ok( $form->valid('bar'), 'bar valid' ); ok( $form->valid('baz'), 'baz valid' ); } # Valid { $form->process( { foo => '', bar => '', baz => '', } ); ok( $form->valid('foo'), 'foo valid' ); ok( $form->valid('bar'), 'bar valid' ); ok( $form->valid('baz'), 'baz valid' ); } # Valid { $form->process( { foo => [ 'a', 'b' ], bar => [ 'a', 'b' ], baz => [ 'b', 'a' ], } ); ok( $form->valid('foo'), 'foo valid' ); ok( $form->valid('bar'), 'bar valid' ); ok( $form->valid('baz'), 'baz valid' ); } # Invalid { $form->process( { foo => 'yada', bar => 'yada', baz => 'x', } ); ok( $form->valid('foo'), 'foo valid' ); ok( $form->valid('bar'), 'bar valid' ); ok( !$form->valid('baz'), 'baz not valid' ); } # Invalid { $form->process( { foo => 'yada', bar => 'yada', baz => '', } ); ok( $form->valid('foo'), 'foo valid' ); ok( $form->valid('bar'), 'bar valid' ); ok( !$form->valid('baz'), 'baz not valid' ); } # Invalid { $form->process( { foo => '', bar => 'yada', baz => 'yada', } ); ok( $form->valid('foo'), 'foo valid' ); ok( !$form->valid('bar'), 'bar not valid' ); ok( !$form->valid('baz'), 'baz not valid' ); } # Invalid { $form->process( { foo => [ 'a', 'b' ], bar => [ 'a', 'b' ], baz => ['a'], } ); ok( $form->valid('foo'), 'foo valid' ); ok( $form->valid('bar'), 'bar valid' ); ok( !$form->valid('baz'), 'baz not valid' ); } HTML-FormFu-2.07/t/constraints/email.t0000644000175100017520000000221213404751171016117 0ustar carlcarluse strict; use warnings; use Test::More tests => 5; use HTML::FormFu; { my $form = HTML::FormFu->new; $form->element('Text')->name('foo')->constraint('Email'); # Valid { $form->process( { foo => 'cfranks@cpan.org', } ); ok( $form->valid('foo'), 'foo valid' ); } # Invalid { $form->process( { foo => 'cfranks@cpan', } ); ok( $form->has_errors('foo'), 'foo has errors' ); } # Email with IP valid by default { $form->process( { foo => 'rjbs@[1.2.3.4]' } ); ok( $form->valid('foo'), 'foo valid - ip ok by default' ); } } { my $form = HTML::FormFu->new; $form->element('Text')->name('foo')->constraint('Email') ->options( { 'allow_ip' => 0 } ); # Email with IP invalid when turned off { $form->process( { foo => 'rjbs@[1.2.3.4]' } ); ok( $form->has_errors('foo'), 'foo valid - ip invalid when turned off' ); } # Email with space - invalid { $form->process( { foo => 'Valid+except @space.org' } ); ok( $form->has_errors('foo'), 'email with space is invalid' ); } } HTML-FormFu-2.07/t/constraints/constraint_when.t0000644000175100017520000000754413404751171020252 0ustar carlcarluse strict; use warnings; package CB; # Just to test we can provide strings as callbacks # used by "coo2" field sub when_string_callback { return 1 } package main; use Test::More tests => 49; use HTML::FormFu; my $form = HTML::FormFu->new; $form->load_config_file('t/constraints/constraint_when.yml'); # When triggered depending on callback my $when_closure = sub { my $params = shift; return 1 if defined $params->{foo} && $params->{foo} eq '1'; }; $form->get_element('coo') ->get_constraint->when( { callback => $when_closure } ); # Valid { $form->process( { foo => 1, bar => 'bar_value', moo => undef, zoo => 'zoo_value', coo => 4, coo2 => 5, } ); # if 'moo' does not *exist* in process params # it wouldn't be valid ok( $form->valid('foo'), 'foo valid' ); ok( $form->valid('bar'), 'bar valid' ); ok( $form->valid('moo'), 'moo valid' ); ok( $form->valid('zoo'), 'zoo valid' ); ok( $form->valid('coo'), 'coo valid' ); ok( $form->valid('coo2'), 'coo2 valid' ); ok( grep { $_ eq 'foo' } $form->valid ); ok( grep { $_ eq 'bar' } $form->valid ); ok( grep { $_ eq 'moo' } $form->valid ); ok( grep { $_ eq 'zoo' } $form->valid ); ok( grep { $_ eq 'coo' } $form->valid ); ok( grep { $_ eq 'coo2' } $form->valid ); $form->process( { foo => 2, bar => undef, moo => 'moo_value', zoo => 'zoo_value', coo => 'not_a_number', } ); # if 'bar' does not *exist* in process params # it wouldn't be valid ok( $form->valid('foo'), 'foo valid' ); ok( $form->valid('bar'), 'bar valid' ); ok( $form->valid('moo'), 'moo valid' ); ok( $form->valid('zoo'), 'zoo valid' ); ok( $form->valid('coo'), 'coo valid' ); ok( grep { $_ eq 'foo' } $form->valid ); ok( grep { $_ eq 'bar' } $form->valid ); ok( grep { $_ eq 'moo' } $form->valid ); ok( grep { $_ eq 'zoo' } $form->valid ); ok( grep { $_ eq 'coo' } $form->valid ); $form->process( { foo => 5, bar => undef, moo => undef, zoo => undef, coo => undef, } ); # if 'bar' does not *exist* in process params # it wouldn't be valid ok( $form->valid('foo'), 'foo valid' ); ok( $form->valid('bar'), 'bar valid' ); ok( $form->valid('moo'), 'moo valid' ); ok( $form->valid('zoo'), 'zoo valid' ); ok( $form->valid('coo'), 'coo valid' ); ok( grep { $_ eq 'foo' } $form->valid ); ok( grep { $_ eq 'bar' } $form->valid ); ok( grep { $_ eq 'moo' } $form->valid ); ok( grep { $_ eq 'zoo' } $form->valid ); ok( grep { $_ eq 'coo' } $form->valid ); } # Invalid { $form->process( { foo => 1, moo => undef, coo => 'not_a_number', } ); ok( $form->has_errors ); ok( $form->valid('foo'), 'foo valid' ); ok( !$form->valid('bar'), 'bar not valid' ); ok( $form->valid('moo'), 'moo valid' ); ok( !$form->valid('zoo'), 'zoo not valid' ); ok( !$form->valid('coo'), 'coo not valid' ); $form->process( { foo => 'false value', bar => undef, moo => undef, zoo => 'zoo_value', coo => 'not_a_number', } ); # if 'bar' and 'moo' does not *exist* in process params # it wouldn't be valid ok( $form->has_errors ); ok( !$form->valid('foo'), 'foo not valid' ); ok( $form->valid('bar'), 'bar valid' ); ok( $form->valid('moo'), 'moo valid' ); ok( $form->valid('zoo'), 'zoo valid' ); ok( $form->valid('coo'), 'coo valid' ); ok( !grep { $_ eq 'foo' } $form->valid ); ok( grep { $_ eq 'bar' } $form->valid ); ok( grep { $_ eq 'moo' } $form->valid ); ok( grep { $_ eq 'zoo' } $form->valid ); ok( grep { $_ eq 'coo' } $form->valid ); } HTML-FormFu-2.07/t/constraints/autoset_group.t0000644000175100017520000000133713404751171017737 0ustar carlcarluse strict; use warnings; use Test::More tests => 2; use HTML::FormFu; my $form = HTML::FormFu->new; # Autoset on Select with optgroups my $field = $form->element('Select')->name('foo'); $field->options( [ ['item 1'], { value => 'item 2', }, { group => [ ['item 3'], { value => 'item 4', } ], }, ['item 5'], { group => [ { value => 'item 6', }, ['item 7'], ], }, ] ); $field->constraint('AutoSet'); # Valid { $form->process( { foo => 'item 6', } ); # Constraint set has 7 values is_deeply( $form->get_constraint->set, [ 'item 1', 'item 2', 'item 3', 'item 4', 'item 5', 'item 6', 'item 7' ], ); ok( $form->valid('foo') ); } HTML-FormFu-2.07/t/constraints/printable.t0000644000175100017520000000114613404751171017015 0ustar carlcarluse strict; use warnings; use Test::More tests => 4; use HTML::FormFu; my $form = HTML::FormFu->new; $form->element('Text')->name('foo'); $form->element('Text')->name('bar'); $form->constraint('Printable'); # Valid { $form->process( { foo => 'aaa', bar => 'bbbbbbb', } ); ok( $form->valid('foo'), 'foo valid' ); ok( $form->valid('bar'), 'bar valid' ); } # Invalid { $form->process( { foo => 'aaa', bar => '日本語', } ); ok( $form->valid('foo'), 'foo valid' ); ok( $form->has_errors('bar'), 'bar has errors' ); } HTML-FormFu-2.07/t/constraints/file_minsize.yml0000644000175100017520000000022713404751171020047 0ustar carlcarl--- action: 'http://www.perl.org/test.cgi' elements: - type: File name: hello_world constraints: - type: File::MinSize min: 1 HTML-FormFu-2.07/t/constraints/dependon_attach_errors_to_base.yml0000644000175100017520000000022413404751171023577 0ustar carlcarl--- elements: - name: foo - name: bar constraints: - type: DependOn others: foo attach_errors_to_base: 1 HTML-FormFu-2.07/t/constraints/constraint_when_default_empty_value.yml0000644000175100017520000000035413404751171024716 0ustar carlcarl--- elements: - name: foo type: Checkbox default_empty_value: 1 - name: bar constraints: - type: Required when: field: foo value: 1 not: 1 HTML-FormFu-2.07/t/constraints/allornone_attach_errors_to_others.yml0000644000175100017520000000024713404751171024373 0ustar carlcarl--- elements: - name: foo - name: bar constraints: - type: AllOrNone others: foo attach_errors_to_others: - foo HTML-FormFu-2.07/t/constraints/regex_common.t0000644000175100017520000000117613404751171017522 0ustar carlcarluse strict; use warnings; use Test::More tests => 4; use HTML::FormFu; my $form = HTML::FormFu->new; $form->element('Text')->name('foo'); $form->element('Text')->name('bar'); map { $_->common( [ 'URI', 'HTTP', { -scheme => 'https?' } ] ) } $form->constraint('Regex'); { $form->process( { foo => 'http://perl.org', bar => 'ftp://perl.org', } ); ok( $form->valid('foo') ); ok( $form->has_errors('bar') ); } { $form->process( { foo => 'https://perl.org', bar => 'www.perl.org', } ); ok( $form->valid('foo') ); ok( $form->has_errors('bar') ); } HTML-FormFu-2.07/t/constraints/not_word.t0000644000175100017520000000112413404751171016664 0ustar carlcarluse strict; use warnings; use Test::More tests => 4; use HTML::FormFu; my $form = HTML::FormFu->new; $form->element('Text')->name('foo'); $form->element('Text')->name('bar'); $form->constraint('Not_Word'); # Valid { $form->process( { foo => ' ', bar => "\t", } ); ok( $form->valid('foo'), 'foo valid' ); ok( $form->valid('bar'), 'bar valid' ); } # Invalid { $form->process( { foo => 'a', bar => "\n", } ); ok( $form->has_errors('foo'), 'foo has_errors' ); ok( $form->valid('bar'), 'bar valid' ); } HTML-FormFu-2.07/t/constraints/repeatable_any_not_increment_field_names.yml0000644000175100017520000000031513404751171025615 0ustar carlcarl--- elements: - type: Hidden name: count - type: Repeatable counter_name: count increment_field_names: 0 elements: - name: foo constraints: - 'Repeatable::Any' HTML-FormFu-2.07/t/constraints/localize.t0000644000175100017520000000105113404751171016632 0ustar carlcarluse strict; use warnings; use Test::More tests => 2; use HTML::FormFu; my $form = HTML::FormFu->new( { tt_args => { INCLUDE_PATH => 'share/templates/tt/xhtml' } } ); $form->element('Text')->name('foo'); $form->constraint('Required'); $form->constraint('MinLength')->min(3); $form->constraint('Regex')->regex(qr/^\d+$/) ->message_loc('form_constraint_integer'); $form->process( { foo => 'a' } ); like( $form->get_field('foo'), qr/This field must be an integer/ ); like( $form->get_field('foo'), qr/Must be at least 3 characters long/ ); HTML-FormFu-2.07/t/constraints/callbackonce.t0000644000175100017520000000122313404751171017432 0ustar carlcarluse strict; use warnings; use Test::More tests => 4; use HTML::FormFu; my $form = HTML::FormFu->new; $form->element('Text')->name('foo')->constraint('CallbackOnce')->callback( sub { is_deeply( \@_, [ 1, { foo => 1, bar => [ 0, 'a' ] } ] ); return 1; } ); $form->element('Text')->name('bar')->constraint('CallbackOnce')->callback( sub { is_deeply( \@_, [ [ 0, 'a' ], { foo => 1, bar => [ 0, 'a' ] } ] ); return 1; } ); # Valid { $form->process( { foo => 1, bar => [ 0, 'a' ], } ); ok( $form->valid('foo'), 'foo valid' ); ok( $form->valid('bar'), 'bar valid' ); } HTML-FormFu-2.07/t/constraints/datetime_parser.t0000644000175100017520000000077213404751171020211 0ustar carlcarluse strict; use warnings; use Test::More tests => 4; use HTML::FormFu; my $form = HTML::FormFu->new; my $foo = $form->element('Text')->name('foo'); $foo->constraint('DateTime')->parser( { strptime => '%d/%m/%Y' } ); # valid { $form->process( { foo => '31/12/2006' } ); ok( $form->submitted_and_valid ); is( $form->params->{foo}, '31/12/2006' ); } # invalid { $form->process( { foo => '12/31/2006' } ); ok( !$form->submitted_and_valid ); ok( $form->has_errors('foo') ); } HTML-FormFu-2.07/t/constraints/file_maxsize.t0000644000175100017520000000351613404751171017517 0ustar carlcarluse strict; use warnings; use Test::More tests => 7; use HTML::FormFu; use CGI; # Copied from CGI.pm - http://search.cpan.org/perldoc?CGI %ENV = ( %ENV, 'SCRIPT_NAME' => '/test.cgi', 'SERVER_NAME' => 'perl.org', 'HTTP_CONNECTION' => 'TE, close', 'REQUEST_METHOD' => 'POST', 'SCRIPT_URI' => 'http://www.perl.org/test.cgi', 'SCRIPT_FILENAME' => '/home/usr/test.cgi', 'SERVER_SOFTWARE' => 'Apache/1.3.27 (Unix) ', 'HTTP_TE' => 'deflate,gzip;q=0.3', 'QUERY_STRING' => '', 'REMOTE_PORT' => '1855', 'HTTP_USER_AGENT' => 'Mozilla/5.0 (compatible; Konqueror/2.1.1; X11)', 'SERVER_PORT' => '80', 'REMOTE_ADDR' => '127.0.0.1', 'CONTENT_TYPE' => 'multipart/form-data; boundary=xYzZY', 'SERVER_PROTOCOL' => 'HTTP/1.1', 'PATH' => '/usr/local/bin:/usr/bin:/bin', 'REQUEST_URI' => '/test.cgi', 'GATEWAY_INTERFACE' => 'CGI/1.1', 'SCRIPT_URL' => '/test.cgi', 'SERVER_ADDR' => '127.0.0.1', 'DOCUMENT_ROOT' => '/home/develop', 'HTTP_HOST' => 'www.perl.org' ); my $q; { my $file = 't/elements/file_post.txt'; local *STDIN; open STDIN, "<", $file or die "missing test file $file"; binmode STDIN; $q = CGI->new; } my $form = HTML::FormFu->new( { tt_args => { INCLUDE_PATH => 'share/templates/tt/xhtml' } } ); $form->load_config_file('t/constraints/file_maxsize.yml'); $form->process($q); { ok( $form->submitted ); ok( !$form->has_errors('hello_world') ); ok( $form->valid('hello_world') ); } $form->process( { hello_world => 'not a file', } ); { ok( $form->submitted ); ok( $form->has_errors('hello_world') ); ok( !$form->valid('hello_world') ); like( "$form", qr/File-size must be no more than 15 bytes/ ); } HTML-FormFu-2.07/t/constraints/minmaxfields_with_filter_split.yml0000644000175100017520000000052013404751171023661 0ustar carlcarl--- elements: - name: foo constraints: - type: MinMaxFields others: - bar - baz min: 0 max: 1 filters: - type: Split regex: ',' - name: bar filters: - type: Split regex: ',' - name: baz filters: - type: Split regex: ',' HTML-FormFu-2.07/t/constraints/regex_anchored.t0000644000175100017520000000140213404751171020005 0ustar carlcarluse strict; use warnings; use Test::More tests => 4; use HTML::FormFu; my $form = HTML::FormFu->new; my $foo = $form->element('Text')->name('foo'); my $bar = $form->element('Text')->name('bar'); $foo->constraint( { type => 'Regex', regex => 'xxx', } ); $bar->constraint( { type => 'Regex', regex => 'xxx', anchored => 1, } ); # Valid { $form->process( { foo => ' xxx ', bar => 'xxx', } ); ok( $form->valid('foo'), 'foo valid' ); ok( $form->valid('bar'), 'bar valid' ); } # Invalid { $form->process( { foo => ' xxx ', bar => ' xxx ', } ); ok( $form->valid('foo'), 'foo valid' ); ok( !$form->valid('bar'), 'foo invalid' ); } HTML-FormFu-2.07/t/constraints/required_file.yml0000644000175100017520000000024013404751171020204 0ustar carlcarl--- action: 'http://www.perl.org/test.cgi' elements: - type: File name: multiple - type: File name: hello_world constraints: - type: Required HTML-FormFu-2.07/t/constraints/repeatable_any.yml0000644000175100017520000000025013404751171020341 0ustar carlcarl--- elements: - type: Hidden name: count - type: Repeatable counter_name: count elements: - name: foo constraints: - 'Repeatable::Any' HTML-FormFu-2.07/t/constraints/minlength.t0000644000175100017520000000132213404751171017016 0ustar carlcarluse strict; use warnings; use Test::More tests => 5; use HTML::FormFu; my $form = HTML::FormFu->new; $form->element('Text')->name('foo')->constraint('MinLength')->min(3); $form->element('Text')->name('bar')->constraint('MinLength')->min(3); # Valid { $form->process( { foo => 'abc', bar => 'abcd', } ); ok( $form->valid('foo'), 'foo valid' ); ok( $form->valid('bar'), 'bar valid' ); } # Invalid { $form->process( { foo => 'ab', bar => 'abcdef', } ); ok( !$form->valid('foo'), 'foo not valid' ); ok( $form->valid('bar'), 'bar valid' ); is( $form->get_error('foo')->message, 'Must be at least 3 characters long' ); } HTML-FormFu-2.07/t/constraints/json.t0000644000175100017520000000101413404751171016000 0ustar carlcarluse strict; use warnings; use Test::More tests => 4; use HTML::FormFu; my $form = HTML::FormFu->new; $form->element('Text')->name('foo'); $form->constraint('JSON'); my @valid = ( '{"foo":"bar"}', '[1,2]', ); for my $string (@valid) { $form->process( { foo => $string, } ); ok( $form->valid('foo'), "foo valid: $string" ); } my @invalid = ( "{'foo':'bar'}", 'plain text', ); for my $string (@invalid) { $form->process( { foo => $string, } ); ok( !$form->valid('foo'), "foo not valid: $string" ); } HTML-FormFu-2.07/t/constraints/repeatable_any.t0000644000175100017520000000316213404751171020010 0ustar carlcarluse strict; use warnings; use Test::More tests => 10; use HTML::FormFu; use lib 't/lib'; use HTMLFormFu::TestLib; my $form = HTML::FormFu->new( { tt_args => { INCLUDE_PATH => 'share/templates/tt/xhtml' } } ); $form->load_config_file('t/constraints/repeatable_any.yml'); $form->get_element( { type => 'Repeatable' } )->repeat(2); # Valid { $form->process( { foo_1 => 'a', foo_2 => 'b', count => 2, } ); ok( $form->submitted_and_valid ); is_deeply( $form->params, { foo_1 => 'a', foo_2 => 'b', count => 2, } ); } # Valid - 1 missing { $form->process( { foo_1 => 'a', foo_2 => '', count => 2, } ); ok( $form->submitted_and_valid ); is_deeply( $form->params, { foo_1 => 'a', foo_2 => '', count => 2, } ); } # Valid - 1 missing { $form->process( { foo_1 => '', foo_2 => 'b', count => 2, } ); ok( $form->submitted_and_valid ); is_deeply( $form->params, { foo_1 => '', foo_2 => 'b', count => 2, } ); } # Missing - Invalid { $form->process( { foo_1 => '', foo_2 => '', count => 2, } ); ok( !$form->submitted_and_valid ); # error is only attached to first rep is_deeply( [ $form->has_errors ], ['foo_1'] ); like( $form->get_field( { nested_name => 'foo_1' } ), qr/is required/ ); unlike( $form->get_field( { nested_name => 'foo_2' } ), qr/is required/ ); } HTML-FormFu-2.07/t/constraints/dependon.t0000644000175100017520000000117113404751171016627 0ustar carlcarluse strict; use warnings; use Test::More tests => 4; use HTML::FormFu; my $form = HTML::FormFu->new; $form->element('Text')->name('foo')->constraint('DependOn') ->others( [qw/ bar baz /] ); $form->element('Text')->name('bar'); $form->element('Text')->name('baz'); # Valid { $form->process( { foo => 1, bar => 'a', baz => [2], } ); ok( !$form->has_errors ); } # Invalid { $form->process( { foo => 1, bar => '', baz => 2, } ); ok( $form->valid('foo') ); ok( $form->has_errors('bar') ); ok( $form->valid('baz') ); } HTML-FormFu-2.07/t/constraints/dependon_attach_errors_to_base.t0000644000175100017520000000101413404751171023237 0ustar carlcarluse strict; use warnings; use Test::More tests => 4; use HTML::FormFu; my $form = HTML::FormFu->new; $form->load_config_file('t/constraints/dependon_attach_errors_to_base.yml'); # Valid { $form->process( { foo => 'a', bar => 'b', } ); ok( $form->submitted_and_valid ); } # Invalid { $form->process( { foo => '', bar => 'b', } ); ok( !$form->submitted_and_valid ); ok( !$form->has_errors('foo') ); ok( $form->has_errors('bar') ); } HTML-FormFu-2.07/t/constraints/constraint_when.yml0000644000175100017520000000120313404751171020572 0ustar carlcarl--- elements: - name: foo constraints: - type: Integer - name: bar constraints: - type: Required when: field: foo value: 1 - name: moo constraints: type: Required when: field: foo values: [2,3,4] - name: zoo constraints: - type: Required when: field: foo value: 5 not: 1 - name: coo constraints: - type: Number - name: coo2 constraints: - type: Integer when: callback: 'CB::when_string_callback' HTML-FormFu-2.07/t/constraints/word.t0000644000175100017520000000251213404751171016006 0ustar carlcarluse strict; use warnings; use Test::More tests => 16; use HTML::FormFu; my $form = HTML::FormFu->new; $form->element('Text')->name('foo'); $form->element('Text')->name('bar'); $form->constraint('Word'); # Valid { $form->process( { foo => 'aaa', bar => 'bbbbbbb', } ); ok( $form->valid('foo'), 'foo valid' ); ok( $form->valid('bar'), 'bar valid' ); ok( grep { $_ eq 'foo' } $form->valid ); ok( grep { $_ eq 'bar' } $form->valid ); } # [space] - Invalid { $form->process( { foo => 'a', bar => 'b c', } ); ok( $form->valid('foo'), 'foo valid' ); ok( !$form->valid('bar'), 'foo valid' ); ok( grep { $_ eq 'foo' } $form->valid ); ok( !grep { $_ eq 'bar' } $form->valid ); } # [newline] - Invalid { $form->process( { foo => 'a', bar => "b\nc", } ); ok( $form->valid('foo'), 'foo valid' ); ok( !$form->valid('bar'), 'foo valid' ); ok( grep { $_ eq 'foo' } $form->valid ); ok( !grep { $_ eq 'bar' } $form->valid ); } # "0" is valid { $form->process( { foo => 0, bar => 2, } ); ok( $form->valid('foo'), 'foo valid' ); ok( $form->valid('bar'), 'foo valid' ); ok( grep { $_ eq 'foo' } $form->valid ); ok( grep { $_ eq 'bar' } $form->valid ); } HTML-FormFu-2.07/t/constraints/allornone.t0000644000175100017520000000157113404751171017030 0ustar carlcarluse strict; use warnings; use Test::More tests => 7; use HTML::FormFu; my $form = HTML::FormFu->new->indicator( sub {1} ); $form->element('Text')->name('foo')->constraint('AllOrNone') ->others( [qw/ bar baz bif /] ); $form->element('Text')->name('bar'); $form->element('Text')->name('baz'); $form->element('Text')->name('bif'); # Valid { $form->process( { foo => 1, bar => 'a', baz => [2], bif => [ 3, 4 ], } ); ok( !$form->has_errors ); } # Valid { $form->process( {} ); ok( !$form->has_errors ); } # Invalid { $form->process( { foo => 1, bar => '', baz => [2], bif => [ 3, 4 ], } ); ok( $form->has_errors ); ok( $form->valid('foo') ); ok( $form->has_errors('bar') ); ok( $form->valid('baz') ); ok( $form->valid('bif') ); } HTML-FormFu-2.07/t/constraints/constraint_when_fields.yml0000644000175100017520000000025613404751171022127 0ustar carlcarl--- elements: - name: a constraints: - type: Bool when: fields: - 'b' - 'c' - name: b - name: c HTML-FormFu-2.07/t/constraints/constraint.t0000644000175100017520000000550413404751171017223 0ustar carlcarluse strict; use warnings; use Test::More tests => 40; use HTML::FormFu; my $form = HTML::FormFu->new; $form->element('Text')->name('foo'); $form->element('Text')->name('bar'); my @c1 = $form->constraint( { type => 'Number', names => [qw/ foo bar /], } ); is( $c1[0]->name, 'foo' ); is( $c1[0]->type, 'Number' ); is( $c1[1]->name, 'bar' ); is( $c1[1]->type, 'Number' ); { my @a = $form->constraint( [ { type => 'Regex', names => [qw/ foo bar /], }, { type => 'Required', names => 'bar', }, ] ); is( $a[0]->name, 'foo' ); is( $a[0]->type, 'Regex' ); is( $a[1]->name, 'bar' ); is( $a[1]->type, 'Regex' ); is( $a[2]->name, 'bar' ); is( $a[2]->type, 'Required' ); } # $element->constraint my $ec_element = $form->element('Text')->name('ec'); $ec_element->constraint('Regex')->regex(qr/^\d+$/); # Valid { $form->process( { foo => 1, bar => 2, ec => 3, } ); ok( $form->valid('foo'), 'foo valid' ); ok( $form->valid('bar'), 'bar valid' ); ok( $form->valid('ec'), 'ec valid' ); ok( grep { $_ eq 'foo' } $form->valid ); ok( grep { $_ eq 'bar' } $form->valid ); ok( grep { $_ eq 'ec' } $form->valid ); } # Invalid { $form->process( { foo => 1, bar => 'baz', ec => 'a', } ); ok( $form->valid('foo'), 'foo valid' ); ok( !$form->valid('bar'), 'bar not valid' ); ok( !$form->valid('ec'), 'ec not valid' ); ok( grep { $_ eq 'foo' } $form->valid ); ok( !grep { $_ eq 'bar' } $form->valid ); ok( !grep { $_ eq 'ec' } $form->valid ); } # Empty string Valid { $form->process( { foo => '', bar => 2, ec => '', } ); ok( $form->valid('foo'), 'foo valid' ); ok( $form->valid('bar'), 'bar valid' ); ok( $form->valid('ec'), 'ec not valid' ); ok( grep { $_ eq 'foo' } $form->valid ); ok( grep { $_ eq 'bar' } $form->valid ); ok( grep { $_ eq 'ec' } $form->valid ); } # Missing Invalid { $form->process( { foo => '', bar => 2, } ); ok( $form->valid('foo'), 'foo valid' ); ok( $form->valid('bar'), 'bar valid' ); ok( !$form->valid('ec'), 'ec not valid' ); ok( grep { $_ eq 'foo' } $form->valid ); ok( grep { $_ eq 'bar' } $form->valid ); ok( !grep { $_ eq 'ec' } $form->valid ); } # zero "0" Valid { $form->process( { foo => 0, bar => 1, ec => 0, } ); ok( $form->valid('foo'), 'foo valid' ); ok( $form->valid('foo'), 'foo valid' ); ok( $form->valid('ec'), 'ec valid' ); ok( grep { $_ eq 'foo' } $form->valid ); ok( grep { $_ eq 'bar' } $form->valid ); ok( grep { $_ eq 'ec' } $form->valid ); } HTML-FormFu-2.07/t/constraints/email-mx.t0000644000175100017520000000204513404751171016545 0ustar carlcarluse strict; use warnings; use Test::RequiresInternet 'cpan.org' => 80; use Test::More tests => 3; use HTML::FormFu; { my $form = HTML::FormFu->new; $form->element('Text')->name('foo')->constraint('Email') ->options('mxcheck'); # Valid - Scalar { $form->process( { foo => 'cfranks@cpan.org' } ); ok( $form->valid('foo'), 'foo valid - mxcheck scalar' ); } } { my $form = HTML::FormFu->new; $form->element('Text')->name('foo')->constraint('Email') ->options( ['mxcheck'] ); # Valid - Array { $form->process( { foo => 'djzort@cpan.org' } ); ok( $form->valid('foo'), 'foo valid - mxcheck array' ); } } { my $form = HTML::FormFu->new; $form->element('Text')->name('foo')->constraint('Email') ->options( { 'mxcheck' => 1 } ); # Valid - Hash { $form->process( { foo => 'djzort@cpan.org', options => { 'mxcheck' => 1 } } ); ok( $form->valid('foo'), 'foo valid - mxcheck hash' ); } } HTML-FormFu-2.07/t/constraints/minmaxfields.t0000644000175100017520000000247113404751171017517 0ustar carlcarluse strict; use warnings; use Test::More tests => 8; use HTML::FormFu; my $form = HTML::FormFu->new; $form->element('Text')->name('foo')->constraint('MinMaxFields') ->others( [qw/ bar baz boz/] )->min(1)->max(2); $form->element('Text')->name('bar'); $form->element('Text')->name('baz'); $form->element('Text')->name('boz'); # Valid { $form->process( { foo => 1, bar => '', baz => [2], boz => '', } ); ok( !$form->has_errors ); $form->process( { foo => 1, bar => '', baz => '', boz => '', } ); ok( !$form->has_errors ); } # Invalid { $form->process( { foo => 1, bar => '', baz => 2, boz => '22', } ); ok( $form->has_errors ); ok( !$form->valid('foo') ); ok( $form->valid('bar') ); ok( $form->valid('baz') ); ok( $form->valid('boz') ); } { # Test setting default for max when others is a single element my $form = HTML::FormFu->new; $form->element('Text')->name('foo')->constraint('MinMaxFields') ->others('bar'); $form->element('Text')->name('bar'); { $form->process( { foo => 1, bar => '', } ); ok( !$form->has_errors ); } } HTML-FormFu-2.07/t/constraints/file_size.t0000644000175100017520000000372513404751171017013 0ustar carlcarluse strict; use warnings; use Test::More; use HTML::FormFu; eval "use CGI"; if ($@) { plan skip_all => 'CGI required'; die $!; } plan tests => 10; # Copied from CGI.pm - http://search.cpan.org/perldoc?CGI %ENV = ( %ENV, 'SCRIPT_NAME' => '/test.cgi', 'SERVER_NAME' => 'perl.org', 'HTTP_CONNECTION' => 'TE, close', 'REQUEST_METHOD' => 'POST', 'SCRIPT_URI' => 'http://www.perl.org/test.cgi', 'SCRIPT_FILENAME' => '/home/usr/test.cgi', 'SERVER_SOFTWARE' => 'Apache/1.3.27 (Unix) ', 'HTTP_TE' => 'deflate,gzip;q=0.3', 'QUERY_STRING' => '', 'REMOTE_PORT' => '1855', 'HTTP_USER_AGENT' => 'Mozilla/5.0 (compatible; Konqueror/2.1.1; X11)', 'SERVER_PORT' => '80', 'REMOTE_ADDR' => '127.0.0.1', 'CONTENT_TYPE' => 'multipart/form-data; boundary=xYzZY', 'SERVER_PROTOCOL' => 'HTTP/1.1', 'PATH' => '/usr/local/bin:/usr/bin:/bin', 'REQUEST_URI' => '/test.cgi', 'GATEWAY_INTERFACE' => 'CGI/1.1', 'SCRIPT_URL' => '/test.cgi', 'SERVER_ADDR' => '127.0.0.1', 'DOCUMENT_ROOT' => '/home/develop', 'HTTP_HOST' => 'www.perl.org' ); my $q; { my $file = 't/elements/file_post.txt'; local *STDIN; open STDIN, "<", $file or die "missing test file $file"; binmode STDIN; $q = CGI->new; } my $form = HTML::FormFu->new; $form->load_config_file('t/constraints/file_size.yml'); $form->process($q); { ok( $form->submitted ); ok( !$form->has_errors('hello_world') ); ok( $form->has_errors('does_not_exist_gif') ); ok( $form->valid('hello_world') ); ok( !$form->valid('does_not_exist_gif') ); } $form->process( { hello_world => 'not a file', } ); { ok( $form->submitted ); ok( $form->has_errors('hello_world') ); ok( !$form->has_errors('does_not_exist_gif') ); ok( !$form->valid('hello_world') ); ok( !$form->valid('does_not_exist_gif') ); } HTML-FormFu-2.07/t/constraints/dependon_attach_errors_to_others.yml0000644000175100017520000000024613404751171024175 0ustar carlcarl--- elements: - name: foo - name: bar constraints: - type: DependOn others: foo attach_errors_to_others: - foo HTML-FormFu-2.07/t/constraints/ascii.t0000644000175100017520000000113113404751171016117 0ustar carlcarluse strict; use warnings; use Test::More tests => 4; use HTML::FormFu; my $form = HTML::FormFu->new; $form->element('Text')->name('foo'); $form->element('Text')->name('bar'); $form->constraint('ASCII'); # Valid { $form->process( { foo => 'aaa', bar => 'bbbbbbb', } ); ok( $form->valid('foo'), 'foo valid' ); ok( $form->valid('bar'), 'bar valid' ); } # Invalid { $form->process( { foo => 'aaa', bar => '日本語', } ); ok( $form->valid('foo'), 'foo valid' ); ok( !$form->valid('bar'), 'bar not valid' ); } HTML-FormFu-2.07/t/constraints/constraint_when_fields.t0000644000175100017520000000430713404751171021572 0ustar carlcarluse strict; use warnings; use Test::More 'no_plan'; use HTML::FormFu; my $form = HTML::FormFu->new; $form->load_config_file('t/constraints/constraint_when_fields.yml'); # Valid { $form->process( { a => '', b => '', c => '', } ); ok( $form->submitted_and_valid ); ok( $form->valid('a'), 'a valid' ); ok( $form->valid('b'), 'b valid' ); ok( $form->valid('c'), 'c valid' ); } # Valid { $form->process( { a => '1', b => '', c => '', } ); ok( $form->submitted_and_valid ); ok( $form->valid('a'), 'a valid' ); ok( $form->valid('b'), 'b valid' ); ok( $form->valid('c'), 'c valid' ); } # Valid { # Bool constraint doesn't run because b & c don't both have values $form->process( { a => 'a', b => '', c => '', } ); ok( $form->submitted_and_valid ); ok( $form->valid('a'), 'a valid' ); ok( $form->valid('b'), 'b valid' ); ok( $form->valid('c'), 'c valid' ); } # Valid { # Bool constraint doesn't run because b & c don't both have values $form->process( { a => 'a', b => '', c => '1', } ); ok( $form->submitted_and_valid ); ok( $form->valid('a'), 'a valid' ); ok( $form->valid('b'), 'b valid' ); ok( $form->valid('c'), 'c valid' ); } # Valid { $form->process( { a => '1', b => '1', c => '1', } ); ok( $form->submitted_and_valid ); ok( $form->valid('a'), 'a valid' ); ok( $form->valid('b'), 'b valid' ); ok( $form->valid('c'), 'c valid' ); } # Valid { # Empty is valid $form->process( { a => '', b => '1', c => '1', } ); ok( $form->submitted_and_valid ); ok( $form->valid('a'), 'a valid' ); ok( $form->valid('b'), 'b valid' ); ok( $form->valid('c'), 'c valid' ); } # Invalid { $form->process( { a => 'a', b => '1', c => '1', } ); ok( !$form->submitted_and_valid ); ok( !$form->valid('a'), 'a not valid' ); ok( $form->valid('b'), 'b valid' ); ok( $form->valid('c'), 'c valid' ); } HTML-FormFu-2.07/t/constraints/autoset.t0000644000175100017520000000146513404751171016525 0ustar carlcarluse strict; use warnings; use Test::More tests => 5; use HTML::FormFu; my $form = HTML::FormFu->new; # Autoset with multiple values $form->element('Select')->name('foo')->values( [qw/ one two three /] ) ->constraint('AutoSet'); # Valid { $form->process( { foo => 'two', } ); # Constraint set has 3 values is_deeply( $form->get_constraint->set, [qw/ one two three /] ); ok( $form->valid('foo') ); } # Invalid { $form->process( { foo => 'yes', } ); ok( $form->has_errors('foo') ); } # Autoset with a single value $form->element('Select')->name('bar')->values( [qw/ one /] ) ->constraint('AutoSet'); # Valid { $form->process( { bar => 'one', } ); ok( $form->valid('bar') ); } # Invalid { $form->process( { bar => 'yes', } ); ok( $form->has_errors('bar') ); } HTML-FormFu-2.07/t/constraints/maxrange.t0000644000175100017520000000114513404751171016636 0ustar carlcarluse strict; use warnings; use Test::More tests => 4; use HTML::FormFu; my $form = HTML::FormFu->new; $form->element('Text')->name('foo')->constraint('MaxRange')->max(5); $form->element('Text')->name('bar')->constraint('MaxRange')->max(5); # Valid { $form->process( { foo => 3, bar => 4, } ); ok( $form->valid('foo'), 'foo valid' ); ok( $form->valid('bar'), 'bar valid' ); } # Invalid { $form->process( { foo => 1, bar => 6, } ); ok( $form->valid('foo'), 'foo not valid' ); ok( !$form->valid('bar'), 'bar not valid' ); } HTML-FormFu-2.07/t/constraints/dependon_attach_errors_to_others.t0000644000175100017520000000101613404751171023633 0ustar carlcarluse strict; use warnings; use Test::More tests => 4; use HTML::FormFu; my $form = HTML::FormFu->new; $form->load_config_file('t/constraints/dependon_attach_errors_to_others.yml'); # Valid { $form->process( { foo => 'a', bar => 'b', } ); ok( $form->submitted_and_valid ); } # Invalid { $form->process( { foo => '', bar => 'b', } ); ok( !$form->submitted_and_valid ); ok( $form->has_errors('foo') ); ok( !$form->has_errors('bar') ); } HTML-FormFu-2.07/t/constraints/required_only_on_reps.yml0000644000175100017520000000076713404751171022011 0ustar carlcarl--- elements: - type: Hidden name: count - type: Repeatable counter_name: count elements: - name: foo constraints: - type: Required only_on_reps: 1 - name: bar constraints: - type: Required only_on_reps: 2 - name: buz constraints: - type: Required only_on_reps: [1, 3] - name: moo constraints: - type: Required HTML-FormFu-2.07/t/constraints/bool.t0000644000175100017520000000110713404751171015765 0ustar carlcarluse strict; use warnings; use Test::More tests => 4; use HTML::FormFu; my $form = HTML::FormFu->new; $form->element('Text')->name('foo'); $form->element('Text')->name('bar'); $form->constraint('Bool'); # Valid { $form->process( { foo => 1, bar => 0, } ); ok( $form->valid('foo'), 'foo valid' ); ok( $form->valid('bar'), 'bar valid' ); } # Invalid { $form->process( { foo => '01', bar => 'a', } ); ok( !$form->valid('foo'), 'foo not valid' ); ok( !$form->valid('bar'), 'bar not valid' ); } HTML-FormFu-2.07/t/constraints/constraint_when_any_field.t0000644000175100017520000000675613404751171022270 0ustar carlcarluse strict; use warnings; use Test::More 'no_plan'; use HTML::FormFu; my $form = HTML::FormFu->new; $form->load_config_file('t/constraints/constraint_when_any_field.yml'); #$ENV{HTML_FORMFU_DEBUG_PROCESS} = 1; # Valid { $form->process( { a => '', b => '', c => '', d => '', } ); ok( $form->submitted_and_valid ); ok( $form->valid('a'), 'a valid' ); ok( $form->valid('b'), 'b valid' ); ok( $form->valid('c'), 'c valid' ); ok( $form->valid('d'), 'd valid' ); } # Valid { $form->process( { a => '1', b => '', c => '', d => '', } ); ok( $form->submitted_and_valid ); ok( $form->valid('a'), 'a valid' ); ok( $form->valid('b'), 'b valid' ); ok( $form->valid('c'), 'c valid' ); ok( $form->valid('d'), 'd valid' ); } # Valid { $form->process( { a => '', b => '1', c => '', d => '', } ); ok( $form->submitted_and_valid ); ok( $form->valid('a'), 'a valid' ); ok( $form->valid('b'), 'b valid' ); ok( $form->valid('c'), 'c valid' ); ok( $form->valid('d'), 'd valid' ); } # Valid { $form->process( { a => '', b => '', c => '1', d => '', } ); ok( $form->submitted_and_valid ); ok( $form->valid('a'), 'a valid' ); ok( $form->valid('b'), 'b valid' ); ok( $form->valid('c'), 'c valid' ); ok( $form->valid('d'), 'd valid' ); } # Valid { $form->process( { a => '', b => '', c => '', d => '1', } ); ok( $form->submitted_and_valid ); ok( $form->valid('a'), 'a valid' ); ok( $form->valid('b'), 'b valid' ); ok( $form->valid('c'), 'c valid' ); ok( $form->valid('d'), 'd valid' ); } # Valid { $form->process( { a => '1', b => '1', c => '', d => '', } ); ok( $form->submitted_and_valid ); ok( $form->valid('a'), 'a valid' ); ok( $form->valid('b'), 'b valid' ); ok( $form->valid('c'), 'c valid' ); ok( $form->valid('d'), 'd valid' ); } # Valid { $form->process( { a => '', b => '1', c => '1', d => '', } ); ok( $form->submitted_and_valid ); ok( $form->valid('a'), 'a valid' ); ok( $form->valid('b'), 'b valid' ); ok( $form->valid('c'), 'c valid' ); ok( $form->valid('d'), 'd valid' ); } # Invalid { $form->process( { a => '1', b => '1', c => '1', d => '', } ); ok( !$form->submitted_and_valid ); ok( !$form->valid('a'), 'a not valid' ); ok( $form->valid('b'), 'b valid' ); ok( $form->valid('c'), 'c valid' ); ok( $form->valid('d'), 'd valid' ); } # Invalid { $form->process( { a => '', b => '1', c => '1', d => '1', } ); ok( !$form->submitted_and_valid ); ok( !$form->valid('a'), 'a not valid' ); ok( $form->valid('b'), 'b valid' ); ok( $form->valid('c'), 'c valid' ); ok( $form->valid('d'), 'd valid' ); } # Invalid { $form->process( { a => '1', b => '1', c => '1', d => '1', } ); ok( !$form->submitted_and_valid ); ok( !$form->valid('a'), 'a not valid' ); ok( $form->valid('b'), 'b valid' ); ok( $form->valid('c'), 'c valid' ); ok( $form->valid('d'), 'd valid' ); } HTML-FormFu-2.07/t/constraints/range.t0000644000175100017520000000115713404751171016133 0ustar carlcarluse strict; use warnings; use Test::More tests => 4; use HTML::FormFu; my $form = HTML::FormFu->new; $form->element('Text')->name('foo')->constraint('Range')->min(3)->max(5); $form->element('Text')->name('bar')->constraint('Range')->min(3)->max(5); # Valid { $form->process( { foo => 3, bar => 4, } ); ok( $form->valid('foo'), 'foo valid' ); ok( $form->valid('bar'), 'bar valid' ); } # Invalid { $form->process( { foo => 1, bar => 6, } ); ok( !$form->valid('foo'), 'foo not valid' ); ok( !$form->valid('bar'), 'bar not valid' ); } HTML-FormFu-2.07/t/constraints/set.t0000644000175100017520000000121313404751171015623 0ustar carlcarluse strict; use warnings; use Test::More tests => 4; use HTML::FormFu; my $form = HTML::FormFu->new; $form->element('Text')->name('foo')->constraint('Set')->set( [qw/ yes no /] ); $form->element('Text')->name('bar')->constraint('Set')->set( [qw/ yes no /] ); # Valid { $form->process( { foo => 'yes', bar => 'no', } ); ok( $form->valid('foo'), 'foo valid' ); ok( $form->valid('bar'), 'bar valid' ); } # Invalid { $form->process( { foo => 'yes', bar => 'x', } ); ok( $form->valid('foo'), 'foo valid' ); ok( $form->has_errors('bar'), 'bar has_errors' ); } HTML-FormFu-2.07/t/constraints/equal_internals.t0000644000175100017520000000066213404751171020225 0ustar carlcarluse strict; use warnings; use Test::More tests => 5; use HTML::FormFu::Constraint::Equal; ok( HTML::FormFu::Constraint::Equal::_values_eq( '1', '1' ) ); ok( HTML::FormFu::Constraint::Equal::_values_eq( ' ', ' ' ) ); ok( HTML::FormFu::Constraint::Equal::_values_eq( 'aa', 'aa' ) ); ok( HTML::FormFu::Constraint::Equal::_values_eq( ['x'], ['x'] ) ); ok( HTML::FormFu::Constraint::Equal::_values_eq( [ 'a', 'b' ], [ 'b', 'a' ] ) ); HTML-FormFu-2.07/t/constraints/allornone_attach_errors_to_base.t0000644000175100017520000000101513404751171023435 0ustar carlcarluse strict; use warnings; use Test::More tests => 4; use HTML::FormFu; my $form = HTML::FormFu->new; $form->load_config_file('t/constraints/allornone_attach_errors_to_base.yml'); # Valid { $form->process( { foo => 'a', bar => 'b', } ); ok( $form->submitted_and_valid ); } # Invalid { $form->process( { foo => '', bar => 'b', } ); ok( !$form->submitted_and_valid ); ok( !$form->has_errors('foo') ); ok( $form->has_errors('bar') ); } HTML-FormFu-2.07/t/constraints/xml.t0000644000175100017520000000063713404751171015641 0ustar carlcarluse strict; use warnings; use Test::More tests => 1; use HTML::FormFu; my $form = HTML::FormFu->new( { tt_args => { INCLUDE_PATH => 'share/templates/tt/xhtml' } } ); $form->element('Text')->name('foo'); $form->constraint('Required'); $form->constraint('Regex')->regex(qr/^\d+$/)->message_xml("don't escape "); $form->process( { foo => 'a' } ); like( $form->get_field('foo'), qr/don't escape / ); HTML-FormFu-2.07/t/constraints/file_minsize.t0000644000175100017520000000351113404751171017510 0ustar carlcarluse strict; use warnings; use Test::More tests => 7; use HTML::FormFu; use CGI; # Copied from CGI.pm - http://search.cpan.org/perldoc?CGI %ENV = ( %ENV, 'SCRIPT_NAME' => '/test.cgi', 'SERVER_NAME' => 'perl.org', 'HTTP_CONNECTION' => 'TE, close', 'REQUEST_METHOD' => 'POST', 'SCRIPT_URI' => 'http://www.perl.org/test.cgi', 'SCRIPT_FILENAME' => '/home/usr/test.cgi', 'SERVER_SOFTWARE' => 'Apache/1.3.27 (Unix) ', 'HTTP_TE' => 'deflate,gzip;q=0.3', 'QUERY_STRING' => '', 'REMOTE_PORT' => '1855', 'HTTP_USER_AGENT' => 'Mozilla/5.0 (compatible; Konqueror/2.1.1; X11)', 'SERVER_PORT' => '80', 'REMOTE_ADDR' => '127.0.0.1', 'CONTENT_TYPE' => 'multipart/form-data; boundary=xYzZY', 'SERVER_PROTOCOL' => 'HTTP/1.1', 'PATH' => '/usr/local/bin:/usr/bin:/bin', 'REQUEST_URI' => '/test.cgi', 'GATEWAY_INTERFACE' => 'CGI/1.1', 'SCRIPT_URL' => '/test.cgi', 'SERVER_ADDR' => '127.0.0.1', 'DOCUMENT_ROOT' => '/home/develop', 'HTTP_HOST' => 'www.perl.org' ); my $q; { my $file = 't/elements/file_post.txt'; local *STDIN; open STDIN, "<", $file or die "missing test file $file"; binmode STDIN; $q = CGI->new; } my $form = HTML::FormFu->new( { tt_args => { INCLUDE_PATH => 'share/templates/tt/xhtml' } } ); $form->load_config_file('t/constraints/file_minsize.yml'); $form->process($q); { ok( $form->submitted ); ok( !$form->has_errors('hello_world') ); ok( $form->valid('hello_world') ); } $form->process( { hello_world => 'not a file', } ); { ok( $form->submitted ); ok( $form->has_errors('hello_world') ); ok( !$form->valid('hello_world') ); like( "$form", qr/File-size must be at least 1 bytes/ ); } HTML-FormFu-2.07/t/constraints/not_equal.t0000644000175100017520000000114113404751171017017 0ustar carlcarluse strict; use warnings; use Test::More tests => 4; use HTML::FormFu; my $form = HTML::FormFu->new; $form->element('Text')->name('foo')->constraint('Not_Equal')->others('bar'); $form->element('Text')->name('bar'); # Valid { $form->process( { foo => 'yada', bar => 'xxxx', } ); ok( $form->valid('foo'), 'foo valid' ); ok( $form->valid('bar'), 'bar valid' ); } # Invalid { $form->process( { foo => 'yada', bar => 'yada', } ); ok( $form->valid('foo'), 'foo valid' ); ok( $form->has_errors('bar'), 'bar valid' ); } HTML-FormFu-2.07/t/constraints/constraint_other_siblings.t0000644000175100017520000000147413404751171022320 0ustar carlcarluse strict; use warnings; use Test::More tests => 7; use HTML::FormFu; my $form = HTML::FormFu->new( { tt_args => { INCLUDE_PATH => 'share/templates/tt/xhtml' } } ); $form->indicator( sub {1} ); $form->load_config_file('t/constraints/constraint_other_siblings.yml'); # Valid { $form->process( { foo => 1, bar => 'a', baz => [2], bif => [ 3, 4 ], } ); ok( !$form->has_errors ); } # Valid { $form->process( {} ); ok( !$form->has_errors ); } # Invalid { $form->process( { foo => 1, bar => '', baz => [2], bif => [ 3, 4 ], } ); ok( $form->has_errors ); ok( $form->valid('foo') ); ok( $form->has_errors('bar') ); ok( $form->valid('baz') ); ok( $form->valid('bif') ); } HTML-FormFu-2.07/t/constraints/file.t0000644000175100017520000000372013404751171015754 0ustar carlcarluse strict; use warnings; use Test::More; use HTML::FormFu; eval "use CGI"; if ($@) { plan skip_all => 'CGI required'; die $!; } plan tests => 10; # Copied from CGI.pm - http://search.cpan.org/perldoc?CGI %ENV = ( %ENV, 'SCRIPT_NAME' => '/test.cgi', 'SERVER_NAME' => 'perl.org', 'HTTP_CONNECTION' => 'TE, close', 'REQUEST_METHOD' => 'POST', 'SCRIPT_URI' => 'http://www.perl.org/test.cgi', 'SCRIPT_FILENAME' => '/home/usr/test.cgi', 'SERVER_SOFTWARE' => 'Apache/1.3.27 (Unix) ', 'HTTP_TE' => 'deflate,gzip;q=0.3', 'QUERY_STRING' => '', 'REMOTE_PORT' => '1855', 'HTTP_USER_AGENT' => 'Mozilla/5.0 (compatible; Konqueror/2.1.1; X11)', 'SERVER_PORT' => '80', 'REMOTE_ADDR' => '127.0.0.1', 'CONTENT_TYPE' => 'multipart/form-data; boundary=xYzZY', 'SERVER_PROTOCOL' => 'HTTP/1.1', 'PATH' => '/usr/local/bin:/usr/bin:/bin', 'REQUEST_URI' => '/test.cgi', 'GATEWAY_INTERFACE' => 'CGI/1.1', 'SCRIPT_URL' => '/test.cgi', 'SERVER_ADDR' => '127.0.0.1', 'DOCUMENT_ROOT' => '/home/develop', 'HTTP_HOST' => 'www.perl.org' ); my $q; { my $file = 't/elements/file_post.txt'; local *STDIN; open STDIN, "<", $file or die "missing test file $file"; binmode STDIN; $q = CGI->new; } my $form = HTML::FormFu->new; $form->load_config_file('t/constraints/file.yml'); $form->process($q); { ok( $form->submitted ); ok( !$form->has_errors('hello_world') ); ok( !$form->has_errors('does_not_exist_gif') ); ok( $form->valid('hello_world') ); ok( $form->valid('does_not_exist_gif') ); } $form->process( { hello_world => 'not a file', } ); { ok( $form->submitted ); ok( $form->has_errors('hello_world') ); ok( !$form->has_errors('does_not_exist_gif') ); ok( !$form->valid('hello_world') ); ok( !$form->valid('does_not_exist_gif') ); } HTML-FormFu-2.07/t/constraints/allornone_attach_errors_to_others.t0000644000175100017520000000101713404751171024031 0ustar carlcarluse strict; use warnings; use Test::More tests => 4; use HTML::FormFu; my $form = HTML::FormFu->new; $form->load_config_file('t/constraints/allornone_attach_errors_to_others.yml'); # Valid { $form->process( { foo => 'a', bar => 'b', } ); ok( $form->submitted_and_valid ); } # Invalid { $form->process( { foo => '', bar => 'b', } ); ok( !$form->submitted_and_valid ); ok( $form->has_errors('foo') ); ok( !$form->has_errors('bar') ); } HTML-FormFu-2.07/t/constraints/allornone_attach_errors_to_base.yml0000644000175100017520000000022613404751171023776 0ustar carlcarl--- elements: - name: foo - name: bar constraints: - type: AllOrNone others: foo attach_errors_to_base: 1 HTML-FormFu-2.07/t/constraints/repeatable_any_not_increment_field_names.t0000644000175100017520000000254513404751171025266 0ustar carlcarluse strict; use warnings; use Test::More 'no_plan'; #tests => 10; use HTML::FormFu; use lib 't/lib'; use HTMLFormFu::TestLib; my $form = HTML::FormFu->new; $form->load_config_file( 't/constraints/repeatable_any_not_increment_field_names.yml'); # Valid { $form->process( { foo => [ 'a', 'b' ], count => 2, } ); ok( $form->submitted_and_valid ); is_deeply( $form->params, { foo => [ 'a', 'b' ], count => 2, } ); is_deeply( [ $form->has_errors ], [] ); } # Valid - 1 missing { $form->process( { foo => [ 'a', '' ], count => 2, } ); ok( $form->submitted_and_valid ); is_deeply( $form->params, { foo => [ 'a', '' ], count => 2, } ); is_deeply( [ $form->has_errors ], [] ); } # Valid - 1 missing { $form->process( { foo => [ '', 'b' ], count => 2, } ); ok( $form->submitted_and_valid ); is_deeply( $form->params, { foo => [ '', 'b' ], count => 2, } ); is_deeply( [ $form->has_errors ], [] ); } # Missing - Invalid { $form->process( { foo => [ '', '' ], count => 2, } ); ok( !$form->submitted_and_valid ); is_deeply( [ $form->has_errors ], ['foo'] ); } HTML-FormFu-2.07/t/constraints/file_mime.yml0000644000175100017520000000043613404751171017322 0ustar carlcarl--- action: 'http://www.perl.org/test.cgi' elements: - type: File name: hello_world constraints: - type: File::MIME types: ['text/rtf', 'text/plain'] - type: File name: 100x100_gif constraints: - type: File::MIME regex: '^ image/.* \z' HTML-FormFu-2.07/t/constraints/constraint_when_any_true_value.t0000644000175100017520000000151513404751171023344 0ustar carlcarluse strict; use warnings; use Test::More tests => 9; use HTML::FormFu; my $form = HTML::FormFu->new; $form->load_config_file('t/constraints/constraint_when_any_true_value.yml'); # Valid { $form->process( { foo => 'a', bar => 'b', } ); ok( $form->submitted_and_valid ); ok( $form->valid('foo'), 'foo valid' ); ok( $form->valid('bar'), 'bar valid' ); } # valid { $form->process( { foo => '', bar => 'b', } ); ok( $form->submitted_and_valid ); ok( $form->valid('foo'), 'foo valid' ); ok( $form->valid('bar'), 'bar valid' ); } # Invalid { $form->process( { foo => 'a', bar => '', } ); ok( $form->has_errors ); ok( $form->valid('foo'), 'foo valid' ); ok( !$form->valid('bar'), 'bar not valid' ); } HTML-FormFu-2.07/t/constraints/constraint_other_siblings.yml0000644000175100017520000000023213404751171022645 0ustar carlcarl--- elements: - name: foo constraints: - type: AllOrNone other_siblings: 1 - name: bar - name: baz - name: bif HTML-FormFu-2.07/t/constraints/constraint_other_siblings_not.yml0000644000175100017520000000022613404751171023530 0ustar carlcarl--- elements: - name: foo constraints: - type: Equal other_siblings: 1 not: 1 - name: bar - name: baz HTML-FormFu-2.07/t/constraints/file_mime.t0000644000175100017520000000367113404751171016770 0ustar carlcarluse strict; use warnings; use Test::More; use HTML::FormFu; eval "use CGI"; if ($@) { plan skip_all => 'CGI required'; die $!; } plan tests => 10; # Copied from CGI.pm - http://search.cpan.org/perldoc?CGI %ENV = ( %ENV, 'SCRIPT_NAME' => '/test.cgi', 'SERVER_NAME' => 'perl.org', 'HTTP_CONNECTION' => 'TE, close', 'REQUEST_METHOD' => 'POST', 'SCRIPT_URI' => 'http://www.perl.org/test.cgi', 'SCRIPT_FILENAME' => '/home/usr/test.cgi', 'SERVER_SOFTWARE' => 'Apache/1.3.27 (Unix) ', 'HTTP_TE' => 'deflate,gzip;q=0.3', 'QUERY_STRING' => '', 'REMOTE_PORT' => '1855', 'HTTP_USER_AGENT' => 'Mozilla/5.0 (compatible; Konqueror/2.1.1; X11)', 'SERVER_PORT' => '80', 'REMOTE_ADDR' => '127.0.0.1', 'CONTENT_TYPE' => 'multipart/form-data; boundary=xYzZY', 'SERVER_PROTOCOL' => 'HTTP/1.1', 'PATH' => '/usr/local/bin:/usr/bin:/bin', 'REQUEST_URI' => '/test.cgi', 'GATEWAY_INTERFACE' => 'CGI/1.1', 'SCRIPT_URL' => '/test.cgi', 'SERVER_ADDR' => '127.0.0.1', 'DOCUMENT_ROOT' => '/home/develop', 'HTTP_HOST' => 'www.perl.org' ); my $q; { my $file = 't/elements/file_post.txt'; local *STDIN; open STDIN, "<", $file or die "missing test file $file"; binmode STDIN; $q = CGI->new; } my $form = HTML::FormFu->new; $form->load_config_file('t/constraints/file_mime.yml'); $form->process($q); { ok( $form->submitted ); ok( !$form->has_errors('hello_world') ); ok( !$form->has_errors('100x100_gif') ); ok( $form->valid('hello_world') ); ok( $form->valid('100x100_gif') ); } $form->process( { hello_world => 'not a file', } ); { ok( $form->submitted ); ok( $form->has_errors('hello_world') ); ok( !$form->has_errors('100x100_gif') ); ok( !$form->valid('hello_world') ); ok( !$form->valid('100x100_gif') ); } HTML-FormFu-2.07/t/constraints/file.yml0000644000175100017520000000024513404751171016311 0ustar carlcarl--- action: 'http://www.perl.org/test.cgi' elements: - type: File name: hello_world - type: File name: does_not_exist_gif constraints: - type: File HTML-FormFu-2.07/t/constraints/length.t0000644000175100017520000000120413404751171016311 0ustar carlcarluse strict; use warnings; use Test::More tests => 4; use HTML::FormFu; my $form = HTML::FormFu->new; $form->element('Text')->name('foo')->constraint('Length')->min(3)->max(5); $form->element('Text')->name('bar')->constraint('Length')->min(3)->max(5); # Valid { $form->process( { foo => 'abc', bar => 'abcd', } ); ok( $form->valid('foo'), 'foo valid' ); ok( $form->valid('bar'), 'bar valid' ); } # Invalid { $form->process( { foo => 'ab', bar => 'abcdef', } ); ok( !$form->valid('foo'), 'foo not valid' ); ok( !$form->valid('bar'), 'bar not valid' ); } HTML-FormFu-2.07/t/00-report-prereqs.dd0000644000175100017520000001126313404751171016022 0ustar carlcarldo { my $x = { 'configure' => { 'requires' => { 'ExtUtils::MakeMaker' => '0', 'File::ShareDir::Install' => '0.06' } }, 'develop' => { 'requires' => { 'File::Spec' => '0', 'IO::Handle' => '0', 'IPC::Open3' => '0', 'Test::CPAN::Meta' => '0', 'Test::EOL' => '0', 'Test::Kwalitee' => '1.21', 'Test::More' => '0.88', 'Test::PAUSE::Permissions' => '0', 'Test::Perl::Critic' => '0', 'Test::Pod' => '1.41' } }, 'runtime' => { 'requires' => { 'Carp' => '0', 'Class::MOP::Method' => '0', 'Clone' => '0.31', 'Config::Any' => '0.18', 'Cwd' => '0', 'Data::Visitor' => '0.26', 'Data::Visitor::Callback' => '0', 'DateTime' => '0.54', 'DateTime::Format::Builder' => '0.7901', 'DateTime::Format::Natural' => '0', 'DateTime::Format::Strptime' => '1.2000', 'DateTime::Locale' => '0.45', 'Email::Valid' => '0', 'Encode' => '0', 'Exporter' => '5.57', 'Fatal' => '0', 'File::Copy' => '0', 'File::Find' => '0', 'File::ShareDir' => '0', 'File::Spec' => '0', 'File::Temp' => '0', 'HTML::Scrubber' => '0', 'HTML::TokeParser::Simple' => '3.14', 'HTTP::Headers' => '1.64', 'Hash::Flatten' => '0', 'IO::File' => '0', 'JSON::MaybeXS' => '0', 'List::MoreUtils' => '0', 'List::Util' => '1.45', 'Locale::Maketext' => '0', 'Module::Pluggable' => '0', 'Moose' => '1.00', 'Moose::Role' => '0', 'Moose::Util' => '0', 'MooseX::Aliases' => '0', 'MooseX::Attribute::Chained' => 'v1.0.2', 'Number::Format' => '0', 'Path::Class::File' => '0', 'Readonly' => '0', 'Regexp::Common' => '0', 'Scalar::Util' => '0', 'Storable' => '0', 'Task::Weaken' => '0', 'YAML::XS' => '0.32', 'perl' => '5.010' } }, 'test' => { 'recommends' => { 'CPAN::Meta' => '2.120900' }, 'requires' => { 'CGI' => '3.37', 'ExtUtils::MakeMaker' => '0', 'File::Spec' => '0', 'POSIX' => '0', 'Regexp::Assemble' => '0', 'Test::Exception' => '0', 'Test::Memory::Cycle' => '0', 'Test::More' => '0.92', 'Test::RequiresInternet' => '0' } } }; $x; }HTML-FormFu-2.07/t/roles/0000775000175100017520000000000013404751171013425 5ustar carlcarlHTML-FormFu-2.07/t/roles/form.t0000644000175100017520000000043613404751171014556 0ustar carlcarluse strict; use warnings; use Test::More tests => 1; use HTML::FormFu; use lib 't/lib'; my $form = HTML::FormFu->new( { tt_args => { INCLUDE_PATH => 'share/templates/tt/xhtml' } } ); $form->load_config_file('t/roles/form.yml'); is( $form->custom_role_method, "form ID: xxx" ); HTML-FormFu-2.07/t/roles/field.t0000644000175100017520000000067113404751171014677 0ustar carlcarluse strict; use warnings; use Test::More tests => 1; use HTML::FormFu; use lib 't/lib'; my $form = HTML::FormFu->new( { tt_args => { INCLUDE_PATH => 'share/templates/tt/xhtml' } } ); $form->load_config_file('t/roles/field.yml'); my $expected_form_xhtml = <
EOF is( "$form", $expected_form_xhtml ); HTML-FormFu-2.07/t/roles/block.yml0000644000175100017520000000015413404751171015240 0ustar carlcarl--- elements: - type: Block roles: - '+HTMLFormFu::MyBlockRole' elements: - name: foo HTML-FormFu-2.07/t/roles/form.yml0000644000175100017520000000006313404751171015110 0ustar carlcarl--- id: xxx roles: - '+HTMLFormFu::MyFormRole' HTML-FormFu-2.07/t/roles/field.yml0000644000175100017520000000013413404751171015227 0ustar carlcarl--- auto_fieldset: 1 elements: - name: foo roles: - '+HTMLFormFu::MyFieldRole' HTML-FormFu-2.07/t/roles/block.t0000644000175100017520000000065713404751171014712 0ustar carlcarluse strict; use warnings; use Test::More tests => 1; use HTML::FormFu; use lib 't/lib'; my $form = HTML::FormFu->new( { tt_args => { INCLUDE_PATH => 'share/templates/tt/xhtml' } } ); $form->load_config_file('t/roles/block.yml'); my $expected_form_xhtml = <
EOF is( "$form", $expected_form_xhtml ); HTML-FormFu-2.07/t/04basic.yml0000644000175100017520000000062113404751171014246 0ustar carlcarl--- action: /foo/bar id: form auto_id: '%n' elements: - type: Fieldset legend: Jimi elements: - name: age type: Text comment: x label: Age constraints: [Integer, Required] - name: name type: Text label: Name - name: ok type: Hidden value: OK constraints: type: Required name: name filters: - HTMLEscape HTML-FormFu-2.07/t/utils/0000775000175100017520000000000013404751171013441 5ustar carlcarlHTML-FormFu-2.07/t/utils/remove_xml_attribute.t0000644000175100017520000000600013404751171020060 0ustar carlcarluse strict; use warnings; use Test::More tests => 22; use HTML::FormFu::Util qw( literal remove_xml_attribute xml_escape ); { # remove literal from literal my %attr = ( key => literal("{key}, "{key}, "{key}, "{key}, "{key}, "{key}, "" ); } { # remove string from literal my %attr = ( key => literal("<foo <bar <foo <bar <foo") ); is( xml_escape( \%attr )->{key}, "<foo <bar <foo <bar <foo" ); remove_xml_attribute( \%attr, "key", "{key}, "<bar <foo <bar <foo" ); remove_xml_attribute( \%attr, "key", "{key}, "<bar <bar <foo" ); remove_xml_attribute( \%attr, "key", "{key}, "<bar <bar" ); remove_xml_attribute( \%attr, "key", "{key}, "<bar" ); remove_xml_attribute( \%attr, "key", "{key}, "" ); } { # remove string from string my %attr = ( key => "{key}, "<foo <bar <foo <bar <foo" ); remove_xml_attribute( \%attr, "key", "{key}, "<bar <foo <bar <foo" ); remove_xml_attribute( \%attr, "key", "{key}, "<bar <bar <foo" ); remove_xml_attribute( \%attr, "key", "{key}, "<bar <bar" ); } { # remove literal from string my %attr = ( key => "{key}, "<foo <bar <foo <bar <foo" ); remove_xml_attribute( \%attr, "key", literal "<foo" ); is( xml_escape( \%attr )->{key}, "<bar <foo <bar <foo" ); remove_xml_attribute( \%attr, "key", literal "<foo" ); is( xml_escape( \%attr )->{key}, "<bar <bar <foo" ); remove_xml_attribute( \%attr, "key", literal "<foo" ); is( xml_escape( \%attr )->{key}, "<bar <bar" ); # ... remove a string remove_xml_attribute( \%attr, "key", '{key}, "<bar" ); } { # doesn't exist my %attr = ( key => "foo" ); remove_xml_attribute( \%attr, "NOT EXIST", 'bar' ); is_deeply( \%attr, { key => "foo", }, "didn't change attributes", ); } HTML-FormFu-2.07/t/utils/has_xml_attribute.t0000644000175100017520000000275113404751171017347 0ustar carlcarluse strict; use warnings; use Test::More tests => 17; use HTML::FormFu::Util qw( literal has_xml_attribute xml_escape ); { # has literal in literal my %attr = ( key => literal(" literal("<foo <bar <baz") ); ok( has_xml_attribute( \%attr, "key", " " " 7; use HTML::FormFu::Util qw( literal append_xml_attribute xml_escape ); { my %attr = ( foo => literal "{foo}, "baz" ); is( xml_escape( \%attr )->{foo}, "baz" ); # literal + string append_xml_attribute( \%attr, "foo", "{foo}, "baz <boo" ); } { my %attr = ( foo => "{foo}, "<bar" ); # string + string append_xml_attribute( \%attr, "foo", ">baz" ); is( xml_escape( \%attr )->{foo}, "<bar >baz" ); # string + literal append_xml_attribute( \%attr, "foo", literal "{foo}, "<bar >baz {foo}, "<bar >baz 'Template.pm required'; die $@; } else { plan tests => 1; } use HTML::FormFu; my $form = HTML::FormFu->new( { tt_args => { INCLUDE_PATH => 'share/templates/tt/xhtml' } } ); $form->auto_fieldset( { legend => 'Foo' } ); $form->element('Text')->name('foo')->label('Foo'); $form->element('Text')->name('bar')->label('Bar'); $form->element('Hidden')->name('baz'); $form->element('Submit')->name('submit'); my $template = Template->new; my $output; $template->process( \*DATA, { form => $form }, \$output ) or die $template->error; my $xhtml = <
Foo : :
EOF is( $output, $xhtml ); __DATA__ [% form.start %][% FOREACH fieldset = form.get_elements %] [% fieldset.start %][% FOREACH field = fieldset.get_fields %] [% IF field.label.defined %][% field.render_label %]: [% field.render_field %][% ELSE %][% field %][% END %][% END %] [% fieldset.end %][% END %] [% form.end %] HTML-FormFu-2.07/t/examples/fields_as_list_items.t0000644000175100017520000000165013404751171020471 0ustar carlcarluse strict; use warnings; use Test::More; eval { require Template; }; if ($@) { plan skip_all => 'Template.pm required'; die $@; } else { plan tests => 1; } use HTML::FormFu; my $form = HTML::FormFu->new; $form->element('Text')->name('foo')->label('Foo'); $form->element('Textarea')->name('bar')->label('Bar'); my $template = Template->new; my $output; $template->process( \*DATA, { form => $form }, \$output ) or die $template->error; my $xhtml = <
  • :
  • :
EOF is( $output, $xhtml ); __DATA__ [% form.start %]
    [% FOREACH field = form.get_fields %]
  • [% field.render_label %] : [% field.render_field %]
  • [% END %]
[% form.end %] HTML-FormFu-2.07/t/examples/field_as.t0000644000175100017520000000374613404751171016062 0ustar carlcarluse strict; use warnings; use Test::More; eval { require Template; }; if ($@) { plan skip_all => 'Template.pm required'; die $@; } else { plan tests => 2; } use HTML::FormFu; my $form = HTML::FormFu->new( { tt_args => { INCLUDE_PATH => 'share/templates/tt/xhtml' } } ); $form->element('Password')->name('foo')->label('Foo') ->label_attributes( { class => 'my_label' } )->comment('Comment') ->render_value(1); $form->element('Submit')->name('submit'); $form->constraint( Required => 'foo' ); my $template = Template->new; my $data = do { local $/; }; my $output; $template->process( \$data, { form => $form }, \$output ) or die $template->error; my $xhtml = <
Comment
Comment
EOF is( $output, $xhtml ); # check that errors are carried to the new field { my $xhtml = <
This field is required Comment
This field is required Comment
EOF $form->process( { submit => 'Submit', } ); my $output = undef; $template->process( \$data, { form => $form }, \$output ) or die $template->error; is( $output, $xhtml ); } __DATA__ [% form.start %] [% form.get_field('foo') %] [% form.get_field('foo').as('Text', 'disabled', 'disabled') %] [% form.get_field('submit') %] [% form.end %] HTML-FormFu-2.07/t/examples/custom_label.t0000644000175100017520000000256613404751171016764 0ustar carlcarluse strict; use warnings; use Test::More; eval { require Template; }; if ($@) { plan skip_all => 'Template.pm required'; die $@; } else { plan tests => 1; } use HTML::FormFu; my $form = HTML::FormFu->new( { tt_args => { INCLUDE_PATH => 'share/templates/tt/xhtml' } } ); $form->auto_fieldset( { legend => 'Foo' } ); $form->element('Text')->name('foo')->label('Foo'); $form->element('Text')->name('bar')->label('Bar'); $form->element('Hidden')->name('baz'); $form->element('Submit')->name('submit'); my $template = Template->new; my $output; $template->process( \*DATA, { form => $form }, \$output ) or die $template->error; my $xhtml = <
Foo : :
EOF is( $output, $xhtml ); __DATA__ [% form.start %] [% form.get_element('type', 'Fieldset').start %] [% form.get_field('foo').render_label %]: [% form.get_field('foo').render_field %] [% form.get_field('bar').render_label %]: [% form.get_field('bar').render_field %] [% form.get_field('baz') %] [% form.get_field('submit') %] [% form.get_element('type', 'Fieldset').end %] [% form.end %] HTML-FormFu-2.07/t/bugs/0000775000175100017520000000000013404751171013241 5ustar carlcarlHTML-FormFu-2.07/t/bugs/result_params_multiple.t0000644000175100017520000000052413404751171020221 0ustar carlcarluse strict; use warnings; use Test::More tests => 2; use HTML::FormFu; my $form = HTML::FormFu->new; $form->element('Text')->name('foo'); # Valid { $form->process( { foo => [ 'one', 'two' ] } ); ok( $form->valid('foo'), 'foo valid' ); my $params = $form->params; is_deeply( $params, { foo => [ 'one', 'two' ] } ); } HTML-FormFu-2.07/t/bugs/empty_block_with_nested_name.yml0000644000175100017520000000023313404751171021665 0ustar carlcarl--- auto_fieldset: 1 elements: - name: foo - type: Fieldset nested_name: bar elements: - type: Label name: baz HTML-FormFu-2.07/t/bugs/populate_element_coderef.t0000644000175100017520000000105313404751171020454 0ustar carlcarluse strict; use warnings; use Test::More tests => 2; use HTML::FormFu; my $callback = sub { my $value = shift; Test::More::ok(1) if $value eq 'a'; return 1; }; my $form = HTML::FormFu->new; $form->populate( { elements => [ { name => 'foo', constraint => { type => 'Callback', callback => $callback, }, }, ], } ); # Valid { $form->process( { foo => 'a', } ); ok( $form->valid('foo'), 'foo valid' ); } HTML-FormFu-2.07/t/bugs/multiple_checkbox_same_name.t0000644000175100017520000000062713404751171021137 0ustar carlcarluse strict; use warnings; use Test::More tests => 2; use HTML::FormFu; my $form = HTML::FormFu->new( { tt_args => { INCLUDE_PATH => 'share/templates/tt/xhtml' } } ); $form->load_config_file('t/bugs/multiple_checkbox_same_name.yml'); $form->process( { foo => [qw( 1 2 )], } ); my $foo = $form->get_fields('foo'); like( $foo->[0], qr/checked="checked"/ ); like( $foo->[1], qr/checked="checked"/ ); HTML-FormFu-2.07/t/bugs/submit_retain_default.t0000644000175100017520000000131013404751171017770 0ustar carlcarluse strict; use warnings; use Test::More tests => 4; use HTML::FormFu; my $form = HTML::FormFu->new( { tt_args => { INCLUDE_PATH => 'share/templates/tt/xhtml' } } ); $form->element( { type => 'Submit', name => 'foo', default => 'Foo' } ); $form->element( { type => 'Submit', name => 'bar', default => 'Bar' } ); my $foo = qq{}; my $bar = qq{}; like( $form->get_field('foo'), qr/\Q$foo/ ); like( $form->get_field('bar'), qr/\Q$bar/ ); # click 1st submit button $form->process( { foo => 'Foo', } ); # output unchanged like( $form->get_field('foo'), qr/\Q$foo/ ); like( $form->get_field('bar'), qr/\Q$bar/ ); HTML-FormFu-2.07/t/bugs/element_class.t0000644000175100017520000000130213404751171016236 0ustar carlcarluse strict; use warnings; use Test::More tests => 2; use HTML::FormFu; =pod The input class was getting " text" appended again. Fixed by cloning the elements in HTML::FormFu::result() =cut my $form = HTML::FormFu->new( { tt_args => { INCLUDE_PATH => 'share/templates/tt/xhtml' } } ); $form->element('Text')->name('foo'); $form->element('Text')->name('bar'); my $xhtml = <
EOF # 1st result { $form->process( {} ); is( "$form", $xhtml, 'stringified form' ); } # 2nd result { $form->process( {} ); is( "$form", $xhtml, 'stringified form' ); } HTML-FormFu-2.07/t/bugs/yaml_utf8.txt0000644000175100017520000000000313404751171015701 0ustar carlcarlfüHTML-FormFu-2.07/t/bugs/element_parent.t0000644000175100017520000000051513404751171016427 0ustar carlcarluse strict; use warnings; use Test::More tests => 1; use HTML::FormFu; =pod Using auto_fieldset, elements were incorrectly getting the form as their parent, not the fieldset =cut my $form = HTML::FormFu->new; $form->auto_fieldset(1); my $foo = $form->element( { name => 'foo' } ); ok( $foo->parent == $form->get_element ); HTML-FormFu-2.07/t/bugs/select_empty_options.t0000644000175100017520000000072513404751171017700 0ustar carlcarluse strict; use warnings; use Test::More tests => 2; use HTML::FormFu; my $form = HTML::FormFu->new( { tt_args => { INCLUDE_PATH => 'share/templates/tt/xhtml' } } ); $form->element('Select')->name('foo'); $form->element('Select')->name('bar')->options(); my $xhtml = <
EOF eval { is( "$form", $xhtml ); }; ok( !$@, "died: $@" ); HTML-FormFu-2.07/t/bugs/repeatable_increase_rep.t0000644000175100017520000000151513404751171020251 0ustar carlcarluse strict; use warnings; use Test::More tests => 2; use HTML::FormFu; my $form = HTML::FormFu->new( { tt_args => { INCLUDE_PATH => 'share/templates/tt/xhtml' } } ); $form->load_config_file('t/bugs/repeatable_increase_rep.yml'); my $repeatable = $form->get_all_element( { type => 'Repeatable' } ); { # form is submitted with a single value $form->process( { foo => 'a' } ); my $html = qq{
}; is( $repeatable, $html ); } { # manually increase repetitions. # want to ensure every rep doesn't get the same value $repeatable->repeat(2); $form->process; my $html = qq{
}; is( $repeatable, $html ); } HTML-FormFu-2.07/t/bugs/date_element_empty_input.t0000644000175100017520000000043213404751171020506 0ustar carlcarluse strict; use warnings; use Test::More tests => 1; use HTML::FormFu; my $form = HTML::FormFu->new; $form->element('Date')->name('foo')->auto_inflate(1); # empty input $form->process( { 'foo_day', '', 'foo_month', '', 'foo_year', '', } ); ok( $form->submitted_and_valid ); HTML-FormFu-2.07/t/bugs/error_multiple_fields_same_name.t0000644000175100017520000000101713404751171022022 0ustar carlcarluse strict; use warnings; use Test::More tests => 4; use HTML::FormFu; my $form = HTML::FormFu->new( { tt_args => { INCLUDE_PATH => 'share/templates/tt/xhtml' } } ); $form->load_config_file('t/bugs/error_multiple_fields_same_name.yml'); $form->process( { foo => [qw( 1 a )], } ); my @fields = @{ $form->get_fields }; ok( !@{ $fields[0]->get_errors } ); is( scalar( @{ $fields[1]->get_errors } ), 1 ); unlike( $fields[0], qr/This field must be an integer/i ); like( $fields[1], qr/This field must be an integer/i ); HTML-FormFu-2.07/t/bugs/submit_no_value.t0000644000175100017520000000143113404751171016616 0ustar carlcarluse strict; use warnings; use Test::More tests => 2; use HTML::FormFu; my $form = HTML::FormFu->new( { tt_args => { INCLUDE_PATH => 'share/templates/tt/xhtml' } } ); $form->element('Text')->name('foo')->constraint('Required'); $form->element('Text')->name('bar'); $form->element('Submit')->name('submit'); { my $xhtml = qq{
}; is( $form->get_field( { type => 'Submit' } ), $xhtml ); } =pod After an error, check that submit doesn't contain C<< value="" >>, because the browser won't display the default text label, "submit Query" or whatever. =cut { $form->process( { bar => 1 } ); my $xhtml = qq{
}; is( $form->get_field( { type => 'Submit' } ), $xhtml ); } HTML-FormFu-2.07/t/bugs/constructor_arg_overwrites_default.t0000644000175100017520000000121413404751171022635 0ustar carlcarluse strict; use warnings; use Test::More tests => 4; use HTML::FormFu; my $form = HTML::FormFu->new( { elements => { type => 'Text', name => 'foo', label_filename => 'foofile', } } ); $form->element( { type => 'Text', name => 'bar', label_filename => 'barfile', } ); is( $form->get_field('foo')->label_filename, 'foofile' ); is( $form->get_field('bar')->label_filename, 'barfile' ); is( $form->get_field('foo')->render_data->{label_filename}, 'foofile' ); is( $form->get_field('bar')->render_data->{label_filename}, 'barfile' ); HTML-FormFu-2.07/t/bugs/yaml_utf8.yml0000644000175100017520000000005313404751171015670 0ustar carlcarl--- elements: - name: foo label: fü HTML-FormFu-2.07/t/bugs/yaml_utf8.t0000644000175100017520000000052013404751171015331 0ustar carlcarluse strict; use warnings; use Encode 'encode'; use Test::More tests => 1; use HTML::FormFu; my $form = HTML::FormFu->new->load_config_file('t/bugs/yaml_utf8.yml'); open my $fh, '<:encoding(UTF-8)', 't/bugs/yaml_utf8.txt' or die $!; my $text = do { local $/; <$fh> }; chomp $text; is( $form->get_field('foo')->label, $text ); HTML-FormFu-2.07/t/bugs/datetime_hour_lt_10.t0000644000175100017520000001176213404751171017263 0ustar carlcarluse strict; use warnings; use Test::More tests => 1; use HTML::FormFu; use DateTime; my $dt = DateTime->new( day => 6, month => 8, year => 2007, hour => 1, minute => 0, ); my $form = HTML::FormFu->new( { tt_args => { INCLUDE_PATH => 'share/templates/tt/xhtml' } } ); $form->load_config_file('t/elements/datetime.yml'); $form->process; # simulate calling $form->model->default_values # without then calling $form->process my $foo_field = $form->get_field('foo'); $foo_field->default($dt); my $xhtml = qq{
}; is( "$foo_field", $xhtml ); HTML-FormFu-2.07/t/bugs/error_multiple_fields_same_name.yml0000644000175100017520000000011713404751171022360 0ustar carlcarl--- elements: - name: foo - name: foo constraints: - type: Integer HTML-FormFu-2.07/t/bugs/empty_block_with_nested_name.t0000644000175100017520000000046013404751171021331 0ustar carlcarluse strict; use warnings; # https://rt.cpan.org/Ticket/Display.html?id=54967 use Test::More tests => 1; use HTML::FormFu; my $form = HTML::FormFu->new; $form->load_config_file('t/bugs/empty_block_with_nested_name.yml'); $form->process( { foo => 'aaa', } ); is_deeply( [ $form->valid ], ['foo'] ); HTML-FormFu-2.07/t/bugs/error_msg.t0000644000175100017520000000112513404751171015422 0ustar carlcarluse strict; use warnings; use Test::More tests => 4; use HTML::FormFu; my $form = HTML::FormFu->new( { tt_args => { INCLUDE_PATH => 'share/templates/tt/xhtml' } } ); $form->element('Text')->name('foo'); $form->constraint('Required'); $form->constraint('Email'); { $form->process( { foo => 'cfranks@cpan', } ); ok( $form->has_errors('foo'), 'foo has errors' ); like( $form, qr/\QThis field must contain an email address/ ); } { $form->process( { foo => '', } ); ok( $form->has_errors('foo'), 'foo has errors' ); like( $form, qr/\QThis field is required/ ); } HTML-FormFu-2.07/t/bugs/name_regex_chars.t0000644000175100017520000000040213404751171016712 0ustar carlcarluse strict; use warnings; use Test::More tests => 1; use HTML::FormFu; my $form = HTML::FormFu->new; $form->element('Text')->name('foo/bar'); { $form->process( { 'foo/bar' => 'bam' } ); is( $form->param('foo/bar'), 'bam', 'foo/bar valid' ); } HTML-FormFu-2.07/t/bugs/repeatable_increase_rep.yml0000644000175100017520000000034013404751171020602 0ustar carlcarl--- auto_fieldset: 1 elements: - type: Repeatable increment_field_names: 0 elements: - name: foo render_processed_value: 1 filter: ForceListValue - type: Submit name: submit HTML-FormFu-2.07/t/bugs/multiple_checkbox_same_name.yml0000644000175100017520000000016613404751171021473 0ustar carlcarl--- elements: - type: Checkbox name: foo value: 1 - type: Checkbox name: foo value: 2 HTML-FormFu-2.07/t/bugs/not_nested.t0000644000175100017520000000031413404751171015564 0ustar carlcarluse strict; use warnings; use Test::More tests => 1; use HTML::FormFu; my $form = HTML::FormFu->new; $form->auto_fieldset(1); my $field = $form->element('Text')->name('foo'); ok( !$field->nested ); HTML-FormFu-2.07/t/bugs/value_no_default.t0000644000175100017520000000524013404751171016741 0ustar carlcarluse strict; use warnings; use Test::More tests => 20; use HTML::FormFu; my $form = HTML::FormFu->new( { tt_args => { INCLUDE_PATH => 'share/templates/tt/xhtml' } } ); $form->indicator('my_hidden'); $form->element('Button')->name('my_button')->value(1); $form->element('Checkbox')->name('my_checkbox1')->value(1) ->attrs( { checked => 'checked' } ); $form->element('Checkbox')->name('my_checkbox2')->value(0); $form->element('ContentButton')->name('my_contentbutton')->value(1); $form->element('Hidden')->name('my_hidden')->value(1); $form->element('Image')->name('my_image')->value(1); #$form->element('Password')->name('my_password')->value(1)->fill(1); $form->element('Radio')->name('my_radio1')->value(1) ->attrs( { checked => 'checked' } ); $form->element('Radio')->name('my_radio2')->value(0); $form->element('Radiogroup')->name('my_radiogroup')->values( [ 1, 0 ] ) ->attrs( { checked => 'checked' } ); $form->element('Reset')->name('my_reset')->value(1); $form->element('Select')->name('my_select') ->options( [ [ 0 => 'unsubscribed' ], [ 1 => 'subscribed' ] ] ) ->attrs( { selected => 'selected' } ); $form->element('Submit')->name('my_submit')->value(1); $form->element('Text')->name('my_text')->value(1); $form->element('Textarea')->name('my_textarea')->value(1); { like( $form->get_field('my_button'), qr/value="1"/ ); like( $form->get_field('my_checkbox1'), qr/value="1"/ ); like( $form->get_field('my_checkbox2'), qr/value="0"/ ); like( $form->get_field('my_contentbutton'), qr/value="1"/ ); like( $form->get_field('my_hidden'), qr/value="1"/ ); like( $form->get_field('my_image'), qr/value="1"/ ); like( $form->get_field('my_radio1'), qr/value="1"/ ); like( $form->get_field('my_radio2'), qr/value="0"/ ); like( $form->get_field('my_radiogroup'), qr/value="1"/ ); like( $form->get_field('my_reset'), qr/value="1"/ ); like( $form->get_field('my_select'), qr/value="1"/ ); like( $form->get_field('my_submit'), qr/value="1"/ ); like( $form->get_field('my_text'), qr/value="1"/ ); like( $form->get_field('my_textarea'), qr!>1! ); } # make sure XML of the result object has empty values, not defaults { $form->process( { my_hidden => '', } ); like( $form->get_field('my_checkbox1'), qr/value="1"/ ); unlike( $form->get_field('my_checkbox1'), qr/"checked"/ ); like( $form->get_field('my_checkbox2'), qr/value="0"/ ); unlike( $form->get_field('my_checkbox2'), qr/"checked"/ ); like( $form->get_field('my_contentbutton'), qr/value=""/ ); like( $form->get_field('my_hidden'), qr/value=""/ ); } HTML-FormFu-2.07/t/bugs/render_processed_value_retain_default.yml0000644000175100017520000000026713404751171023557 0ustar carlcarl--- elements: - name: foo render_processed_value: 1 retain_default: 1 deflator: - type: Strftime strftime: '%d/%m/%Y' - type: Submit name: submit HTML-FormFu-2.07/t/bugs/value_empty_string.t0000644000175100017520000000047013404751171017345 0ustar carlcarluse strict; use warnings; use Test::More tests => 1; use HTML::FormFu; my $form = HTML::FormFu->new( { tt_args => { INCLUDE_PATH => 'share/templates/tt/xhtml' } } ); $form->element('Text')->name('foo')->default(''); like( $form->get_field('foo'), qr/\Q value="" /x, 'empty value appears in XML' ); HTML-FormFu-2.07/t/bugs/filter_run_once.t0000644000175100017520000000043613404751171016604 0ustar carlcarluse strict; use warnings; use Test::More tests => 1; use HTML::FormFu; my $count = 0; my $form = HTML::FormFu->new; $form->element('Text')->name('foo'); $form->filter( Callback => 'foo' )->callback( sub { $count++ } ); $form->process( { foo => 'whatever', } ); is( $count, 1 ); HTML-FormFu-2.07/t/bugs/date_element_deflator.t0000644000175100017520000000067113404751171017736 0ustar carlcarluse strict; use warnings; use Test::More tests => 1; use HTML::FormFu; my $form = HTML::FormFu->new; my $field = $form->element('Date')->name('foo'); $field->deflator( { type => 'Callback', callback => 'A::epoch2datetime' } ); $form->default_values( { foo => time() } ); eval { $form->process; }; ok( !$@ ); package A; use DateTime; sub epoch2datetime { my ($value) = @_; return DateTime->from_epoch( epoch => $value ); } HTML-FormFu-2.07/t/bugs/render_processed_value_retain_default.t0000644000175100017520000000106113404751171023212 0ustar carlcarluse strict; use warnings; use Test::More tests => 1; use HTML::FormFu; use DateTime; my $form = HTML::FormFu->new( { tt_args => { INCLUDE_PATH => 'share/templates/tt/xhtml' } } ); $form->load_config_file('t/bugs/render_processed_value_retain_default.yml'); # set default my $dt = DateTime->new( day => 7, month => 5, year => 2008, ); $form->get_field('foo')->default($dt); # don't submit foo $form->process( { submit => 'Submit', } ); # default is kept, and deflated like( $form->get_field('foo')->render, qr|value="07/05/2008"| ); HTML-FormFu-2.07/t/bugs/pre_1_00_compat.yml0000644000175100017520000000070213404751171016631 0ustar carlcarl--- id: formfu auto_fieldset: 1 auto_id: '%f_%n' elements: - name: foo label: Foo comment: The Foo constraint: - type: Required # config to attain compatability below auto_container_class: '%t' auto_container_label_class: 'label' auto_container_comment_class: 'comment' auto_comment_class: 'comment' auto_container_error_class: 'error' auto_container_per_error_class: 'error_%s_%t' auto_error_class: 'error_message error_%s_%t' HTML-FormFu-2.07/t/bugs/disabled_select_default_value.yml0000644000175100017520000000050213404751171021765 0ustar carlcarl--- auto_fieldset: 1 elements: - type: Select name: select values: - 1 - 2 - 3 empty_first: 1 retain_default: 1 attributes: disabled: disabled - type: Text name: text constraints: - Required - type: Submit name: submit HTML-FormFu-2.07/t/bugs/field_no_name.t0000644000175100017520000000067113404751171016207 0ustar carlcarluse strict; use warnings; use Test::More tests => 2; use HTML::FormFu; my $form = HTML::FormFu->new; $form->element('Text'); $form->element('Text')->name('foo'); my $div = $form->element('Block'); $div->element('Text'); $div->element('Text')->name('bar'); $form->process( { foo => 1 } ); is( @{ $form->get_fields('foo') }, 1 ); { my $div = $form->get_element( { type => 'Block' } ); is( @{ $div->get_fields('bar') }, 1 ); } HTML-FormFu-2.07/t/bugs/pre_1_00_compat.t0000644000175100017520000000205313404751171016274 0ustar carlcarluse strict; use warnings; use Test::More tests => 2; use HTML::FormFu; # # The HTML below should never be changed # If necessary, the form config should be changed to show # how to achieve legacy HTML generation # my $form = HTML::FormFu->new( { tt_args => { INCLUDE_PATH => 'share/templates/tt/xhtml' } } ); $form->load_config_file('t/bugs/pre_1_00_compat.yml'); is( "$form", <
The Foo
HTML $form->process( { foo => '', } ); is( "$form", <
This field is required The Foo
HTML HTML-FormFu-2.07/t/nested/0000775000175100017520000000000013404751171013563 5ustar carlcarlHTML-FormFu-2.07/t/nested/pre_expanded.t0000644000175100017520000000115713404751171016410 0ustar carlcarluse strict; use warnings; use Test::More tests => 1; use HTML::FormFu; my $form = HTML::FormFu->new; $form->auto_fieldset( { nested_name => 'foo' } ); $form->element('Text')->name('bar')->constraint('Number'); $form->element('Text')->name('baz')->constraint('Number'); $form->element('Text')->name('bag')->constraint('Number'); $form->process( { foo => { bar => 1, baz => [ 2, 3 ], bag => 'yada', unknown => 4, }, } ); is_deeply( $form->params, { foo => { bar => 1, baz => [ 2, 3 ], }, } ); HTML-FormFu-2.07/t/nested/form_input.t0000644000175100017520000000053713404751171016135 0ustar carlcarluse strict; use warnings; use Test::More tests => 1; use HTML::FormFu; my $form = HTML::FormFu->new; $form->auto_fieldset( { nested_name => 'foo' } ); my $bar = $form->element('Text')->name('bar'); $form->process( { 'foo.bar' => 'x', foo => { bar => 'x', }, } ); is_deeply( $form->input, { foo => { bar => 'x', }, }, ); HTML-FormFu-2.07/t/nested/constraints/0000775000175100017520000000000013404751171016132 5ustar carlcarlHTML-FormFu-2.07/t/nested/constraints/required.t0000644000175100017520000000061313404751171020135 0ustar carlcarluse strict; use warnings; use Test::More tests => 2; use HTML::FormFu; my $form = HTML::FormFu->new; $form->auto_fieldset( { nested_name => 'foo' } ); $form->element('Text')->name('bar')->constraint('Required'); $form->element('Text')->name('baz')->constraint('Required'); $form->process( { 'foo.bar' => 'x', } ); ok( !$form->has_errors('foo.bar') ); ok( $form->has_errors('foo.baz') ); HTML-FormFu-2.07/t/nested/constraints/equal.t0000644000175100017520000000110513404751171017421 0ustar carlcarluse strict; use warnings; use Test::More tests => 3; use HTML::FormFu; my $form = HTML::FormFu->new; $form->auto_fieldset( { nested_name => 'foo' } ); $form->element('Text')->name('bar')->constraint('Equal')->others('foo.baz'); $form->element('Text')->name('baz'); { $form->process( { 'foo.bar' => 'x', 'foo.baz' => 'x', } ); ok( !$form->has_errors('foo.bar') ); ok( !$form->has_errors ); } { $form->process( { 'foo.bar' => 'x', 'foo.baz' => 'y', } ); ok( !$form->has_errors('foo.bar') ); } HTML-FormFu-2.07/t/nested/constraints/constraint_when.t0000644000175100017520000001030713404751171021523 0ustar carlcarluse strict; use warnings; package CB; # Just to test we can provide strings as callbacks # used by "coo2" field sub nested_when_string_callback { return 1 } package main; use Test::More tests => 49; use HTML::FormFu; my $form = HTML::FormFu->new; $form->load_config_file('t/nested/constraints/constraint_when.yml'); # When triggered depending on callback my $when_closure = sub { my $params = shift; return 1 if defined $params->{xyz}{foo} && $params->{xyz}{foo} eq '1'; }; $form->get_field('coo')->get_constraint->when( { callback => $when_closure } ); # Valid { $form->process( { 'xyz.foo' => 1, 'xyz.bar' => 'bar_value', 'xyz.moo' => undef, 'xyz.zoo' => 'zoo_value', 'xyz.coo' => 4, 'xyz.coo2' => 5, } ); # if 'moo' does not *exist* in process params # it wouldn't be valid ok( $form->valid('xyz.foo'), 'foo valid' ); ok( $form->valid('xyz.bar'), 'bar valid' ); ok( $form->valid('xyz.moo'), 'moo valid' ); ok( $form->valid('xyz.zoo'), 'zoo valid' ); ok( $form->valid('xyz.coo'), 'coo valid' ); ok( $form->valid('xyz.coo2'), 'coo2 valid' ); ok( grep { $_ eq 'xyz.foo' } $form->valid ); ok( grep { $_ eq 'xyz.bar' } $form->valid ); ok( grep { $_ eq 'xyz.moo' } $form->valid ); ok( grep { $_ eq 'xyz.zoo' } $form->valid ); ok( grep { $_ eq 'xyz.coo' } $form->valid ); ok( grep { $_ eq 'xyz.coo2' } $form->valid ); } { $form->process( { 'xyz.foo' => 2, 'xyz.bar' => undef, 'xyz.moo' => 'moo_value', 'xyz.zoo' => 'zoo_value', 'xyz.coo' => 'not_a_number', } ); # if 'bar' does not *exist* in process params # it wouldn't be valid ok( $form->valid('xyz.foo'), 'foo valid' ); ok( $form->valid('xyz.bar'), 'bar valid' ); ok( $form->valid('xyz.moo'), 'moo valid' ); ok( $form->valid('xyz.zoo'), 'zoo valid' ); ok( $form->valid('xyz.coo'), 'coo valid' ); ok( grep { $_ eq 'xyz.foo' } $form->valid ); ok( grep { $_ eq 'xyz.bar' } $form->valid ); ok( grep { $_ eq 'xyz.moo' } $form->valid ); ok( grep { $_ eq 'xyz.zoo' } $form->valid ); ok( grep { $_ eq 'xyz.coo' } $form->valid ); } { $form->process( { 'xyz.foo' => 5, 'xyz.bar' => undef, 'xyz.moo' => undef, 'xyz.zoo' => undef, 'xyz.coo' => undef, } ); # if 'bar' does not *exist* in process params # it wouldn't be valid ok( $form->valid('xyz.foo'), 'foo valid' ); ok( $form->valid('xyz.bar'), 'bar valid' ); ok( $form->valid('xyz.moo'), 'moo valid' ); ok( $form->valid('xyz.zoo'), 'zoo valid' ); ok( $form->valid('xyz.coo'), 'coo valid' ); ok( grep { $_ eq 'xyz.foo' } $form->valid ); ok( grep { $_ eq 'xyz.bar' } $form->valid ); ok( grep { $_ eq 'xyz.moo' } $form->valid ); ok( grep { $_ eq 'xyz.zoo' } $form->valid ); ok( grep { $_ eq 'xyz.coo' } $form->valid ); } # Invalid { $form->process( { 'xyz.foo' => 1, 'xyz.moo' => undef, 'xyz.coo' => 'not_a_number', } ); ok( $form->has_errors ); ok( $form->valid('xyz.foo'), 'foo valid' ); ok( !$form->valid('xyz.bar'), 'bar not valid' ); ok( $form->valid('xyz.moo'), 'moo valid' ); ok( !$form->valid('xyz.zoo'), 'zoo not valid' ); ok( !$form->valid('xyz.coo'), 'coo not valid' ); $form->process( { 'xyz.foo' => 'false value', 'xyz.bar' => undef, 'xyz.moo' => undef, 'xyz.zoo' => 'zoo_value', 'xyz.coo' => 'not_a_number', } ); # if 'bar' and 'moo' does not *exist* in process params # it wouldn't be valid ok( $form->has_errors ); ok( !$form->valid('xyz.foo'), 'foo not valid' ); ok( $form->valid('xyz.bar'), 'bar valid' ); ok( $form->valid('xyz.moo'), 'moo valid' ); ok( $form->valid('xyz.zoo'), 'zoo valid' ); ok( $form->valid('xyz.coo'), 'coo valid' ); ok( !grep { $_ eq 'xyz.foo' } $form->valid ); ok( grep { $_ eq 'xyz.bar' } $form->valid ); ok( grep { $_ eq 'xyz.moo' } $form->valid ); ok( grep { $_ eq 'xyz.zoo' } $form->valid ); ok( grep { $_ eq 'xyz.coo' } $form->valid ); } HTML-FormFu-2.07/t/nested/constraints/callbackonce.t0000644000175100017520000000112513404751171020715 0ustar carlcarluse strict; use warnings; use Test::More tests => 5; use HTML::FormFu; my $form = HTML::FormFu->new; $form->auto_fieldset( { nested_name => 'foo' } ); $form->element('Text')->name('bar')->constraint('CallbackOnce')->callback( sub { ok(1); return 1; } ); $form->element('Text')->name('baz')->constraint('CallbackOnce')->callback( sub { ok(1); return 1; } ); $form->process( { 'foo.bar' => 'x', 'foo.baz' => [ 1, 2 ], } ); ok( !$form->has_errors('foo.bar') ); ok( !$form->has_errors('foo.baz') ); ok( !$form->has_errors ); HTML-FormFu-2.07/t/nested/constraints/dependon.t0000644000175100017520000000136213404751171020113 0ustar carlcarluse strict; use warnings; use Test::More tests => 4; use HTML::FormFu; my $form = HTML::FormFu->new; $form->auto_fieldset( { nested_name => 'foo' } ); $form->element('Text')->name('bar')->constraint('DependOn') ->others( [qw/ foo.baz foo.bag /] ); $form->element('Text')->name('baz'); $form->element('Text')->name('bag'); # Valid { $form->process( { 'foo.bar' => 1, 'foo.baz' => 'a', 'foo.bag' => [2], } ); ok( !$form->has_errors ); } # Invalid { $form->process( { 'foo.bar' => 1, 'foo.baz' => '', 'foo.bag' => 2, } ); ok( !$form->has_errors('foo.bar') ); ok( $form->has_errors('foo.baz') ); ok( !$form->has_errors('foo.bag') ); } HTML-FormFu-2.07/t/nested/constraints/constraint_when.yml0000644000175100017520000000150113404751171022055 0ustar carlcarl--- elements: type: Block nested_name: xyz elements: - name: foo constraints: - type: Integer - name: bar constraints: - type: Required when: field: xyz.foo value: 1 - name: moo constraints: type: Required when: field: xyz.foo values: [2,3,4] - name: zoo constraints: - type: Required when: field: xyz.foo value: 5 not: 1 - name: coo constraints: - type: Number - name: coo2 constraints: - type: Integer when: callback: 'CB::nested_when_string_callback' HTML-FormFu-2.07/t/nested/constraints/allornone.t0000644000175100017520000000146613404751171020315 0ustar carlcarluse strict; use warnings; use Test::More tests => 5; use HTML::FormFu; my $form = HTML::FormFu->new; $form->indicator('submit'); $form->auto_fieldset( { nested_name => 'foo' } ); $form->element('Text')->name('bar')->constraint('AllOrNone')->others('foo.baz'); $form->element('Text')->name('baz'); $form->element('Submit')->name('submit'); { $form->process( { 'foo.bar' => 'x', 'foo.baz' => 'y', 'submit' => 'Submit', } ); ok( !$form->has_errors('foo.bar') ); ok( !$form->has_errors ); } { $form->process( { 'submit' => 'Submit', } ); ok( !$form->has_errors('foo.bar') ); ok( !$form->has_errors ); } { $form->process( { 'foo.bar' => 'x', 'submit' => 'Submit', } ); ok( $form->has_errors('foo.baz') ); } HTML-FormFu-2.07/t/nested/constraints/minmaxfields.t0000644000175100017520000000212413404751171020774 0ustar carlcarluse strict; use warnings; use Test::More tests => 6; use HTML::FormFu; my $form = HTML::FormFu->new; $form->auto_fieldset( { nested_name => 'foo' } ); $form->element('Text')->name('bar')->constraint('MinMaxFields') ->others( [qw/ foo.baz foo.bag foo.nod /] )->min(1)->max(2); $form->element('Text')->name('baz'); $form->element('Text')->name('bag'); $form->element('Text')->name('nod'); # Valid { $form->process( { 'foo.bar' => 1, 'foo.baz' => '', 'foo.bag' => [2], 'foo.nod' => '', } ); ok( !$form->has_errors ); } # Valid { $form->process( { 'foo.bar' => 1, 'foo.baz' => '', 'foo.bag' => '', 'foo.nod' => '', } ); ok( !$form->has_errors ); } # Invalid { $form->process( { 'foo.bar' => 1, 'foo.baz' => 2, 'foo.bag' => '', 'foo.nod' => 22, } ); ok( $form->has_errors('foo.bar') ); ok( !$form->has_errors('foo.baz') ); ok( !$form->has_errors('foo.bag') ); ok( !$form->has_errors('foo.nod') ); } HTML-FormFu-2.07/t/nested/valid.t0000644000175100017520000000175413404751171015054 0ustar carlcarluse strict; use warnings; use Test::More tests => 7; use HTML::FormFu; my $form = HTML::FormFu->new; $form->auto_fieldset( { nested_name => 'foo' } ); $form->element('Text')->name('bar')->constraint('Number'); $form->element('Text')->name('baz')->constraint('Number'); $form->element('Text')->name('bag')->constraint('Number'); $form->process( { 'foo.bar' => 1, 'foo.baz' => [ 2, 3 ], 'foo.bag' => 'yada', 'foo.unknown' => 4, } ); is_deeply( [ sort( $form->valid ) ], [ qw/ foo.bar foo.baz / ] ); ok( $form->valid('foo.bar') ); ok( $form->valid('foo.baz') ); ok( !$form->valid('foo.bag') ); ok( !$form->valid('foo.unknown') ); # new behaviour # because a child has errors... ok( !$form->valid('foo') ); # with no errors... $form->process( { 'foo.bar' => 1, 'foo.baz' => [ 2, 3 ], 'foo.bag' => 9, 'foo.unknown' => 4, } ); ok( $form->valid('foo') ); HTML-FormFu-2.07/t/nested/param.t0000644000175100017520000000235113404751171015047 0ustar carlcarluse strict; use warnings; use Test::More tests => 11; use HTML::FormFu; my $form = HTML::FormFu->new; $form->auto_fieldset( { nested_name => 'foo' } ); $form->element('Text')->name('bar')->constraint('Number'); $form->element('Text')->name('baz')->constraint('Number'); $form->element('Text')->name('bag')->constraint('Number'); $form->process( { 'foo.bar' => 1, 'foo.baz' => [ 2, 3 ], 'foo.bag' => 'yada', 'foo.unknown' => 4, } ); my @valid = $form->param; ok( grep { $_ eq 'foo.bar' } @valid ); ok( grep { $_ eq 'foo.baz' } @valid ); ok( !grep { $_ eq 'foo.bag' } @valid ); ok( !grep { $_ eq 'foo.unknown' } @valid ); is( $form->param('foo.bar'), 1 ); my $bar = $form->param('foo.baz'); is( $bar, 2 ); my @bar = $form->param('foo.baz'); is_deeply( \@bar, [ 2, 3 ] ); ok( !$form->param('foo.bag') ); ok( !$form->param('foo.unknown') ); # new behaviour # because a child has errors... ok( !defined $form->param('foo') ); # with no errors... $form->process( { 'foo.bar' => 1, 'foo.baz' => [ 2, 3 ], 'foo.bag' => 9, 'foo.unknown' => 4, } ); is_deeply( $form->param('foo'), { bar => 1, baz => [ 2, 3 ], bag => 9, } ); HTML-FormFu-2.07/t/nested/inflators/0000775000175100017520000000000013404751171015564 5ustar carlcarlHTML-FormFu-2.07/t/nested/inflators/datetime_strptime.t0000644000175100017520000000153513404751171021476 0ustar carlcarluse strict; use warnings; use Test::More tests => 4; use HTML::FormFu; my $form = HTML::FormFu->new; $form->auto_fieldset( { nested_name => 'foo' } ); # attach to field $form->element('Text')->name('bar')->inflator('DateTime') ->parser( { strptime => '%d/%m/%Y' } )->strptime('%d/%m/%Y'); $form->element('Text')->name('baz'); # attach via form $form->inflator( { type => 'DateTime', name => 'foo.baz', parser => { strptime => '%d/%m/%Y' }, strptime => { pattern => '%m-%d-%Y' }, } ); $form->process( { 'foo.bar' => '31/12/2006', 'foo.baz' => '1/07/2007', } ); { my $value = $form->param('foo.bar'); isa_ok( $value, 'DateTime' ); is( $value, "31/12/2006" ); } { my $value = $form->param('foo.baz'); isa_ok( $value, 'DateTime' ); is( $value, "07-01-2007" ); } HTML-FormFu-2.07/t/nested/params.t0000644000175100017520000000113313404751171015227 0ustar carlcarluse strict; use warnings; use Test::More tests => 1; use HTML::FormFu; my $form = HTML::FormFu->new; $form->auto_fieldset( { nested_name => 'foo' } ); $form->element('Text')->name('bar')->constraint('Number'); $form->element('Text')->name('baz')->constraint('Number'); $form->element('Text')->name('bag')->constraint('Number'); $form->process( { 'foo.bar' => 1, 'foo.baz' => [ 2, 3 ], 'foo.bag' => 'yada', 'foo.unknown' => 4, } ); is_deeply( $form->params, { foo => { bar => 1, baz => [ 2, 3 ], }, } ); HTML-FormFu-2.07/t/nested/illegal_name.t0000644000175100017520000000025513404751171016361 0ustar carlcarluse strict; use warnings; use Test::More tests => 1; use HTML::FormFu; my $form = HTML::FormFu->new; eval { $form->element( { name => 'foo.bar' } ); }; # died ok($@); HTML-FormFu-2.07/t/nested/element_name.yml0000644000175100017520000000022113404751171016730 0ustar carlcarl--- auto_id: '%n' auto_fieldset: nested_name: foo elements: - name: bar - type: Block nested_name: baz elements: - name: 0 HTML-FormFu-2.07/t/nested/validators/0000775000175100017520000000000013404751171015733 5ustar carlcarlHTML-FormFu-2.07/t/nested/validators/callback.t0000644000175100017520000000217713404751171017661 0ustar carlcarluse strict; use warnings; # base the package name on the test file path # to stop 'redefined' warnings under Test::Aggregate::Nested package My::Nested::Validators::Callback; sub cb { my $value = shift; my $params = shift; ::ok(1) if grep { $value eq $_ ? 1 : 0 } qw/ 1 0 a /; ::ok( ref($params) eq 'HASH' && keys %$params, 'params hashref is passed' ); return 1; } package main; use Test::More tests => 11; use HTML::FormFu; my $form = HTML::FormFu->new; $form->auto_fieldset( { nested_name => 'foo' } ); $form->element('Text')->name('bar')->validator('Callback') ->callback( \&My::Nested::Validators::Callback::cb ); $form->element('Text')->name('baz'); # attached via form $form->validator( { type => 'Callback', name => 'foo.baz', callback => 'My::Nested::Validators::Callback::cb', } ); # Valid { $form->process( { 'foo.bar' => 1, 'foo.baz' => [ 0, 'a', 'b' ], } ); ok( $form->valid('foo.bar') ); ok( $form->valid('foo.baz') ); is( $form->param('foo.bar'), 1 ); is_deeply( [ $form->param('foo.baz') ], [ 0, 'a', 'b' ] ); } HTML-FormFu-2.07/t/nested/filters/0000775000175100017520000000000013404751171015233 5ustar carlcarlHTML-FormFu-2.07/t/nested/filters/regex.t0000644000175100017520000000103013404751171016522 0ustar carlcarluse strict; use warnings; use Test::More tests => 2; use HTML::FormFu; my $form = HTML::FormFu->new; $form->auto_fieldset( { nested_name => 'foo' } ); $form->element('Text')->name('bar'); $form->element('Text')->name('baz'); $form->filters( { type => 'Regex', names => [qw/ foo.bar foo.baz /], match => 'a', replace => 'A', } ); $form->process( { 'foo.bar' => 'abc', 'foo.baz' => 'def', } ); is( $form->param('foo.bar'), 'Abc' ); is( $form->param('foo.baz'), 'def' ); HTML-FormFu-2.07/t/nested/elements/0000775000175100017520000000000013404751171015377 5ustar carlcarlHTML-FormFu-2.07/t/nested/elements/radiogroup.t0000644000175100017520000000200513404751171017732 0ustar carlcarluse strict; use warnings; use Test::More tests => 3; use HTML::FormFu; my $form = HTML::FormFu->new( { tt_args => { INCLUDE_PATH => 'share/templates/tt/xhtml' } } ); $form->auto_fieldset( { nested_name => 'rg' } ); my $field = $form->element('Radiogroup')->name('foo')->value(2) ->options( [ [ 1 => 'One' ], [ 2 => 'Two' ] ] ); is( "$form", <
EOF $form->process( { "rg.foo" => 1, } ); is( $form->param('rg.foo'), 1 ); is( "$form", <
EOF HTML-FormFu-2.07/t/nested/elements/radio_retain_default.t0000644000175100017520000000167113404751171021733 0ustar carlcarluse strict; use warnings; use Test::More tests => 10; use HTML::FormFu; my $form = HTML::FormFu->new( { tt_args => { INCLUDE_PATH => 'share/templates/tt/xhtml' } } ); $form->auto_fieldset( { nested_name => 'radio' } ); $form->element('Radio')->name('foo')->value('a')->retain_default(1); $form->element('Radio')->name('fox')->value('b')->retain_default(1); $form->element('Radio')->name('bar')->value('c'); $form->process( { "radio.foo" => '', "radio.bar" => '', } ); ok( $form->valid('radio.foo') ); ok( !$form->valid('radio.fox') ); ok( $form->valid('radio.bar') ); is( $form->param('radio.foo'), '' ); is( $form->param('radio.fox'), undef ); is( $form->param('radio.bar'), '' ); like( $form->get_field('foo'), qr/value="a" [^>] checked="checked"/x ); like( $form->get_field('fox'), qr/value="b" [^>] checked="checked"/x ); like( $form->get_field('bar'), qr/value="c"/ ); unlike( $form->get_field('bar'), qr/checked/ ); HTML-FormFu-2.07/t/nested/elements/select_force_default.t0000644000175100017520000000213113404751171021720 0ustar carlcarluse strict; use warnings; use Test::More tests => 9; use HTML::FormFu; my $form = HTML::FormFu->new( { tt_args => { INCLUDE_PATH => 'share/templates/tt/xhtml' } } ); $form->auto_fieldset( { nested_name => 'select' } ); $form->element('Select')->name('foo')->values( [qw/ one two three /] ) ->default('two')->force_default(1); $form->element('Select')->name('bar')->values( [qw/ one two three /] ) ->default('one')->force_default(1); $form->element('Select')->name('baz')->values( [qw/ one two three /] ) ->default('three')->force_default(1); $form->process( { "select.foo" => '', "select.bar" => 'three', } ); ok( $form->valid('select.foo') ); ok( $form->valid('select.bar') ); ok( $form->valid('select.baz') ); is( $form->param('select.foo'), 'two' ); is( $form->param('select.bar'), 'one' ); is( $form->param('select.baz'), 'three' ); like( $form->get_field('foo'), qr/value="two" [^>]* selected="selected"/x ); like( $form->get_field('bar'), qr/value="one" [^>]* selected="selected"/x ); like( $form->get_field('baz'), qr/value="three" [^>]* selected="selected"/x ); HTML-FormFu-2.07/t/nested/elements/select_same_name.t0000644000175100017520000000116513404751171021051 0ustar carlcarluse strict; use warnings; use Test::More tests => 1; use HTML::FormFu; my $form = HTML::FormFu->new( { tt_args => { INCLUDE_PATH => 'share/templates/tt/xhtml' } } ); $form->load_config_file('t/nested/elements/select_same_name.yml'); $form->process( { 'x.foo' => [ 1, 2 ], } ); is( "$form", <
EOF HTML-FormFu-2.07/t/nested/elements/repeatable_repeatable.t0000644000175100017520000000310013404751171022044 0ustar carlcarluse strict; use warnings; use Test::More tests => 6; use HTML::FormFu; my $form = HTML::FormFu->new( { tt_args => { INCLUDE_PATH => 'share/templates/tt/xhtml' } } ); $form->load_config_file('t/nested/elements/repeatable_repeatable.yml'); $form->process( { 'count' => 2, 'outer_1.foo' => 'a', 'outer_1.count' => 3, 'outer_1.inner_1.bar' => 'b', 'outer_1.inner_2.bar' => 'c', 'outer_1.inner_3.bar' => 'd', 'outer_2.foo' => 'e', 'outer_2.count' => 4, 'outer_2.inner_1.bar' => 'f', 'outer_2.inner_2.bar' => 'g', 'outer_2.inner_3.bar' => 'h', 'outer_2.inner_4.bar' => 'i', } ); ok( $form->submitted_and_valid ); is_deeply( $form->params, { count => 2, outer_1 => { foo => 'a', count => 3, inner_1 => { bar => 'b', }, inner_2 => { bar => 'c', }, inner_3 => { bar => 'd', }, }, outer_2 => { foo => 'e', count => 4, inner_1 => { bar => 'f', }, inner_2 => { bar => 'g', }, inner_3 => { bar => 'h', }, inner_4 => { bar => 'i', }, }, } ); my $outer = $form->get_element( { type => 'Repeatable' } ); my $inner = $outer->get_element->get_element( { type => 'Repeatable' } ); is( $outer->original_nested_name, 'outer' ); is( $inner->original_nested_name, 'inner' ); is( $outer->get_field->original_name, 'foo' ); is( $inner->get_field->original_name, 'bar' ); HTML-FormFu-2.07/t/nested/elements/radiogroup_force_default.t0000644000175100017520000000207313404751171022621 0ustar carlcarluse strict; use warnings; use Test::More tests => 9; use HTML::FormFu; my $form = HTML::FormFu->new( { tt_args => { INCLUDE_PATH => 'share/templates/tt/xhtml' } } ); $form->auto_fieldset( { nested_name => 'rg' } ); $form->element('Radiogroup')->name('foo')->values( [qw/ one two three /] ) ->default('two')->force_default(1); $form->element('Radiogroup')->name('bar')->values( [qw/ one two three /] ) ->default('one')->force_default(1); $form->element('Radiogroup')->name('baz')->values( [qw/ one two three /] ) ->default('three')->force_default(1); $form->process( { "rg.foo" => '', "rg.bar" => 'three', } ); ok( $form->valid('rg.foo') ); ok( $form->valid('rg.bar') ); ok( $form->valid('rg.baz') ); is( $form->param('rg.foo'), 'two' ); is( $form->param('rg.bar'), 'one' ); is( $form->param('rg.baz'), 'three' ); like( $form->get_field('foo'), qr/value="two" [^>]* checked="checked"/x ); like( $form->get_field('bar'), qr/value="one" [^>]* checked="checked"/x ); like( $form->get_field('baz'), qr/value="three" [^>]* checked="checked"/x ); HTML-FormFu-2.07/t/nested/elements/select_same_name.yml0000644000175100017520000000034213404751171021403 0ustar carlcarl--- auto_fieldset: nested_name: x elements: - type: Select name: foo options: - [1, One] - [2, Two] - type: Select name: foo options: - [1, One] - [2, Two] HTML-FormFu-2.07/t/nested/elements/checkbox_retain_default.t0000644000175100017520000000164713404751171022426 0ustar carlcarluse strict; use warnings; use Test::More tests => 10; use HTML::FormFu; my $form = HTML::FormFu->new( { tt_args => { INCLUDE_PATH => 'share/templates/tt/xhtml' } } ); $form->auto_fieldset( { nested_name => 'cb' } ); $form->element('Checkbox')->name('foo')->value('a')->retain_default(1); $form->element('Checkbox')->name('fox')->value('b')->retain_default(1); $form->element('Checkbox')->name('bar')->value('c'); $form->process( { "cb.foo" => '', "cb.bar" => '', } ); ok( $form->valid('cb.foo') ); ok( !$form->valid('cb.fox') ); ok( $form->valid('cb.bar') ); is( $form->param('cb.foo'), '' ); is( $form->param('cb.fox'), undef ); is( $form->param('cb.bar'), '' ); like( $form->get_field('foo'), qr/value="a" [^>] checked="checked"/x ); like( $form->get_field('fox'), qr/value="b" [^>] checked="checked"/x ); like( $form->get_field('bar'), qr/value="c"/ ); unlike( $form->get_field('bar'), qr/checked/ ); HTML-FormFu-2.07/t/nested/elements/multi.t0000644000175100017520000000102213404751171016707 0ustar carlcarluse strict; use warnings; use Test::More tests => 1; use HTML::FormFu; my $form = HTML::FormFu->new( { tt_args => { INCLUDE_PATH => 'share/templates/tt/xhtml' } } ); $form->auto_fieldset( { nested_name => 'nested' } ); my $multi = $form->element('Multi'); $multi->element('Text')->name('foo'); my $form_xhtml = <
EOF is( "$form", $form_xhtml, 'stringified form' ); HTML-FormFu-2.07/t/nested/elements/date.t0000644000175100017520000003257213404751171016510 0ustar carlcarluse strict; use warnings; use Test::More tests => 11; use HTML::FormFu; use DateTime; my $dt = DateTime->new( day => 6, month => 8, year => 2007 ); my $form = HTML::FormFu->new( { tt_args => { INCLUDE_PATH => 'share/templates/tt/xhtml' } } ); $form->auto_fieldset( { nested_name => 'date' } ); $form->element('Date')->name('foo')->strftime("%m/%d/%Y") ->day( { prefix => '-- Day --', } )->month( { prefix => '-- Month --', short_names => 1, } )->year( { prefix => '-- Year --', list => [ 2007 .. 2017 ], } )->default($dt)->auto_inflate(1)->constraint('Required'); $form->element('Date')->name('bar')->default('14-08-2007') ->year( { list => [ 2007 .. 2017 ] } ); $form->process; is( "$form", <
HTML $form->process( { 'date.foo_day', 30, 'date.foo_month', 6, 'date.foo_year', 2007, 'date.bar_day', 1, 'date.bar_month', 7, 'date.bar_year', 2007, } ); ok( $form->submitted_and_valid ); my $foo = $form->param('date.foo'); my $bar = $form->param('date.bar'); isa_ok( $foo, 'DateTime' ); ok( !ref $bar ); is( $foo, "06/30/2007" ); is( $bar, "01-07-2007" ); my $foo_field = $form->get_field('foo'); my $bar_field = $form->get_field('bar'); is( "$form", <
HTML # incorrect date $form->process( { 'date.foo_day', 29, 'date.foo_month', 2, 'date.foo_year', 2007, } ); ok( $form->submitted ); ok( $form->has_errors ); ok( !defined $form->param('date.foo') ); is( "$form", <
Invalid date
HTML_ERRORS HTML-FormFu-2.07/t/nested/elements/block_repeatable_multi_named_filter.t0000644000175100017520000000150213404751171024761 0ustar carlcarluse strict; use warnings; use Test::More tests => 4; use HTML::FormFu; my $form = HTML::FormFu->new( { tt_args => { INCLUDE_PATH => 'share/templates/tt/xhtml' } } ); $form->load_config_file( 't/nested/elements/block_repeatable_multi_named_filter.yml'); my $fieldset = $form->get_element; my $repeatable = $fieldset->get_element; my $multi = $repeatable->get_element; $form->process( { 'counter' => 1, 'nested_1.foo' => 'aaa', 'nested_1.multi.bar' => 'bbb', 'nested_1.multi.baz' => 'ccc', } ); ok( $form->submitted_and_valid ); is_deeply( $form->params, { nested_1 => { foo => 'aaa', multi => 'bbb ccc' } } ); is( $form->param_value('nested_1.foo'), 'aaa' ); is( $form->param_value('nested_1.multi'), 'bbb ccc' ); HTML-FormFu-2.07/t/nested/elements/combobox.t0000644000175100017520000000305013404751171017370 0ustar carlcarluse strict; use warnings; use Test::More tests => 5; use HTML::FormFu; my $form = HTML::FormFu->new( { tt_args => { INCLUDE_PATH => 'share/templates/tt/xhtml' } } ); $form->auto_fieldset( { nested_name => 'foo' } ); my $field = $form->element('ComboBox')->name('bar') ->options( [ [ 1 => 'One' ], [ 2 => 'Two' ] ] ); $form->process; is( "$form", <
EOF $form->process( { "foo.bar_select" => '2', "foo.bar_text" => '', } ); is( $form->param("foo.bar"), 2 ); is( "$form", <
EOF $form->process( { "foo.bar_select" => '', "foo.bar_text" => '3', } ); is( $form->param("foo.bar"), 3 ); is( "$form", <
EOF HTML-FormFu-2.07/t/nested/elements/radio_force_default.t0000644000175100017520000000332313404751171021543 0ustar carlcarluse strict; use warnings; use Test::More tests => 20; use HTML::FormFu; my $form = HTML::FormFu->new( { tt_args => { INCLUDE_PATH => 'share/templates/tt/xhtml' } } ); $form->auto_fieldset( { nested_name => 'radio' } ); $form->element('Radio')->name('foo')->value('a')->force_default(1); $form->element('Radio')->name('fox')->value('b')->force_default(1); $form->element('Radio')->name('bar')->value('c')->checked('checked') ->force_default(1); $form->element('Radio')->name('bax')->value('d')->checked('checked') ->force_default(1); $form->element('Radio')->name('moo')->value('e')->default('e') ->force_default(1); $form->element('Radio')->name('mox')->value('f')->default('f') ->force_default(1); $form->process( { "radio.foo" => '', "radio.bar" => 'z', "radio.moo" => 'y', } ); ok( $form->valid('radio.foo') ); ok( $form->valid('radio.fox') ); ok( $form->valid('radio.bar') ); ok( $form->valid('radio.bax') ); ok( $form->valid('radio.moo') ); ok( $form->valid('radio.mox') ); is( $form->param('radio.foo'), undef ); is( $form->param('radio.fox'), undef ); is( $form->param('radio.bar'), 'c' ); is( $form->param('radio.bax'), 'd' ); is( $form->param('radio.moo'), 'e' ); is( $form->param('radio.mox'), 'f' ); like( $form->get_field('foo'), qr/value="a"/ ); unlike( $form->get_field('foo'), qr/checked/ ); like( $form->get_field('fox'), qr/value="b"/ ); unlike( $form->get_field('fox'), qr/checked/ ); like( $form->get_field('bar'), qr/value="c" [^>] checked="checked"/x ); like( $form->get_field('bax'), qr/value="d" [^>] checked="checked"/x ); like( $form->get_field('moo'), qr/value="e" [^>] checked="checked"/x ); like( $form->get_field('mox'), qr/value="f" [^>] checked="checked"/x ); HTML-FormFu-2.07/t/nested/elements/block_without_name.t0000644000175100017520000000034713404751171021443 0ustar carlcarluse strict; use warnings; use Test::More tests => 1; use HTML::FormFu; my $form = HTML::FormFu->new; $form->load_config_file('t/nested/elements/block_without_name.yml'); is( $form->get_field('bar')->nested_name, 'foo.bar' ); HTML-FormFu-2.07/t/nested/elements/select_retain_default.t0000644000175100017520000000204113404751171022104 0ustar carlcarluse strict; use warnings; use Test::More tests => 9; use HTML::FormFu; my $form = HTML::FormFu->new( { tt_args => { INCLUDE_PATH => 'share/templates/tt/xhtml' } } ); $form->auto_fieldset( { nested_name => 'select' } ); $form->element('Select')->name('foo')->values( [qw/ one two three /] ) ->default('two')->retain_default(1); $form->element('Select')->name('bar')->values( [qw/ one two three /] ) ->default('one'); $form->element('Select')->name('baz')->values( [qw/ one two three /] ) ->default('three')->retain_default(1); $form->process( { "select.foo" => '', "select.bar" => '', } ); ok( $form->valid('select.foo') ); ok( $form->valid('select.bar') ); ok( !$form->valid('select.baz') ); is( $form->param('select.foo'), '' ); is( $form->param('select.bar'), '' ); is( $form->param('select.baz'), undef ); like( $form->get_field('foo'), qr/value="two" [^>]* selected="selected"/x ); unlike( $form->get_field('bar'), qr/selected/ ); like( $form->get_field('baz'), qr/value="three" [^>]* selected="selected"/x ); HTML-FormFu-2.07/t/nested/elements/select.t0000644000175100017520000000146613404751171017050 0ustar carlcarluse strict; use warnings; use Test::More tests => 3; use HTML::FormFu; my $form = HTML::FormFu->new( { tt_args => { INCLUDE_PATH => 'share/templates/tt/xhtml' } } ); $form->auto_fieldset( { nested_name => 'foo' } ); my $field = $form->element('Select')->name('bar') ->options( [ [ 1 => 'One' ], [ 2 => 'Two' ] ] ); is( "$form", <
EOF $form->process( { "foo.bar" => '2', } ); is( $form->param("foo.bar"), 2 ); is( "$form", <
EOF HTML-FormFu-2.07/t/nested/elements/radiogroup_retain_default.t0000644000175100017520000000200413404751171022777 0ustar carlcarluse strict; use warnings; use Test::More tests => 9; use HTML::FormFu; my $form = HTML::FormFu->new( { tt_args => { INCLUDE_PATH => 'share/templates/tt/xhtml' } } ); $form->auto_fieldset( { nested_name => 'rg' } ); $form->element('Radiogroup')->name('foo')->values( [qw/ one two three /] ) ->default('two')->retain_default(1); $form->element('Radiogroup')->name('bar')->values( [qw/ one two three /] ) ->default('one'); $form->element('Radiogroup')->name('baz')->values( [qw/ one two three /] ) ->default('three')->retain_default(1); $form->process( { "rg.foo" => '', "rg.bar" => '', } ); ok( $form->valid('rg.foo') ); ok( $form->valid('rg.bar') ); ok( !$form->valid('rg.baz') ); is( $form->param('rg.foo'), '' ); is( $form->param('rg.bar'), '' ); is( $form->param('rg.baz'), undef ); like( $form->get_field('foo'), qr/value="two" [^>]* checked="checked"/x ); unlike( $form->get_field('bar'), qr/checked/ ); like( $form->get_field('baz'), qr/value="three" [^>]* checked="checked"/x ); HTML-FormFu-2.07/t/nested/elements/block_repeatable_multi_named.t0000644000175100017520000000165313404751171023423 0ustar carlcarluse strict; use warnings; use Test::More tests => 5; use HTML::FormFu; my $form = HTML::FormFu->new( { tt_args => { INCLUDE_PATH => 'share/templates/tt/xhtml' } } ); $form->load_config_file('t/nested/elements/block_repeatable_multi_named.yml'); my $fieldset = $form->get_element; my $repeatable = $fieldset->get_element; my $multi = $repeatable->get_element; $form->process( { 'counter' => 1, 'nested_1.foo' => 'aaa', 'nested_1.multi.bar' => 'bbb', 'nested_1.multi.baz' => 'ccc', } ); ok( $form->submitted_and_valid ); is_deeply( $form->params, { nested_1 => { foo => 'aaa', multi => { bar => 'bbb', baz => 'ccc', } } } ); is( $form->param_value('nested_1.foo'), 'aaa' ); is( $form->param_value('nested_1.multi.bar'), 'bbb' ); is( $form->param_value('nested_1.multi.baz'), 'ccc' ); HTML-FormFu-2.07/t/nested/elements/block_repeatable_multi_named_filter.yml0000644000175100017520000000047213404751171025324 0ustar carlcarl--- auto_fieldset: 1 elements: - type: Hidden name: count - type: Repeatable nested_name: nested counter_name: counter elements: - name: foo - type: Multi name: multi elements: - name: bar - name: baz filter: - CompoundJoin HTML-FormFu-2.07/t/nested/elements/multi_named.t0000644000175100017520000000125413404751171020062 0ustar carlcarluse strict; use warnings; use Test::More tests => 3; use HTML::FormFu; my $form = HTML::FormFu->new( { tt_args => { INCLUDE_PATH => 'share/templates/tt/xhtml' } } ); $form->auto_fieldset( { nested_name => 'nested' } ); my $multi = $form->element('Multi')->name('foo'); $multi->element('Text')->name('bar'); my $form_xhtml = <
EOF is( "$form", $form_xhtml, 'stringified form' ); $form->process( { 'nested.foo.bar' => 'aaa', } ); ok( $form->submitted_and_valid ); is( $form->param_value('nested.foo.bar'), 'aaa' ); HTML-FormFu-2.07/t/nested/elements/text.t0000644000175100017520000000121013404751171016540 0ustar carlcarluse strict; use warnings; use Test::More tests => 3; use HTML::FormFu; my $form = HTML::FormFu->new( { tt_args => { INCLUDE_PATH => 'share/templates/tt/xhtml' } } ); $form->auto_fieldset( { nested_name => 'text' } ); my $element = $form->element('Text')->name('foo'); is( "$form", <
EOF $form->process( { "text.foo" => 42, } ); is( $form->param('text.foo'), 42 ); is( "$form", <
EOF HTML-FormFu-2.07/t/nested/elements/block_without_name.yml0000644000175100017520000000014113404751171021771 0ustar carlcarl--- auto_fieldset: nested_name: foo elements: - type: Block elements: - name: bar HTML-FormFu-2.07/t/nested/elements/block_repeatable_multi_named.yml0000644000175100017520000000035713404751171023761 0ustar carlcarl--- auto_fieldset: 1 elements: - type: Repeatable nested_name: nested counter_name: counter elements: - name: foo - type: Multi name: multi elements: - name: bar - name: baz HTML-FormFu-2.07/t/nested/elements/checkbox_force_default.t0000644000175100017520000000323413404751171022234 0ustar carlcarluse strict; use warnings; use Test::More tests => 20; use HTML::FormFu; my $form = HTML::FormFu->new( { tt_args => { INCLUDE_PATH => 'share/templates/tt/xhtml' } } ); $form->auto_fieldset( { nested_name => 'cb' } ); $form->element('Checkbox')->name('foo')->value('a')->force_default(1); $form->element('Checkbox')->name('fox')->value('b')->force_default(1); $form->element('Checkbox')->name('bar')->value('c')->default('c') ->force_default(1); $form->element('Checkbox')->name('bax')->value('d')->default('d') ->force_default(1); $form->element('Checkbox')->name('moo')->value('e')->checked('checked') ->force_default(1); $form->element('Checkbox')->name('mox')->value('f')->checked('checked') ->force_default(1); $form->process( { "cb.foo" => '', "cb.bar" => 'z', } ); ok( $form->valid('cb.foo') ); ok( $form->valid('cb.fox') ); ok( $form->valid('cb.bar') ); ok( $form->valid('cb.bax') ); ok( $form->valid('cb.moo') ); ok( $form->valid('cb.mox') ); is( $form->param('cb.foo'), undef ); is( $form->param('cb.fox'), undef ); is( $form->param('cb.bar'), 'c' ); is( $form->param('cb.bax'), 'd' ); is( $form->param('cb.moo'), 'e' ); is( $form->param('cb.mox'), 'f' ); like( $form->get_field('foo'), qr/value="a"/ ); unlike( $form->get_field('foo'), qr/checked/ ); like( $form->get_field('fox'), qr/value="b"/ ); unlike( $form->get_field('fox'), qr/checked/ ); like( $form->get_field('bar'), qr/value="c" [^>] checked="checked"/x ); like( $form->get_field('bax'), qr/value="d" [^>] checked="checked"/x ); like( $form->get_field('moo'), qr/value="e" [^>] checked="checked"/x ); like( $form->get_field('mox'), qr/value="f" [^>] checked="checked"/x ); HTML-FormFu-2.07/t/nested/elements/radio.t0000644000175100017520000000116113404751171016657 0ustar carlcarluse strict; use warnings; use Test::More tests => 4; use HTML::FormFu; my $form = HTML::FormFu->new( { tt_args => { INCLUDE_PATH => 'share/templates/tt/xhtml' } } ); $form->auto_fieldset( { nested_name => 'radio' } ); $form->element('Radio')->name('foo')->value('foox'); is( "$form", <
EOF { $form->process( { 'radio.foo' => 'foox', } ); ok( $form->valid('radio.foo') ); is( $form->param('radio.foo'), 'foox' ); like( $form->get_field('foo'), qr/checked/ ); } HTML-FormFu-2.07/t/nested/elements/repeatable_repeatable.yml0000644000175100017520000000047013404751171022411 0ustar carlcarl--- elements: - type: Hidden name: count - type: Repeatable nested_name: outer counter_name: count elements: - name: foo - type: Hidden name: count - type: Repeatable nested_name: inner counter_name: count elements: - name: bar HTML-FormFu-2.07/t/nested/transformers/0000775000175100017520000000000013404751171016310 5ustar carlcarlHTML-FormFu-2.07/t/nested/transformers/callback.t0000644000175100017520000000127313404751171020232 0ustar carlcarluse strict; use warnings; package CB; sub cb2 { my $value = shift; $value =~ s/a/A/; return $value; } package main; use Test::More tests => 3; use HTML::FormFu; my $form = HTML::FormFu->new; $form->auto_fieldset( { nested_name => 'foo' } ); $form->element('Text')->name('bar')->transformer('Callback') ->callback( \&CB::cb2 ); $form->element('Text')->name('baz')->transformer('Callback') ->callback("CB::cb2"); # Valid { $form->process( { "foo.bar" => 1, "foo.baz" => [ 0, 'a', 'b' ], } ); ok( $form->submitted_and_valid ); is( $form->param('foo.bar'), 1 ); is_deeply( [ $form->param('foo.baz') ], [ 0, 'A', 'b' ] ); } HTML-FormFu-2.07/t/nested/form/0000775000175100017520000000000013404751171014526 5ustar carlcarlHTML-FormFu-2.07/t/nested/form/render_processed_value.yml0000644000175100017520000000055113404751171021772 0ustar carlcarl--- render_processed_value: 1 auto_fieldset: nested_name: ack elements: - name: foo deflator: - type: Strftime strftime: '%d/%m/%Y' filter: - type: Regex match: 2007 replace: 2006 inflator: - type: DateTime parser: strptime: '%d/%m/%Y' - name: bar filter: - UpperCase HTML-FormFu-2.07/t/nested/form/render_processed_value.t0000644000175100017520000000133313404751171021433 0ustar carlcarluse strict; use warnings; use Test::More tests => 5; use HTML::FormFu; my $form = HTML::FormFu->new( { tt_args => { INCLUDE_PATH => 'share/templates/tt/xhtml' } } ); $form->load_config_file('t/nested/form/render_processed_value.yml'); $form->process( { 'ack.foo' => '27/04/2007', 'ack.bar' => 'hello', } ); # inflator has run isa_ok( $form->params->{ack}{foo}, 'DateTime' ); # filter has run is( $form->params->{ack}{foo}->year, '2006' ); is( $form->params->{ack}{bar}, 'HELLO' ); # deflator is run during render() # maintains filtered value like( $form->get_field('foo')->render, qr|value="27/04/2006"| ); # maintains filtered value like( $form->get_field('bar')->render, qr/value="HELLO"/ ); HTML-FormFu-2.07/t/nested/internals/0000775000175100017520000000000013404751171015562 5ustar carlcarlHTML-FormFu-2.07/t/nested/internals/form_processed_params.t0000644000175100017520000000055313404751171022325 0ustar carlcarluse strict; use warnings; use Test::More tests => 1; use HTML::FormFu; my $form = HTML::FormFu->new; $form->auto_fieldset( { nested_name => 'foo' } ); my $bar = $form->element('Text')->name('bar'); $form->process( { 'foo.bar' => 'x', foo => { bar => 'x', }, } ); is_deeply( $form->_processed_params, { foo => { bar => 'x', }, }, ); HTML-FormFu-2.07/t/nested/internals/hash_keys.t0000644000175100017520000000130313404751171017720 0ustar carlcarluse strict; use warnings; use Test::More tests => 2; use HTML::FormFu; my $data = { a => 1, b => { c => 2, d => 3, }, e => [ 4, 5 ], }; { my @names = HTML::FormFu::_hash_keys($data); @names = sort @names; is_deeply( \@names, [ qw/ a b.c b.d e.0 e.1 / ] ); } { my @names = HTML::FormFu::_hash_keys( $data, 'subscript' ); @names = sort @names; is_deeply( \@names, [ qw/ a b[c] b[d] e[0] e[1] / ] ); } HTML-FormFu-2.07/t/nested/element_name.t0000644000175100017520000000125713404751171016404 0ustar carlcarluse strict; use warnings; use Test::More tests => 3; use HTML::FormFu; my $form = HTML::FormFu->new( { tt_args => { INCLUDE_PATH => 'share/templates/tt/xhtml' } } ); $form->load_config_file('t/nested/element_name.yml'); is( $form->get_field('bar')->nested_name, 'foo.bar' ); my $baz_fs = $form->get_element( { type => 'Fieldset' } ) ->get_element( { type => 'Block' } ); is( $baz_fs->get_field('0')->nested_name, 'foo.baz.0' ); is( "$form", <
EO_RENDER HTML-FormFu-2.07/t/templates/0000775000175100017520000000000013404751171014277 5ustar carlcarlHTML-FormFu-2.07/t/templates/field_layout0000644000175100017520000000004613404751171016700 0ustar carlcarlHTML-FormFu-2.07/t/plugins/0000775000175100017520000000000013404751171013762 5ustar carlcarlHTML-FormFu-2.07/t/plugins/stashvalid.t0000644000175100017520000000044313404751171016310 0ustar carlcarluse strict; use warnings; use Test::More tests => 2; use HTML::FormFu; my $form = HTML::FormFu->new; $form->load_config_file('t/plugins/stashvalid.yml'); $form->process( { foo => 'a', bar => 'b', } ); is( $form->stash->{foo}, 'a' ); is( $form->stash->{bar}, undef ); HTML-FormFu-2.07/t/plugins/stashvalid.yml0000644000175100017520000000013013404751171016637 0ustar carlcarl--- elements: - name: foo - name: bar plugins: - type: StashValid name: foo HTML-FormFu-2.07/t/plugins/stashvalid_on_field.t0000644000175100017520000000045413404751171020151 0ustar carlcarluse strict; use warnings; use Test::More tests => 2; use HTML::FormFu; my $form = HTML::FormFu->new; $form->load_config_file('t/plugins/stashvalid_on_field.yml'); $form->process( { foo => 'a', bar => 'b', } ); is( $form->stash->{foo}, 'a' ); is( $form->stash->{bar}, undef ); HTML-FormFu-2.07/t/plugins/stashvalid_on_field.yml0000644000175100017520000000010213404751171020475 0ustar carlcarl--- elements: - name: foo plugin: StashValid - name: bar HTML-FormFu-2.07/t/inflators/0000775000175100017520000000000013404751171014302 5ustar carlcarlHTML-FormFu-2.07/t/inflators/datetime_optional.t0000644000175100017520000000042513404751171020167 0ustar carlcarluse strict; use warnings; use Test::More tests => 1; use HTML::FormFu; my $form = HTML::FormFu->new; $form->element('Text')->name('foo')->inflator('DateTime') ->parser( { strptime => '%d/%m/%Y' } ); $form->process( { foo => "" } ); ok( $form->submitted_and_valid ); HTML-FormFu-2.07/t/inflators/callback.t0000644000175100017520000000172213404751171016223 0ustar carlcarluse strict; use warnings; use Test::More tests => 4; use HTML::FormFu; use lib 'lib'; my $form = HTML::FormFu->new; $form->element('Text')->name('foo')->inflator('Callback') ->callback( sub { return uc( $_[0] ) } ); $form->element('Text')->name('bar')->inflator('Callback') ->callback('InflatorCallback::my_def'); my $original_foo = "abc123"; my $inflated_foo = "ABC123"; my $original_bar = "abcdef"; my $inflated_bar = "ABCdef"; $form->process( { foo => $original_foo, bar => $original_bar, } ); # foo is changed is( $form->param('foo'), $inflated_foo, 'foo inflated' ); is( $form->params->{foo}, $inflated_foo, 'foo inflated' ); # bar is changed is( $form->param('bar'), $inflated_bar, 'bar inflated' ); is( $form->params->{bar}, $inflated_bar, 'bar inflated' ); { package InflatorCallback; use strict; use warnings; sub my_def { my ($value) = @_; $value =~ tr/abc/ABC/; return $value; } } HTML-FormFu-2.07/t/inflators/datetime_with_constraint.t0000644000175100017520000000076013404751171021563 0ustar carlcarluse strict; use warnings; use Test::More tests => 5; use HTML::FormFu; my $form = HTML::FormFu->new; # yaml config uses references to share the same parser spec between # the constraint and inflator $form->load_config_file('t/inflators/datetime_with_constraint.yml'); $form->process( { foo => '31-12-2006' } ); ok( $form->submitted_and_valid ); my $value = $form->params->{foo}; isa_ok( $value, 'DateTime' ); is( $value->day, 31 ); is( $value->month, 12 ); is( $value->year, 2006 ); HTML-FormFu-2.07/t/inflators/compounddatetime.yml0000644000175100017520000000027513404751171020370 0ustar carlcarl--- elements: - type: Multi name: dob elements: - name: day - name: month - name: year inflators: type: CompoundDateTime strptime: '%d-%m-%Y' HTML-FormFu-2.07/t/inflators/datetime_regex.t0000644000175100017520000000073113404751171017454 0ustar carlcarluse strict; use warnings; use Test::More tests => 4; use HTML::FormFu; my $form = HTML::FormFu->new; $form->element('Text')->name('foo'); $form->inflator('DateTime')->parser( { regex => qr/^ (\d{2}) \/ (\d{2}) \/ (\d{4}) $/x, params => [qw/ month day year /], } ); $form->process( { foo => '12/31/2006' } ); ok( !$form->has_errors ); my $value = $form->params->{foo}; is( $value->day, 31 ); is( $value->month, 12 ); is( $value->year, 2006 ); HTML-FormFu-2.07/t/inflators/compounddatetime_field_order.yml0000644000175100017520000000034013404751171022717 0ustar carlcarl--- elements: - type: Multi name: dob elements: - name: m - name: d - name: y inflators: type: CompoundDateTime strptime: '%m-%d-%Y' field_order: ['month', 'day', 'year'] HTML-FormFu-2.07/t/inflators/datetime_parser.t0000644000175100017520000000065613404751171017644 0ustar carlcarluse strict; use warnings; use Test::More tests => 5; use HTML::FormFu; my $form = HTML::FormFu->new; $form->element('Text')->name('foo')->inflator('DateTime') ->parser( { strptime => '%d/%m/%Y' } ); $form->process( { foo => '31/12/2006' } ); ok( $form->submitted_and_valid ); my $value = $form->params->{foo}; isa_ok( $value, 'DateTime' ); is( $value->day, 31 ); is( $value->month, 12 ); is( $value->year, 2006 ); HTML-FormFu-2.07/t/inflators/datetime_regex_string.t0000644000175100017520000000072013404751171021040 0ustar carlcarluse strict; use warnings; use Test::More tests => 4; use HTML::FormFu; my $form = HTML::FormFu->new; $form->element('Text')->name('foo'); $form->inflator('DateTime')->parser( { regex => '^(\d{2})\/(\d{2})\/(\d{4})$', params => [qw/ month day year /], } ); $form->process( { foo => '12/31/2006' } ); ok( !$form->has_errors ); my $value = $form->params->{foo}; is( $value->day, 31 ); is( $value->month, 12 ); is( $value->year, 2006 ); HTML-FormFu-2.07/t/inflators/datetime_timezone.t0000644000175100017520000000073713404751171020202 0ustar carlcarluse strict; use warnings; use Test::More tests => 2; use HTML::FormFu; my $form = HTML::FormFu->new; $form->element('Text')->name('foo')->inflator('DateTime') ->parser( { strptime => '%Y-%m-%d %H:%M' } ) ->strptime('%H:%M [%Y-%m-%d] %z')->time_zone('Europe/Rome'); $form->process( { foo => '2008-07-23 08:52', } ); is( ref $form->params->{foo}->time_zone, 'DateTime::TimeZone::Europe::Rome' ); is( $form->params->{foo}, '08:52 [2008-07-23] +0200' ); HTML-FormFu-2.07/t/inflators/datetime_with_constraint.yml0000644000175100017520000000031313404751171022113 0ustar carlcarl--- elements: - name: foo constraints: - type: DateTime parser: &PARSER strptime: '%d-%m-%Y' inflators: - type: DateTime parser: *PARSER HTML-FormFu-2.07/t/inflators/compounddatetime_field_order.t0000644000175100017520000000105113404751171022361 0ustar carlcarluse strict; use warnings; use Test::More tests => 7; use HTML::FormFu; my $form = HTML::FormFu->new; $form->load_config_file('t/inflators/compounddatetime_field_order.yml'); $form->process( { 'dob.d' => '31', 'dob.m' => '12', 'dob.y' => '1999', } ); ok( $form->submitted_and_valid ); isa_ok( $form->param_value('dob'), 'DateTime' ); my $dob = $form->params->{dob}; isa_ok( $dob, 'DateTime' ); is( $dob->day, '31' ); is( $dob->month, '12' ); is( $dob->year, '1999' ); # check strptime is( "$dob", "12-31-1999" ); HTML-FormFu-2.07/t/inflators/datetime_strptime.t0000644000175100017520000000104013404751171020203 0ustar carlcarluse strict; use warnings; use Test::More tests => 2; use HTML::FormFu; my $form = HTML::FormFu->new; $form->element('Text')->name('foo')->inflator('DateTime') ->parser( { strptime => '%d/%m/%Y' } )->strptime('%d/%m/%Y'); $form->element('Text')->name('bar')->inflator('DateTime') ->parser( { strptime => '%d/%m/%Y' } ) ->strptime( { pattern => '%m-%d-%Y' } ); $form->process( { foo => '31/12/2006', bar => '1/07/2007', } ); is( $form->params->{foo}, "31/12/2006" ); is( $form->params->{bar}, "07-01-2007" ); HTML-FormFu-2.07/t/inflators/compounddatetime.t0000644000175100017520000000105113404751171020023 0ustar carlcarluse strict; use warnings; use Test::More tests => 7; use HTML::FormFu; my $form = HTML::FormFu->new; $form->load_config_file('t/inflators/compounddatetime.yml'); $form->process( { 'dob.day' => '31', 'dob.month' => '12', 'dob.year' => '1999', } ); ok( $form->submitted_and_valid ); isa_ok( $form->param_value('dob'), 'DateTime' ); my $dob = $form->params->{dob}; isa_ok( $dob, 'DateTime' ); is( $dob->day, '31' ); is( $dob->month, '12' ); is( $dob->year, '1999' ); # check strptime is( "$dob", "31-12-1999" ); HTML-FormFu-2.07/t/inflators/array.t0000644000175100017520000000110613404751171015601 0ustar carlcarluse strict; use warnings; use Test::More tests => 8; use HTML::FormFu; my $form = HTML::FormFu->new; my $field = $form->element('Text')->name('foo'); $field->inflator('DateTime')->parser( { strptime => '%d/%m/%Y' } ); $form->process( { foo => [ '31/12/2006', '01/01/2007' ], } ); my $value = $form->param_array('foo'); isa_ok( $value->[0], 'DateTime' ); is( $value->[0]->day, 31 ); is( $value->[0]->month, 12 ); is( $value->[0]->year, 2006 ); isa_ok( $value->[1], 'DateTime' ); is( $value->[1]->day, 1 ); is( $value->[1]->month, 1 ); is( $value->[1]->year, 2007 ); HTML-FormFu-2.07/t/block_insert_after.t0000644000175100017520000000152013404751171016321 0ustar carlcarluse strict; use warnings; use Test::More tests => 7; use HTML::FormFu; { my $form = HTML::FormFu->new; my $fs = $form->element('Fieldset'); my $e1 = $fs->element('Text')->name('foo'); my $e2 = $fs->element('Hidden')->name('foo'); my $e3 = $e1->clone; $fs->insert_after( $e3, $e1 ); my $elems = $fs->get_elements; is( scalar(@$elems), 3 ); ok( $elems->[0] == $e1 ); ok( $elems->[1] == $e3 ); ok( $elems->[2] == $e2 ); } # ensure elements only occur once { my $form = HTML::FormFu->new; my $fs = $form->element('Fieldset'); my $e1 = $fs->element( { name => 'foo' } ); my $e2 = $fs->element( { name => 'bar' } ); $fs->insert_after( $e1, $e2 ); my $elems = $fs->get_elements; is( scalar(@$elems), 2 ); ok( $elems->[0] == $e2 ); ok( $elems->[1] == $e1 ); } HTML-FormFu-2.07/t/04basic.t0000644000175100017520000000473213404751171013717 0ustar carlcarluse strict; use warnings; use YAML::XS qw( LoadFile ); use Test::More tests => 7; use HTML::FormFu; my $form = HTML::FormFu->new( { tt_args => { INCLUDE_PATH => 'share/templates/tt/xhtml' } } ); $form->action('/foo/bar')->id('form')->auto_id('%n'); my $fs = $form->element('Fieldset')->legend('Jimi'); $fs->element('Text')->name('age')->label('Age')->comment('x') ->constraints( [ 'Integer', 'Required', ] ); $fs->element('Text')->name('name')->label('Name'); $fs->element('Hidden')->name('ok')->value('OK'); $form->constraints( { type => 'Required', name => 'name', } ); $form->filter('HTMLEscape'); # hash-ref my $alt_hash = { action => '/foo/bar', id => 'form', auto_id => '%n', elements => [ { type => 'Fieldset', legend => 'Jimi', elements => [ { type => 'Text', name => 'age', label => 'Age', comment => 'x', constraints => [ 'Integer', 'Required', ], }, { type => 'Text', name => 'name', label => 'Name', }, { type => 'Hidden', name => 'ok', value => 'OK', }, ], } ], constraints => { type => 'Required', name => 'name', }, filters => ['HTMLEscape'], }; # hash-ref from yaml my $yml_hash = LoadFile('t/04basic.yml'); # compare hash-refs is_deeply( $yml_hash, $alt_hash ); # xhtml output my $alt_form = HTML::FormFu->new($alt_hash); $alt_form->tt_args( { INCLUDE_PATH => 'share/templates/tt/xhtml' } ); my $yml_form = HTML::FormFu->new( { tt_args => { INCLUDE_PATH => 'share/templates/tt/xhtml' } } ); $yml_form->load_config_file('t/04basic.yml'); my $xhtml = <
Jimi
x
EOF is( "$form", $xhtml ); is( "$alt_form", $xhtml ); is( "$yml_form", $xhtml ); # With mocked basic query { $form->process( { age => 'a', name => 'sri', } ); ok( $form->valid('name'), 'name is valid' ); ok( !$form->valid('age'), 'age is not valid' ); my $errors = $form->get_errors; is( @$errors, 1 ); } HTML-FormFu-2.07/t/validators/0000775000175100017520000000000013404751171014451 5ustar carlcarlHTML-FormFu-2.07/t/validators/validator.t0000644000175100017520000000145513404751171016626 0ustar carlcarluse strict; use warnings; use Test::More tests => 6; use lib 't/lib'; use HTML::FormFu; my $form = HTML::FormFu->new->localize_class('HTMLFormFu::I18N'); $form->element('Text')->name('foo'); $form->element('Text')->name('bar'); $form->validator('+HTMLFormFu::MyValidator'); # Valid { $form->process( { foo => 'aaa', bar => 'bbbbbbb', } ); ok( $form->valid('foo'), 'foo valid' ); ok( $form->valid('bar'), 'bar valid' ); } # Invalid { $form->process( { foo => 'aaa', bar => 'foo', } ); ok( $form->valid('foo'), 'foo valid' ); ok( !$form->valid('bar'), 'bar not valid' ); my ($error) = @{ $form->get_errors }; is( $error->type, 'HTMLFormFu::MyValidator' ); is( $error->message, 'myvalidator error!' ); } HTML-FormFu-2.07/t/validators/callback.t0000644000175100017520000000141213404751171016366 0ustar carlcarluse strict; use warnings; # base the package name on the test file path # to stop 'redefined' warnings under Test::Aggregate::Nested package My::Validators::Callback; sub cb { my $value = shift; ::ok(1) if grep { $value eq $_ ? 1 : 0 } qw/ 1 0 a /; return 1; } package main; use Test::More tests => 5; use HTML::FormFu; my $form = HTML::FormFu->new; $form->element('Text')->name('foo')->validator('Callback') ->callback( \&My::Validators::Callback::cb ); $form->element('Text')->name('bar')->validator('Callback') ->callback("My::Validators::Callback::cb"); # Valid { $form->process( { foo => 1, bar => [ 0, 'a', 'b' ], } ); ok( $form->valid('foo'), 'foo valid' ); ok( $form->valid('bar'), 'bar valid' ); } HTML-FormFu-2.07/t/filters/0000775000175100017520000000000013404751171013751 5ustar carlcarlHTML-FormFu-2.07/t/filters/regex.t0000644000175100017520000000127313404751171015251 0ustar carlcarluse strict; use warnings; use Test::More tests => 4; use HTML::FormFu; my $form = HTML::FormFu->new; # add config-callback to replicate Catalyst-Controller-HTML-FormFu $form->config_callback( { plain_value => sub { return if !defined $_; s{__uri_for()\((.+?)\)__} {$1}g; }, } ); $form->load_config_file('t/filters/regex.yml'); { $form->process( { foo => ' 4.5 ', } ); ok( $form->submitted_and_valid ); is( $form->param_value('foo'), '4.5' ); } { # clone form my $form = $form->clone; $form->process( { foo => " abc\t", } ); ok( $form->submitted_and_valid ); is( $form->param_value('foo'), 'abc' ); } HTML-FormFu-2.07/t/filters/htmlescape.t0000644000175100017520000000066713404751171016272 0ustar carlcarluse strict; use warnings; use Test::More tests => 2; use HTML::FormFu; my $form = HTML::FormFu->new; $form->element('Text')->name('foo')->filter('HTMLEscape'); my $original_foo = qq{&escape "this"}; my $filtered_foo = "&escape "this""; $form->process( { foo => $original_foo, } ); # foo is filtered is( $form->param('foo'), $filtered_foo, 'foo filtered' ); is( $form->params->{foo}, $filtered_foo, 'foo filtered' ); HTML-FormFu-2.07/t/filters/compoundjoin_join.yml0000644000175100017520000000025413404751171020216 0ustar carlcarl--- elements: - type: Multi name: sortcode elements: - name: p1 - name: p2 - name: p3 filters: type: CompoundJoin join: '-' HTML-FormFu-2.07/t/filters/filter.t0000644000175100017520000000152613404751171015425 0ustar carlcarluse strict; use warnings; use Test::More tests => 6; use HTML::FormFu; my $form = HTML::FormFu->new; $form->element('Text')->name('foo'); $form->element('Text')->name('bar'); $form->element('Text')->name('bif')->constraint('Number'); $form->filter( { type => 'HTMLEscape', names => [qw/ bar bif /], } ); my $original_foo = qq{escape "this"}; my $original_bar = qq{escape "that"}; my $escaped_bar = qq{escape "that"}; $form->process( { foo => $original_foo, bar => $original_bar, bif => "not a number", } ); # foo isn't quoted is( $form->param('foo'), $original_foo ); is( $form->params->{foo}, $original_foo ); # bar is( $form->param('bar'), $escaped_bar ); is( $form->params->{bar}, $escaped_bar ); # bif ok( !defined( $form->param('bif') ) ); ok( !defined( $form->params->{bif} ) ); HTML-FormFu-2.07/t/filters/all_by_default.t0000644000175100017520000000135013404751171017101 0ustar carlcarluse strict; use warnings; use Test::More tests => 4; use HTML::FormFu; my $form = HTML::FormFu->new; $form->element('Text')->name('foo'); $form->element('Text')->name('bar'); # should filter all fields, if no explicit name list $form->filter('HTMLEscape'); my $original_foo = qq{escape "this"}; my $escaped_foo = qq{escape "this"}; my $original_bar = qq{escape "that"}; my $escaped_bar = qq{escape "that"}; $form->process( { foo => $original_foo, bar => $original_bar, } ); # foo is( $form->param('foo'), $escaped_foo, 'quoted' ); is( $form->params->{foo}, $escaped_foo, 'quoted' ); # bar is( $form->param('bar'), $escaped_bar, 'quoted' ); is( $form->params->{bar}, $escaped_bar, 'quoted' ); HTML-FormFu-2.07/t/filters/uppercase.t0000644000175100017520000000063013404751171016122 0ustar carlcarluse strict; use warnings; use Test::More tests => 2; use HTML::FormFu; my $form = HTML::FormFu->new; $form->element('Text')->name('foo')->filter('UpperCase'); my $original_foo = "Foo Bar"; my $filtered_foo = "FOO BAR"; $form->process( { foo => $original_foo, } ); # foo is filtered is( $form->param('foo'), $filtered_foo, 'foo filtered' ); is( $form->params->{foo}, $filtered_foo, 'foo filtered' ); HTML-FormFu-2.07/t/filters/compoundsprintf_field_order.t0000644000175100017520000000066113404751171021727 0ustar carlcarluse strict; use warnings; use Test::More tests => 3; use HTML::FormFu; my $form = HTML::FormFu->new; $form->load_config_file('t/filters/compoundsprintf_field_order.yml'); $form->process( { 'date.month' => '6', 'date.day' => '26', 'date.year' => '2008', } ); ok( $form->submitted_and_valid ); is( $form->param_value('date'), '26-06-2008' ); is_deeply( $form->params, { date => '26-06-2008', }, ); HTML-FormFu-2.07/t/filters/callback.t0000644000175100017520000000240513404751171015671 0ustar carlcarluse strict; use warnings; use Test::More tests => 6; use HTML::FormFu; use lib 'lib'; my $form = HTML::FormFu->new; $form->element('Text')->name('foo')->filter('Callback') ->callback( sub { $_[0] =~ s/(\d)(\d)/$2$1/g; shift; } ); $form->element('Text')->name('bar')->filter('Callback'); $form->element('Text')->name('baz')->filter('Callback') ->callback('FilterCallback::my_filter'); my $original_foo = "ab123456"; my $filtered_foo = "ab214365"; my $original_bar = "ab123456"; my $filtered_bar = "ab123456"; my $original_baz = "abcdef"; my $filtered_baz = "ABCdef"; $form->process( { foo => $original_foo, bar => $original_bar, baz => $original_baz, } ); # foo is quoted is( $form->param('foo'), $filtered_foo, 'foo filtered' ); is( $form->params->{foo}, $filtered_foo, 'foo filtered' ); # bar is filtered is( $form->param('bar'), $filtered_bar, 'bar filtered' ); is( $form->params->{bar}, $filtered_bar, 'bar filtered' ); # baz is filtered is( $form->param('baz'), $filtered_baz, 'baz filtered' ); is( $form->params->{baz}, $filtered_baz, 'baz filtered' ); { package FilterCallback; use strict; use warnings; sub my_filter { my ($value) = @_; $value =~ tr/abc/ABC/; return $value; } } HTML-FormFu-2.07/t/filters/compoundjoin.yml0000644000175100017520000000034613404751171017201 0ustar carlcarl--- elements: - type: Repeatable nested_name: rep elements: - type: Multi name: address elements: - name: number - name: street filters: type: CompoundJoin HTML-FormFu-2.07/t/filters/formatnumber.yml0000644000175100017520000000012313404751171017167 0ustar carlcarl--- locale: de_DE elements: - name: foo filters: - type: FormatNumber HTML-FormFu-2.07/t/filters/split.t0000644000175100017520000000064013404751171015267 0ustar carlcarluse strict; use warnings; use Test::More tests => 4; use HTML::FormFu; my $form = HTML::FormFu->new; $form->load_config_file('t/filters/split.yml'); $form->process( { foo => 'FOO', bar => '1-2-3', } ); is_deeply( $form->param_array('foo'), [ 'F', 'O', 'O' ] ); is( $form->param_value('foo'), 'F' ); is_deeply( $form->param_array('bar'), [ 1, '2-3' ] ); is( $form->param_value('bar'), 1 ); HTML-FormFu-2.07/t/filters/htmlscrubber.t0000644000175100017520000000231513404751171016631 0ustar carlcarluse strict; use warnings; use Test::More tests => 6; use HTML::FormFu; my $form = HTML::FormFu->new; $form->element('Text')->name('foo')->filter('HTMLScrubber'); $form->element('Text')->name('bar')->filter('HTMLScrubber')->allow( ['b'] ); $form->element('Text')->name('fum')->filter('HTMLScrubber') ->rules( [ '*' => 0, p => { '*' => 0 }, a => { href => 1, '*' => 0 } ] ); my $original_foo = "

message

"; my $filtered_foo = "message"; my $original_bar = "

message

"; my $filtered_bar = "message"; my $original_fum = "

messagetext

"; my $filtered_fum = "

messagetext

"; $form->process( { foo => $original_foo, bar => $original_bar, fum => $original_fum, } ); # foo is quoted is( $form->param('foo'), $filtered_foo, 'foo filtered' ); is( $form->params->{foo}, $filtered_foo, 'foo filtered' ); # bar is filtered is( $form->param('bar'), $filtered_bar, 'bar filtered' ); is( $form->params->{bar}, $filtered_bar, 'bar filtered' ); # fum is filtered is( $form->param('fum'), $filtered_fum, 'fum filtered' ); is( $form->params->{fum}, $filtered_fum, 'fum filtered' ); HTML-FormFu-2.07/t/filters/regex_eval.t0000644000175100017520000000106713404751171016261 0ustar carlcarluse strict; use warnings; use Test::More tests => 4; use HTML::FormFu; my $form = HTML::FormFu->new; $form->load_config_file('t/filters/regex_eval.yml'); { $form->process( { foo => '.4.5 ', } ); is( $form->param_value('foo'), '4.5' ); } { $form->process( { foo => '4.', } ); is( $form->param_value('foo'), '4' ); } { $form->process( { foo => '4.0', } ); is( $form->param_value('foo'), '4.0' ); } # doesn't filter, as it doesn't match the regex { $form->process( { foo => ' a', } ); is( $form->param_value('foo'), ' a' ); } HTML-FormFu-2.07/t/filters/compoundsprintf.yml0000644000175100017520000000030013404751171017715 0ustar carlcarl--- elements: - type: Multi name: date elements: - name: day - name: month - name: year filters: type: CompoundSprintf sprintf: '%02d-%02d-%04d' HTML-FormFu-2.07/t/filters/compoundjoin_join.t0000644000175100017520000000056213404751171017662 0ustar carlcarluse strict; use warnings; use Test::More tests => 2; use HTML::FormFu; my $form = HTML::FormFu->new; $form->load_config_file('t/filters/compoundjoin_join.yml'); $form->process( { 'sortcode.p1' => '01', 'sortcode.p2' => '02', 'sortcode.p3' => '03', } ); ok( $form->submitted_and_valid ); is( $form->param_value('sortcode'), '01-02-03' ); HTML-FormFu-2.07/t/filters/nonnumeric.t0000644000175100017520000000064513404751171016316 0ustar carlcarluse strict; use warnings; use Test::More tests => 2; use HTML::FormFu; my $form = HTML::FormFu->new; $form->element('Text')->name('foo')->filter('NonNumeric'); my $original_foo = " 0123-4567 (8a9)"; my $filtered_foo = "0123456789"; $form->process( { foo => $original_foo, } ); # foo is filtered is( $form->param('foo'), $filtered_foo, 'foo filtered' ); is( $form->params->{foo}, $filtered_foo, 'foo filtered' ); HTML-FormFu-2.07/t/filters/compoundjoin.t0000644000175100017520000000104013404751171016633 0ustar carlcarluse strict; use warnings; use Test::More tests => 3; use HTML::FormFu; my $form = HTML::FormFu->new( { tt_args => { INCLUDE_PATH => 'share/templates/tt/xhtml' } } ); $form->load_config_file('t/filters/compoundjoin.yml'); $form->process; $form->process( { 'rep_1.address.number' => '10', 'rep_1.address.street' => 'Downing Street', } ); ok( $form->submitted_and_valid ); is( $form->param_value('rep_1.address'), '10 Downing Street' ); is_deeply( $form->params, { rep_1 => { address => '10 Downing Street' }, }, ); HTML-FormFu-2.07/t/filters/compoundsprintf_field_order.yml0000644000175100017520000000040013404751171022254 0ustar carlcarl--- elements: - type: Multi name: date elements: - name: month - name: day - name: year filters: type: CompoundSprintf sprintf: '%02d-%02d-%04d' field_order: - day - month - year HTML-FormFu-2.07/t/filters/regex.yml0000644000175100017520000000015713404751171015607 0ustar carlcarl--- elements: - name: foo filters: - type: Regex match: !!perl/regexp (?-xism:\A\s+|\s+\z) HTML-FormFu-2.07/t/filters/lowercase.t0000644000175100017520000000063013404751171016117 0ustar carlcarluse strict; use warnings; use Test::More tests => 2; use HTML::FormFu; my $form = HTML::FormFu->new; $form->element('Text')->name('foo')->filter('LowerCase'); my $original_foo = "Foo Bar"; my $filtered_foo = "foo bar"; $form->process( { foo => $original_foo, } ); # foo is filtered is( $form->param('foo'), $filtered_foo, 'foo filtered' ); is( $form->params->{foo}, $filtered_foo, 'foo filtered' ); HTML-FormFu-2.07/t/filters/encode.t0000644000175100017520000000117113404751171015371 0ustar carlcarluse strict; use warnings; use Encode; use Test::More tests => 2; use HTML::FormFu; my $form = HTML::FormFu->new; $form->element('Text')->name('foo')->filter('Encode') ->candidates(qw(euc-jp sjis jis))->encode_to('euc-jp'); my $utf8_foo = decode_utf8('エイãƒãƒ†ã‚£ãƒ¼ã‚¨ãƒ ã‚¨ãƒ«::フォームフー'); my $original_foo = encode( 'sjis', $utf8_foo ); my $filtered_foo = encode( 'euc-jp', $utf8_foo ); $form->process( { foo => $original_foo, } ); # foo is filtered is( decode( 'euc-jp', $form->param('foo') ), $utf8_foo, 'foo filtered' ); is( decode( 'euc-jp', $form->params->{foo} ), $utf8_foo, 'foo filtered' ); HTML-FormFu-2.07/t/filters/formatnumber.t0000644000175100017520000000205113404751171016633 0ustar carlcarluse strict; use warnings; our $count; BEGIN { $count = 3 } use Test::More tests => $count; use HTML::FormFu; use Number::Format; use POSIX qw( setlocale LC_NUMERIC ); my $form = HTML::FormFu->new; $form->load_config_file('t/filters/formatnumber.yml'); my $backup_locale = setlocale(LC_NUMERIC); SKIP: { # first test the de_DE locale is available my $ok = setlocale( LC_NUMERIC, 'de_DE' ); if ( !$ok ) { # not available - restore locale and bail setlocale( LC_NUMERIC, $backup_locale ); skip 'de_DE locale not available', $count; } my $format = Number::Format->new; my $formatted_number = $format->format_number('23000222.22'); isnt( $formatted_number, '23000222.22', 'format of number has changed' ); # restore orginal locale setlocale( LC_NUMERIC, $backup_locale ); { $form->process( { foo => $formatted_number, } ); ok( $form->submitted_and_valid ); is( $form->param_value('foo'), '23000222.22', 'number no longer in german formatting' ); } } HTML-FormFu-2.07/t/filters/compoundjoin_field_order.t0000644000175100017520000000056413404751171021203 0ustar carlcarluse strict; use warnings; use Test::More tests => 2; use HTML::FormFu; my $form = HTML::FormFu->new; $form->load_config_file('t/filters/compoundjoin_field_order.yml'); $form->process( { 'address.street' => 'Downing Street', 'address.number' => '10', } ); ok( $form->submitted_and_valid ); is( $form->param_value('address'), '10 Downing Street' ); HTML-FormFu-2.07/t/filters/copyvalue.t0000644000175100017520000000122713404751171016145 0ustar carlcarluse strict; use warnings; use Test::More tests => 4; use HTML::FormFu; my $form = HTML::FormFu->new; $form->element('Text')->name('foo'); $form->element('Text')->name('bar')->filter('CopyValue')->field('foo'); my $original_foo = "ab123456"; my $filtered_foo = "ab123456"; my $filtered_bar = $filtered_foo; $form->process( { foo => $original_foo, bar => undef, } ); # foo is quoted is( $form->param('foo'), $filtered_foo, 'foo filtered' ); is( $form->params->{foo}, $filtered_foo, 'foo filtered' ); # bar is filtered is( $form->param('bar'), $filtered_bar, 'bar filtered' ); is( $form->params->{bar}, $filtered_bar, 'bar filtered' ); HTML-FormFu-2.07/t/filters/compoundsprintf.t0000644000175100017520000000064513404751171017373 0ustar carlcarluse strict; use warnings; use Test::More tests => 3; use HTML::FormFu; my $form = HTML::FormFu->new; $form->load_config_file('t/filters/compoundsprintf.yml'); $form->process( { 'date.day' => '26', 'date.month' => '6', 'date.year' => '2008', } ); ok( $form->submitted_and_valid ); is( $form->param_value('date'), '26-06-2008' ); is_deeply( $form->params, { date => '26-06-2008', }, ); HTML-FormFu-2.07/t/filters/split.yml0000644000175100017520000000022113404751171015620 0ustar carlcarl--- elements: - name: foo filters: - type: Split - name: bar filters: - type: Split regex: '-' limit: 2 HTML-FormFu-2.07/t/filters/trimedges.t0000644000175100017520000000071013404751171016115 0ustar carlcarluse strict; use warnings; use Test::More tests => 2; use HTML::FormFu; my $form = HTML::FormFu->new( { tt_args => { INCLUDE_PATH => 'share/templates/tt/xhtml' } } ); $form->element('Text')->name('foo')->filter('TrimEdges'); my $original_foo = " Foo Bar "; my $filtered_foo = "Foo Bar"; $form->process( { foo => $original_foo } ); # foo is filtered is( $form->params->{foo}, $filtered_foo ); like( $form->get_field('foo'), qr/$original_foo/ ); HTML-FormFu-2.07/t/filters/compoundjoin_field_order.yml0000644000175100017520000000030613404751171021533 0ustar carlcarl--- elements: - type: Multi name: address elements: - name: street - name: number filters: type: CompoundJoin field_order: - number - street HTML-FormFu-2.07/t/filters/regex_eval.yml0000644000175100017520000000022313404751171016610 0ustar carlcarl--- elements: - name: foo filters: - type: Regex match: '\A.*?([0-9]+(?:\.[0-9]+)?).*\z' replace: '$1' eval: 1 HTML-FormFu-2.07/t/filters/whitespace.t0000644000175100017520000000063013404751171016267 0ustar carlcarluse strict; use warnings; use Test::More tests => 2; use HTML::FormFu; my $form = HTML::FormFu->new; $form->element('Text')->name('foo')->filter('Whitespace'); my $original_foo = "Foo Bar"; my $filtered_foo = "FooBar"; $form->process( { foo => $original_foo, } ); # foo is filtered is( $form->param('foo'), $filtered_foo, 'foo filtered' ); is( $form->params->{foo}, $filtered_foo, 'foo filtered' ); HTML-FormFu-2.07/t/block_insert_before.t0000644000175100017520000000152213404751171016464 0ustar carlcarluse strict; use warnings; use Test::More tests => 7; use HTML::FormFu; { my $form = HTML::FormFu->new; my $fs = $form->element('Fieldset'); my $e1 = $fs->element('Text')->name('foo'); my $e2 = $fs->element('Hidden')->name('foo'); my $e3 = $e1->clone; $fs->insert_before( $e3, $e1 ); my $elems = $fs->get_elements; is( scalar(@$elems), 3 ); ok( $elems->[0] == $e3 ); ok( $elems->[1] == $e1 ); ok( $elems->[2] == $e2 ); } # ensure elements only occur once { my $form = HTML::FormFu->new; my $fs = $form->element('Fieldset'); my $e1 = $fs->element( { name => 'foo' } ); my $e2 = $fs->element( { name => 'bar' } ); $fs->insert_before( $e2, $e1 ); my $elems = $fs->get_elements; is( scalar(@$elems), 2 ); ok( $elems->[0] == $e2 ); ok( $elems->[1] == $e1 ); } HTML-FormFu-2.07/t/field_accessor_loc_arrayref.yml0000644000175100017520000000013113404751171020512 0ustar carlcarl--- elements: - name: foo label_loc: - test_two_args - one - two HTML-FormFu-2.07/t/deflators/0000775000175100017520000000000013404751171014264 5ustar carlcarlHTML-FormFu-2.07/t/deflators/compoundsplit_split.t0000644000175100017520000000112613404751171020562 0ustar carlcarluse strict; use warnings; use Test::More tests => 1; use HTML::FormFu; my $form = HTML::FormFu->new( { tt_args => { INCLUDE_PATH => 'share/templates/tt/xhtml' } } ); $form->load_config_file('t/deflators/compoundsplit_split.yml'); $form->default_values( { sortcode => '01-02-03', } ); $form->process; my $html = <
HTML is( "$form", $html ); HTML-FormFu-2.07/t/deflators/pathclassfile.t0000644000175100017520000000242613404751171017275 0ustar carlcarluse strict; use warnings; use Test::More tests => 4; use HTML::FormFu; use Path::Class::File; my $form = HTML::FormFu->new( { tt_args => { INCLUDE_PATH => 'share/templates/tt/xhtml' } } ); $form->elements( [ { type => "Text", name => "test1", deflator => { type => "PathClassFile" } }, { type => "Text", name => "test2", deflator => { type => "PathClassFile", relative => 't' } }, { type => "Text", name => "test3", deflator => { type => "PathClassFile", absolute => 1 } }, { type => "Text", name => "test4", deflator => { type => "PathClassFile", basename => 1 } }, ] ); $form->process; my $file = Path::Class::File->new('t/deflators/pathclassfile.t'); for ( 1 .. 4 ) { $form->get_field("test$_")->default($file); } my $value1 = $file->relative; my $value2 = $file->relative('t'); my $value3 = $file->absolute; my $value4 = $file->basename; like( $form->get_field('test1'), qr{value="\Q$value1\E"} ); like( $form->get_field('test2'), qr{value="\Q$value2\E"} ); like( $form->get_field('test3'), qr{value="\Q$value3\E"} ); like( $form->get_field('test4'), qr{value="\Q$value4\E"} ); HTML-FormFu-2.07/t/deflators/compoundsplit_after_submit.t0000644000175100017520000000130013404751171022105 0ustar carlcarluse strict; use warnings; use Test::More tests => 2; use HTML::FormFu; my $form = HTML::FormFu->new( { tt_args => { INCLUDE_PATH => 'share/templates/tt/xhtml' } } ); $form->load_config_file('t/deflators/compoundsplit_after_submit.yml'); $form->process( { 'address.number' => '10', 'address.street' => 'Downing Street', } ); # check Filter::CompoundJoin worked ok is( $form->param_value('address'), '10 Downing Street' ); my $html = <
HTML is( "$form", $html ); HTML-FormFu-2.07/t/deflators/compoundsplit_field_order.yml0000644000175100017520000000031113404751171022236 0ustar carlcarl--- elements: - type: Multi name: address elements: - name: street - name: number deflators: type: CompoundSplit field_order: - number - street HTML-FormFu-2.07/t/deflators/callback.t0000644000175100017520000000200113404751171016174 0ustar carlcarluse strict; use warnings; use Test::More tests => 2; use HTML::FormFu; use lib 'lib'; my $original_foo = "abc123"; my $deflated_foo = "ABC123"; my $original_bar = "abcdef"; my $deflated_bar = "ABCdef"; my $form = HTML::FormFu->new( { tt_args => { INCLUDE_PATH => 'share/templates/tt/xhtml' } } ); $form->element( { name => 'foo', default => $original_foo, deflator => { type => 'Callback', callback => sub { return uc( $_[0] ) }, }, } ); $form->element( { name => 'bar', default => $original_bar, deflator => { type => 'Callback', callback => 'DeflatorCallback::my_def', }, } ); $form->process; like( $form->get_field('foo'), qr/\Q$deflated_foo/ ); like( $form->get_field('bar'), qr/\Q$deflated_bar/ ); { package DeflatorCallback; use strict; use warnings; sub my_def { my ($value) = @_; $value =~ tr/abc/ABC/; return $value; } } HTML-FormFu-2.07/t/deflators/compoundsplit_after_submit.yml0000644000175100017520000000027313404751171022453 0ustar carlcarl--- elements: - type: Multi name: address elements: - name: number - name: street filters: type: CompoundJoin deflators: type: CompoundSplit HTML-FormFu-2.07/t/deflators/formatnumber.yml0000644000175100017520000000016613404751171017511 0ustar carlcarl--- elements: - name: foo deflators: - type: FormatNumber precision: 8 trailing_zeroes: 1 HTML-FormFu-2.07/t/deflators/compounddatetime.yml0000644000175100017520000000024313404751171020345 0ustar carlcarl--- elements: - type: Multi name: dob elements: - name: day - name: month - name: year deflator: - type: CompoundDateTime HTML-FormFu-2.07/t/deflators/compoundsplit.t0000644000175100017520000000106613404751171017352 0ustar carlcarluse strict; use warnings; use Test::More tests => 1; use HTML::FormFu; my $form = HTML::FormFu->new( { tt_args => { INCLUDE_PATH => 'share/templates/tt/xhtml' } } ); $form->load_config_file('t/deflators/compoundsplit.yml'); $form->default_values( { address => '10 Downing Street', } ); $form->process; my $html = <
HTML is( "$form", $html ); HTML-FormFu-2.07/t/deflators/compounddatetime_field_order.yml0000644000175100017520000000031013404751171022676 0ustar carlcarl--- elements: - type: Multi name: dob elements: - name: m - name: d - name: y deflator: - type: CompoundDateTime field_order: ['month', 'day', 'year'] HTML-FormFu-2.07/t/deflators/compoundsplit_field_order.t0000644000175100017520000000110213404751171021677 0ustar carlcarluse strict; use warnings; use Test::More tests => 1; use HTML::FormFu; my $form = HTML::FormFu->new( { tt_args => { INCLUDE_PATH => 'share/templates/tt/xhtml' } } ); $form->load_config_file('t/deflators/compoundsplit_field_order.yml'); $form->default_values( { address => '10 Downing Street', } ); $form->process; my $html = <
HTML is( "$form", $html ); HTML-FormFu-2.07/t/deflators/compoundsplit_split.yml0000644000175100017520000000025713404751171021124 0ustar carlcarl--- elements: - type: Multi name: sortcode elements: - name: p1 - name: p2 - name: p3 deflators: type: CompoundSplit split: '-' HTML-FormFu-2.07/t/deflators/formatnumber.t0000644000175100017520000000124613404751171017153 0ustar carlcarluse strict; use warnings; use Test::More tests => 1; use HTML::FormFu; use Number::Format; # This test is pretty hard to write # you cannot know which locales are installed on a system # and how the result should look like for every locale # I simply check here whether the number looks right. my $form = HTML::FormFu->new( { tt_args => { INCLUDE_PATH => 'share/templates/tt/xhtml' } } ); $form->load_config_file('t/deflators/formatnumber.yml'); $form->get_field('foo')->default('10002300.123'); { $form->process; like( $form->render, qr/\"10[,. ]{0,2}002[,. ]{0,2}300[., ]123[,. ]?000[,. ]?00\"/, 'formatted number is there' ); } HTML-FormFu-2.07/t/deflators/compounddatetime_field_order.t0000644000175100017520000000124013404751171022343 0ustar carlcarluse strict; use warnings; use Test::More tests => 1; use HTML::FormFu; use DateTime; my $form = HTML::FormFu->new( { tt_args => { INCLUDE_PATH => 'share/templates/tt/xhtml' } } ); $form->load_config_file('t/deflators/compounddatetime_field_order.yml'); my $datetime = DateTime->new( day => '31', month => '12', year => '1999', ); $form->get_field('dob')->default($datetime); my $html = <
HTML is( "$form", $html ); HTML-FormFu-2.07/t/deflators/compounddatetime.t0000644000175100017520000000123513404751171020011 0ustar carlcarluse strict; use warnings; use Test::More tests => 1; use HTML::FormFu; use DateTime; my $form = HTML::FormFu->new( { tt_args => { INCLUDE_PATH => 'share/templates/tt/xhtml' } } ); $form->load_config_file('t/deflators/compounddatetime.yml'); my $datetime = DateTime->new( day => '31', month => '12', year => '1999', ); $form->get_field('dob')->default($datetime); my $html = <
HTML is( "$form", $html ); HTML-FormFu-2.07/t/deflators/compoundsplit.yml0000644000175100017520000000022413404751171017703 0ustar carlcarl--- elements: - type: Multi name: address elements: - name: number - name: street deflators: type: CompoundSplit HTML-FormFu-2.07/t/elements/0000775000175100017520000000000013404751171014115 5ustar carlcarlHTML-FormFu-2.07/t/elements/combobox_repeatable.t0000644000175100017520000000136413404751171020300 0ustar carlcarluse strict; use warnings; use Test::More tests => 5; use HTML::FormFu; my $form = HTML::FormFu->new( { tt_args => { INCLUDE_PATH => 'share/templates/tt/xhtml' } } ); $form->load_config_file('t/elements/combobox_repeatable.yml'); # repeatable { my $container = $form->get_all_element('container'); $form->process( { count => 3, combo_1_select => 'one', combo_2_select => 'two', combo_3_select => 'three', } ); ok( $form->submitted_and_valid ); is( $form->param_value('combo_1'), 'one' ); is( $form->param_value('combo_2'), 'two' ); is( $form->param_value('combo_3'), 'three' ); is( $form->param_value('combo_3_select'), 'three' ); } HTML-FormFu-2.07/t/elements/block_repeatable_tag.yml0000644000175100017520000000023313404751171020745 0ustar carlcarl--- auto_fieldset: 1 elements: - type: Repeatable tag: fieldset elements: - name: foo - name: bar - type: Submit name: submit HTML-FormFu-2.07/t/elements/block_repeatable_auto_block_id.yml0000644000175100017520000000026713404751171022777 0ustar carlcarl--- elements: - type: Repeatable elements: - type: Block tag: span auto_block_id: 'inner_%r' elements: - name: foo - name: bar HTML-FormFu-2.07/t/elements/date_order_error.t0000644000175100017520000000105213404751171017617 0ustar carlcarluse strict; use warnings; use Test::More tests => 2; use HTML::FormFu; { my $form = HTML::FormFu->new; eval { my $element = $form->element('Date'); $element->name('date'); $element->field_order( [qw/ month day foo /] ); $form->process; }; ok($@); } { my $form = HTML::FormFu->new; eval { my $element = $form->element('Date'); $element->name('date'); $form->process; $element->field_order( [qw/ month month day /] )->value('01-01-2007'); }; ok($@); } HTML-FormFu-2.07/t/elements/radiogroup.t0000644000175100017520000000601013404751171016450 0ustar carlcarluse strict; use warnings; use Test::More tests => 5; use HTML::FormFu; my $form = HTML::FormFu->new( { tt_args => { INCLUDE_PATH => 'share/templates/tt/xhtml' } } ); my $field1 = $form->element('Radiogroup')->name('foo')->value(2) ->options( [ [ 1 => 'One' ], [ 2 => 'Two' ] ] ); # add element to test non-reversed labels my $field2 = $form->element('Radiogroup')->name('foo2') ->options( [ [ 'a' => 'A' ], [ 'b' => 'B' ] ] )->reverse_group(0); # add more elements to test accessor output $form->element('Radiogroup')->name('foo3')->options( [ { label => 'Ein', value => 1 }, { label => 'Zwei', value => 2, attributes => { class => 'foobar' }, container_attributes => { class => 'item 2' } }, ] ); $form->element('Radiogroup')->name('bar')->values( [qw/ one two three /] ) ->value('two')->label('My Bar'); $form->process; my $field1_xhtml = qq{
}; is( "$field1", $field1_xhtml, 'basic radiogroup' ); my $field2_xhtml = qq{
}; is( "$field2", $field2_xhtml, 'radiogroup with reverse_group off' ); my $form_xhtml = < $field1_xhtml $field2_xhtml
My Bar
EOF is( "$form", $form_xhtml, 'stringified form' ); # With mocked basic query { $form->process( { foo => 1, bar => 'three', } ); my $foo_xhtml = qq{
}; is( $form->get_field('foo'), $foo_xhtml, 'radiogroup after query' ); my $bar_xhtml = qq{
My Bar
}; is( $form->get_field('bar'), $bar_xhtml, 'second radiogroup after query' ); } HTML-FormFu-2.07/t/elements/block_repeatable_inc.yml0000644000175100017520000000031213404751171020741 0ustar carlcarl--- auto_fieldset: 1 elements: - type: Repeatable # it's now the default behaviour # increment_field_names: 1 elements: - name: foo - name: bar - type: Submit name: submit HTML-FormFu-2.07/t/elements/fieldset_legend_attrs.t0000644000175100017520000000066013404751171020634 0ustar carlcarluse strict; use warnings; use Test::More tests => 1; use HTML::FormFu; my $form = HTML::FormFu->new( { tt_args => { INCLUDE_PATH => 'share/templates/tt/xhtml' } } ); my $outer = $form->load_config_file('t/elements/fieldset_legend_attrs.yml'); my $form_xhtml = <
The Legend! The Content!
EOF is( "$form", $form_xhtml ); HTML-FormFu-2.07/t/elements/block_auto_block_id.t0000644000175100017520000000053413404751171020252 0ustar carlcarluse strict; use warnings; use Test::More tests => 1; use HTML::FormFu; my $form = HTML::FormFu->new( { tt_args => { INCLUDE_PATH => 'share/templates/tt/xhtml' } } ); $form->load_config_file('t/elements/block_auto_block_id.yml'); is( "$form", <
Hello
EOF HTML-FormFu-2.07/t/elements/escaping.t0000644000175100017520000000177013404751171016076 0ustar carlcarluse strict; use warnings; use Test::More tests => 1; use HTML::FormFu; my $form = HTML::FormFu->new( { tt_args => { INCLUDE_PATH => 'share/templates/tt/xhtml' } } ); $form->element('Text')->name('foo&')->label('comment('foo>') ->default("'foo")->attrs( { class => "foo'" } ) ->add_attrs( { class => 'bar"' } )->container_attrs( { class => 'foo"' } ); $form->element('Text')->name('foo&')->label_xml('comment_xml('foo>') ->default_xml("'foo")->attrs_xml( { class => "foo'" } ) ->add_attrs_xml( { class => 'bar"' } ) ->container_attrs_xml( { class => 'foo"' } ); my $form_xhtml = <
foo>
EOF is( "$form", $form_xhtml, 'stringified form' ); HTML-FormFu-2.07/t/elements/block_repeatable.yml0000644000175100017520000000021113404751171020106 0ustar carlcarl--- auto_fieldset: 1 elements: - type: Repeatable elements: - name: foo - name: bar - type: Submit name: submit HTML-FormFu-2.07/t/elements/fieldset_legend_attrs.yml0000644000175100017520000000020013404751171021160 0ustar carlcarl--- elements: - type: Fieldset legend: 'The Legend!' legend_attrs: class: my_legend content: 'The Content!' HTML-FormFu-2.07/t/elements/radio_retain_default.t0000644000175100017520000000152013404751171020442 0ustar carlcarluse strict; use warnings; use Test::More tests => 10; use HTML::FormFu; my $form = HTML::FormFu->new( { tt_args => { INCLUDE_PATH => 'share/templates/tt/xhtml' } } ); $form->element('Radio')->name('foo')->value('a')->retain_default(1); $form->element('Radio')->name('fox')->value('b')->retain_default(1); $form->element('Radio')->name('bar')->value('c'); $form->process( { foo => '', bar => '', } ); ok( $form->valid('foo') ); ok( !$form->valid('fox') ); ok( $form->valid('bar') ); is( $form->param('foo'), '' ); is( $form->param('fox'), undef ); is( $form->param('bar'), '' ); like( $form->get_field('foo'), qr/value="a" [^>] checked="checked"/x ); like( $form->get_field('fox'), qr/value="b" [^>] checked="checked"/x ); like( $form->get_field('bar'), qr/value="c"/ ); unlike( $form->get_field('bar'), qr/checked/ ); HTML-FormFu-2.07/t/elements/select_force_default.t0000644000175100017520000000174713404751171020452 0ustar carlcarluse strict; use warnings; use Test::More tests => 9; use HTML::FormFu; my $form = HTML::FormFu->new( { tt_args => { INCLUDE_PATH => 'share/templates/tt/xhtml' } } ); $form->element('Select')->name('foo')->values( [qw/ one two three /] ) ->default('two')->force_default(1); $form->element('Select')->name('bar')->values( [qw/ one two three /] ) ->default('one')->force_default(1); $form->element('Select')->name('baz')->values( [qw/ one two three /] ) ->default('three')->force_default(1); $form->process( { foo => '', bar => 'three', } ); ok( $form->valid('foo') ); ok( $form->valid('bar') ); ok( $form->valid('baz') ); is( $form->param('foo'), 'two' ); is( $form->param('bar'), 'one' ); is( $form->param('baz'), 'three' ); like( $form->get_field('foo'), qr/value="two" [^>]* selected="selected"/x ); like( $form->get_field('bar'), qr/value="one" [^>]* selected="selected"/x ); like( $form->get_field('baz'), qr/value="three" [^>]* selected="selected"/x ); HTML-FormFu-2.07/t/elements/text_auto_container_class.t0000644000175100017520000000076113404751171021547 0ustar carlcarluse strict; use warnings; use Test::More tests => 1; use HTML::FormFu; my $form = HTML::FormFu->new( { tt_args => { INCLUDE_PATH => 'share/templates/tt/xhtml' } } ); $form->load_config_file('t/elements/text_auto_container_class.yml'); my $expected_form_xhtml = <
EOF is( "$form", $expected_form_xhtml ); HTML-FormFu-2.07/t/elements/checkbox_reverse.yml0000644000175100017520000000022313404751171020154 0ustar carlcarl--- elements: - type: Checkbox name: foo label: Foo - type: Checkbox name: bar label: Bar reverse_single: 1 HTML-FormFu-2.07/t/elements/text_auto_container_error_class.t0000644000175100017520000000125213404751171022754 0ustar carlcarluse strict; use warnings; use Test::More tests => 1; use HTML::FormFu; my $form = HTML::FormFu->new( { tt_args => { INCLUDE_PATH => 'share/templates/tt/xhtml' } } ); $form->load_config_file('t/elements/text_auto_container_error_class.yml'); $form->process( { submit => 'Submit', } ); my $expected_form_xhtml = <
This field is required
This field is required
EOF is( "$form", $expected_form_xhtml ); HTML-FormFu-2.07/t/elements/error_attributes_failing_test.text-with-attrs.yml0000644000175100017520000000033213404751171026052 0ustar carlcarl--- elements: - type: Text name: foo label: Foo error_attributes: class: 'class-error_attributes' constraints: - type: MaxLength max: 3 message: 'test' HTML-FormFu-2.07/t/elements/datetime.t0000644000175100017520000004641613404751171016107 0ustar carlcarluse strict; use warnings; use Test::More tests => 16; use HTML::FormFu; use DateTime; my $dt = DateTime->new( day => 6, month => 8, year => 2007, hour => 1, minute => 0, ); my $form = HTML::FormFu->new( { tt_args => { INCLUDE_PATH => 'share/templates/tt/xhtml' } } ); $form->load_config_file('t/elements/datetime.yml'); $form->get_field('foo')->default($dt); $form->process; is( "$form", <
HTML $form->process( { foo_hour => '00', foo_minute => '00', foo_day => 30, foo_month => 6, foo_year => 2007, bar_hour => '01', bar_minute => '30', bar_day => 1, bar_month => 7, bar_year => 2007, } ); ok( $form->submitted_and_valid ); my $foo = $form->param('foo'); my $bar = $form->param('bar'); isa_ok( $foo, 'DateTime' ); ok( !ref $bar ); is( $foo, "06/30/2007 00:00" ); is( $bar, "01-07-2007 01:30" ); like( $form->get_field('foo'), qr/\Q