Add Catalyst::Test::crequest to return both HTTP::Response object & $c for
[catagits/Catalyst-Runtime.git] / t / live_component_controller_args.t
CommitLineData
855ed931 1#!perl
2
3use strict;
4use warnings;
5
6use FindBin;
7use lib "$FindBin::Bin/lib";
8
9use URI::Escape;
10
11our @paths;
12our $iters;
13
12cd259d 14BEGIN { $iters = $ENV{CAT_BENCH_ITERS} || 1;
855ed931 15
c7ded7aa 16 # add special paths to test here
17 @paths = (
18 # all reserved in uri's
19 qw~ : / ? [ ] @ ! $ & ' ( ) * + ; = ~, ',' , '#',
855ed931 20
c7ded7aa 21 # unreserved
22 'a'..'z','A'..'Z',0..9,qw( - . _ ~ ),
23 " ",
855ed931 24
c7ded7aa 25 # just to test %2F/%
26 [ qw~ / / ~ ],
855ed931 27
c7ded7aa 28 # testing %25/%25
29 [ qw~ % % ~ ],
30 );
855ed931 31}
32
642026ea 33use Test::More tests => 6*@paths * $iters;
855ed931 34use Catalyst::Test 'TestApp';
35
36if ( $ENV{CAT_BENCHMARK} ) {
37 require Benchmark;
38 Benchmark::timethis( $iters, \&run_tests );
39
40 # new dispatcher:
41 # 11 wallclock secs (10.14 usr + 0.20 sys = 10.34 CPU) @ 15.18/s (n=157)
42 # old dispatcher (r1486):
43 # 11 wallclock secs (10.34 usr + 0.20 sys = 10.54 CPU) @ 13.76/s (n=145)
44}
45else {
46 for ( 1 .. $iters ) {
47 run_tests();
48 }
49}
50
51sub run_tests {
52 run_test_for($_) for @paths;
53}
54
55sub run_test_for {
56 my $test = shift;
57
58 my $path;
59 if (ref $test) {
60 $path = join "/", map uri_escape($_), @$test;
61 $test = join '', @$test;
62 } else {
63 $path = uri_escape($test);
64 }
12cd259d 65
66 SKIP:
67 {
e7ca2e0e 68 # Skip %2F, ., [, (, and ) tests on real webservers
69 # Both Apache and lighttpd don't seem to like these
70 if ( $ENV{CATALYST_SERVER} && $path =~ /(?:%2F|\.|%5B|\(|\))/ ) {
12cd259d 71 skip "Skipping $path tests on remote server", 6;
72 }
855ed931 73
12cd259d 74 my $response;
855ed931 75
12cd259d 76 ok( $response = request("http://localhost/args/args/$path"), "Requested args for path $path");
855ed931 77
12cd259d 78 is( $response->content, $test, "$test as args" );
855ed931 79
12cd259d 80 undef $response;
855ed931 81
12cd259d 82 ok( $response = request("http://localhost/args/params/$path"), "Requested params for path $path");
855ed931 83
12cd259d 84 is( $response->content, $test, "$test as params" );
642026ea 85
12cd259d 86 undef $response;
642026ea 87
12cd259d 88 if( $test =~ m{/} ) {
89 $test =~ s{/}{}g;
90 $path = uri_escape( $test );
91 }
642026ea 92
12cd259d 93 ok( $response = request("http://localhost/chained/multi_cap/$path/baz"), "Requested capture for path $path");
642026ea 94
12cd259d 95 is( $response->content, join( ', ', split( //, $test ) ) ."; ", "$test as capture" );
96 }
855ed931 97}
98