Fix engine_request_uri tests to work on remote server with different URI
[catagits/Catalyst-Runtime.git] / t / aggregate / live_engine_request_uri.t
index 7d1628d..4f60c49 100644 (file)
@@ -4,7 +4,7 @@ use warnings;
 use FindBin;
 use lib "$FindBin::Bin/../lib";
 
-use Test::More tests => 66;
+use Test::More tests => 68;
 use Catalyst::Test 'TestApp';
 use Catalyst::Request;
 
@@ -121,27 +121,31 @@ SKIP:
 # more tests with undef - should be ignored
 {
     my $uri = "http://localhost/engine/request/uri/uri_with_undef_only";
+    my ($check) = $uri =~ m{^http://localhost(.+)}; # needed to work with remote servers
     ok( my $response = request($uri), 'Request' );
     ok( $response->is_success, 'Response Successful 2xx' );
-    is( $response->header( 'X-Catalyst-uri-with' ), $uri, 'uri_with ok' );
+    like( $response->header( 'X-Catalyst-uri-with' ), qr/$check$/, 'uri_with ok' );
 
     # try with existing param
     $uri = "$uri?x=1";
+    ($check) = $uri =~ m{^http://localhost(.+)}; # needed to work with remote servers
+    $check =~ s/\?/\\\?/g;
     ok( $response = request($uri), 'Request' );
     ok( $response->is_success, 'Response Successful 2xx' );
-    is( $response->header( 'X-Catalyst-uri-with' ), $uri, 'uri_with ok' );
+    like( $response->header( 'X-Catalyst-uri-with' ), qr/$check$/, 'uri_with ok' );
 }
 
 {
     my $uri = "http://localhost/engine/request/uri/uri_with_undef_ignore";
+    my ($check) = $uri =~ m{^http://localhost(.+)}; # needed to work with remote servers
     ok( my $response = request($uri), 'Request' );
     ok( $response->is_success, 'Response Successful 2xx' );
-    is( $response->header( 'X-Catalyst-uri-with' ), "${uri}?a=1", 'uri_with ok' );
+    like( $response->header( 'X-Catalyst-uri-with' ), qr/$check\?a=1/, 'uri_with ok' );
 
     # remove an existing param
     ok( $response = request("${uri}?b=1"), 'Request' );
     ok( $response->is_success, 'Response Successful 2xx' );
-    is( $response->header( 'X-Catalyst-uri-with' ), "${uri}?a=1", 'uri_with ok' );
+    like( $response->header( 'X-Catalyst-uri-with' ), qr/$check\?a=1/, 'uri_with ok' );
 
     # remove an existing param, leave one, and add a new one
     ok( $response = request("${uri}?b=1&c=1"), 'Request' );
@@ -151,3 +155,16 @@ SKIP:
     is( $response->header( 'X-Catalyst-Param-c' ), '1', 'param "c" ok' );
 }
 
+# Test an overridden uri method which calls the base method, SmartURI does this.
+SKIP:
+{
+    if ( $ENV{CATALYST_SERVER} ) {
+        skip 'Using remote server', 2;
+    }
+    require TestApp::RequestBaseBug;
+    TestApp->request_class('TestApp::RequestBaseBug');
+    ok( my $response = request('http://localhost/engine/request/uri'), 'Request' );
+    ok( $response->is_success, 'Response Successful 2xx' );
+    TestApp->request_class('Catalyst::Request');
+}