~ubuntu-branches/ubuntu/intrepid/libcgi-formbuilder-perl/intrepid

« back to all changes in this revision

Viewing changes to t/2c-template-tt2.t

  • Committer: Bazaar Package Importer
  • Author(s): Jonas Smedegaard
  • Date: 2008-06-28 20:29:04 UTC
  • mfrom: (2.1.7 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080628202904-81kzjon8e8silx88
Tags: 3.05.01-6
Set urgency=medium as 3.05.01-6 included a FTBFS bugfix.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/perl -Ilib -I../lib
 
1
#!/usr/bin/perl
2
2
 
3
3
# Copyright (c) 2000-2006 Nathan Wiger <nate@wiger.org>.
4
4
# All Rights Reserved. If you're reading this, you're bored.
5
5
# 2c-template-tt2.t - test Template AssKit support
6
6
 
7
7
use strict;
8
 
use vars qw($TESTING $DEBUG $SKIP);
9
 
$TESTING = 1;
10
 
$DEBUG = $ENV{DEBUG} || 0;
 
8
 
 
9
our $TESTING = 1;
 
10
our $DEBUG = $ENV{DEBUG} || 0;
 
11
our $VERSION;
 
12
BEGIN { $VERSION = '3.0501'; }
 
13
 
11
14
use Test;
 
15
use FindBin;
12
16
 
13
17
# use a BEGIN block so we print our plan before CGI::FormBuilder is loaded
 
18
our $SKIP;
14
19
BEGIN {
15
20
    my $numtests = 4;
 
21
    unshift @INC, "$FindBin::Bin/../lib";
16
22
 
17
23
    plan tests => $numtests;
18
24
 
28
34
    }
29
35
}
30
36
 
31
 
# No tests written for TT2 because I don't use it and apparently
32
 
# nobody else really does either...
33
 
 
34
 
skip($SKIP, 1);
35
 
skip($SKIP, 1);
36
 
skip($SKIP, 1);
37
 
skip($SKIP, 1);
 
37
# Need to fake a request or else we stall
 
38
$ENV{REQUEST_METHOD} = 'GET';
 
39
$ENV{QUERY_STRING}   = 'ticket=111&user=pete&replacement=TRUE';
 
40
 
 
41
use CGI::FormBuilder 3.0501;
 
42
use CGI::FormBuilder::Test;
 
43
 
 
44
# Create our template and store it in a scalarref
 
45
my $template = outfile(0);
 
46
 
 
47
# What options we want to use, and what we expect to see
 
48
my @test = (
 
49
    {
 
50
        opt => { fields => [qw/name color/],
 
51
                 submit => 'No esta una button del resetto',
 
52
                 template => { type => 'TT2', template => \$template, variable => 'form' },
 
53
                 validate => { name => 'NAME' },
 
54
               },
 
55
        mod => { color => { options => [qw/red green blue/],
 
56
                            label => 'Best Color', value => 'red' },
 
57
                 size  => { value => 42 },
 
58
                 sex   => { options => [[M=>'Male'],[F=>'Female']] }
 
59
               },
 
60
    },
 
61
 
 
62
    {
 
63
        opt => { fields => [qw/name color size/],
 
64
                 template => { type => 'TT2', template => \$template, variable => 'form' },
 
65
                 values => {color => [qw/purple/], size => 8},
 
66
                 submit => 'Start over, boob!',
 
67
               },
 
68
 
 
69
        mod => { color => { options => [[white=>'White'],[black=>'Black'],[red=>'Green']],
 
70
                            label => 'Mom', },
 
71
                 name => { size => 80, maxlength => 80, comment => 'Fuck off' },
 
72
                 sex   => { options => [[1=>'Yes'], [0=>'No'], [-1=>'Maybe']],
 
73
                            label => 'Fuck me?<br>' },
 
74
               },
 
75
    },
 
76
 
 
77
    {
 
78
        opt => { fields => [qw/name color email/], submit => [qw/Update Delete/], reset => 0,
 
79
                 template => { type => 'TT2', template => \$template, variable => 'form' },
 
80
                 values => {color => [qw/yellow green orange/]},
 
81
                 validate => { sex => [qw(1 3 5)] },
 
82
               },
 
83
 
 
84
        mod => { color => {options => [[red => 1], [blue => 2], [yellow => 3], [pink => 4]] },
 
85
                 size  => {comment => '(unknown)', value => undef, force => 1 } ,
 
86
                 sex   => {label => 'glass EYE fucker', options => [[1,2],[3,4],[5,6]] },
 
87
               },
 
88
    },
 
89
 
 
90
    {
 
91
        opt => { fields => [qw/yomomma mymomma/], submit => [qw/Remove Dance_With/], reset => 1,
 
92
                 template => { type => 'TT2', template => \$template, variable => 'form' },
 
93
                 values => {mymomma => [qw/medium large xxl/]},
 
94
                 validate => { yomomma => 'NAME' },
 
95
               },
 
96
 
 
97
        mod => {},
 
98
    },
 
99
 
 
100
);
 
101
 
 
102
# Perl 5 is sick sometimes.
 
103
@test = @test[$ARGV[0] - 1] if @ARGV;
 
104
my $seq = $ARGV[0] || 1;
 
105
 
 
106
# Cycle thru and try it out
 
107
for (@test) {
 
108
    my $form = CGI::FormBuilder->new(
 
109
                    debug => $DEBUG,
 
110
                    action => 'TEST',
 
111
                    title  => 'TEST',
 
112
                    %{ $_->{opt} },
 
113
               );
 
114
 
 
115
    # the ${mod} key twiddles fields
 
116
    while(my($f,$o) = each %{$_->{mod} || {}}) {
 
117
        $o->{name} = $f;
 
118
        $form->field(%$o);
 
119
    }
 
120
 
 
121
    #
 
122
    # Just compare the output of render with what's expected
 
123
    # the correct string output is now in external files.
 
124
    # The seemingly extra eval is required so that failures
 
125
    # to import the template modules do not kill the tests.
 
126
    # (since render is called regardless of whether $SKIP is set)
 
127
    #
 
128
    my $out = outfile($seq++);
 
129
    my $ren = $SKIP ? '' : $form->render;
 
130
    my $ok = skip($SKIP, $ren, $out);
 
131
 
 
132
    if (! $ok && $ENV{LOGNAME} eq 'nwiger') {
 
133
        open(O, ">/tmp/fb.1.html");
 
134
        print O $out;
 
135
        close O;
 
136
 
 
137
        open(O, ">/tmp/fb.2.html");
 
138
        print O $ren;
 
139
        close O;
 
140
 
 
141
        system "diff /tmp/fb.1.html /tmp/fb.2.html";
 
142
        exit 1;
 
143
    }
 
144
}
38
145