5 4_app_00_base.t - Check for the basic functionality of CGI::Ex::App.
9 These tests are extremely stripped down to test the basic path flow. Normally
10 unit tests are useful for garnering information about a module. For CGI::Ex::App
11 it is suggested to stick to live use cases or the CGI::Ex::App perldoc.
15 use Test::More tests => 9;
21 use base qw(CGI::Ex::App);
22 use vars qw($test_stdout);
24 sub ready_validate { 1 }
33 my ($self, $step, $file, $swap) = @_;
34 my $out = ref($file) ? $$file : "No filenames allowed during test mode";
35 $self->cgix->swap_template(\$out, $swap);
39 ###----------------------------------------------------------------###
41 sub main_info_complete { 0 }
43 sub main_file_print { return \ "Main Content" }
45 sub step2_hash_validation { return {wow => {required => 1, required_error => 'wow is required'}} }
47 sub step2_path_info_map { [[qr{^/step2/(\w+)$}, 'wow']] }
49 sub step2_file_print { return \ "Some step2 content ([% foo %], [% one %]) <input type=text name=wow>[% wow_error %]" }
51 sub step2_hash_swap { return {foo => 'bar', one => 'two'} }
53 sub step2_hash_fill { return {wow => 'wee'} }
55 sub step2_finalize { shift->append_path('step3') }
57 sub step3_info_complete { 0 }
59 sub step3_file_print { return \ "All good" }
64 ###----------------------------------------------------------------###
66 #$ENV{'REQUEST_METHOD'} = 'GET';
67 #$ENV{'QUERY_STRING'} = '';
72 ok($Foo::test_stdout eq "Main Content", "Got the right output");
74 ###----------------------------------------------------------------###
76 #$ENV{'REQUEST_METHOD'} = 'GET';
77 #$ENV{'QUERY_STRING'} = 'step=step2';
80 form => {step => 'step2'},
82 ok($Foo::test_stdout eq "Some step2 content (bar, two) <input type=text name=wow value=\"wee\">wow is required", "Got the right output");
84 ###----------------------------------------------------------------###
86 #$ENV{'REQUEST_METHOD'} = 'GET';
87 #$ENV{'QUERY_STRING'} = 'step=step2&wow=something';
90 form=> {step => 'step2', wow => 'something'},
92 ok($Foo::test_stdout eq "All good", "Got the right output");
94 ###----------------------------------------------------------------###
96 #$ENV{'REQUEST_METHOD'} = 'GET';
97 #$ENV{'QUERY_STRING'} = '';
98 local $ENV{'PATH_INFO'} = '/step2';
103 ok($Foo::test_stdout eq "Some step2 content (bar, two) <input type=text name=wow value=\"wee\">wow is required", "Got the right output");
105 ###----------------------------------------------------------------###
107 #$ENV{'REQUEST_METHOD'} = 'GET';
108 #$ENV{'QUERY_STRING'} = 'wow=something';
109 local $ENV{'PATH_INFO'} = '/step2';
112 form=> {wow => 'something'},
114 ok($Foo::test_stdout eq "All good", "Got the right output");
115 ok($f->form->{'step'} eq 'step2', "Got the right variable set in form");
117 ###----------------------------------------------------------------###
119 #$ENV{'REQUEST_METHOD'} = 'GET';
120 #$ENV{'QUERY_STRING'} = '';
121 local $ENV{'PATH_INFO'} = '/step2/something';
126 ok($Foo::test_stdout eq "All good", "Got the right output");
127 ok($f->form->{'step'} eq 'step2', "Got the right variable set in form");
128 ok($f->form->{'wow'} eq 'something', "Got the right variable set in form");
130 ###----------------------------------------------------------------###