Revision 9866d032
Von Sven Schöling vor etwa 1 Jahr hinzugefügt
t/fxtransaction/ap_transactions.t | ||
---|---|---|
|
||
use HTML::Query;
|
||
use Support::TestSetup;
|
||
use Support::Integration;
|
||
|
||
my $part;
|
||
my $vendor;
|
||
... | ... | |
|
||
}
|
||
|
||
package MockDispatcher {
|
||
sub end_request { die "END_OF_REQUEST" }
|
||
};
|
||
$::dispatcher = bless { }, "MockDispatcher";
|
||
|
||
# make a pseudo request to an old bin/mozilla style entry point
|
||
# captures STDOUT, STDERR and the return values of the called action
|
||
#
|
||
# the given form should be set up like it would be in Dispatcher after read_cgi_input
|
||
sub make_request {
|
||
my ($script, $form, $action) = @_;
|
||
|
||
my ($out, $err, @ret);
|
||
|
||
package main {
|
||
local $SIG{__WARN__} = sub {
|
||
# ignore spurious warnings, TAP::Harness calls this warnings enabled
|
||
};
|
||
|
||
require "bin/mozilla/$script.pl";
|
||
|
||
open(my $out_fh, '>', \$out) or die;
|
||
open(my $err_fh, '>', \$err) or die;
|
||
|
||
local *STDOUT = $out_fh;
|
||
local *STDERR = $err_fh;
|
||
|
||
local $::form = Form->new;
|
||
$::form->{$_} = $form->{$_} for keys %$form;
|
||
$::form->{script} = $script.'.pl'; # usually set by dispatcher, needed for checks in update_exchangerate
|
||
local $ENV{REQUEST_URI} = "http://localhost/$script.pl"; # needed for Form::redirect_header
|
||
|
||
no strict "refs";
|
||
eval {
|
||
no warnings;
|
||
@ret = &{ "::$action" }();
|
||
1;
|
||
} or do { my $err = $@;
|
||
die unless $err =~ /^END_OF_REQUEST/;
|
||
@ret = (1);
|
||
}
|
||
}
|
||
return ($out, $err, @ret);
|
||
}
|
||
|
||
sub form_from_html {
|
||
my ($html) = @_;
|
||
my $q = HTML::Query->new(text => $html);
|
||
|
||
my %form;
|
||
for my $input ($q->query('#form input')->get_elements()) {
|
||
next if !$input->attr('name') || $input->attr('disabled');
|
||
$form{ $input->attr('name') } = $input->attr('value') // "";
|
||
tests: t/fx/aptransactions.t auf t/Support/Integration.pm umgeschrieben