WWW-Mechanize-Chrome-DOMops
view release on metacpan or search on metacpan
t/600-domops_zap.t view on Meta::CPAN
# check if there are duplicates if not supposed to be
if( exists($tv->{'must-have-duplicates'}) ){
my %someids = map { $_ => 1 } map { $_->{'id'} } @{ $found->{'all-levels'} };
my $has_dups = scalar(keys %someids) < scalar(@{ $found->{'all-levels'} });
%someids = map { $_ => 1 } map { $_->{'id'} } @{ $found->{'first-level'} };
$has_dups ||= scalar(keys %someids) < scalar(@{ $found->{'first-level'} });
is($tv->{'must-have-duplicates'}, $has_dups ? 1 : 0, "Returned results must ".($tv->{'must-have-duplicates'}==1?"":"not ")."have duplicates.") or BAIL_OUT(perl2dump($ret)."test '${tk}' (executed JS in '$js_outfile_tmp') : failed above is what it wa...
}
# domops_find() those deleted, they must all fail
%returnedids = map { $_ => 1 } grep { not /^\s*$/ } map { $_->{'id'} } (@{ $found->{'all-levels'} }, @{ $found->{'first-level'} });
for my $anid (keys %returnedids){
my $tt = domops_find({
'mech-obj' => $mech_obj,
'element-id' => $anid
});
ok(defined($tt), 'domops_zap()'." : test '${tk}' : calling domops_find() to confirm deletions for id '$anid'") or BAIL_OUT("test '${tk}' : failed.");
is(ref($tt), 'HASH', 'domops_zap()'." : test '${tk}' : domops_find() called and got defined returned value which is a HASHref.") or BAIL_OUT(perl2dump($tt)."test '${tk}' (executed JS in '$js_outfile_tmp') : failed above is what it was returned from...
ok(exists($tt->{'status'}), 'domops_zap()'." : test '${tk}' : domops_find() called and returned value contains key 'status'.") or BAIL_OUT(perl2dump($tt)."test '${tk}' (executed JS in '$js_outfile_tmp') : failed above is what it was returned from t...
ok($tt->{'status'}>=0, 'domops_zap()'." : test '${tk}' : domops_find() called and returned value contains key 'status' which is ".$tt->{'status'}." >= 0 (meaning success).") or BAIL_OUT(perl2dump($tt)."test '${tk}' (executed JS in '$js_outfile_tmp'...
ok(exists($tt->{'found'}), 'domops_zap()'." : test '${tk}' : domops_find() called and returned value contains key 'found'.") or BAIL_OUT(perl2dump($tt)."test '${tk}' (executed JS in '$js_outfile_tmp') : failed above is what it was returned from the...
ok(defined($tt->{'found'}), 'domops_zap()'." : test '${tk}' : domops_find() called and returned value contains key 'found' which has a defined value.") or BAIL_OUT(perl2dump($tt)."test '${tk}' (executed JS in '$js_outfile_tmp') : failed above is wh...
is(ref($tt->{'found'}), 'HASH', 'domops_zap()'." : test '${tk}' : domops_find() called and returned value contains key 'found' which is an HASHref.") or BAIL_OUT(perl2dump($tt)."test '${tk}' (executed JS in '$js_outfile_tmp') : failed above is what...
my $found = $tt->{'found'};
for my $aresname ('first-level', 'all-levels'){
ok(exists($found->{$aresname}), 'domops_zap()'." : test '${tk}' : domops_find() called and 'found' contains key '${aresname}'.") or BAIL_OUT(perl2dump($tt)."test '${tk}' (executed JS in '$js_outfile_tmp') : failed above is what it was returned fro...
ok(defined($found->{$aresname}), 'domops_zap()'." : test '${tk}' : domops_find() called and 'found' contains key '${aresname}' which has a defined value.") or BAIL_OUT(perl2dump($tt)."test '${tk}' (executed JS in '$js_outfile_tmp') : failed above ...
is(ref($found->{$aresname}), 'ARRAY', 'domops_zap()'." : test '${tk}' : domops_find() called and result contains key '${aresname}' which is an ARRAYref.") or BAIL_OUT(perl2dump($tt)."test '${tk}' (executed JS in '$js_outfile_tmp') : failed above i...
}
is(scalar(@{$found->{'first-level'}}), 0, 'domops_zap()'." : test '${tk}' : domops_find() called and 'found'->'first-level' contains exactly 0 items'.") or BAIL_OUT(perl2dump($tt)."test '${tk}' (executed JS in '$js_outfile_tmp') : failed above is w...
}
# check return of the callbacks if any
for my $acbname (@known_callbacks){
next unless exists($tv->{'params'}->{$acbname}) && defined($tv->{'params'}->{$acbname});
my $TV = $tv->{'params'}->{$acbname};
# we must have a 'cb-results' in the returned value which must contain
# an array of results (one item for each html element found)
# under key $acbname (e.g. 'find-cb-on-matched' etc.)
ok(exists($ret->{'cb-results'}), 'domops_find()'." : test '${tk}' : called with a '${acbname}' callback and returned value contains key 'cb-results'.") or BAIL_OUT(perl2dump($ret)."test '${tk}' (executed JS in '$js_outfile_tmp') : failed above is w...
ok(defined($ret->{'cb-results'}), 'domops_find()'." : test '${tk}' : called with a '${acbname}' callback and returned value contains key 'cb-results' and it is defined.") or BAIL_OUT(perl2dump($ret)."test '${tk}' (executed JS in '$js_outfile_tmp') ...
ok(exists($ret->{'cb-results'}->{$acbname}), 'domops_find()'." : test '${tk}' : called with a '${acbname}' callback and returned value contains key 'cb-results'->$acbname.") or BAIL_OUT(perl2dump($ret)."test '${tk}' (executed JS in '$js_outfile_tmp...
ok(defined($ret->{'cb-results'}->{$acbname}), 'domops_find()'." : test '${tk}' : called with a '${acbname}' callback and returned value contains key 'cb-results'->$acbname and it is defined.") or BAIL_OUT(perl2dump($ret)."test '${tk}' (executed JS ...
is(ref($ret->{'cb-results'}->{$acbname}), 'ARRAY', 'domops_find()'." : test '${tk}' : called with a '${acbname}' callback and returned value contains key 'cb-results'->$acbname and it is an ARRAY.") or BAIL_OUT(perl2dump($ret)."test '${tk}' (execut...
# and now under it we must have an array for each function callback we declared
# and that array must have a size of as many html elements were returned
# and each item of the array must contain keys 'result' and 'name' (which is the func name declared)
# domops_zap() adds one more callback under 'find-cb-on-matched' named '_thezapper' and it is the last in sequence
if( $acbname eq 'find-cb-on-matched' ){
is(scalar(@{$ret->{'cb-results'}->{$acbname}}), 1+scalar(@{$TV}), 'domops_find()'." : test '${tk}' : called with a '${acbname}' callback and returned value contains key 'cb-results'->$acbname and it is an ARRAY which has exactly as many items as t...
} else {
# this does not contain _thezapper
is(scalar(@{$ret->{'cb-results'}->{$acbname}}), scalar(@{$TV}), 'domops_find()'." : test '${tk}' : called with a '${acbname}' callback and returned value contains key 'cb-results'->$acbname and it is an ARRAY which has exactly as many items as the...
}
# we make a special case for the _thezapper from the tests (it is the last)
for(my $i=scalar(@{$ret->{'cb-results'}->{$acbname}});$i-->0;){
my $ares1 = $ret->{'cb-results'}->{$acbname}->[$i];
my $funcdata = (($acbname eq 'find-cb-on-matched') && (($i+1) == scalar(@{$ret->{'cb-results'}->{$acbname}})))
? {'name'=>'_thezapper'} : $TV->[$i]
;
if( $acbname eq 'find-cb-on-matched' ){
is(scalar(@$ares1), scalar(@{$found->{'first-level'}}), 'domops_find()'." : test '${tk}' : called with a '${acbname}' callback and returned value contains key 'cb-results'->$acbname and it is an ARRAY which has exactly as many items as the HTML e...
} else {
is(scalar(@$ares1), scalar(@{$found->{'all-levels'}}), 'domops_find()'." : test '${tk}' : called with a '${acbname}' callback and returned value contains key 'cb-results'->$acbname and it is an ARRAY which has exactly as many items as the HTML el...
}
for my $ares2 (@$ares1){
is($ares2->{'name'}, $funcdata->{'name'}, 'domops_find()'." : test '${tk}' : called with a '${acbname}' callback and verified function name it is as it was declared '".$funcdata->{'name'}."'.") or BAIL_OUT(perl2dump($ret)."test '${tk}' (executed ...
is($ares2->{'result'}, 1, 'domops_find()'." : test '${tk}' : called with a '${acbname}' callback and returned result is '1'.") or BAIL_OUT(perl2dump($ret)."test '${tk}' (executed JS in '$js_outfile_tmp') : failed above is what it was returned fro...
}
}
}
}
diag "temp dir: $tmpdir ..." if exists($ENV{'PERL_TEST_TEMPDIR_TINY_NOCLEANUP'}) && $ENV{'PERL_TEST_TEMPDIR_TINY_NOCLEANUP'}>0;
# END
done_testing();
( run in 2.090 seconds using v1.01-cache-2.11-cpan-99c4e6809bf )