44a21851757d61c3a783646bc61b0bd49a1518ae
[catagits/Catalyst-Runtime.git] / t / lib / TestApp / Controller / Engine / Request / URI.pm
1 package TestApp::Controller::Engine::Request::URI;
2
3 use strict;
4 use base 'Catalyst::Base';
5
6 sub default : Private {
7     my ( $self, $c ) = @_;
8     
9     $c->forward('TestApp::View::Dump::Request');
10 }
11
12 sub change_path : Local {
13     my ( $self, $c ) = @_;
14     
15     # change the path
16     $c->req->path( '/my/app/lives/here' );
17     
18     $c->forward('TestApp::View::Dump::Request');
19 }
20
21 sub change_base : Local {
22     my ( $self, $c ) = @_;
23     
24     # change the base and uri paths
25     $c->req->base->path( '/new/location' );
26     $c->req->uri->path( '/new/location/engine/request/uri/change_base' );
27     
28     $c->forward('TestApp::View::Dump::Request');
29 }
30
31 sub uri_with : Local {
32     my ( $self, $c ) = @_;
33
34     # change the current uri
35     my $uri   = $c->req->uri_with( { b => 1 } );
36     my %query = $uri->query_form;
37     
38     $c->res->header( 'X-Catalyst-Param-a' => $query{ a } );
39     $c->res->header( 'X-Catalyst-Param-b' => $query{ b } );
40     
41     $c->forward('TestApp::View::Dump::Request');
42 }
43
44 sub uri_with_object : Local {
45     my ( $self, $c ) = @_;
46
47     my $uri   = $c->req->uri_with( { a => $c->req->base } );
48     my %query = $uri->query_form;
49     
50     $c->res->header( 'X-Catalyst-Param-a' => $query{ a } );
51     
52     $c->forward('TestApp::View::Dump::Request');
53 }
54
55 sub uri_with_utf8 : Local {
56     my ( $self, $c ) = @_;
57
58     # change the current uri
59     my $uri = $c->req->uri_with( { unicode => "\x{2620}" } );
60     
61     $c->res->header( 'X-Catalyst-uri-with' => "$uri" );
62     
63     $c->forward('TestApp::View::Dump::Request');
64 }
65
66 sub uri_with_undef : Local {
67     my ( $self, $c ) = @_;
68
69     my $warnings = 0;
70     local $SIG{__WARN__} = sub { $warnings++ };
71
72     # change the current uri
73     my $uri = $c->req->uri_with( { foo => undef } );
74     
75     $c->res->header( 'X-Catalyst-warnings' => $warnings );
76     
77     $c->forward('TestApp::View::Dump::Request');
78 }
79
80 sub uri_with_undef_only : Local {
81     my ( $self, $c ) = @_;
82
83     my $uri = $c->req->uri_with( { a => undef } );
84     
85     $c->res->header( 'X-Catalyst-uri-with' => "$uri" );
86     $c->forward('TestApp::View::Dump::Request');
87 }
88
89 sub uri_with_undef_ignore : Local {
90     my ( $self, $c ) = @_;
91
92     my $uri = $c->req->uri_with( { a => 1, b => undef } );
93     
94     my %query = $uri->query_form;
95     $c->res->header( 'X-Catalyst-uri-with' => "$uri" );
96     $c->res->header( 'X-Catalyst-Param-a' => $query{ a } );
97     $c->res->header( 'X-Catalyst-Param-b' => $query{ b } );
98     $c->res->header( 'X-Catalyst-Param-c' => $query{ c } );
99     $c->forward('TestApp::View::Dump::Request');
100 }
101
102 1;