comparison sub_filter.t @ 304:6bee817c9e97

Tests: sub filter tests.
author Maxim Dounin <mdounin@mdounin.ru>
date Mon, 08 Jul 2013 20:50:09 +0400
parents
children e9de4da234c0
comparison
equal deleted inserted replaced
303:ad51e58c2d7a 304:6bee817c9e97
1 #!/usr/bin/perl
2
3 # (C) Maxim Dounin
4
5 # Tests for sub filter.
6
7 ###############################################################################
8
9 use warnings;
10 use strict;
11
12 use Test::More;
13
14 use Socket qw/ CRLF /;
15
16 BEGIN { use FindBin; chdir($FindBin::Bin); }
17
18 use lib 'lib';
19 use Test::Nginx;
20
21 ###############################################################################
22
23 select STDERR; $| = 1;
24 select STDOUT; $| = 1;
25
26 my $t = Test::Nginx->new()->has(qw/http rewrite sub/)->plan(14)
27 ->write_file_expand('nginx.conf', <<'EOF');
28
29 %%TEST_GLOBALS%%
30
31 daemon off;
32
33 events {
34 }
35
36 http {
37 %%TEST_GLOBALS_HTTP%%
38
39 server {
40 listen 127.0.0.1:8080;
41 server_name localhost;
42
43 sub_filter_types *;
44 sub_filter foo bar;
45
46 location / {
47 }
48
49 location /once {
50 return 200 $arg_b;
51 }
52
53 location /many {
54 sub_filter_once off;
55 return 200 $arg_b;
56 }
57
58 location /complex {
59 sub_filter abac _replaced;
60 return 200 $arg_b;
61 }
62
63 location /complex2 {
64 sub_filter ababX _replaced;
65 return 200 $arg_b;
66 }
67
68 location /complex3 {
69 sub_filter aab _replaced;
70 return 200 $arg_b;
71 }
72 }
73 }
74
75 EOF
76
77 $t->write_file('foo.html', 'foo');
78 $t->write_file('foofoo.html', 'foofoo');
79 $t->run();
80
81 ###############################################################################
82
83 like(http_get('/foo.html'), qr/bar/, 'sub_filter');
84 like(http_get('/foofoo.html'), qr/barfoo/, 'once default');
85
86 like(http_get('/once?b=foofoo'), qr/barfoo/, 'once');
87 like(http_get('/many?b=foofoo'), qr/barbar/, 'many');
88
89 TODO: {
90 local $TODO = 'not yet';
91
92 like(http_get('/many?b=fo'), qr/fo/, 'incomplete');
93 like(http_get('/many?b=foofo'), qr/barfo/, 'incomplete long');
94
95 }
96
97 like(http_get('/complex?b=abac'), qr/_replaced/, 'complex');
98 like(http_get('/complex?b=abaabac'), qr/aba_replaced/, 'complex 1st char');
99
100 TODO: {
101 local $TODO = 'not yet';
102
103 like(http_get('/complex?b=ababac'), qr/replaced/, 'complex 2nd char');
104
105 }
106
107 like(http_get('/complex2?b=ababX'), qr/_replaced/, 'complex2');
108
109 TODO: {
110 local $TODO = 'not yet';
111
112 like(http_get('/complex2?b=abababX'), qr/ab_replaced/, 'complex2 long');
113
114 }
115
116 like(http_get('/complex3?b=aab'), qr/_replaced/, 'complex3 aab in aab');
117
118 TODO: {
119 local $TODO = 'not yet';
120
121 like(http_get('/complex3?b=aaab'), qr/a_replaced/, 'complex3 aab in aaab');
122
123 }
124
125 like(http_get('/complex3?b=aaaab'), qr/aa_replaced/, 'complex3 aab in aaaab');
126
127 ###############################################################################