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