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