blib/lib/HTTP/WebTest/Plugin/Sticky.pm

filter: Statementstmt 30.4% 14 / 46 Branchbran 0.0% 0 / 24 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 66.6% 4 / 6 Podpod 50.0% 1 / 2 totaltotal 22.8% 19 / 83 SCAR 49.0
CC
15
Cov
19%
prepare_request
240.0
param_types
2.0
BEGIN
1.0
CRAP 133.8
↑ Summary
1 package HTTP::WebTest::Plugin::Sticky;
2  
3 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 =head1 NAME
7  
8 HTTP::WebTest::Plugin::Sticky - Propagate hidden and text form fields
9  
10 =head1 VERSION
11  
12 Version 0.02
13  
14 =cut
15  
16 1 our $VERSION = '0.02';
17  
18 =head1 SYNOPSIS
19  
20 plugins = ( ::Sticky )
21  
22 test_name = Some test
23 sticky = yes
24 click_button = Next
25 params = (
26 name => 'This is a new text field'
27 )
28 end_test
29  
30 =head1 DESCRIPTION
31  
32 This plugin for the HTTP::WebTest module let you post a form that
33 includes all the inputs from the page, including hidden ones.
34  
35 Also you can add new inputs using the "params" hash.
36  
37 In case of inputs of type "checkbox", they are included only if
38 they have the "checked" property. In other case, you must set it
39 on purpose using the normal "params" hash.
40  
41 =head1 TEST PARAMETERS
42
43 =head2 sticky
44  
45 Allow/disallows the fields propagation. Values allowed: yes / no.
46
47 =cut
48  
49  
50 1 ▶use HTML::TokeParser;
Subroutine BEGIN: called CC=1 SCAR=0.0
51  
52 1 ▶use base qw(HTTP::WebTest::Plugin);
Subroutine BEGIN: called CC=1 SCAR=0.0
53  
54 sub param_types {
55 0 ▶ return 'sticky yesno
Subroutine param_types: not called CC=1 SCAR=6.9
Pod documented
56 params hashlist';
57 }
58  
59 sub prepare_request {
60 0 ▶ my $self = shift;
Subroutine prepare_request: not called CC=15 SCAR=54.8
Pod undocumented
61 0 $self->validate_params(qw(sticky params));
62  
63 0 my $request = $self->webtest->current_request;
64  
65 0 my $prev_test_num = $self->webtest->current_test_num - 1;
66 0 ▶ return if $prev_test_num < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $prev_test_num < 0 0 0 0
67  
68 0 my $response = $self->webtest->tests->[$prev_test_num]->response;
69  
70 0 ▶ return unless defined $response;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $response 0 0 0
71  
72 0 ▶ return unless $response->content_type eq 'text/html';
Branch: 1 branch
BranchTrueFalseTotal
unless $response->content_type eq "text/html" 0 0 0
73  
74 0 my $sticky = $self->test_param('sticky');
75  
76 0 ▶ return unless defined($sticky);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $sticky 0 0 0
77 0 ▶ return unless $sticky eq 'yes';
Branch: 1 branch
BranchTrueFalseTotal
unless $sticky eq "yes" 0 0 0
78  
79 0 my $params = $self->test_param('params');
80  
81 0 my $content = $response->content;
82  
83 0 my %inputs = ();
84 0 my $parser = HTML::TokeParser->new(\$content);
85 0 ▶ while(my $token = $parser->get_tag('input')) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $token = $parser->get_tag("input")) 0 0 0
86 0 my $type = $token->[1]{type};
87 0 ▶ next unless defined $type;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $type 0 0 0
88 0 my $name = $token->[1]{name};
89 0 ▶ next unless defined $name;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $name 0 0 0
90 0 my $value = $token->[1]{value};
91 0 ▶ next unless defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 0 0 0
92  
93 0 ▶ next if (lc($type) eq 'checkbox') and not defined($token->[1]{checked});
Branch: 1 branch
BranchTrueFalseTotal
if lc $type eq "checkbox" and not defined $token->[1]{"checked"} 0 0 0
Condition0%0/3
lc $type eq "checkbox" and not defined $token->[1]{"checked"}
!ll&&!rl&&r
000
MC/DC0%0/2
lc $type eq "checkbox" and not defined $token->[1]{"checked"}
lc $type eq "checkbox" not defined $token->[1]{"checked"}
Truth table0%0/3
A and not(B)
A= lc $type eq "checkbox"B= not defined $token->[1]{"checked"}
ABresult
0X0
100
111
94  
95 0 $inputs{$name} = $value;
96 }
97 0 ▶ if(defined $params) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $params) 0 0 0
98 0 ▶ my %params = ref($params) eq "ARRAY" ? @$params : %$params;
Branch: 1 branch
BranchTrueFalseTotal
ref $params eq 'ARRAY' ? : 0 0 0
99 0 for my $key (keys(%params)) {
100 0 $inputs{$key} = $params{$key};
101 }
102 }
103 0 my @inputs = %inputs;
104 0 $request->params(\@inputs);
105 0 return [];
106 }
107  
108  
109  
110  
111 =head1 AUTHOR
112  
113 Hugo Salgado H., C<< <huguei at cpan.org> >>
114  
115 =head1 BUGS
116  
117 Please report any bugs or feature requests to
118 C<bug-http-webtest-plugin-sticky at rt.cpan.org>, or through the web interface at
119 L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=HTTP-WebTest-Plugin-Sticky>.
120 I will be notified, and then you'll automatically be notified of progress on
121 your bug as I make changes.
122  
123 =head1 SUPPORT
124  
125 You can find documentation for this module with the perldoc command.
126  
127 perldoc HTTP::WebTest::Plugin::Sticky
128  
129 You can also look for general information at:
130  
131 perldoc HTTP::WebTest
132  
133 =over 4
134  
135 =item * AnnoCPAN: Annotated CPAN documentation
136  
137 L<http://annocpan.org/dist/HTTP-WebTest-Plugin-Sticky>
138  
139 =item * CPAN Ratings
140  
141 L<http://cpanratings.perl.org/d/HTTP-WebTest-Plugin-Sticky>
142  
143 =item * RT: CPAN's request tracker
144  
145 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=HTTP-WebTest-Plugin-Sticky>
146  
147 =item * Search CPAN
148  
149 L<http://search.cpan.org/dist/HTTP-WebTest-Plugin-Sticky>
150  
151 =back
152  
153 =head1 ACKNOWLEDGEMENTS
154  
155 The code was based in a lost posting on the webtest mailing list. Thanks
156 to whoever was responsible for that.
157  
158 =head1 COPYRIGHT & LICENSE
159  
160 Copyright 2006 Hugo Salgado H., all rights reserved.
161  
162 This program is free software; you can redistribute it and/or modify it
163 under the same terms as Perl itself.
164  
165 =head1 SEE ALSO
166  
167 L<HTTP::WebTest|HTTP::WebTest>
168  
169 L<HTTP::WebTest::API|HTTP::WebTest::API>
170  
171 L<HTTP::WebTest::Plugin|HTTP::WebTest::Plugin>
172  
173 =cut
174  
175 1 1; # End of HTTP::WebTest::Plugin::Sticky
176  
↑ Summary