improved docs for action_namespace and path_prefix and made path configurable
[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
9use Test::More tests => 22;
10use Catalyst::Test 'TestApp';
11use Data::Dumper;
12
13local $^W = 0;
14
15my $uri_base = 'http://localhost/priorities';
16my @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
34while ( @tests ) {
35
36 my $name = shift @tests;
37 my $data = shift @tests;
38
39 # Run tests for path with trailing slash and without
40 SKIP: for my $req_uri
41 (
42 join( '' => $uri_base, $data->{ path } ), # Without trailing path
43 join( '' => $uri_base, $data->{ path }, '/' ), # With trailing path
44 ) {
45 my $end_slash = ( $req_uri =~ qr(/$) ? 1 : 0 );
46
47 # use slash_expect argument if URI ends with slash
48 # and the slash_expect argument is defined
49 my $expect = $data->{ expect } || '';
50 if ( $end_slash and exists $data->{ slash_expect } ) {
51 $expect = $data->{ slash_expect };
52 }
53
54 # Call the URI on the TestApp
55 my $response = request( $req_uri );
56
57 # Leave expect out to see the result
58 unless ( $expect ) {
59 skip 'Nothing expected, winner is ' . $response->content, 1;
60 }
61
62 # Show error if response was no success
63 if ( not $response->is_success ) {
64 diag 'Error: ' . $response->headers->{ 'x-catalyst-error' };
65 }
66
67 # Test if content matches expectations.
68 # TODO This might flood the screen with the catalyst please-come-later
69 # page. So I don't know it is a good idea.
70 is( $response->content, $expect,
71 "$name: @{[ $data->{ expect } ]} wins"
72 . ( $end_slash ? ' (trailing slash)' : '' )
73 );
74 }
75}
76