Catalyst-Engine-Apache

 view release on metacpan or  search on metacpan

t/author-live_engine_request_parameters.t  view on Meta::CPAN

#!perl

BEGIN {
  unless ($ENV{AUTHOR_TESTING}) {
    require Test::More;
    Test::More::plan(skip_all => 'these tests are for testing by the author');
  }
}


use strict;
use warnings;

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

use Test::More tests => 35;
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' );
    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;

    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'
    );

    unshift( @{ $parameters->{a} }, 1, 2, 3 );

    ok( my $response = request($request), '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' );



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