Skip Menu |

This queue is for tickets about the Test-FormValidator CPAN distribution.

Report information
The Basics
Id: 19663
Status: open
Priority: 0/
Queue: Test-FormValidator

People
Owner: Nobody in particular
Requestors: MARKSTOS [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: (no value)
Fixed in: 0.06



Subject: wish: check dependencies for html_ok()
Great module. :) DFV allows you have fields that are only in 'dependencies' that are not in 'required' or 'optional'. It would be nice if html_ok() checked for this. 'dependency_groups' could use similar treatment. Thanks! Mark
From: markstos [...] cpan.org
Here's a patch, including a test. Solving this made me realize there is more that could be done along these lines: Adding support for required_regexp and optional_regexp would be next on my list. Mark
Fri Jun 2 20:24:21 EST 2006 mark@summersault.com * - html_ok() now considers values in dependencies and dependency_groups diff -rN -u -N Test-FormValidator-0.06-old/Changes Test-FormValidator-0.06-new/Changes --- Test-FormValidator-0.06-old/Changes 2006-06-02 20:25:03.000000000 -0500 +++ Test-FormValidator-0.06-new/Changes 2006-06-02 20:15:18.000000000 -0500 @@ -1,5 +1,8 @@ Revision history for Test-FormValidator + - html_ok() now considers values in dependencies and dependency_groups + as well as 'required' and 'optional' + 0.06 November 16, 2005 - $tfv->check_ok now returns a $results object on failure as well as on success diff -rN -u -N Test-FormValidator-0.06-old/lib/Test/FormValidator.pm Test-FormValidator-0.06-new/lib/Test/FormValidator.pm --- Test-FormValidator-0.06-old/lib/Test/FormValidator.pm 2006-06-02 20:25:03.000000000 -0500 +++ Test-FormValidator-0.06-new/lib/Test/FormValidator.pm 2006-06-02 20:16:57.000000000 -0500 @@ -763,7 +763,7 @@ $required = [$required] unless ref $required eq 'ARRAY'; $optional = [$optional] unless ref $optional eq 'ARRAY'; - my @profile_fields = sort (@$required, @$optional); + my @profile_fields = sort (@$required, @$optional, _dependent_fields($profile) ); my @html_fields = $self->_extract_form_fields_from_html($filename); if (%ignore_list) { @@ -775,6 +775,8 @@ @html_fields = grep { ! /$ignore_match/ } @html_fields; } + # TODO: Account for required_regexp and optional_regexp + my $success = Test::More::eq_array(\@profile_fields, \@html_fields); if (!$success) { $Test->diag("Profile fields: ". (join ", ", @profile_fields)); @@ -784,6 +786,40 @@ return $Test->ok($success, $self->_format_description($description)); } +sub _dependent_fields { + my $profile = shift; + my $dependencies = $profile->{'dependencies'} || {}; + my $groups = $profile->{'dependency_groups'} || {}; + use Data::FormValidator::Results; + *_arrayify = \&Data::FormValidator::Results::_arrayify; + + my @fields; + + # Cases to handle: + # dependencies => { + # a => 'target1', + # b => ['target2','target3'], + # c => { + # d => [ qw( target4 ) ], + # e => 'target5' + # } + # }, + # dependency_groups => { + # f => [qw/target6 target7/], + # } + + for my $value (map { _arrayify($_) } values %$dependencies, values %$groups) { + if (ref $value eq 'HASH') { + push @fields, map { _arrayify($_) } values %$value; + } + else { + push @fields, $value; + } + } + return @fields; +} + + sub _extract_form_fields_from_html { my ($self, $file) = @_; diff -rN -u -N Test-FormValidator-0.06-old/t/07-dependencies.t Test-FormValidator-0.06-new/t/07-dependencies.t --- Test-FormValidator-0.06-old/t/07-dependencies.t 1969-12-31 19:00:00.000000000 -0500 +++ Test-FormValidator-0.06-new/t/07-dependencies.t 2006-06-02 20:14:04.000000000 -0500 @@ -0,0 +1,35 @@ +use strict; +use Test::More 'no_plan'; + +use Test::FormValidator; + +my $profile = { + dependencies => { + a => 'target1', + b => ['target2','target3'], + c => { + d => [ qw( target4 ) ], + e => 'target5' + } + }, + dependency_groups => { + f => [qw/target6 target7/], + } +}; + +is_deeply( + [ sort &Test::FormValidator::_dependent_fields($profile) ], + [qw/ + target1 + target2 + target3 + target4 + target5 + target6 + target7 + /], + "extracting dependent fields works" +); + + +