]> Dogcows Code - chaz/p5-CGI-Ex/blob - t/4_app_00_base.t
CGI::Ex 2.08
[chaz/p5-CGI-Ex] / t / 4_app_00_base.t
1 # -*- Mode: Perl; -*-
2
3 =head1 NAME
4
5 4_app_00_base.t - Check for the basic functionality of CGI::Ex::App.
6
7 =head1 NOTE
8
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.
12
13 =cut
14
15 use Test::More tests => 9;
16 use strict;
17
18 {
19 package Foo;
20
21 use base qw(CGI::Ex::App);
22 use vars qw($test_stdout);
23
24 sub ready_validate { 1 }
25
26 sub print_out {
27 my $self = shift;
28 my $step = shift;
29 $test_stdout = shift;
30 }
31
32 sub swap_template {
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);
36 return $out;
37 }
38
39 ###----------------------------------------------------------------###
40
41 sub main_info_complete { 0 }
42
43 sub main_file_print { return \ "Main Content" }
44
45 sub step2_hash_validation { return {wow => {required => 1, required_error => 'wow is required'}} }
46
47 sub step2_path_info_map { [[qr{^/step2/(\w+)$}, 'wow']] }
48
49 sub step2_file_print { return \ "Some step2 content ([% foo %], [% one %]) <input type=text name=wow>[% wow_error %]" }
50
51 sub step2_hash_swap { return {foo => 'bar', one => 'two'} }
52
53 sub step2_hash_fill { return {wow => 'wee'} }
54
55 sub step2_finalize { shift->append_path('step3') }
56
57 sub step3_info_complete { 0 }
58
59 sub step3_file_print { return \ "All good" }
60
61
62 }
63
64 ###----------------------------------------------------------------###
65
66 #$ENV{'REQUEST_METHOD'} = 'GET';
67 #$ENV{'QUERY_STRING'} = '';
68
69 Foo->new({
70 form => {},
71 })->navigate;
72 ok($Foo::test_stdout eq "Main Content", "Got the right output");
73
74 ###----------------------------------------------------------------###
75
76 #$ENV{'REQUEST_METHOD'} = 'GET';
77 #$ENV{'QUERY_STRING'} = 'step=step2';
78
79 Foo->new({
80 form => {step => 'step2'},
81 })->navigate;
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");
83
84 ###----------------------------------------------------------------###
85
86 #$ENV{'REQUEST_METHOD'} = 'GET';
87 #$ENV{'QUERY_STRING'} = 'step=step2&wow=something';
88
89 Foo->new({
90 form=> {step => 'step2', wow => 'something'},
91 })->navigate;
92 ok($Foo::test_stdout eq "All good", "Got the right output");
93
94 ###----------------------------------------------------------------###
95
96 #$ENV{'REQUEST_METHOD'} = 'GET';
97 #$ENV{'QUERY_STRING'} = '';
98 local $ENV{'PATH_INFO'} = '/step2';
99
100 Foo->new({
101 form=> {},
102 })->navigate;
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");
104
105 ###----------------------------------------------------------------###
106
107 #$ENV{'REQUEST_METHOD'} = 'GET';
108 #$ENV{'QUERY_STRING'} = 'wow=something';
109 local $ENV{'PATH_INFO'} = '/step2';
110
111 my $f = Foo->new({
112 form=> {wow => 'something'},
113 })->navigate;
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");
116
117 ###----------------------------------------------------------------###
118
119 #$ENV{'REQUEST_METHOD'} = 'GET';
120 #$ENV{'QUERY_STRING'} = '';
121 local $ENV{'PATH_INFO'} = '/step2/something';
122
123 $f = Foo->new({
124 form => {},
125 })->navigate;
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");
129
130 ###----------------------------------------------------------------###
This page took 0.034428 seconds and 4 git commands to generate.