785ae5db71388311e25738ff4cf86af25be7be06
[catagits/Catalyst-Runtime.git] / t / live_priorities.t
1 #!perl
2
3 use strict;
4 use warnings;
5
6 use FindBin;
7 use lib "$FindBin::Bin/lib";
8
9 use Test::More tests => 28;
10 use Catalyst::Test 'TestApp';
11 use Data::Dumper;
12
13 local $^W = 0;
14
15 my $uri_base = 'http://localhost/priorities';
16 my @tests = (
17
18     #   Simple
19     'Regex vs. Local',      { path => '/re_vs_loc',      expect => 'local' },
20     'Regex vs. LocalRegex', { path => '/re_vs_locre',    expect => 'regex' },
21     'Regex vs. Path',       { path => '/re_vs_path',     expect => 'path' },
22     'Local vs. LocalRegex', { path => '/loc_vs_locre',   expect => 'local' },
23     'Local vs. Path 1',     { path => '/loc_vs_path1',   expect => 'local' },
24     'Local vs. Path 2',     { path => '/loc_vs_path2',   expect => 'path' },
25     'Path  vs. LocalRegex', { path => '/path_vs_locre',  expect => 'path' },
26
27     #   index
28     'index vs. Regex',      { path => '/re_vs_index',    expect => 'index' },
29     'index vs. Local',      { path => '/loc_vs_index',   expect => 'index' },
30     'index vs. LocalRegex', { path => '/locre_vs_index', expect => 'index' },
31     'index vs. Path',       { path => '/path_vs_index',  expect => 'index' },
32
33     'multimethod zero',     { path => '/multimethod',    expect => 'zero' },
34     'multimethod one',      { path => '/multimethod/1',  expect => 'one 1' },
35     'multimethod two',      { path => '/multimethod/1/2',
36                                                          expect => 'two 1 2' },
37 );
38
39 while ( @tests ) {
40
41     my $name = shift @tests;
42     my $data = shift @tests;
43
44     #   Run tests for path with trailing slash and without
45   SKIP: for my $req_uri 
46     ( 
47         join( '' => $uri_base, $data->{ path } ),      # Without trailing path
48         join( '' => $uri_base, $data->{ path }, '/' ), # With trailing path
49     ) {
50         my $end_slash = ( $req_uri =~ qr(/$) ? 1 : 0 );
51
52         #   use slash_expect argument if URI ends with slash 
53         #   and the slash_expect argument is defined
54         my $expect = $data->{ expect } || '';
55         if ( $end_slash and exists $data->{ slash_expect } ) {
56             $expect = $data->{ slash_expect };
57         }
58
59         #   Call the URI on the TestApp
60         my $response = request( $req_uri );
61
62         #   Leave expect out to see the result
63         unless ( $expect ) {
64             skip 'Nothing expected, winner is ' . $response->content, 1;
65         }
66
67         #   Show error if response was no success
68         if ( not $response->is_success ) {
69             diag 'Error: ' . $response->headers->{ 'x-catalyst-error' };
70         }
71
72         #   Test if content matches expectations.
73         #   TODO This might flood the screen with the catalyst please-come-later
74         #        page. So I don't know it is a good idea.
75         is( $response->content, $expect,
76             "$name: @{[ $data->{ expect } ]} wins"
77             . ( $end_slash ? ' (trailing slash)' : '' )
78         );
79     }
80 }
81