Jifty/Test/WWW/Mechanize.pm

filter: Statementstmt 21.4% 49 / 228 Branchbran 0.0% 0 / 60 Conditioncond 0.0% 0 / 25 MC/DCmcdc 0.0% 0 / 14 Subroutinesub 38.4% 15 / 39 Podpod 100% 20 / 20 totaltotal 21.7% 84 / 386 CC 50 SCAR 39.8
CC
50
Cov
16%
moniker_for
240.0
action_form
48.8
warnings_like
42.0
CRAP 53.7
« Jifty/Config.pm ↑ Summary Jifty.pm »
1 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 package Jifty::Test::WWW::Mechanize;
5 2 ▶use base qw/Test::WWW::Mechanize/;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 2 delete $ENV{'http_proxy'}; # Otherwise Test::WWW::Mechanize tries to go through your HTTP proxy
8  
9 2 ▶use Test::More;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use Jifty::YAML;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use HTML::Lint;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 2 ▶use Test::HTML::Lint qw();
Subroutine BEGIN: called CC=1 SCAR=0.0
13 2 ▶use HTTP::Cookies;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 2 ▶use HTML::TreeBuilder::XPath;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 2 ▶use List::Util qw(first);
Subroutine BEGIN: called CC=1 SCAR=0.0
16 2 ▶use Plack::Test;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 # XXX TODO: We're leaving out FLUFF errors because it complains about non-standard
20 # attributes such as "autocomplete" on <form> elements. There should be a better
21 # way to fix this.
22 2 my $lint = HTML::Lint->new( only_types => [HTML::Lint::Error::STRUCTURE,
23 HTML::Lint::Error::HELPER] );
24  
25 =head1 NAME
26  
27 Jifty::Test::WWW::Mechanize - Subclass of L<Test::WWW::Mechanize> with
28 extra Jifty features
29  
30 =head1 METHODS
31  
32 =head2 new
33  
34 Overrides L<Test::WWW::Mechanize>'s C<new> to automatically give the
35 bot a cookie jar.
36  
37 =cut
38  
39 2 my $plack_server_pid;
40  
41 0 ▶sub new {
Subroutine new: not called CC=2 SCAR=17.9
Pod documented
42 0 my ($class, @args) = @_;
43  
44 0 ▶ push @args, app => Jifty->handler->psgi_app
Branch: 1 branch
BranchTrueFalseTotal
if $class->isa("Test::WWW::Mechanize::PSGI") 0 0 0
45 if $class->isa('Test::WWW::Mechanize::PSGI');
46  
47 0 my $self = $class->SUPER::new(@args);
48 0 $self->cookie_jar(HTTP::Cookies->new);
49  
50 0 return $self;
51 }
52  
53 =head2 request
54  
55 We override L<WWW::Mechanize>'s default request method so accept-encoding is
56 not set to gzip by default.
57  
58 =cut
59  
60 0 ▶sub _modify_request {
Subroutine _modify_request: not called CC=2 SCAR=17.9
61 0 my ($self, $req) = @_;
62 0 ▶ $req->header( 'Accept-Encoding', 'identity' )
Branch: 1 branch
BranchTrueFalseTotal
unless $req->header("Accept-Encoding") 0 0 0
63 unless $req->header( 'Accept-Encoding' );
64 0 return $self->SUPER::_modify_request($req);
65 }
66  
67 =head2 moniker_for ACTION, FIELD1 => VALUE1, FIELD2 => VALUE2
68  
69 Finds the moniker of the first action of type I<ACTION> whose
70 "constructor" field I<FIELD1> is I<VALUE1>, and so on.
71  
72 my $mon = $mech->moniker_for('MyApp::Action::UpdateInfo');
73  
74 If there is only one action of type ACTION, be sure not to pass
75 any more arguments to this method, or the method will return undef.
76  
77 NOTE that if you're using this in a series of different pages or forms,
78 you'll need to run it again for each new form:
79  
80 $mech->fill_in_action_ok($mech->moniker_for('MyApp::Action::UpdateInfo'),
81 owner_id => 'someone');
82 $mech->submit_html_ok();
83  
84 is($mech->action_field_value($mech->moniker_for("MyApp::Action::UpdateInfo"),
85 'owner_id'),
86 'someone',
87 "Owner was reassigned properly to owner 'someone'");
88  
89 =cut
90  
91 0 ▶sub moniker_for {
Subroutine moniker_for: not called CC=15 SCAR=54.8
Pod documented
92 0 my $self = shift;
93 0 my $action = Jifty->api->qualify(shift);
94 0 my %args = @_;
95  
96 0 for my $f ($self->forms) {
97 INPUT:
98 0 for my $input ($f->inputs) {
99 0 ▶ if ($input->type eq "hidden" and $input->name =~ /^J:A-(?:\d+-)?(.*)/ and $input->value eq $action) {
Branch: 1 branch
BranchTrueFalseTotal
if ($input->type eq "hidden" and $input->name =~ /^J:A-(?:\d+-)?(.*)/ and $input->value eq $action) 0 0 0
Condition0%0/6
$input->type eq "hidden" and $input->name =~ /^J:A-(?:\d+-)?(.*)/ and $input->value eq $action
!ll&&!rl&&r
000
$input->type eq "hidden" and $input->name =~ /^J:A-(?:\d+-)?(.*)/
!ll&&!rl&&r
000
MC/DC0%0/3
$input->type eq "hidden" and $input->name =~ /^J:A-(?:\d+-)?(.*)/ and $input->value eq $action
$input->type eq "hidden" $input->name =~ /^J:A-(?:\d+-)?(.*)/ $input->value eq $action
Truth table0%0/4
A and B and C
A= $input->type eq "hidden"B= $input->name =~ /^J:A-(?:\d+-)?(.*)/C= $input->value eq $action
ABCresult
0XX0
10X0
1100
1111
100  
101 0 my $moniker = $1;
102  
103 0 for my $id (keys %args) {
104 0 ▶ my $idfield = $f->find_input("J:A:F:F-$id-$moniker")
Condition0%0/3
$f->find_input("J:A:F:F-$id-$moniker") || $f->find_input("J:A:F-$id-$moniker")
l!l&&r!l&&!r
000
MC/DC0%0/2
$f->find_input("J:A:F:F-$id-$moniker") || $f->find_input("J:A:F-$id-$moniker")
$f->find_input("J:A:F:F-$id-$moniker") $f->find_input("J:A:F-$id-$moniker")
Truth table0%0/3
A || B
A= $f->find_input("J:A:F:F-$id-$moniker")B= $f->find_input("J:A:F-$id-$moniker")
ABresult
1X1
011
000
105 || $f->find_input("J:A:F-$id-$moniker");
106 0 ▶ next INPUT unless $idfield and $idfield->value eq $args{$id};
Branch: 1 branch
BranchTrueFalseTotal
unless $idfield and $idfield->value eq $args{$id} 0 0 0
Condition0%0/3
$idfield and $idfield->value eq $args{$id}
!ll&&!rl&&r
000
MC/DC0%0/2
$idfield and $idfield->value eq $args{$id}
$idfield $idfield->value eq $args{$id}
Truth table0%0/3
A and B
A= $idfieldB= $idfield->value eq $args{$id}
ABresult
0X0
100
111
107 }
108  
109 0 return $1;
110 }
111 }
112 # if we've gotten to this point, there were no hidden fields with a moniker,
113 # possibly a form with only its continuation-marking hidden field.
114 # Fall back to a submit field with similar attributes.
115 0 for my $input ($f->inputs) {
116 0 ▶ my $name = $input->name || '';
Condition0%0/2
$input->name || ''
l!l
00
MC/DC0%0/1
$input->name || ''
$input->name
Truth table0%0/2
A
A= $input->name
Aresult
11
00
117  
118 0 ▶ next unless $input->type eq "submit";
Branch: 1 branch
BranchTrueFalseTotal
unless $input->type eq "submit" 0 0 0
119 0 ▶ next unless $name =~ /\Q$action\E/;
Branch: 1 branch
BranchTrueFalseTotal
unless $name =~ /\Q$action\E/ 0 0 0
120 0 ▶ my ($moniker) = $name =~ /J:ACTIONS=([^|]+)\|/
Branch: 1 branch
BranchTrueFalseTotal
my($moniker) = $name =~ /J:ACTIONS=([^|]+)\|/ or next 0 0 0
121 or next;
122 0 return $moniker;
123 }
124 }
125 0 return undef;
126 }
127  
128 =head2 fill_in_action MONIKER, FIELD1 => VALUE1, FIELD2 => VALUE2, ...
129  
130 Finds the fields on the current page with the names FIELD1, FIELD2,
131 etc in the MONIKER action, and fills them in. Returns the
132 L<HTML::Form> object of the form that the action is in, or undef if it
133 can't find all the fields.
134  
135 =cut
136  
137 0 ▶sub fill_in_action {
Subroutine fill_in_action: not called CC=4 SCAR=30.0
Pod documented
138 0 my $self = shift;
139 0 my $moniker = shift;
140 0 my %args = @_;
141  
142 0 my $action_form = $self->action_form($moniker, keys %args);
143 0 ▶ return unless $action_form;
Branch: 1 branch
BranchTrueFalseTotal
unless $action_form 0 0 0
144  
145 0 for my $arg (keys %args) {
146 0 my $input = $action_form->find_input("J:A:F-$arg-$moniker");
147 0 ▶ unless ($input) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($input) 0 0 0
148 0 return;
149 }
150  
151 # not $input->value($args{$arg}), because it doesn't handle arrayref
152 0 $action_form->param( $input->name, $args{$arg} );
153 }
154  
155 0 return $action_form;
156 }
157  
158 =head2 fill_in_action_ok MONIKER, FIELD1 => VALUE1, FIELD2 => VALUE2, ...
159  
160 Finds the fields on the current page with the names FIELD1, FIELD2,
161 etc in the MONIKER action, and fills them in. Returns the
162 L<HTML::Form> object of the form that the action is in, or undef if it
163 can't find all the fields.
164  
165 Also, passes if it finds all of the fields and fails if any of the
166 fields are missing.
167  
168 =cut
169  
170 0 ▶sub fill_in_action_ok {
Subroutine fill_in_action_ok: not called CC=1 SCAR=6.9
Pod documented
171 0 my $self = shift;
172 0 my $moniker = shift;
173  
174 0 my $ret = $self->fill_in_action($moniker, @_);
175 0 my $Test = Test::Builder->new;
176 0 $Test->ok($ret, "Filled in action $moniker");
177 }
178  
179 =head2 action_form MONIKER [ARGUMENTNAMES]
180  
181 Returns the form (as an L<HTML::Form> object) corresponding to the
182 given moniker (which also contains inputs for the given
183 argumentnames), and also selects it as the current form. Returns
184 undef if it can't be found.
185  
186 =cut
187  
188 0 ▶sub action_form {
Subroutine action_form: not called CC=8 SCAR=38.9
Pod documented
189 0 my $self = shift;
190 0 my $moniker = shift;
191 0 my @fields = @_;
192 0 ▶ Carp::confess("No moniker") unless $moniker;
Branch: 1 branch
BranchTrueFalseTotal
unless $moniker 0 0 0
193  
194 0 my $i;
195 0 for my $form ($self->forms) {
196 2 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
197  
198 0 $i++;
199 0 ▶ next unless first { $_->name =~ /J:A-(?:\d+-)?$moniker/
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
$_->name =~ /J:A-(?:\d+-)?$moniker/ and $_->type eq "hidden" 0 0 0
200 && $_->type eq "hidden" }
201 0 ▶ $form->inputs;
Branch: 1 branch
BranchTrueFalseTotal
unless &first(sub { $_->name =~ /J:A-(?:\d+-)?$moniker/ and $_->type eq "hidden"; } , $form->inputs) 0 0 0
202 0 ▶ next if grep {not $form->find_input("J:A:F-$_-$moniker")} @fields;
Branch: 1 branch
BranchTrueFalseTotal
if grep {not $form->find_input("J:A:F-$_-$moniker");} @fields 0 0 0
203  
204 0 $self->form_number($i); #select it, for $mech->submit etc
205 0 return $form;
206 }
207  
208 # A fallback for forms that don't have any named fields except their
209 # submit button. Could stand to be refactored.
210 0 $i = 0;
211 0 for my $form ($self->forms) {
212 2 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
213  
214 0 $i++;
215 0 ▶ next unless first { $_->name =~ /J:A-(?:\d+-)?$moniker/
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
$_->name =~ /J:A-(?:\d+-)?$moniker/ and $_->type eq "submit" 0 0 0
216 && $_->type eq "submit" }
217 0 ▶ $form->inputs;
Branch: 1 branch
BranchTrueFalseTotal
unless &first(sub { $_->name =~ /J:A-(?:\d+-)?$moniker/ and $_->type eq "submit"; } , $form->inputs) 0 0 0
218 0 ▶ next if grep {not $form->find_input("J:A:F-$_-$moniker")} @fields;
Branch: 1 branch
BranchTrueFalseTotal
if grep {not $form->find_input("J:A:F-$_-$moniker");} @fields 0 0 0
219  
220 0 $self->form_number($i); #select it, for $mech->submit etc
221 0 return $form;
222 }
223 0 return;
224 }
225  
226 =head2 action_field_input MONIKER, FIELD
227  
228 Finds the field on the current page with the names FIELD in the
229 action MONIKER, and returns its L<HTML::Form::Input>, or undef if it can't be
230 found.
231  
232 =cut
233  
234 0 ▶sub action_field_input {
Subroutine action_field_input: not called CC=2 SCAR=17.9
Pod documented
235 0 my $self = shift;
236 0 my $moniker = shift;
237 0 my $field = shift;
238  
239 0 my $action_form = $self->action_form($moniker, $field);
240 0 ▶ return unless $action_form;
Branch: 1 branch
BranchTrueFalseTotal
unless $action_form 0 0 0
241  
242 0 my $input = $action_form->find_input("J:A:F-$field-$moniker");
243 0 return $input;
244 }
245  
246 =head2 action_field_value MONIKER, FIELD
247  
248 Finds the field on the current page with the names FIELD in the
249 action MONIKER, and returns its value, or undef if it can't be found.
250  
251 =cut
252  
253 0 ▶sub action_field_value {
Subroutine action_field_value: not called CC=2 SCAR=17.9
Pod documented
254 0 my $self = shift;
255 0 my $input = $self->action_field_input(@_);
256 0 ▶ return $input ? $input->value : undef;
Branch: 1 branch
BranchTrueFalseTotal
$input ? : 0 0 0
257 }
258  
259 =head2 send_action CLASS ARGUMENT => VALUE, [ ... ]
260  
261 Sends a request to the server via the webservices API, and returns the
262 L<Jifty::Result> of the action. C<CLASS> specifies the class of the
263 action, and all parameters thereafter supply argument keys and values.
264  
265 The URI of the page is unchanged after this; this is accomplished by
266 using the "back button" after making the webservice request.
267  
268 =cut
269  
270 0 ▶sub _build_webservices_request {
Subroutine _build_webservices_request: not called CC=1 SCAR=6.9
271 0 my ($self, $endpoint, $data) = @_;
272  
273 0 my $uri = $self->uri->clone;
274 0 $uri->path($endpoint);
275 0 $uri->query('');
276  
277 0 my $body = Jifty::YAML::Dump({ path => $endpoint, %$data});
278  
279 0 HTTP::Request->new(
280 POST => $uri,
281 [ 'Content-Type' => 'text/x-yaml',
282 'Content-Length' => length($body) ],
283 $body
284 );
285 }
286  
287 0 ▶sub send_action {
Subroutine send_action: not called CC=2 SCAR=17.9
Pod documented
288 0 my $self = shift;
289 0 my $class = shift;
290 0 my %args = @_;
291  
292 0 my $request = $self->_build_webservices_request
293 ( "__jifty/webservices/yaml",
294 { actions => {
295 action => {
296 moniker => 'action',
297 class => $class,
298 fields => \%args
299 }
300 }
301 });
302  
303 0 my $result = $self->request( $request );
304 0 ▶ my $content = eval { Jifty::YAML::Load($result->content)->{action} } || undef;
Condition0%0/2
eval { do { Jifty::YAML::Load($result->content)->{'action'} } } || undef
l!l
00
MC/DC0%0/1
eval { do { Jifty::YAML::Load($result->content)->{'action'} } } || undef
eval { do { Jifty::YAML::Load($result->content)->{'action'} } }
Truth table0%0/2
A
A= eval { do { Jifty::YAML::Load($result->content)->{'action'} } }
Aresult
11
00
305 0 $self->back;
306 0 return $content;
307 }
308  
309 =head2 fragment_request PATH ARGUMENT => VALUE, [ ... ]
310  
311 Makes a request for the fragment at PATH, using the webservices API,
312 and returns the string of the result.
313  
314 =cut
315  
316 0 ▶sub fragment_request {
Subroutine fragment_request: not called CC=2 SCAR=13.7
Pod documented
317 0 my $self = shift;
318 0 my $path = shift;
319 0 my %args = @_;
320  
321 0 my $request = $self->_build_webservices_request
322 ( "__jifty/webservices/xml",
323 { fragments => {
324 fragment => {
325 name => 'fragment',
326 path => $path,
327 args => \%args
328 }
329 }
330 });
331  
332 0 my $result = $self->request( $request );
333  
334 2 ▶ use XML::Simple;
Subroutine BEGIN: called CC=1 SCAR=0.0
335 0 ▶ my $content = eval { XML::Simple::XMLin($result->content, SuppressEmpty => '')->{fragment}{content} } || '';
Condition0%0/2
eval { do { XML::Simple::XMLin($result->content, 'SuppressEmpty', '')->{'fragment'}{'content'} } } || ''
l!l
00
MC/DC0%0/1
eval { do { XML::Simple::XMLin($result->content, 'SuppressEmpty', '')->{'fragment'}{'content'} } } || ''
eval { do { XML::Simple::XMLin($result->content, 'SuppressEmpty', '')->{'fragment'}{'content'} } }
Truth table0%0/2
A
A= eval { do { XML::Simple::XMLin($result->content, 'SuppressEmpty', '')->{'fragment'}{'content'} } }
Aresult
11
00
336 0 $self->back;
337 0 return $content;
338 }
339  
340 =head2 field_error_text MONIKER, FIELD
341  
342 Finds the error span on the current page for the name FIELD in the
343 action MONIKER, and returns the text (tags stripped) from it. (If the
344 field can't be found, return undef).
345  
346 =cut
347  
348 0 ▶sub field_error_text {
Subroutine field_error_text: not called CC=1 SCAR=6.9
Pod documented
349 0 my $self = shift;
350 0 my $moniker = shift;
351 0 my $field = shift;
352  
353 # Setup the XPath processor and the ID we're looking for
354 0 my $tree = HTML::TreeBuilder::XPath->new;
355 0 $tree->parse($self->content);
356 0 $tree->eof;
357  
358 0 my $id = "errors-J:A:F-$field-$moniker";
359  
360 # Search for the span containing that error
361 0 return $tree->findvalue(qq{//span[\@id = "$id"]});
362 }
363  
364 =head2 uri
365  
366 L<WWW::Mechanize> has a bug where it returns the wrong value for
367 C<uri> after redirect. This fixes that. See
368 http://rt.cpan.org/NoAuth/Bug.html?id=9059
369  
370 =cut
371  
372 0 ▶sub uri { shift->response->request->uri }
Subroutine uri: not called CC=1 SCAR=6.9
Pod documented
373  
374 =head2 get_html_ok URL
375  
376 Calls C<get> URL, followed by testing the HTML using
377 L<Test::HTML::Lint>.
378  
379 =cut
380  
381 0 ▶sub get_html_ok {
Subroutine get_html_ok: not called CC=1 SCAR=6.9
Pod documented
382 0 my $self = shift;
383 0 $self->get(@_);
384 {
385 0 local $Test::Builder::Level = $Test::Builder::Level;
386 0 $Test::Builder::Level++;
387 0 Test::HTML::Lint::html_ok( $lint, $self->content, "html_ok for ".$self->uri );
388 }
389 }
390  
391 =head2 html_ok [STRING]
392  
393 Tests the current C<content> using L<Test::HTML::Lint>. If passed a string,
394 tests against that instead of the current content.
395  
396 =cut
397  
398 0 ▶sub html_ok {
Subroutine html_ok: not called CC=2 SCAR=17.9
Pod documented
399 0 my $self = shift;
400 0 ▶ my $content = shift || $self->content;
Condition0%0/3
shift() || $self->content
l!l&&r!l&&!r
000
MC/DC0%0/2
shift() || $self->content
shift() $self->content
Truth table0%0/3
A || B
A= shift()B= $self->content
ABresult
1X1
011
000
401 {
402 0 local $Test::Builder::Level = $Test::Builder::Level;
403 0 $Test::Builder::Level++;
404 0 Test::HTML::Lint::html_ok( $lint, $content );
405 }
406 }
407  
408 =head2 submit_html_ok
409  
410 Calls C<submit>, followed by testing the HTML using
411 L<Test::HTML::Lint>.
412  
413 =cut
414  
415 0 ▶sub submit_html_ok {
Subroutine submit_html_ok: not called CC=1 SCAR=6.9
Pod documented
416 0 my $self = shift;
417 0 $self->submit(@_);
418 {
419 0 local $Test::Builder::Level = $Test::Builder::Level;
420 0 $Test::Builder::Level++;
421 0 Test::HTML::Lint::html_ok( $lint, $self->content );
422 }
423 }
424  
425 =head2 follow_link_ok
426  
427 Calls C<follow_link>, followed by testing the HTML using
428 L<Test::HTML::Lint>. Warns if it cannot find the specified link (you
429 should use C<ok> on C<find_link> first to check its existence).
430  
431 =cut
432  
433 0 ▶sub follow_link_ok {
Subroutine follow_link_ok: not called CC=5 SCAR=34.0
Pod documented
434 0 my $self = shift;
435  
436  
437 0 my $desc;
438  
439 # Test::WWW::Mechanize allows passing in a hashref of arguments, so we should to
440 0 ▶ if ( ref($_[0]) eq 'HASH') {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $_[0] eq 'HASH') { } 0 0 0
elsif (@_ % 2) { } 0 0 0
441 # if the user is pashing in { text => 'foo' } ...
442 0 ▶ $desc = $_[1] if $_[1];
Branch: 1 branch
BranchTrueFalseTotal
if $_[1] 0 0 0
443 0 @_ = %{$_[0]};
444 } elsif (@_ % 2 ) {
445 # IF the user is passing in text => 'foo' ,"Cicked the right thing"
446 # Remove reason from end if it's there
447 0 $desc = pop @_ ;
448 }
449  
450 0 ▶ carp("Couldn't find link") unless $self->follow_link(@_);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->follow_link(@_) 0 0 0
451 {
452 0 local $Test::Builder::Level = $Test::Builder::Level;
453 0 $Test::Builder::Level++;
454 0 Test::HTML::Lint::html_ok( $lint, $self->content, $desc );
455 }
456 }
457  
458 =head2 warnings_like WARNING, [REASON]
459  
460 Tests that the warnings generated by the server (since the last such
461 check) match the given C<WARNING>, which should be a regular
462 expression. If an array reference of regular expressions is passed as
463 C<WARNING>, checks that one warning per element was received.
464  
465 =cut
466  
467 0 ▶sub warnings_like {
Subroutine warnings_like: not called CC=6 SCAR=37.4
Pod documented
468 0 my $self = shift;
469 0 my @args = shift;
470 0 ▶ @args = @{$args[0]} if ref $args[0] eq "ARRAY";
Branch: 1 branch
BranchTrueFalseTotal
if ref $args[0] eq "ARRAY" 0 0 0
471 0 ▶ my $reason = pop || "Server warnings matched";
Condition0%0/2
pop() || 'Server warnings matched'
l!l
00
MC/DC0%0/1
pop() || 'Server warnings matched'
pop()
Truth table0%0/2
A
A= pop()
Aresult
11
00
472  
473 0 local $Test::Builder::Level = $Test::Builder::Level;
474 0 $Test::Builder::Level++;
475  
476 0 my $plugin = Jifty->find_plugin("Jifty::Plugin::TestServerWarnings");
477 0 my @warnings = $plugin->decoded_warnings($self->uri);
478 0 ▶ my $max = @warnings > @args ? $#warnings : $#args;
Branch: 1 branch
BranchTrueFalseTotal
@warnings > @args ? : 0 0 0
479 0 for (0 .. $max) {
480 0 ▶ like($warnings[$_], $_ <= $#args ? qr/$args[$_]/ : qr/(?!unexpected)unexpected warning/, $reason);
Branch: 1 branch
BranchTrueFalseTotal
$_ <= $#args ? : 0 0 0
481 }
482 }
483  
484 =head2 no_warnings_ok [REASON]
485  
486 Checks that no warnings were generated by the server (since the last
487 such check).
488  
489 =cut
490  
491 0 ▶sub no_warnings_ok {
Subroutine no_warnings_ok: not called CC=3 SCAR=24.8
Pod documented
492 0 my $self = shift;
493 0 ▶ my $reason = shift || "no warnings emitted";
Condition0%0/2
shift() || 'no warnings emitted'
l!l
00
MC/DC0%0/1
shift() || 'no warnings emitted'
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
494  
495 0 local $Test::Builder::Level = $Test::Builder::Level;
496 0 $Test::Builder::Level++;
497  
498 0 my $plugin = Jifty->find_plugin("Jifty::Plugin::TestServerWarnings");
499 0 my @warnings = $plugin->decoded_warnings( $self->uri );
500  
501 0 is( @warnings, 0, $reason );
502 0 for (@warnings) {
503 0 diag("got warning: $_");
504 }
505 }
506  
507 =head2 session
508  
509 Returns the server-side L<Jifty::Web::Session> object associated with
510 this Mechanize object.
511  
512 =cut
513  
514 0 ▶sub session {
Subroutine session: not called CC=2 SCAR=17.9
Pod documented
515 0 my $self = shift;
516  
517 0 my $cookie = Jifty->config->framework('Web')->{'SessionCookieName'};
518 0 $cookie =~ s/\$PORT/(?:\\d+|NOPORT)/g;
519  
520 0 ▶ return undef unless $self->cookie_jar->as_string =~ /$cookie=([^;]+)/;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->cookie_jar->as_string =~ /$cookie=([^;]+)/ 0 0 0
521  
522 0 my $session = Jifty::Web::Session->new;
523 0 $session->load($1);
524 0 return $session;
525 }
526  
527 =head2 continuation [ID]
528  
529 Returns the current continuation of the Mechanize object, if any. Or,
530 given an ID, returns the continuation with that ID.
531  
532 =cut
533  
534 0 ▶sub continuation {
Subroutine continuation: not called CC=3 SCAR=24.8
Pod documented
535 0 my $self = shift;
536  
537 0 my $session = $self->session;
538 0 ▶ return undef unless $session;
Branch: 1 branch
BranchTrueFalseTotal
unless $session 0 0 0
539
540 0 my $id = shift;
541 0 ▶ ($id) = $self->uri =~ /J:(?:C|CALL|RETURN)=([^&;]+)/ unless $id;
Branch: 1 branch
BranchTrueFalseTotal
unless $id 0 0 0
542  
543 0 return $session->get_continuation($id);
544 }
545  
546 =head2 current_user
547  
548 Returns the L<Jifty::CurrentUser> object or descendant, if any.
549  
550 =cut
551  
552 0 ▶sub current_user {
Subroutine current_user: not called CC=3 SCAR=24.8
Pod documented
553 0 my $self = shift;
554  
555 0 my $session = $self->session;
556 0 ▶ return undef unless $session;
Branch: 1 branch
BranchTrueFalseTotal
unless $session 0 0 0
557  
558 0 my $id = $session->get('user_id');
559  
560 0 ▶ return undef unless ($id);
Branch: 1 branch
BranchTrueFalseTotal
unless $id 0 0 0
561  
562 0 my $object = Jifty->app_class("CurrentUser")->new(id => $id);
563 0 return $object;
564 }
565  
566  
567 2 1;
« Jifty/Config.pm ↑ Summary Jifty.pm »