ruby-web 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/ChangeLog +474 -0
- data/INSTALL.txt +9 -0
- data/InstalledFiles +180 -0
- data/LICENSE.txt +74 -0
- data/Rakefile +529 -0
- data/TODO +65 -0
- data/doc/additional.xml +149 -0
- data/doc/core.xml +652 -0
- data/doc/credits/index.xml +52 -0
- data/doc/credits/php.contributors.xml +118 -0
- data/doc/credits/php.language-snippets.ent +622 -0
- data/doc/install/index.xml +136 -0
- data/doc/install/mac/index.xml +21 -0
- data/doc/install/ruby-web.install.rb.instructions.xml +7 -0
- data/doc/install/unix/index.xml +46 -0
- data/doc/install/win/apache1.xml +166 -0
- data/doc/install/win/apache2.xml +141 -0
- data/doc/install/win/iis.xml +162 -0
- data/doc/install/win/index.xml +24 -0
- data/doc/install/win/installer.xml +31 -0
- data/doc/install/win/manual.xml +43 -0
- data/doc/manual.xml +69 -0
- data/doc/old/apache_cgi.txt +23 -0
- data/doc/old/fastcgi.txt +23 -0
- data/doc/old/mod_ruby.txt +21 -0
- data/doc/old/snippets.rdoc +183 -0
- data/doc/old/webrick.txt +23 -0
- data/doc/old/windows_cgi.txt +9 -0
- data/doc/tutorial.xml +14 -0
- data/doc/xsl/manual-multi.xsl +10 -0
- data/doc/xsl/manual-pdf.xsl +6 -0
- data/doc/xsl/manual-single.xsl +6 -0
- data/doc/xsl/manual.css +22 -0
- data/install.rb +1022 -0
- data/lib/formatter.rb +314 -0
- data/lib/html-parser.rb +429 -0
- data/lib/htmlrepair.rb +113 -0
- data/lib/htmlsplit.rb +842 -0
- data/lib/sgml-parser.rb +332 -0
- data/lib/web.rb +68 -0
- data/lib/web/assertinclude.rb +129 -0
- data/lib/web/config.rb +50 -0
- data/lib/web/connection.rb +1070 -0
- data/lib/web/convenience.rb +154 -0
- data/lib/web/formreader.rb +318 -0
- data/lib/web/htmlparser/html-parser.rb +429 -0
- data/lib/web/htmlparser/sgml-parser.rb +332 -0
- data/lib/web/htmltools/element.rb +296 -0
- data/lib/web/htmltools/stparser.rb +276 -0
- data/lib/web/htmltools/tags.rb +286 -0
- data/lib/web/htmltools/tree.rb +139 -0
- data/lib/web/htmltools/xmltree.rb +160 -0
- data/lib/web/htmltools/xpath.rb +71 -0
- data/lib/web/info.rb +63 -0
- data/lib/web/load.rb +210 -0
- data/lib/web/mime.rb +87 -0
- data/lib/web/phprb.rb +340 -0
- data/lib/web/resources/test/cookie.rb +33 -0
- data/lib/web/resources/test/counter.rb +20 -0
- data/lib/web/resources/test/multipart.rb +14 -0
- data/lib/web/resources/test/redirect.rb +8 -0
- data/lib/web/resources/test/stock.rb +33 -0
- data/lib/web/sapi/apache.rb +129 -0
- data/lib/web/sapi/fastcgi.rb +22 -0
- data/lib/web/sapi/install/apache.rb +180 -0
- data/lib/web/sapi/install/iis.rb +93 -0
- data/lib/web/sapi/install/macosx.rb +90 -0
- data/lib/web/sapi/webrick.rb +86 -0
- data/lib/web/session.rb +83 -0
- data/lib/web/shim/cgi.rb +129 -0
- data/lib/web/shim/rails.rb +175 -0
- data/lib/web/stringio.rb +78 -0
- data/lib/web/strscanparser.rb +24 -0
- data/lib/web/tagparser.rb +96 -0
- data/lib/web/testing.rb +666 -0
- data/lib/web/traceoutput.rb +75 -0
- data/lib/web/unit.rb +56 -0
- data/lib/web/upload.rb +59 -0
- data/lib/web/validate.rb +52 -0
- data/lib/web/wiki.rb +557 -0
- data/lib/web/wiki/linker.rb +72 -0
- data/lib/web/wiki/page.rb +201 -0
- data/lib/webunit.rb +27 -0
- data/lib/webunit/assert.rb +152 -0
- data/lib/webunit/converter.rb +154 -0
- data/lib/webunit/cookie.rb +118 -0
- data/lib/webunit/domwalker.rb +185 -0
- data/lib/webunit/exception.rb +14 -0
- data/lib/webunit/form.rb +116 -0
- data/lib/webunit/frame.rb +37 -0
- data/lib/webunit/htmlelem.rb +122 -0
- data/lib/webunit/image.rb +26 -0
- data/lib/webunit/jscript.rb +31 -0
- data/lib/webunit/link.rb +33 -0
- data/lib/webunit/params.rb +321 -0
- data/lib/webunit/parser.rb +229 -0
- data/lib/webunit/response.rb +464 -0
- data/lib/webunit/runtest.rb +41 -0
- data/lib/webunit/table.rb +148 -0
- data/lib/webunit/testcase.rb +45 -0
- data/lib/webunit/ui/cui/testrunner.rb +50 -0
- data/lib/webunit/utils.rb +68 -0
- data/lib/webunit/webunit.rb +28 -0
- data/test/dev/action.rb +83 -0
- data/test/dev/forms.rb +104 -0
- data/test/dev/forms2.rb +104 -0
- data/test/dev/parser.rb +17 -0
- data/test/dev/scripts/dump.rb +24 -0
- data/test/dev/scripts/makedist.rb +62 -0
- data/test/dev/scripts/uri.rb +41 -0
- data/test/dev/scripts/uri/common.rb +432 -0
- data/test/dev/scripts/uri/ftp.rb +149 -0
- data/test/dev/scripts/uri/generic.rb +1106 -0
- data/test/dev/scripts/uri/http.rb +76 -0
- data/test/dev/scripts/uri/https.rb +26 -0
- data/test/dev/scripts/uri/ldap.rb +238 -0
- data/test/dev/scripts/uri/mailto.rb +260 -0
- data/test/dev/scripts/urireg.rb +174 -0
- data/test/dev/simpledispatcher.rb +156 -0
- data/test/dev/test.action.rb +146 -0
- data/test/dev/test.formreader.rb +463 -0
- data/test/dev/test.simpledispatcher.rb +186 -0
- data/test/dev/webunit/conv/digit-0.rb +21 -0
- data/test/dev/webunit/conv/digit-1.rb +17 -0
- data/test/dev/webunit/conv/digit.rb +23 -0
- data/test/dev/webunit/conv/test_digit-0.rb +16 -0
- data/test/dev/webunit/conv/test_digit-1.rb +19 -0
- data/test/dev/webunit/conv/test_digit.rb +26 -0
- data/test/dev/webunit/conv/test_digit_view-0.rb +76 -0
- data/test/dev/webunit/conv/test_digit_view-1.rb +102 -0
- data/test/dev/webunit/conv/test_digit_view.rb +134 -0
- data/test/installation/htdocs/cgi_test.rb +296 -0
- data/test/installation/htdocs/test_install.rb +4 -0
- data/test/installation/runwebtest.rb +5 -0
- data/test/installation/test_cookie.rb +128 -0
- data/test/installation/test_form.rb +47 -0
- data/test/installation/test_multipart.rb +51 -0
- data/test/installation/test_request.rb +24 -0
- data/test/installation/test_response.rb +35 -0
- data/test/unit/htdocs/cookie.rb +32 -0
- data/test/unit/htdocs/multipart.rb +28 -0
- data/test/unit/htdocs/redirect.rb +12 -0
- data/test/unit/htdocs/simple.rb +13 -0
- data/test/unit/htdocs/stock.rb +33 -0
- data/test/unit/test_assert.rb +162 -0
- data/test/unit/test_cookie.rb +114 -0
- data/test/unit/test_domwalker.rb +77 -0
- data/test/unit/test_form.rb +42 -0
- data/test/unit/test_frame.rb +40 -0
- data/test/unit/test_htmlelem.rb +74 -0
- data/test/unit/test_image.rb +45 -0
- data/test/unit/test_jscript.rb +57 -0
- data/test/unit/test_link.rb +85 -0
- data/test/unit/test_multipart.rb +51 -0
- data/test/unit/test_params.rb +210 -0
- data/test/unit/test_parser.rb +53 -0
- data/test/unit/test_response.rb +150 -0
- data/test/unit/test_table.rb +70 -0
- data/test/unit/test_utils.rb +106 -0
- data/test/unit/test_webunit.rb +28 -0
- data/test/web/mod_ruby_stub.rb +39 -0
- data/test/web/test.assertinclude.rb +109 -0
- data/test/web/test.buffer.rb +182 -0
- data/test/web/test.code.loader.rb +78 -0
- data/test/web/test.config.rb +31 -0
- data/test/web/test.error.handling.rb +91 -0
- data/test/web/test.formreader-2.0.rb +352 -0
- data/test/web/test.load.rb +125 -0
- data/test/web/test.mime-type.rb +23 -0
- data/test/web/test.narf.cgi.rb +106 -0
- data/test/web/test.phprb.rb +239 -0
- data/test/web/test.request.rb +368 -0
- data/test/web/test.response.rb +637 -0
- data/test/web/test.ruby-web.rb +10 -0
- data/test/web/test.session.rb +50 -0
- data/test/web/test.shim.cgi.rb +96 -0
- data/test/web/test.tagparser.rb +65 -0
- data/test/web/test.template2.rb +297 -0
- data/test/web/test.testing2.rb +318 -0
- data/test/web/test.upload.rb +45 -0
- data/test/web/test.validate.rb +46 -0
- data/test/web/test.web.test.rb +495 -0
- data/test/wiki/test.history.rb +297 -0
- data/test/wiki/test.illustration_page.rb +287 -0
- data/test/wiki/test.linker.rb +197 -0
- data/test/wiki/test.tarpit.rb +56 -0
- data/test/wiki/test.wiki.rb +300 -0
- data/test/wikitestroot/admin.rb +7 -0
- data/test/wikitestroot/wiki.rb +6 -0
- metadata +234 -0
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
class TestLoad < Test::Unit::TestCase
|
|
2
|
+
def cleanup
|
|
3
|
+
if File.exists?( make_temp( "script.narf" ) )
|
|
4
|
+
File.delete( make_temp( "script.narf" ) )
|
|
5
|
+
end
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def setup
|
|
9
|
+
cleanup
|
|
10
|
+
Web::connection = Web::Connection::new( :out => "" )
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def teardown
|
|
14
|
+
cleanup
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def script( src )
|
|
18
|
+
File.open( make_temp( "script.narf" ), 'w' ) do |f|
|
|
19
|
+
f.write src
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def run_script
|
|
24
|
+
Web::open(:out => '') do
|
|
25
|
+
Web::load( make_temp( "script.narf" ) )
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def test_hello_world1
|
|
30
|
+
script <<-SCRIPT
|
|
31
|
+
Hello World
|
|
32
|
+
SCRIPT
|
|
33
|
+
run_script
|
|
34
|
+
assert_equal( "Hello World\n", Web::get_content )
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def test_hello_world2
|
|
38
|
+
script <<-SCRIPT
|
|
39
|
+
<%= "Hello World" %>
|
|
40
|
+
SCRIPT
|
|
41
|
+
run_script
|
|
42
|
+
assert_equal( "Hello World\n", Web::get_content )
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def test_hello_world3
|
|
46
|
+
script <<-SCRIPT
|
|
47
|
+
<% print "Hello World" %>
|
|
48
|
+
SCRIPT
|
|
49
|
+
run_script
|
|
50
|
+
assert_equal( "Hello World\n", Web::get_content )
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def test_hello_world4
|
|
54
|
+
script <<-SCRIPT
|
|
55
|
+
<%= "Hello World" %>
|
|
56
|
+
SCRIPT
|
|
57
|
+
run_script
|
|
58
|
+
assert_equal( "Hello World\n", Web::get_content )
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def test_hello_world5
|
|
62
|
+
script <<-SCRIPT
|
|
63
|
+
<% print "Hello World" %>
|
|
64
|
+
SCRIPT
|
|
65
|
+
run_script
|
|
66
|
+
assert_equal( "Hello World\n", Web::get_content )
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def test_hello_world6
|
|
70
|
+
script <<-SCRIPT
|
|
71
|
+
<% def print_hello
|
|
72
|
+
print "Hello World"
|
|
73
|
+
end
|
|
74
|
+
print_hello
|
|
75
|
+
%>
|
|
76
|
+
SCRIPT
|
|
77
|
+
run_script
|
|
78
|
+
assert_equal( "Hello World\n", Web::get_content )
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
class TestApplication < Test::Unit::TestCase
|
|
84
|
+
include Web::Testing
|
|
85
|
+
|
|
86
|
+
def setup
|
|
87
|
+
teardown
|
|
88
|
+
Web::docroot = make_temp
|
|
89
|
+
Web::setup
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
def teardown
|
|
93
|
+
Web::teardown
|
|
94
|
+
rm_rf make_temp
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
def test_application_rb
|
|
98
|
+
write_file('application.rb', <<-APP )
|
|
99
|
+
Web::puts "application"
|
|
100
|
+
APP
|
|
101
|
+
|
|
102
|
+
write_file('script.rb', <<-SCRIPT )
|
|
103
|
+
Web::puts "script"
|
|
104
|
+
SCRIPT
|
|
105
|
+
|
|
106
|
+
do_request('script.rb')
|
|
107
|
+
assert_content( "application\nscript\n" )
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
def test_application_in_parent_dir
|
|
111
|
+
write_file('application.rb', <<-APP )
|
|
112
|
+
Web::puts "application"
|
|
113
|
+
APP
|
|
114
|
+
|
|
115
|
+
write_file('subdir/script.rb', <<-SCRIPT )
|
|
116
|
+
Web::puts "subdir/script"
|
|
117
|
+
SCRIPT
|
|
118
|
+
|
|
119
|
+
#Web::load_application( 'subdir/script.rb' )
|
|
120
|
+
|
|
121
|
+
do_request('subdir/script.rb')
|
|
122
|
+
assert_content( "application\nsubdir/script\n" )
|
|
123
|
+
end
|
|
124
|
+
end
|
|
125
|
+
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
class TestMimeType < Test::Unit::TestCase
|
|
2
|
+
def test_all_mime_types_work
|
|
3
|
+
# this is somewhat circular.
|
|
4
|
+
Web::Mime.mime_types.each { |extension, mimetype|
|
|
5
|
+
assert_equal( mimetype,
|
|
6
|
+
Web::Mime.get_mime_type( "../some/directory/file." + extension ) )
|
|
7
|
+
}
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def test_some_standard_mimetypes
|
|
11
|
+
assert_equal( "text/plain", Web::Mime.get_mime_type( "file.txt" ) )
|
|
12
|
+
assert_equal( "text/html", Web::Mime.get_mime_type( "file.html" ) )
|
|
13
|
+
assert_equal( "image/jpeg", Web::Mime.get_mime_type( "file.jpg" ) )
|
|
14
|
+
assert_equal( "application/zip", Web::Mime.get_mime_type( "file.zip" ) )
|
|
15
|
+
assert_equal( "application/octet-stream", Web::Mime.get_mime_type( "file.exe" ) )
|
|
16
|
+
|
|
17
|
+
assert_equal( "text/plain", Web::get_mime_type( "file.txt" ) )
|
|
18
|
+
assert_equal( "text/html", Web::get_mime_type( "file.html" ) )
|
|
19
|
+
assert_equal( "image/jpeg", Web::get_mime_type( "file.jpg" ) )
|
|
20
|
+
assert_equal( "application/zip", Web::get_mime_type( "file.zip" ) )
|
|
21
|
+
assert_equal( "application/octet-stream", Web::get_mime_type( "file.exe" ) )
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
class TestWebCgi < Test::Unit::TestCase
|
|
2
|
+
def set_up
|
|
3
|
+
teardown
|
|
4
|
+
end
|
|
5
|
+
|
|
6
|
+
def teardown
|
|
7
|
+
$stderr = $deferr #@old_stderr
|
|
8
|
+
@cgi = @options = @mockio = @params = @cookie = nil
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def output
|
|
12
|
+
@mockio ||= ""
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def params
|
|
16
|
+
@params ||= { "field" => "value" }
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def cookie
|
|
20
|
+
@cookie ||= { "cookie" => "monster" }
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def options
|
|
24
|
+
@options ||= {:out => output,
|
|
25
|
+
:request => params,
|
|
26
|
+
:cookie => cookie }
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def cgi
|
|
30
|
+
@cgi ||= Web::Connection.new options
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def test_initialize
|
|
34
|
+
assert_equal( output, cgi.output )
|
|
35
|
+
assert_equal( params, cgi.request )
|
|
36
|
+
assert_equal( Web::Connection::normalize(cookie), cgi.cookie )
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def test_output
|
|
40
|
+
cgi << "<h1>Hello</h1>"
|
|
41
|
+
cgi.flush
|
|
42
|
+
assert_match( /Content-Type: text\/html\r\n/, output )
|
|
43
|
+
assert_match( /\r\n<h1>Hello<\/h1>/, output )
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def test_get_content
|
|
47
|
+
# test blank result
|
|
48
|
+
assert_equal( "", cgi.get_content )
|
|
49
|
+
|
|
50
|
+
# test content
|
|
51
|
+
cgi << "<h1>hola mundo!</h1>"
|
|
52
|
+
cgi.close
|
|
53
|
+
assert_equal( "<h1>hola mundo!</h1>", cgi.get_content )
|
|
54
|
+
|
|
55
|
+
# test return value, not reference
|
|
56
|
+
content = cgi.get_content
|
|
57
|
+
content += " some trailing garbage"
|
|
58
|
+
assert_equal( "<h1>hola mundo!</h1>", cgi.get_content )
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def test_assert_content
|
|
62
|
+
assert_raises(Test::Unit::AssertionFailedError){
|
|
63
|
+
cgi.assert_content "No content here"
|
|
64
|
+
}
|
|
65
|
+
cgi.write "Here is some content"
|
|
66
|
+
cgi.flush
|
|
67
|
+
cgi.assert_content "Here is some content"
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
# this is a bit incomplete -- only encodes ampersands
|
|
71
|
+
def test_html_encode
|
|
72
|
+
assert_equal( '&', Web::html_encode( '&' ) )
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def test_escape
|
|
76
|
+
assert_equal( '%21%40%24%25%5E%26%2A%28%29', Web::escape('!@$%^&*()') )
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
def test_unescape
|
|
80
|
+
assert_equal( '!@$%^&*()', Web::unescape('%21%40%24%25%5E%26%2A%28%29') )
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
def test_rfc1123_date
|
|
84
|
+
assert_match( /[A-Z][a-z]{2}, \d{1,2} [A-Z][a-z]{2} \d{4} \d\d:\d\d:\d\d GMT/,
|
|
85
|
+
Web::rfc1123_date(Time.now) )
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
def test_web_process_returns_the_cgi
|
|
89
|
+
cgi = Web::open( :out => "" ){ |cgi|
|
|
90
|
+
cgi.write "Hello World"
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
assert_equal( "Hello World", cgi.get_content )
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
# instead of one instance per output stream,
|
|
97
|
+
# how about one instance per thread
|
|
98
|
+
# this is tested by testing installation under webrick
|
|
99
|
+
def deprecated_test_get_instance_of_cgi_per_output_stream
|
|
100
|
+
out = ""
|
|
101
|
+
assert_equal Web::Connection.create( :out => out ), Web::Connection.create( :out => out )
|
|
102
|
+
assert_not_equal Web::Connection.create( :out => "" ), Web::Connection.create( :out => "" )
|
|
103
|
+
end
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
|
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
class TestPHPRBTemplate < Test::Unit::TestCase
|
|
2
|
+
include Web::Testing
|
|
3
|
+
|
|
4
|
+
def setup
|
|
5
|
+
teardown
|
|
6
|
+
|
|
7
|
+
Web::setup( :document_root => get_test_dir, :out => '' )
|
|
8
|
+
|
|
9
|
+
template_dir = File.expand_path((File.join("#{get_test_dir}","templates")))
|
|
10
|
+
|
|
11
|
+
unless Web::config[:load_path].include? template_dir
|
|
12
|
+
Web::config[:load_path] << template_dir
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
Dir.mkdir(get_test_dir)
|
|
16
|
+
Dir.mkdir(template_dir)
|
|
17
|
+
|
|
18
|
+
@old_default_handler ||= Web::config['load_suffix'].default
|
|
19
|
+
Web::config['load_suffix'].default = lambda do |script|
|
|
20
|
+
PHPRB::load(script)
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def teardown
|
|
25
|
+
Web::teardown
|
|
26
|
+
@old_default_handler ||= Web::config['load_suffix'].default
|
|
27
|
+
Web::config['load_suffix'].default = @old_default_handler
|
|
28
|
+
|
|
29
|
+
if File.exists? get_test_dir
|
|
30
|
+
rm_rf(get_test_dir)
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def get_test_dir
|
|
37
|
+
File.expand_path(File.join(temp_dir,"test_dir"))
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def temp_file filename
|
|
41
|
+
File.expand_path(File.join(get_test_dir,"templates",filename))
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def write_template contents, filename = "test.html"
|
|
45
|
+
File.open( File.expand_path(File.join(get_test_dir,"templates",filename)) ,"w") { | file | file.write contents }
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def handle_request cgi, filename = "test.html"
|
|
49
|
+
cgi.print_template( filename, { "var" => cgi["displayVar"] } )
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def write_file file, filename="app.rb"
|
|
53
|
+
File.open( File.expand_path(File.join("#{get_test_dir}",filename)), "w" ) { |f| f.write(file) }
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def test_template_file
|
|
57
|
+
write_template( "here's a test" )
|
|
58
|
+
assert_equal( "#{temp_dir}/test_dir/templates/test.html",
|
|
59
|
+
Web::template_file( "test.html" ) )
|
|
60
|
+
|
|
61
|
+
teardown
|
|
62
|
+
setup
|
|
63
|
+
|
|
64
|
+
begin
|
|
65
|
+
File.open( "test.html", "w" ) { |f|
|
|
66
|
+
f.write("here's a test")
|
|
67
|
+
}
|
|
68
|
+
assert_equal( "./test.html",
|
|
69
|
+
Web::template_file( "test.html" ) )
|
|
70
|
+
ensure
|
|
71
|
+
File.delete( "test.html" )
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
def test_template_dir_precedence
|
|
77
|
+
write_template( "here's a test" )
|
|
78
|
+
begin
|
|
79
|
+
File.open( "test.html", "w" ) { |f|
|
|
80
|
+
f.write("here's a test")
|
|
81
|
+
}
|
|
82
|
+
assert_equal( "./test.html",
|
|
83
|
+
Web::template_file( "test.html" ) )
|
|
84
|
+
ensure
|
|
85
|
+
File.delete( "test.html" )
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
# ========= Variable Resolution ==========
|
|
90
|
+
def test_print_vars
|
|
91
|
+
write_template "x<?= Web::local['foo'] ?>y<?= Web::local['bar'] ?>z"
|
|
92
|
+
vars = { "foo" => "FOO", "bar" => "BAR" }
|
|
93
|
+
Web::options[:local] = vars
|
|
94
|
+
Web::load( "test.html" )
|
|
95
|
+
Web::close
|
|
96
|
+
|
|
97
|
+
Web::assert_content "xFOOyBARz"
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
def test_xml_embeding
|
|
101
|
+
write_template "x<?= 'foo' ?>y<? Web::write('bar') ?>z"
|
|
102
|
+
Web::options[:xml] = true
|
|
103
|
+
Web::load( "test.html" )
|
|
104
|
+
Web::close
|
|
105
|
+
Web::assert_content "x<?= 'foo' ?>y<? Web::write('bar') ?>z"
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
def test_xml_embeding2
|
|
109
|
+
write_template "x<?= 'foo'\n\n ?>y<? Web::write('bar') ?>z"
|
|
110
|
+
Web::load( "test.html")
|
|
111
|
+
Web::close
|
|
112
|
+
Web::assert_content "xfooybarz"
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
def test_xml_open_tags
|
|
116
|
+
write_template "x<?ruby= 'foo' ?>y<?ruby Web::write('bar') ?>z"
|
|
117
|
+
Web::load( "test.html" )
|
|
118
|
+
Web::close
|
|
119
|
+
Web::assert_content "xfooybarz"
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
def test_comments
|
|
123
|
+
write_template "x<!--- this will be missing --->y<!--- this too --->z"
|
|
124
|
+
Web::load( "test.html" )
|
|
125
|
+
Web::close
|
|
126
|
+
Web::assert_content "xyz"
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
def test_comments_with_internal_tags
|
|
130
|
+
write_template "x<!--- this will be <?= missing ?> --->y<!--- this too --->z"
|
|
131
|
+
Web::load( "test.html" )
|
|
132
|
+
Web::close
|
|
133
|
+
Web::assert_content "xyz"
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
def deprecated_test_throw_exception_if_var_doesnt_exist
|
|
137
|
+
write_template "x<?= Web::local['foo'] ?>y<?= Web::local['bar'] ?>z"
|
|
138
|
+
vars = { "foo" => "FOO" }
|
|
139
|
+
|
|
140
|
+
assert_raises(NameError) {
|
|
141
|
+
Web::options[:local] = vars
|
|
142
|
+
Web::load( "test.html" )
|
|
143
|
+
|
|
144
|
+
}
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
def test_nil_values_display_nothing
|
|
148
|
+
write_template "x<?= Web::local['foo'] ?>yz"
|
|
149
|
+
vars = { "foo" => nil }
|
|
150
|
+
Web::options[:local] = vars
|
|
151
|
+
Web::load( "test.html" )
|
|
152
|
+
Web::close
|
|
153
|
+
Web::assert_content "xyz"
|
|
154
|
+
end
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
class TestClass
|
|
158
|
+
attr_reader :var
|
|
159
|
+
|
|
160
|
+
def initialize var
|
|
161
|
+
@var = var
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
def foo
|
|
165
|
+
TestClass.new("XXX")
|
|
166
|
+
end
|
|
167
|
+
end
|
|
168
|
+
|
|
169
|
+
def test_print_method
|
|
170
|
+
write_template "x<?= Web::local['foo'].var ?>y<?= Web::local['bar'] ?>z"
|
|
171
|
+
vars = { "foo" => TestClass.new("FOO"), "bar" => "BAR" }
|
|
172
|
+
|
|
173
|
+
Web::options[:local] = vars
|
|
174
|
+
Web::load( "test.html" )
|
|
175
|
+
Web::close
|
|
176
|
+
Web::assert_content "xFOOyBARz"
|
|
177
|
+
end
|
|
178
|
+
|
|
179
|
+
def test_template
|
|
180
|
+
write_template "<html><body><h1>hi</h1></body></html>"
|
|
181
|
+
|
|
182
|
+
Web::load( "test.html" )
|
|
183
|
+
Web::close
|
|
184
|
+
Web::assert_template_used( "test.html" )
|
|
185
|
+
end
|
|
186
|
+
|
|
187
|
+
def test_exception_thrown_if_no_template_used
|
|
188
|
+
write_template "<html><body><h1>{$var}</h1></body></html>"
|
|
189
|
+
|
|
190
|
+
assert_raises(Test::Unit::AssertionFailedError) do
|
|
191
|
+
Web::assert_template_used( "/test.html" )
|
|
192
|
+
end
|
|
193
|
+
end
|
|
194
|
+
|
|
195
|
+
def test_template_fails_assertion_with_wrong_template
|
|
196
|
+
write_template "<html><body><h1>{$var}</h1></body></html>"
|
|
197
|
+
|
|
198
|
+
Web::load( "test.html" )
|
|
199
|
+
Web::close
|
|
200
|
+
|
|
201
|
+
assert_raises( Test::Unit::AssertionFailedError ) do
|
|
202
|
+
Web::assert_template_used( "test_not_it.html" )
|
|
203
|
+
end
|
|
204
|
+
|
|
205
|
+
end
|
|
206
|
+
|
|
207
|
+
def test_assert_template_not_used
|
|
208
|
+
write_template "<html><body><h1>foo</h1></body></html>"
|
|
209
|
+
Web::load( "test.html" )
|
|
210
|
+
Web::assert_template_not_used( "foo.html" )
|
|
211
|
+
end
|
|
212
|
+
|
|
213
|
+
def test_assert_template_not_used_with_no_template_used
|
|
214
|
+
write_template "<html><body><h1>foo</h1></body></html>"
|
|
215
|
+
|
|
216
|
+
Web::assert_template_not_used( "test.html" )
|
|
217
|
+
end
|
|
218
|
+
|
|
219
|
+
def test_basic_load
|
|
220
|
+
write_template "blah blah blah"
|
|
221
|
+
Web::load( "test.html" )
|
|
222
|
+
Web::close
|
|
223
|
+
Web::assert_content "blah blah blah"
|
|
224
|
+
end
|
|
225
|
+
|
|
226
|
+
def test_print_template_survives_enormous_templates
|
|
227
|
+
bad_template = ""
|
|
228
|
+
|
|
229
|
+
1.upto(1000){ |i|
|
|
230
|
+
bad_template += "this template sucks\n"
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
write_template( bad_template )
|
|
234
|
+
Web::load( "test.html" )
|
|
235
|
+
Web::close
|
|
236
|
+
|
|
237
|
+
Web::assert_content bad_template
|
|
238
|
+
end
|
|
239
|
+
end
|