WWW-Mechanize-Chrome-DOMops

 view release on metacpan or  search on metacpan

t/500-domops_find.t  view on Meta::CPAN

		# check that it contains the fields of our default info-extractor js code or some fields in case of user-specified
		for my $afl (@{ $found->{$aresname} }){
			is(ref($afl), 'HASH', 'domops_find()'." : test '${tk}' : called and result contains key '${aresname}' which is an ARRAYref which contains a HASH.") or BAIL_OUT(perl2dump($ret)."test '${tk}' (executed JS in '$js_outfile_tmp') : failed, above is wha...
			ok(scalar(keys %$afl)>0, 'domops_find()'." : test '${tk}' : called and result contains key '${aresname}' which is an ARRAYref which contains a HASH which it has at least one entry.") or BAIL_OUT(perl2dump($ret)."test '${tk}' (executed JS in '$js_o...
			if( $exists_element_inform ){
				for my $ak (exists($tv->{'keys-in-found'}) ? @{ $tv->{'keys-in-found'} } : qw/tag id/){
					ok(exists($afl->{$ak}), 'domops_find()'." : test '${tk}' : called and result contains key '${aresname}' which is an ARRAYref which contains a HASH which contains key '$ak'.") or BAIL_OUT(perl2dump($ret)."test '${tk}' (executed JS in '$js_outfile...
					ok(defined($afl->{$ak}), 'domops_find()'." : test '${tk}' : called and result contains key '${aresname}' which is an ARRAYref which contains a HASH which contains key '$ak' which is defined.") or BAIL_OUT(perl2dump($ret)."test '${tk}' (executed ...
				}
			}
		}
	}

	my %returnedids = map { $_ => 1 } grep { not /^\s*$/ } map { $_->{'id'} } @{ $found->{'all-levels'} };
	# check that those which were supposed to be removed are in the returned results and vice versa
	my %theids = map { $_ => 1 } @{ $tv->{'must-be-returned'} };
	for my $anid (sort keys %theids){
		ok(exists($returnedids{$anid}), "test '${tk}' : element with id '$anid' was found in the returned results.") or BAIL_OUT(perl2dump($ret)."test '${tk}' (executed JS in '$js_outfile_tmp') : failed, above is what it was returned from the call to domop...
	}
	for my $anid (sort keys %returnedids){
		ok(exists($theids{$anid}), "test '${tk}' : element with id '$anid' of the returned results is in the list of expected ids.") or BAIL_OUT(perl2dump($ret)."test '${tk}' (executed JS in '$js_outfile_tmp') : failed, above is what it was returned from t...
	}
	# now check that those which were supposed not to be removed are not in the returned results and vice versa
	%theids = map { $_ => 1 } @{ $tv->{'must-not-be-returned'} };
	for my $anid (sort keys %theids){
		ok(! exists($returnedids{$anid}), "test '${tk}' : element with id '$anid' was not found in the returned results.") or BAIL_OUT(perl2dump($ret)."test '${tk}' (executed JS in '$js_outfile_tmp') : failed, above is what it was returned from the call to...
	}
	for my $anid (sort keys %returnedids){
		ok(! exists($theids{$anid}), "test '${tk}' : element with id '$anid' of the returned results is not in the list of expected ids.") or BAIL_OUT(perl2dump($ret)."test '${tk}' (executed JS in '$js_outfile_tmp') : failed, above is what it was returned ...
	}

	# 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 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 ...
		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)
		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 ther...
		for(my $i=scalar(@{$ret->{'cb-results'}->{$acbname}});$i-->0;){
			my $ares1 = $ret->{'cb-results'}->{$acbname}->[$i];
			my $funcdata = $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 fr...
			}
		}
	}
}

diag "temp dir: $tmpdir ..." if exists($ENV{'PERL_TEST_TEMPDIR_TINY_NOCLEANUP'}) && $ENV{'PERL_TEST_TEMPDIR_TINY_NOCLEANUP'}>0;

# END
done_testing();



( run in 1.980 second using v1.01-cache-2.11-cpan-995e09ba956 )