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