| 1 | package Test::Mojo::Role::SubmitForm; | ||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use Mojo::Base -base; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use Role::Tiny; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use Carp qw/croak/; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||
| 7 | 2 | our $VERSION = '1.004005'; # VERSION | |||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||
| 9 | 16 | ▶ | sub click_ok { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
click_ok: called CC=16 SCAR=28.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 10 | 16 | my ( $self, $selector_or_dom, $extra_params ) = @_; | |||||||||||||||||||||||||||||||||||||
| 11 | 16 | ▶ | $extra_params ||= {}; | ||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$extra_params ||= {}
MC/DC100%1/1
$extra_params ||= {}
$extra_params
Truth table100%2/2
A
A= $extra_params
| |||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||
| 13 | 16 | ▶ | my $el = eval { $selector_or_dom->isa('Mojo::DOM') } | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$self->tx->res->dom->at($selector_or_dom) or croak('Test::Mojo::Role::SubmitForm::click_ok()' . " Did not find element matching selector $selector_or_dom")
MC/DC100%1/1
$self->tx->res->dom->at($selector_or_dom) or croak('Test::Mojo::Role::SubmitForm::click_ok()' . " Did not find element matching selector $selector_or_dom")
$self->tx->res->dom->at($selector_or_dom)
Truth table100%2/2
A
A= $self->tx->res->dom->at($selector_or_dom)
| |||||||||||||||||||||||||||||||||||||||
| 14 | ? $selector_or_dom | ||||||||||||||||||||||||||||||||||||||
| 15 | : $self->tx->res->dom->at($selector_or_dom) | ||||||||||||||||||||||||||||||||||||||
| 16 | || croak 'Test::Mojo::Role::SubmitForm::click_ok()' | ||||||||||||||||||||||||||||||||||||||
| 17 | . " Did not find element matching selector $selector_or_dom"; | ||||||||||||||||||||||||||||||||||||||
| 18 | 15 | ▶ | unless ( $el->tag eq 'form' ) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 19 | 7 | ▶ | if (length $el->{name}) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 20 | 7 | ▶ | if ( ($el->{type}//'') eq 'image' ) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$el->{"type"} // ""
MC/DC0%0/1
$el->{"type"} // ""
$el->{"type"}
Truth table50%1/2
A
A= $el->{"type"}
| |||||||||||||||||||||||||||||||||||||||
| 21 | 2 | $extra_params->{ $el->{name} . '.x' } = 1; | |||||||||||||||||||||||||||||||||||||
| 22 | 2 | $extra_params->{ $el->{name} . '.y' } = 1; | |||||||||||||||||||||||||||||||||||||
| 23 | } | ||||||||||||||||||||||||||||||||||||||
| 24 | else { | ||||||||||||||||||||||||||||||||||||||
| 25 | 5 | $extra_params->{ $el->{name} } = $el->val; | |||||||||||||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||||||||||||
| 27 | } | ||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||
| 29 | 7 | $el = $el->ancestors('form')->first; | |||||||||||||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||
| 32 | 15 | for ( sort keys %$extra_params ) { | |||||||||||||||||||||||||||||||||||||
| 33 | 19 | ▶ | next unless ref $extra_params->{$_} eq 'CODE'; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 34 | 5 | ( my $name = $_ ) =~ s/"/\\"/g; | |||||||||||||||||||||||||||||||||||||
| 35 | 5 | $extra_params->{$_} = $extra_params->{$_}->( | |||||||||||||||||||||||||||||||||||||
| 36 | $self->_gather_vals( $el->find(qq{[name="$name"]})->each ) | ||||||||||||||||||||||||||||||||||||||
| 37 | ); | ||||||||||||||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||
| 40 | 15 | my %form = ( | |||||||||||||||||||||||||||||||||||||
| 41 | $self->_get_controls($el), | ||||||||||||||||||||||||||||||||||||||
| 42 | %$extra_params, | ||||||||||||||||||||||||||||||||||||||
| 43 | ); | ||||||||||||||||||||||||||||||||||||||
| 44 | 15 | for (keys %form) { | |||||||||||||||||||||||||||||||||||||
| 45 | 82 | ▶ | delete $form{$_} unless defined $form{$_} | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||
| 48 | 15 | ▶ | if ( $ENV{MOJO_SUBMITFORM_DEBUG} ) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 49 | 0 | warn "\n########## SUBMITTING FORM ##########\n"; | |||||||||||||||||||||||||||||||||||||
| 50 | 0 | require Mojo::Util; | |||||||||||||||||||||||||||||||||||||
| 51 | 0 | warn Mojo::Util::dumper(\%form); | |||||||||||||||||||||||||||||||||||||
| 52 | 0 | warn "########## END FORM ##########\n\n"; | |||||||||||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||
| 55 | my $tx = $self->ua->build_tx( | ||||||||||||||||||||||||||||||||||||||
| 56 | 15 | ▶ | $el->{method}||'GET' => defined $el->{action} && $el->{action} ne '' ? $el->{action} : $self->tx->req->url | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%5/5
$el->{'method'} || 'GET'
defined $el->{"action"} and $el->{"action"} ne ""
MC/DC100%1/1
$el->{'method'} || 'GET'
$el->{'method'}
MC/DC100%2/2
defined $el->{"action"} and $el->{"action"} ne ""
defined $el->{"action"}
$el->{"action"} ne ""
Truth table100%2/2
A
A= $el->{'method'}
Truth table100%3/3
A and B
A= defined $el->{"action"}B= $el->{"action"} ne ""
| |||||||||||||||||||||||||||||||||||||||
| 57 | => form => \%form, | ||||||||||||||||||||||||||||||||||||||
| 58 | ); | ||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||
| 60 | 15 | $self->request_ok( $tx ); | |||||||||||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||
| 63 | 123 | ▶ | sub _gather_vals { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_gather_vals: called CC=7 SCAR=19.5
| |||||||||||||||||||||||||||||||||||||||
| 64 | 123 | my ( $self, @els ) = @_; | |||||||||||||||||||||||||||||||||||||
| 65 | 123 | my @vals; | |||||||||||||||||||||||||||||||||||||
| 66 | 123 | for ( @els ) { | |||||||||||||||||||||||||||||||||||||
| 67 | 125 | ▶ | next if $_ | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 68 | ->matches('[type=radio]:not(:checked), [type=checkbox]:not(:checked)'); | ||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||
| 70 | 109 | ▶ | defined( my $val = $_->val ) or next; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 71 | 104 | ▶ | push @vals, ref $val ? @$val : $val; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||||||||||
| 73 | 123 | ▶ | return @vals == 1 ? $vals[0] : @vals ? \@vals : undef; | ||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||
| 76 | 15 | ▶ | sub _get_controls { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_controls: called CC=6 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||
| 77 | 15 | my ( $self, $form ) = @_; | |||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||
| 79 | 15 | my @els = $form->find( | |||||||||||||||||||||||||||||||||||||
| 80 | 'input:not([type=button]):not([type=submit]):not([type=image]):not([disabled]),' . | ||||||||||||||||||||||||||||||||||||||
| 81 | 'select:not([disabled]),' . | ||||||||||||||||||||||||||||||||||||||
| 82 | 'textarea:not([disabled])' | ||||||||||||||||||||||||||||||||||||||
| 83 | )->each; | ||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||
| 85 | # remove controls defined in templates | ||||||||||||||||||||||||||||||||||||||
| 86 | 15 | @els = grep { $_->ancestors('template')->size() == 0 } @els; | |||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||
| 88 | 15 | my %controls; | |||||||||||||||||||||||||||||||||||||
| 89 | 15 | for ( @els ) { | |||||||||||||||||||||||||||||||||||||
| 90 | 118 | ▶ | defined(my $vals = $self->_gather_vals( $_ )) or next; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 91 | 98 | ▶ | push @{ $controls{$_->{name}} }, ref $vals ? @$vals : $vals; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||||||||||||
| 93 | 15 | ▶ | $#$_ or $_= $_->[0] for values %controls; # chage 1-el arrayrefs to strings | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||
| 95 | 15 | return %controls; | |||||||||||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||
| 98 | 2 | q| | |||||||||||||||||||||||||||||||||||||
| 99 | The fantastic element that explains the appeal of games to | ||||||||||||||||||||||||||||||||||||||
| 100 | many developers is neither the fire-breathing monsters nor the | ||||||||||||||||||||||||||||||||||||||
| 101 | milky-skinned, semi-clad sirens; it is the experience of | ||||||||||||||||||||||||||||||||||||||
| 102 | carrying out a task from start to finish without any change | ||||||||||||||||||||||||||||||||||||||
| 103 | in the user requirements. | ||||||||||||||||||||||||||||||||||||||
| 104 | |; | ||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||
| 106 | __END__ | ||||||||||||||||||||||||||||||||||||||