Skip %2F and period tests on remote servers
[catagits/Catalyst-Runtime.git] / t / live_component_controller_args.t
1 #!perl
2
3 use strict;
4 use warnings;
5
6 use FindBin;
7 use lib "$FindBin::Bin/lib";
8
9 use URI::Escape;
10
11 our @paths;
12 our $iters;
13
14 BEGIN { $iters = $ENV{CAT_BENCH_ITERS} || 1;
15
16         # add special paths to test here
17         @paths = (
18                     # all reserved in uri's
19                     qw~ : / ? [ ] @ ! $ & ' ( ) * + ; = ~, ',' , '#',
20
21                     # unreserved
22                     'a'..'z','A'..'Z',0..9,qw( - . _ ~ ),
23                     " ",
24
25                     # just to test %2F/%
26                     [ qw~ / / ~ ],
27
28                     # testing %25/%25
29                     [ qw~ % % ~ ],
30                  );
31 }
32
33 use Test::More tests => 6*@paths * $iters;
34 use Catalyst::Test 'TestApp';
35
36 if ( $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 }
45 else {
46     for ( 1 .. $iters ) {
47         run_tests();
48     }
49 }
50
51 sub run_tests {
52     run_test_for($_) for @paths;
53 }
54
55 sub 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     }
65     
66     SKIP:
67     {   
68         # Skip %2F and . tests on real webservers, they are often ignored by default
69         if ( $ENV{CATALYST_SERVER} && $path =~ /(?:%2F|\.)/ ) {
70             skip "Skipping $path tests on remote server", 6;
71         }
72
73         my $response;
74
75         ok( $response = request("http://localhost/args/args/$path"), "Requested args for path $path");
76
77         is( $response->content, $test, "$test as args" );
78
79         undef $response;
80
81         ok( $response = request("http://localhost/args/params/$path"), "Requested params for path $path");
82
83         is( $response->content, $test, "$test as params" );
84
85         undef $response;
86
87         if( $test =~ m{/} ) {
88             $test =~ s{/}{}g;
89             $path = uri_escape( $test ); 
90         }
91
92         ok( $response = request("http://localhost/chained/multi_cap/$path/baz"), "Requested capture for path $path");
93
94         is( $response->content, join( ', ', split( //, $test ) ) ."; ", "$test as capture" );
95     }
96 }
97