first pass RT4 merge, RT#13852
[freeside.git] / rt / t / api / web-config.t
1 use strict;
2 use warnings;
3 use RT;
4 use RT::Test nodb => 1, tests => 89;
5
6 sub no_warnings_ok {
7     local $Test::Builder::Level = $Test::Builder::Level + 1;
8
9     my $option = shift;
10     my $value  = shift;
11     my $name   = shift;
12
13     is(warnings_from($option => $value), 0, $name);
14 }
15
16 sub one_warning_like {
17     local $Test::Builder::Level = $Test::Builder::Level + 1;
18
19     my $option = shift;
20     my $value  = shift;
21     my $regex  = shift;
22     my $name   = shift;
23
24     my @w = warnings_from($option => $value);
25     is(@w, 1);
26     like($w[0], $regex, $name);
27 }
28
29
30 sub warnings_from {
31     my $option = shift;
32     my $value  = shift;
33
34     my @warnings;
35     local $SIG{__WARN__} = sub {
36         push @warnings, $_[0];
37     };
38
39     RT->Config->Set($option => $value);
40     RT->Config->PostLoadCheck;
41
42     return @warnings;
43 }
44
45 # WebPath
46 no_warnings_ok(WebPath => '');
47 no_warnings_ok(WebPath => '/foo');
48 no_warnings_ok(WebPath => '/foo/bar');
49
50 one_warning_like(WebPath => '/foo/', qr/The WebPath config option requires no trailing slash/);
51
52 one_warning_like(WebPath => 'foo', qr/The WebPath config option requires a leading slash/);
53
54 my @w = warnings_from(WebPath => 'foo/');
55 is(@w, 2);
56 like($w[0], qr/The WebPath config option requires no trailing slash/);
57 like($w[1], qr/The WebPath config option requires a leading slash/);
58
59 one_warning_like(WebPath => '/foo/bar/', qr/The WebPath config option requires no trailing slash/);
60
61 one_warning_like(WebPath => 'foo/bar', qr/The WebPath config option requires a leading slash/);
62
63 @w = warnings_from(WebPath => 'foo/bar/');
64 is(@w, 2);
65 like($w[0], qr/The WebPath config option requires no trailing slash/);
66 like($w[1], qr/The WebPath config option requires a leading slash/);
67
68 one_warning_like(WebPath => '/', qr{For the WebPath config option, use the empty string instead of /});
69
70 # reinstate a valid WebPath for other tests
71 no_warnings_ok(WebPath => '/rt');
72
73 # WebDomain
74 no_warnings_ok(WebDomain => 'example.com');
75 no_warnings_ok(WebDomain => 'rt.example.com');
76 no_warnings_ok(WebDomain => 'localhost');
77
78 one_warning_like(WebDomain => '', qr{You must set the WebDomain config option});
79
80 one_warning_like(WebDomain => 'http://rt.example.com', qr{The WebDomain config option must not contain a scheme \(http://\)});
81
82 one_warning_like(WebDomain => 'https://rt.example.com', qr{The WebDomain config option must not contain a scheme \(https://\)});
83
84 one_warning_like(WebDomain => 'rt.example.com/path', qr{The WebDomain config option must not contain a path \(/path\)});
85
86 one_warning_like(WebDomain => 'rt.example.com/path/more', qr{The WebDomain config option must not contain a path \(/path/more\)});
87
88 one_warning_like(WebDomain => 'rt.example.com:80', qr{The WebDomain config option must not contain a port \(80\)});
89
90 # reinstate a valid WebDomain for other tests
91 no_warnings_ok(WebDomain => 'rt.example.com');
92
93 # WebPort
94 no_warnings_ok(WebDomain => 80);
95 no_warnings_ok(WebDomain => 443);
96 no_warnings_ok(WebDomain => 8888);
97
98 one_warning_like(WebPort => '', qr{You must set the WebPort config option});
99
100 one_warning_like(WebPort => 3.14, qr{The WebPort config option must be an integer});
101
102 one_warning_like(WebPort => 'wha?', qr{The WebPort config option must be an integer});
103
104 # reinstate a valid WebDomain for other tests
105 no_warnings_ok(WebPort => 443);
106
107 # WebBaseURL
108 no_warnings_ok(WebBaseURL => 'http://rt.example.com');
109 no_warnings_ok(WebBaseURL => 'HTTP://rt.example.com', 'uppercase scheme is okay');
110 no_warnings_ok(WebBaseURL => 'http://rt.example.com:8888', 'nonstandard port is okay');
111 no_warnings_ok(WebBaseURL => 'https://rt.example.com:8888', 'nonstandard port with https is okay');
112
113 one_warning_like(WebBaseURL => '', qr{You must set the WebBaseURL config option});
114
115 one_warning_like(WebBaseURL => 'rt.example.com', qr{The WebBaseURL config option must contain a scheme});
116
117 one_warning_like(WebBaseURL => 'xtp://rt.example.com', qr{The WebBaseURL config option must contain a scheme \(http or https\)});
118
119 one_warning_like(WebBaseURL => 'http://rt.example.com/', qr{The WebBaseURL config option requires no trailing slash});
120
121 one_warning_like(WebBaseURL => 'http://rt.example.com/rt', qr{The WebBaseURL config option must not contain a path \(/rt\)});
122
123 @w = warnings_from(WebBaseURL => 'http://rt.example.com/rt/');
124 is(@w, 2);
125 like($w[0], qr{The WebBaseURL config option requires no trailing slash});
126 like($w[1], qr{The WebBaseURL config option must not contain a path \(/rt/\)});
127
128 one_warning_like(WebBaseURL => 'http://rt.example.com/rt/ir', qr{The WebBaseURL config option must not contain a path \(/rt/ir\)});
129
130 @w = warnings_from(WebBaseURL => 'http://rt.example.com/rt/ir/');
131 is(@w, 2);
132 like($w[0], qr{The WebBaseURL config option requires no trailing slash});
133 like($w[1], qr{The WebBaseURL config option must not contain a path \(/rt/ir/\)});
134
135 # reinstate a valid WebBaseURL for other tests
136 no_warnings_ok(WebBaseURL => 'http://rt.example.com');
137
138 # WebURL
139 no_warnings_ok(WebURL => 'http://rt.example.com/');
140 no_warnings_ok(WebURL => 'HTTP://rt.example.com/', 'uppercase scheme is okay');
141 no_warnings_ok(WebURL => 'http://example.com/rt/');
142 no_warnings_ok(WebURL => 'http://example.com/rt/ir/');
143 no_warnings_ok(WebURL => 'http://rt.example.com:8888/', 'nonstandard port is okay');
144 no_warnings_ok(WebURL => 'https://rt.example.com:8888/', 'nonstandard port with https is okay');
145
146 one_warning_like(WebURL => '', qr{You must set the WebURL config option});
147
148 @w = warnings_from(WebURL => 'rt.example.com');
149 is(@w, 2);
150 like($w[0], qr{The WebURL config option must contain a scheme});
151 like($w[1], qr{The WebURL config option requires a trailing slash});
152
153 one_warning_like(WebURL => 'http://rt.example.com', qr{The WebURL config option requires a trailing slash});
154
155 one_warning_like(WebURL => 'xtp://example.com/rt/', qr{The WebURL config option must contain a scheme \(http or https\)});
156
157 one_warning_like(WebURL => 'http://rt.example.com/rt', qr{The WebURL config option requires a trailing slash});
158
159 one_warning_like(WebURL => 'http://rt.example.com/rt/ir', qr{The WebURL config option requires a trailing slash});
160
161 # reinstate a valid WebURL for other tests
162 no_warnings_ok(WebURL => 'http://rt.example.com/rt/');
163