|
| 1 | +#------------------------------------------------------------------- |
| 2 | +# WebGUI is Copyright 2001-2011 Plain Black Corporation. |
| 3 | +#------------------------------------------------------------------- |
| 4 | +# Please read the legal notices (docs/legal.txt) and the license |
| 5 | +# (docs/license.txt) that came with this distribution before using |
| 6 | +# this software. |
| 7 | +#------------------------------------------------------------------- |
| 8 | +# http://www.plainblack.com [email protected] |
| 9 | +#------------------------------------------------------------------- |
| 10 | + |
| 11 | +use FindBin; |
| 12 | +use strict; |
| 13 | +use lib "$FindBin::Bin/../lib"; |
| 14 | + |
| 15 | +use WebGUI::Test; |
| 16 | +use WebGUI::Session; |
| 17 | +use WebGUI::Macro::AdminBar; |
| 18 | +use HTML::TokeParser; |
| 19 | +use HTML::Form; |
| 20 | +use Tie::IxHash; |
| 21 | +use WebGUI::Form_Checking; |
| 22 | +use WebGUI::Macro::FormField; |
| 23 | + |
| 24 | +use Test::More; # increment this value for each test you create |
| 25 | +use Test::Deep; |
| 26 | + |
| 27 | +use Data::Dumper; |
| 28 | + |
| 29 | +my $session = WebGUI::Test->session; |
| 30 | + |
| 31 | +# taken from t/Form/SelectList.t |
| 32 | + |
| 33 | +my $testBlock = [ |
| 34 | + { |
| 35 | + key => 'List1', |
| 36 | + testValue => [qw/a/], |
| 37 | + expected => 'a', |
| 38 | + comment => 'single element array, scalar', |
| 39 | + dataType => 'SCALAR' |
| 40 | + }, |
| 41 | + { |
| 42 | + key => 'List2', |
| 43 | + testValue => [qw/a/], |
| 44 | + expected => 'EQUAL', |
| 45 | + comment => 'single element array, array', |
| 46 | + dataType => 'ARRAY' |
| 47 | + }, |
| 48 | + { |
| 49 | + key => 'List3', |
| 50 | + testValue => [qw/a b c/], |
| 51 | + expected => "a\nb\nc", |
| 52 | + comment => 'multi element array, scalar', |
| 53 | + dataType => 'SCALAR' |
| 54 | + }, |
| 55 | + { |
| 56 | + key => 'List4', |
| 57 | + testValue => [qw/a b c/], |
| 58 | + expected => 'EQUAL', |
| 59 | + comment => 'multi element array, array', |
| 60 | + dataType => 'ARRAY' |
| 61 | + }, |
| 62 | +]; |
| 63 | + |
| 64 | +my $formType = 'SelectList'; |
| 65 | + |
| 66 | +my $output; |
| 67 | +$output = WebGUI::Macro::FormField::process( |
| 68 | + $session, 'SelectList', 'ListMultiple', [ qw(a c e), ''], # args to macro |
| 69 | + # args to particular Form subclass |
| 70 | + options => { a=>'aa', b=>'bb', c=>'cc', d=>'dd', e=>'ee', ''=>'Empty' }, |
| 71 | + value => [ qw(a c e), ''], |
| 72 | + sortByValue => 1, |
| 73 | +); |
| 74 | + |
| 75 | +warn $output; |
| 76 | + |
| 77 | +my $numTests = 11 + scalar @{ $testBlock } + 1; |
| 78 | + |
| 79 | +plan tests => $numTests; |
| 80 | + |
| 81 | +my ($header, $footer) = (WebGUI::Form::formHeader($session), WebGUI::Form::formFooter($session)); |
| 82 | + |
| 83 | +my $html = join "\n", $header, $output, $footer; |
| 84 | + |
| 85 | +my @forms = HTML::Form->parse($html, 'http://www.webgui.org'); |
| 86 | + |
| 87 | +##Test Form Generation |
| 88 | + |
| 89 | +is(scalar @forms, 1, '1 form was parsed'); |
| 90 | + |
| 91 | +my $form = $forms[0]; |
| 92 | +use Data::Dumper; warn Data::Dumper::Dumper $form; # XXX |
| 93 | +my @inputs = $form->inputs; |
| 94 | +is(scalar @inputs, 8, 'The form has 8 inputs'); |
| 95 | + |
| 96 | +#Basic tests |
| 97 | + |
| 98 | +my @options = $form->find_input('ListMultiple'); |
| 99 | + |
| 100 | +is( scalar(grep {$_->type ne 'option'} @options), 0, 'All inputs are of type option'); |
| 101 | + |
| 102 | +is( scalar(grep {$_->{multiple} ne 'multiple'} @options), 0, 'All inputs have multiple'); |
| 103 | + |
| 104 | +my @names = map { $_->name } @options; |
| 105 | +cmp_deeply( [@names], bag(('ListMultiple')x6), 'correct number of names and names'); |
| 106 | + |
| 107 | +cmp_set([ $form->param('ListMultiple') ], [qw(a c e), ''], 'preselected values in order'); |
| 108 | + |
| 109 | +my @values = map { $_->possible_values } @options; |
| 110 | +cmp_bag([ @values ], [qw(a b c d e), '', (undef)x6], 'list of all options'); |
| 111 | + |
| 112 | +my @value_names = map { $_->value_names } @options; |
| 113 | +cmp_bag([ @value_names ], [qw(aa bb cc dd ee Empty), ('off')x6], 'list of all displayed value names'); |
| 114 | + |
0 commit comments