Apache-ExtDirect
view release on metacpan or search on metacpan
t/03_poll.t view on Meta::CPAN
or die "Can't eval $dfile: '$@'";
for my $test ( @$tests ) {
my $name = $test->{name};
my $url = $test->{plack_url};
my $method = lc $test->{method};
my $input_content = $test->{input_content};
my $http_status_exp = $test->{http_status};
my $content_regex = $test->{content_type};
my $expected_output = $test->{expected_content};
my $password = $test->{password};
my $password_file = '/tmp/apache-extdirect-password';
if ( $password ) {
open my $fh, '>', $password_file
or BAIL_OUT "Can't open $password_file: $!\n";
print $fh $password;
close $fh;
};
my $ua = LWP::UserAgent->new(requests_redirectable => []);
my $res = $ua->$method($url, @$input_content);
if ( ok $res, "$name not empty" ) {
my $content_type = $res->content_type();
my $http_status = $res->code;
t/03_poll.t view on Meta::CPAN
is $http_status, $http_status_exp, "$name HTTP status";
my $http_output = $res->content();
$http_output =~ s/\s//g;
$expected_output =~ s/\s//g;
is $http_output, $expected_output, "$name content"
or diag explain $res;
};
unlink $password_file if $password;
};
exit 0;
sub raw_post {
my $input = shift;
use bytes;
my $cgi_input = CGI::Test::Input::URL->new();
$cgi_input->add_field('POSTDATA', $input);
t/data/extdirect/poll view on Meta::CPAN
[
{ name => 'Two events', method => 'POST',
password => 'Usual, please',
cgi_url => 'http://localhost/cgi-bin/poll1.cgi',
plack_url => 'http://localhost:8529/events',
plack_input => [ poll_path => '/events', debug => 1, ],
input_content => undef,
http_status => 200, content_type => qr|^application/json\b|,
expected_content =>
q|[{"data":["foo"],|.
q| "name":"foo_event",|.
q| "type":"event"},|.
q| {"data":{"foo":"bar"},|.
q| "name":"bar_event",|.
q| "type":"event"}]|,
},
{ name => 'One event', method => 'POST',
password => 'Ein kaffe bitte',
cgi_url => 'http://localhost/cgi-bin/poll2.cgi',
plack_url => 'http://localhost:8529/events',
plack_input => [ poll_path => '/events', debug => 1, ],
input_content => undef,
http_status => 200, content_type => qr|^application/json\b|,
expected_content =>
q|{"data":"Uno cappuccino, presto!",|.
q| "name":"coffee",|.
q| "type":"event"}|,
},
{ name => 'Failed method', method => 'POST',
password => 'Whiskey, straight away!',
cgi_url => 'http://localhost/cgi-bin/poll3.cgi',
plack_url => 'http://localhost:8529/events',
plack_input => [ poll_path => '/events', debug => 1, ],
input_content => undef,
http_status => 200, content_type => qr|^application/json\b|,
expected_content => q|{"data":"","name":"__NONE__","type":"event"}|,
},
{ name => 'No events at all', method => 'POST',
password => "Sorry sir, but that's not on the menu?",
cgi_url => 'http://localhost/cgi-bin/poll4.cgi',
plack_url => 'http://localhost:8529/events',
plack_input => [ poll_path => '/events', debug => 1, ],
input_content => undef,
http_status => 200, content_type => qr|^application/json\b|,
expected_content => q|{"data":"","name":"__NONE__","type":"event"}|,
},
{ name => 'Invalid Event provider output', method => 'POST',
password => "Hey man! There's a roach in my soup!",
cgi_url => 'http://localhost/cgi-bin/poll5.cgi',
plack_url => 'http://localhost:8529/events',
plack_input => [ poll_path => '/events', debug => 1, ],
input_content => undef,
http_status => 200, content_type => qr|^application/json\b|,
expected_content => q|{"data":"","name":"__NONE__","type":"event"}|,
},
]
t/lib/RPC/ExtDirect/Test/PollProvider.pm view on Meta::CPAN
use RPC::ExtDirect;
use RPC::ExtDirect::Event;
# This is to control what gets returned
our $WHAT_YOURE_HAVING = 'Usual, please';
sub foo : ExtDirect( pollHandler ) {
my ($class) = @_;
my $password_file = '/tmp/apache-extdirect-password';
if ( -r $password_file ) {
open my $fh, '<', $password_file;
$WHAT_YOURE_HAVING = <$fh>;
};
# There ought to be something more substantive, but...
if ( $WHAT_YOURE_HAVING eq 'Usual, please' ) {
return (
RPC::ExtDirect::Event->new('foo_event', [ 'foo' ]),
RPC::ExtDirect::Event->new('bar_event', { foo => 'bar' }),
);
}
( run in 1.347 second using v1.01-cache-2.11-cpan-49f99fa48dc )