[Rt-commit] rt branch, 4.0/redirect-tests, created. rt-4.0.2-58-g4ed94ce

Ruslan Zakirov ruz at bestpractical.com
Thu Sep 8 11:24:11 EDT 2011


The branch, 4.0/redirect-tests has been created
        at  4ed94cec491c606d1fbb410ad13c8541c3a51d1f (commit)

- Log -----------------------------------------------------------------
commit 4ed94cec491c606d1fbb410ad13c8541c3a51d1f
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Thu Sep 8 19:23:11 2011 +0400

    test how we generate urls during redirect

diff --git a/t/web/redirect.t b/t/web/redirect.t
new file mode 100644
index 0000000..492db84
--- /dev/null
+++ b/t/web/redirect.t
@@ -0,0 +1,106 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use RT::Test tests => 122;
+
+my $r = $HTML::Mason::Commands::r = bless {}, 'R';
+my $m = $HTML::Mason::Commands::m = bless {}, 'M';
+
+set_config(
+    CanonicalizeRedirectURLs => 0,
+    WebDomain => 'localhost',
+    WebPort => 80,
+    WebPath => '',
+);
+is( RT->Config->Get('WebBaseURL'), 'http://localhost' );
+is( RT->Config->Get('WebURL'), 'http://localhost/' );
+
+redirect_ok(
+    'http://localhost/Ticket/', 'http://localhost/Ticket/',
+    { SERVER_NAME => 'localhost', SERVER_PORT => 80 },
+);
+redirect_ok(
+    '/Ticket/', 'http://localhost/Ticket/',
+    { SERVER_NAME => 'localhost', SERVER_PORT => 80 },
+);
+redirect_ok(
+    'http://localhost/Ticket/', 'http://example.com/Ticket/',
+    { SERVER_NAME => 'example.com', SERVER_PORT => 80 },
+);
+
+set_config(
+    CanonicalizeRedirectURLs => 0,
+    WebDomain => 'localhost',
+    WebPort => 443,
+    WebPath => '',
+);
+is( RT->Config->Get('WebBaseURL'), 'https://localhost' );
+is( RT->Config->Get('WebURL'), 'https://localhost/' );
+
+redirect_ok(
+    'https://localhost/Ticket/', 'https://localhost/Ticket/',
+    { SERVER_NAME => 'localhost', SERVER_PORT => 443, HTTPS => 'on' },
+);
+redirect_ok(
+    '/Ticket/', 'https://localhost/Ticket/',
+    { SERVER_NAME => 'localhost', SERVER_PORT => 443, HTTPS => 'on' },
+);
+redirect_ok(
+    'https://localhost/Ticket/', 'http://localhost/Ticket/',
+    { SERVER_NAME => 'localhost', SERVER_PORT => 80 },
+);
+redirect_ok(
+    '/Ticket/', 'http://localhost/Ticket/',
+    { SERVER_NAME => 'localhost', SERVER_PORT => 80 },
+);
+redirect_ok(
+    'https://localhost/Ticket/', 'http://example.com/Ticket/',
+    { SERVER_NAME => 'example.com', SERVER_PORT => 80 },
+);
+redirect_ok(
+    'https://localhost/Ticket/', 'https://example.com/Ticket/',
+    { SERVER_NAME => 'example.com', SERVER_PORT => 443, HTTPS => 'on' },
+);
+
+sub set_config {
+    my %values = @_;
+    while ( my ($k, $v) = each %values ) {
+        RT->Config->Set( $k => $v );
+    }
+
+    unless ( $values{'WebBaseURL'} ) {
+        my $port = RT->Config->Get('WebPort');
+        RT->Config->Set(
+            WebBaseURL => 
+                ($port == 443? 'https': 'http') .'://'
+                . RT->Config->Get('WebDomain')
+                . ($port != 80 && $port != 443? ":$port" : '')
+        );
+    }
+    unless ( $values{'WebURL'} ) {
+        RT->Config->Set(
+            WebURL => RT->Config->Get('WebBaseURL') . RT->Config->Get('WebPath') . "/"
+        );
+    }
+}
+
+sub redirect_ok {
+    my ($to, $expected, $env, $details) = @_;
+
+    local %ENV = %ENV;
+    while ( my ($k, $v) = each %{ $env || {} } ) {
+        $ENV{ $k } = $v;
+    }
+    RT::Interface::Web::Redirect( $to );
+    is($m->redirect, $expected, $details || "correct for '$to'");
+}
+
+package R;
+sub status {};
+
+package M;
+sub redirect { $_[0]{'last'} = $_[1] if @_ > 1; return $_[0]{'last'} }
+sub abort {}
+

-----------------------------------------------------------------------


More information about the Rt-commit mailing list