Catalyst-Runtime

 view release on metacpan or  search on metacpan

t/aggregate/live_engine_request_parameters.t  view on Meta::CPAN

use strict;
use warnings;

use FindBin;
use lib "$FindBin::Bin/../lib";

use Test::More tests => 56;
use Catalyst::Test 'TestApp';

use Catalyst::Request;
use HTTP::Headers;
use HTTP::Request::Common;

{
    my $creq;

    my $parameters = { 'a' => [qw(A b C d E f G)], };

    my $query = join( '&', map { 'a=' . $_ } @{ $parameters->{a} } );

    ok( my $response = request("http://localhost/dump/request?$query"),
        'Request' );
    ok( $response->is_success, 'Response Successful 2xx' );
    is( $response->content_type, 'text/plain', 'Response Content-Type' );
    like(
        $response->content,
        qr/^bless\( .* 'Catalyst::Request' \)$/s,
        'Content is a serialized Catalyst::Request'
    );
    ok( eval '$creq = ' . $response->content, 'Unserialize Catalyst::Request' );
    isa_ok( $creq, 'Catalyst::Request' )
      or fail("EXCEPTION: $@");
    is( $creq->method, 'GET', 'Catalyst::Request method' );
    is_deeply( $creq->parameters, $parameters,
        'Catalyst::Request parameters' );
}
{
    my $creq;
    ok( my $response = request("http://localhost/dump/request?q=foo%2bbar"),
        'Request' );
    ok( $response->is_success, 'Response Successful 2xx' );
    is( $response->content_type, 'text/plain', 'Response Content-Type' );
    ok( eval '$creq = ' . $response->content );
    is $creq->parameters->{q}, 'foo+bar', '%2b not double decoded';
}

{
    my $creq;
    ok( my $response = request("http://localhost/dump/request?q=foo=bar"),
        'Request' );
    ok( $response->is_success, 'Response Successful 2xx' );
    is( $response->content_type, 'text/plain', 'Response Content-Type' );
    ok( eval '$creq = ' . $response->content );
    is $creq->parameters->{q}, 'foo=bar', '= not ignored';
}

{
    my $creq;

    my $parameters = {
        'a'     => [qw(A b C d E f G)],
        '%'     => [ '%', '"', '& - &' ],
        'blank' => '',
    };

    my $request = POST(
        'http://localhost/dump/request/a/b?a=1&a=2&a=3',
        'Content'      => $parameters,
        'Content-Type' => 'application/x-www-form-urlencoded'
    );

    ok( my $response = request($request), 'Request' );



( run in 1.237 second using v1.01-cache-2.11-cpan-39bf76dae61 )