r12983@zaphod: kd | 2008-04-28 18:10:27 +1000
[catagits/Catalyst-Runtime.git] / t / live_priorities.t
CommitLineData
6ea96b03 1#!perl
2
3use strict;
4use warnings;
5
6use FindBin;
7use lib "$FindBin::Bin/lib";
8
0bd5f8a2 9use Test::More tests => 28;
6ea96b03 10use Catalyst::Test 'TestApp';
6ea96b03 11
12local $^W = 0;
13
14my $uri_base = 'http://localhost/priorities';
15my @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' },
0bd5f8a2 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' },
6ea96b03 36);
37
38while ( @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