Wiki2Go 1.15.1 → 1.16.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (89) hide show
  1. data/bin/DebugWiki2GoServer.rb +10 -0
  2. data/bin/{Wiki2Go_make_repository.rb → Wiki2Go_make_cvs_repository.rb} +1 -1
  3. data/lib/Web2Go/WebrickRequest.rb +1 -1
  4. data/lib/Web2Go/WebrickResponse.rb +3 -3
  5. data/lib/Wiki2Go/BlackList.rb +24 -11
  6. data/lib/Wiki2Go/DotGraphics.rb +45 -5
  7. data/lib/Wiki2Go/FileStorage.rb +8 -2
  8. data/lib/Wiki2Go/GreyList.rb +38 -22
  9. data/lib/Wiki2Go/Install/make_repository.rb +351 -36
  10. data/lib/Wiki2Go/Install/make_site.rb +17 -8
  11. data/lib/Wiki2Go/Install/site/ruby.css +18 -0
  12. data/lib/Wiki2Go/Install/templates/admin.htm +11 -0
  13. data/lib/Wiki2Go/Install/templates/admin_pages/commit_site.txt +21 -0
  14. data/lib/Wiki2Go/Install/templates/admin_pages/edit.txt +33 -0
  15. data/lib/Wiki2Go/Install/templates/admin_pages/editfiles.txt +33 -0
  16. data/lib/Wiki2Go/Install/templates/admin_pages/greylist.txt +19 -37
  17. data/lib/Wiki2Go/Install/templates/admin_pages/show_log.txt +21 -0
  18. data/lib/Wiki2Go/Install/templates/admin_pages/update_conflicts.txt +38 -0
  19. data/lib/Wiki2Go/Install/templates/admin_pages/update_site.txt +49 -0
  20. data/lib/Wiki2Go/Install/wiki/ruby.css +18 -0
  21. data/lib/Wiki2Go/LineFormatter.rb +504 -0
  22. data/lib/Wiki2Go/Page.rb +50 -18
  23. data/lib/Wiki2Go/PublicWikiConfig.rb +34 -11
  24. data/lib/Wiki2Go/Server.rb +13 -2
  25. data/lib/Wiki2Go/SpamFilter.rb +27 -8
  26. data/lib/Wiki2Go/SyntaxHighlighter.rb +41 -0
  27. data/lib/Wiki2Go/Web.rb +0 -3
  28. data/lib/Wiki2Go/WebrickServlet.rb +2 -0
  29. data/lib/Wiki2Go/Wiki2Go.rb +19 -8
  30. data/lib/Wiki2Go/Wiki2GoConfig.rb +125 -18
  31. data/lib/Wiki2Go/Wiki2GoServlet.rb +32 -21
  32. data/lib/Wiki2Go/WikiFormatter.rb +55 -468
  33. data/lib/Wiki2Go/cgi/secure/log_rss +21 -0
  34. data/test/All.rb +21 -0
  35. data/test/TestBlackList.rb +82 -0
  36. data/test/TestConfig.rb +205 -0
  37. data/test/TestDot.rb +109 -0
  38. data/test/TestFormatter.rb +491 -0
  39. data/test/TestInstall.rb +120 -0
  40. data/test/TestLineFormatter.rb +553 -0
  41. data/test/TestMail.rb +29 -0
  42. data/test/TestRSS.rb +183 -0
  43. data/test/TestRepositoryMaker.rb +101 -0
  44. data/test/TestServer.rb +65 -0
  45. data/test/TestSpamFilter.rb +130 -0
  46. data/test/TestStorage.rb +212 -0
  47. data/test/TestSyntaxHighlighter.rb +41 -0
  48. data/test/TestUnitTestFiles.rb +27 -0
  49. data/test/TestUrlFinder.rb +39 -0
  50. data/test/TestWeb.rb +197 -0
  51. data/test/TestWeb2Go.rb +90 -0
  52. data/test/TestWiki2Go.rb +184 -0
  53. data/test/TestWiki2GoServlet.rb +747 -0
  54. data/test/UnitTestFiles.rb +102 -0
  55. data/test/Wiki2GoConfigForTest.rb +93 -0
  56. data/test/checksite.rb +56 -0
  57. data/test/testdata/changes.txt +4 -0
  58. data/test/testdata/expected_changes.html +93 -0
  59. data/test/testdata/expected_edit.html +105 -0
  60. data/test/testdata/expected_full_rss.xml +29 -0
  61. data/test/testdata/expected_header_rss.xml +13 -0
  62. data/test/testdata/expected_out.html +97 -0
  63. data/test/testdata/expected_put.html +99 -0
  64. data/test/testdata/expected_save.html +66 -0
  65. data/test/testdata/expected_savehtml.html +66 -0
  66. data/test/testdata/expected_search.html +67 -0
  67. data/test/testdata/expected_upload.html +69 -0
  68. data/test/testdata/expected_versions.html +85 -0
  69. data/test/testdata/expected_view.html +97 -0
  70. data/test/testdata/site/html/Xpday/rss.xml +103 -0
  71. data/test/testdata/templates/Test/child.htm +2 -0
  72. data/test/testdata/templates/Test/grandchild.htm +1 -0
  73. data/test/testdata/templates/Test/master.htm +3 -0
  74. data/test/testdata/texts/Test/FrontPage.txt +7 -0
  75. data/test/testdata/texts/Test/NewPage.txt +3 -0
  76. data/test/testdata/texts/Test/Subdir/Subpage.txt +1 -0
  77. data/test/testdata/texts/Test/empty.txt +3 -0
  78. data/test/testdata/texts/Test/test.txt +3 -0
  79. data/test/testdata/texts/Xpday/FrontPage.txt +36 -0
  80. data/test/testdata/texts/Xpday/Page.txt +3 -0
  81. data/test/testdata/texts/Xpday/VersionedPage.log +14 -0
  82. data/test/testdata/texts/Xpday/VersionedPage.txt +3 -0
  83. data/test/testdata/texts/Xpday/empty.log +3482 -0
  84. data/test/testdata/texts/Xpday/empty.txt +4 -0
  85. data/test/testdata/texts/Xpday/test.log +9425 -0
  86. data/test/testdata/texts/Xpday/test.txt +5 -0
  87. data/test/testdata/texts/whitelist.txt +1 -0
  88. metadata +85 -5
  89. data/lib/Wiki2Go/Install/templates/admin_pages/update.txt +0 -13
@@ -0,0 +1,21 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "CgiOptions.rb"
4
+
5
+ require "cgi"
6
+
7
+ require 'Web2Go/CGIRequest'
8
+ require 'Web2Go/CGIResponse'
9
+ require 'Wiki2Go/Wiki2GoServlet'
10
+
11
+ config = CgiOptions.new
12
+
13
+ cgi = CGI.new("html4Tr")
14
+
15
+ request = Web2Go::CGIRequest.new(cgi)
16
+ response = Web2Go::CGIResponse.new(cgi)
17
+
18
+ servlet = Wiki2Go::Servlet.new(config)
19
+ servlet.execute(request,response)
20
+
21
+
data/test/All.rb ADDED
@@ -0,0 +1,21 @@
1
+ #!/usr/bin/ruby
2
+ $:.unshift File.expand_path(File.join(File.dirname(__FILE__),'..','lib'))
3
+
4
+ require 'test/unit'
5
+ require 'test/unit/ui/console/testrunner'
6
+
7
+ require 'TestWeb'
8
+ require 'TestConfig'
9
+ require 'TestLineFormatter'
10
+ require 'TestFormatter'
11
+ require 'TestStorage'
12
+ require 'TestRSS'
13
+ require 'TestWiki2Go'
14
+ require 'TestBlacklist'
15
+ require 'TestUrlFinder'
16
+ require 'TestSpamFilter'
17
+ require 'TestWeb2Go'
18
+ require 'TestDot'
19
+ require 'TestWiki2GoServlet'
20
+ require 'TestSyntaxHighlighter'
21
+
@@ -0,0 +1,82 @@
1
+ #!/usr/bin/ruby
2
+ $:.unshift File.expand_path(File.join(File.dirname(__FILE__),'..','lib'))
3
+
4
+
5
+ require 'test/unit'
6
+
7
+ require "Wiki2Go/FileStorage"
8
+ require "Wiki2Go/BlackList"
9
+ require "Wiki2Go/GreyList"
10
+
11
+ require 'UnitTestFiles'
12
+
13
+ class TestBlackList < Test::Unit::TestCase
14
+
15
+ include UnitTestFiles
16
+
17
+ def setup
18
+ @storage = Wiki2Go::FileStorage.new(scratchdata,scratchdata('html'))
19
+ end
20
+
21
+ def teardown
22
+ end
23
+
24
+ def test_patterns
25
+ blacklist = Wiki2Go::BlackList.new("user_blacklist.txt",[])
26
+ blacklist.add('^55.66')
27
+ assert(blacklist.contains('55.66.00.1'))
28
+ assert(!blacklist.contains('55x66x00x1'))
29
+ assert(!blacklist.contains('155.66.00.1'))
30
+ end
31
+
32
+ def test_find_patterns_in_text
33
+ text = ["Some ok text", 'a bad url http://buy.viagra.com must be found' , 'some more innocent text']
34
+ bad_urls = Wiki2Go::BlackList.new("url_blacklist.txt",['viagra\.'])
35
+
36
+ assert(bad_urls.found_in(text))
37
+ end
38
+
39
+ def test_dont_find_patterns_in_ok_text
40
+ text = "Some ok text\ndon''t care if viagra is mentioned\nsome more innocent text"
41
+ bad_urls = Wiki2Go::BlackList.new("url_blacklist.txt",['viagra\.'])
42
+
43
+ assert(!bad_urls.found_in(text))
44
+ end
45
+
46
+ def test_file
47
+ list = @storage.load_blacklist
48
+ size = list.length
49
+ evil_user = "evil" + rand(10000).to_s + ".com"
50
+ list.add(evil_user)
51
+ @storage.save_list(list)
52
+ list = @storage.load_blacklist
53
+ assert_equal(size+1,list.length)
54
+ assert(list.contains(evil_user))
55
+ url_list = @storage.load_blacklist('url')
56
+ assert_equal(0,url_list.length)
57
+ end
58
+
59
+ def test_greylist
60
+ list = Wiki2Go::GreyList.new('.',[])
61
+ assert !list.contains_user?('pvc')
62
+
63
+ list.add('pvc','http://www.xp.be')
64
+ assert list.contains_user?('pvc')
65
+ assert list.url_found_in("this is a link to {xpbe@http://www.xp.be/FrontPage} ")
66
+
67
+ assert !list.contains_user?('vera')
68
+ assert !list.url_found_in("this is a link to {xpbe@www.xp.be/FrontPage} ")
69
+
70
+ end
71
+
72
+
73
+ def test_only_keep_hostnames
74
+ bad_urls = Wiki2Go::BlackList.new("url_blacklist.txt",[])
75
+ bad_urls.add("http://www.somehost.com/selling_useless_stuff")
76
+ bad_urls.add("http://www.somehost.com/selling_illegal_stuff")
77
+ bad_urls.add("http://www.somehost.com:80/selling_illegal_stuff")
78
+
79
+ assert_equal 1,bad_urls.length
80
+ end
81
+
82
+ end
@@ -0,0 +1,205 @@
1
+ #!/usr/bin/ruby
2
+ $:.unshift File.expand_path(File.join(File.dirname(__FILE__),'..','lib'))
3
+
4
+ require 'test/unit'
5
+ require 'uri'
6
+ require 'fileutils'
7
+
8
+ require "Wiki2Go/Web"
9
+ require "Wiki2Go/BlackList"
10
+ require "Wiki2Go/PublicWikiConfig"
11
+ require 'Web2Go/MockRequest'
12
+ require "Wiki2GoConfigForTest"
13
+ require "UnitTestFiles"
14
+
15
+ module TestConfig_local
16
+ class MockStorage < Wiki2Go::FileStorage
17
+
18
+ include UnitTestFiles
19
+
20
+ def initialize
21
+ super(scratchdata,scratchdata('html'))
22
+
23
+ @blacklist = Hash.new
24
+ @blacklist['user'] = Wiki2Go::BlackList.new(scratchdata('user_blacklist.txt'),[])
25
+ @blacklist['url'] = Wiki2Go::BlackList.new(scratchdata('url_blacklist.txt'),[])
26
+ @blacklist['chonqed'] = Wiki2Go::BlackList.new(scratchdata('chonqed_blacklist.txt'),[])
27
+ end
28
+
29
+ def load_blacklist(type)
30
+ @blacklist[type]
31
+ end
32
+
33
+ def blacklist(type,value)
34
+ @blacklist[type].add(value)
35
+ end
36
+ end
37
+
38
+ class MockPublicConfig < PublicWikiConfig
39
+
40
+ attr_accessor :tarpitted
41
+
42
+ def initialize(dir)
43
+ super(dir)
44
+ @tarpitted = false
45
+ end
46
+
47
+ def make_storage
48
+ MockStorage.new
49
+ end
50
+
51
+ def tarpit
52
+ @tarpitted = true
53
+ end
54
+ end
55
+ end
56
+
57
+ class TestConfig < Test::Unit::TestCase
58
+
59
+ include UnitTestFiles
60
+
61
+ def setup
62
+ FileUtils.mkdir_p scratchdata
63
+ @config = nil
64
+ end
65
+
66
+ def teardown
67
+ @config.close unless @config.nil?
68
+ UnitTestFiles.clean
69
+ end
70
+
71
+ def test_static_web
72
+ @config = TestWiki2GoConfig.new
73
+ wikiweb = Wiki2Go::Web.from_page_url("http://localhost/view/Xpday/test","view",@config)
74
+
75
+ static_web = @config.static_web(wikiweb)
76
+ assert_equal(static_web.base_url,wikiweb.base_url)
77
+
78
+ wikiweb = Wiki2Go::Web.from_page_url("http://edit.this.site/view/Xpday/test","view",@config)
79
+ static_web = @config.static_web(wikiweb)
80
+ assert_equal("http://www.this.site/",static_web.base_url)
81
+
82
+ wikiweb = Wiki2Go::Web.from_page_url("http://localhost/scripts/view/Xpday/test","view",@config)
83
+
84
+ static_web = @config.static_web(wikiweb)
85
+ assert_equal("scripts",static_web.script_prefix)
86
+
87
+ wikiweb = Wiki2Go::Web.from_page_url("http://localhost/scripts/secure/view/Xpday/test","view",@config)
88
+
89
+ static_web = @config.static_web(wikiweb)
90
+ assert_equal("scripts",static_web.script_prefix)
91
+ end
92
+
93
+ def test_public_wiki_accepts_non_spam
94
+ web = Wiki2Go::Web.new('localhost','80','','','view','Wiki2Go','FrontPage')
95
+ @config = TestConfig_local::MockPublicConfig.new(scratchdata)
96
+
97
+ clean_page = "simple page\nwithout spam"
98
+ assert @config.accept_page?(web,clean_page)
99
+
100
+ @config.storage.blacklist('user','evilguy')
101
+ @config.storage.blacklist('url','xp.be')
102
+ assert @config.accept_page?(web,clean_page)
103
+ end
104
+
105
+ def test_public_wiki_rejects_spam_from_known_spammer
106
+ @config = TestConfig_local::MockPublicConfig.new(scratchdata)
107
+
108
+ web = Wiki2Go::Web.from_request(Web2Go::MockRequest.new('http://localhost/view/Wiki2Go/FrontPage',{ 'REMOTE_USER' => 'unknown'} ),@config)
109
+
110
+
111
+ spam_page = "simple page\nwith spam link to http://www.xp.be"
112
+ assert @config.accept_page?(web,spam_page)
113
+
114
+ web = Wiki2Go::Web.from_request(Web2Go::MockRequest.new('http://localhost/view/Wiki2Go/FrontPage',{ 'REMOTE_USER' => 'evilguy'} ),@config)
115
+ @config.storage.blacklist('user','evilguy')
116
+ assert !@config.accept_page?(web,spam_page)
117
+ assert @config.tarpitted
118
+ end
119
+
120
+ def check_logged_method(config, log_method, log_string, should_match)
121
+ unique_log_string = log_string + Time.now.to_s
122
+ config.send(log_method, unique_log_string)
123
+ File.open(config.logfile ,"r") do |f|
124
+ lines = f.readlines
125
+ last_line = lines.pop.strip
126
+ if should_match then
127
+ assert last_line =~ Regexp.new(unique_log_string)
128
+ else
129
+ assert !(last_line =~ Regexp.new(unique_log_string))
130
+ end
131
+ end
132
+ end
133
+
134
+ def test_log
135
+ @config = TestWiki2GoConfig.new
136
+ @config.debug = true
137
+ check_logged_method(@config, :log, "test the log method debug true ", true)
138
+ @config.debug = false
139
+ assert_equal(false, @config.debug)
140
+ check_logged_method(@config, :log, "test the log method debug false ", false)
141
+ end
142
+
143
+ def test_error_log
144
+ @config = TestWiki2GoConfig.new
145
+ @config.debug = true
146
+ check_logged_method(@config, :errorlog, "test the error_log method debug true ", true)
147
+ @config.debug = false
148
+ check_logged_method(@config, :errorlog, "test the error_log method debug false ", true)
149
+ end
150
+
151
+ # def test_scm_connection
152
+ # @config = TestWiki2GoConfig.new
153
+ # puts @config.update_from_repository
154
+ # @config.use_repository('/home/pvc/repo','mymodule')
155
+ # puts @config.update_from_repository
156
+ # end
157
+
158
+
159
+ def test_plugins
160
+ @config = ScratchWikiConfig.new
161
+ web = Wiki2Go::Web.from_request(Web2Go::MockRequest.new('http://localhost/view/Wiki2Go/FrontPage',{ 'REMOTE_USER' => 'evilguy'} ),@config)
162
+ content = dotgraphics
163
+
164
+ page = Wiki2Go::Page.new(web.current_page,content,web.user,Time.now,web.title,web.alias)
165
+
166
+ @config.save(web,page)
167
+ end
168
+
169
+ def process(content)
170
+ if content =~ /^(.*)(<!--(.*)-->)(.*)$/m then
171
+ before,match,after = $1,$2,$4
172
+ process(before)
173
+ # puts "Matched <#{match}>"
174
+ process(after)
175
+ end
176
+
177
+ end
178
+
179
+ def test_match
180
+ content = dotgraphics
181
+ process(content)
182
+ end
183
+
184
+ def dotgraphics
185
+ return <<-END_OF_GRAPHICS
186
+ Example use of dot
187
+
188
+ <!--GRAPH:test.jpg digraph G {Hello->World} -->
189
+
190
+ OK? ok.
191
+
192
+ Big Picture
193
+
194
+ <!--GRAPH:test2.jpg
195
+ digraph G {
196
+ Hello->World
197
+ Cruel->World
198
+ Hello->Bye
199
+ }
200
+ -->
201
+
202
+
203
+ END_OF_GRAPHICS
204
+ end
205
+ end
data/test/TestDot.rb ADDED
@@ -0,0 +1,109 @@
1
+ #!/usr/bin/ruby
2
+ $:.unshift File.expand_path(File.join(File.dirname(__FILE__),'..','lib'))
3
+
4
+ require 'test/unit'
5
+
6
+ require 'fileutils'
7
+
8
+ require 'Wiki2Go/DotGraphics'
9
+ require 'Wiki2Go/Web'
10
+ require 'Wiki2GoConfigForTest'
11
+ require 'UnitTestFiles'
12
+
13
+ include FileUtils
14
+
15
+ class TestDot < Test::Unit::TestCase
16
+
17
+ include UnitTestFiles
18
+
19
+ def setup
20
+ @config = ScratchWikiConfig.new
21
+ @config.cleanup
22
+
23
+ @web = Wiki2Go::Web.new('localhost','80','','','view','Wiki2Go','EmbedDotFiles')
24
+ end
25
+
26
+ def teardown
27
+ @config.cleanup
28
+ end
29
+
30
+ def test_processing_with_one_graph
31
+ outfile = File.join(@config.site_directory,'Wiki2Go','graphics','test.gif')
32
+ assert(!File.exists?(outfile))
33
+
34
+ content = 'test.gif \r\n digraph G {Hello->World} \r\n'
35
+ graphics = Wiki2Go::DotGraphics.new
36
+ processed = graphics.save(@config,@web,content)
37
+ expected = '<img src="Wiki2Go/graphics/test.gif" border=0 alt="test.gif">'
38
+ assert_equal(expected,processed)
39
+ assert(File.exists?(outfile))
40
+ end
41
+
42
+ def test_processing_imagemap
43
+ outfile = File.join(@config.site_directory,'Wiki2Go','graphics','test.gif')
44
+ assert(!File.exists?(outfile))
45
+
46
+ content = content_for_mapping
47
+ graphics = Wiki2Go::DotGraphics.new('')
48
+ processed = graphics.save(@config,@web,content)
49
+ expected = expected_mapped_file
50
+ assert_same_strings(expected,processed)
51
+ assert(File.exists?(outfile))
52
+ end
53
+
54
+ def test_rewriting_urls
55
+ outfile = File.join(@config.site_directory,'Wiki2Go','graphics','test.gif')
56
+ assert(!File.exists?(outfile))
57
+
58
+ @config.redirect_url(true)
59
+
60
+ content = content_with_urls
61
+ graphics = Wiki2Go::DotGraphics.new('')
62
+ processed = graphics.save(@config,@web,content)
63
+ expected = expected_rewritten_urls
64
+ assert_same_strings(expected,processed)
65
+ assert(File.exists?(outfile))
66
+ end
67
+
68
+ private
69
+
70
+ def content_for_mapping
71
+ return <<-END_OF_CONTENT
72
+ test.gif
73
+ digraph G {
74
+ Hello [URL="http://wiki2go.nayima.be"];
75
+ Hello->World
76
+ }
77
+ END_OF_CONTENT
78
+ end
79
+ def expected_mapped_file
80
+ return <<-END_OF_EXPECTED
81
+ <img src="Wiki2Go/graphics/test.gif" border=0 alt="test.gif" usemap="#test">
82
+ <map id="test" name="test">
83
+ <area shape="rect" href="http://wiki2go.nayima.be" title="Hello" alt="" coords="10,8,88,56" />
84
+ </map>
85
+ END_OF_EXPECTED
86
+ end
87
+
88
+ def content_with_urls
89
+ return <<-END_OF_CONTENT
90
+ test.gif
91
+ digraph G {
92
+ Hello [URL="http://wiki2go.nayima.be"];
93
+ World [url = "Some/WikiPage"];
94
+ Hello->World
95
+ }
96
+ END_OF_CONTENT
97
+ end
98
+
99
+ def expected_rewritten_urls
100
+ return <<-END_OF_EXPECTED
101
+ <img src="Wiki2Go/graphics/test.gif" border=0 alt="test.gif" usemap="#test">
102
+ <map id="test" name="test">
103
+ <area shape="rect" href="http://localhost/redirect/Wiki2Go?url=http%3A%2F%2Fwiki2go.nayima.be" title="Hello" alt="" coords="10,8,88,56" />
104
+ <area shape="rect" href="http://localhost/Wiki2Go/Some/WikiPage.html" title="World" alt="" coords="8,104,90,152" />
105
+ </map>
106
+ END_OF_EXPECTED
107
+ end
108
+
109
+ end
@@ -0,0 +1,491 @@
1
+ #!/usr/bin/ruby
2
+ $:.unshift File.expand_path(File.join(File.dirname(__FILE__),'..','lib'))
3
+
4
+
5
+ require "test/unit"
6
+
7
+ require 'Wiki2Go/WikiFormatter'
8
+ require "Wiki2Go/Web"
9
+ require "Wiki2Go/FileStorage"
10
+ require "Wiki2Go/WhiteList"
11
+ require "Wiki2GoConfigForTest"
12
+ require "UnitTestFiles"
13
+
14
+ class MockStorage
15
+ attr_accessor :find_it
16
+
17
+ def exists?(path)
18
+ return @find_it
19
+ end
20
+
21
+ def load_whitelist
22
+ return Wiki2Go::WhiteList.new(Array.new)
23
+ end
24
+
25
+ def initialize
26
+ @find_it = false
27
+ end
28
+ end
29
+
30
+ class TestFormatter < Test::Unit::TestCase
31
+ include UnitTestFiles
32
+
33
+ def test_donotinterpret_line_flag
34
+ formatter = makePublicFormatter
35
+ formatted = formatter.format_page("{!WikiWord!}")
36
+ assert_equal("WikiWord",formatted)
37
+
38
+ formatted = formatter.format_page("{!http://www.nayima.be!}")
39
+ assert_equal("http://www.nayima.be",formatted)
40
+
41
+ input = <<END_OF_INPUT
42
+ * {!Don't interpret!} *me*
43
+ END_OF_INPUT
44
+
45
+ formatted = formatter.format_page(input)
46
+ assert_equal("<ul><li> Don't interpret <STRONG>me</STRONG>\n</ul>",formatted)
47
+
48
+ end
49
+
50
+ def test_donotinterpret_page_flag
51
+ formatter = makePublicFormatter
52
+ formatted = formatter.format_page("{{!ok\nWikiWord\n!}}")
53
+ assert_equal("ok\nWikiWord",formatted)
54
+
55
+ content = '<form action="doit.cgi" method="post">\n<input type="submit">\n</form>'
56
+ formatted = formatter.format_page("{{!#{content}!}}")
57
+ assert_equal(content,formatted)
58
+
59
+ end
60
+
61
+ def test_dynamic_pages
62
+ formatter = makePublicFormatter
63
+
64
+ formatter.config.allow_dynamic_pages
65
+
66
+ formatted = formatter.format_page("{%DynamicPage%}")
67
+ assert_equal("<a href=\"view/Xpday/DynamicPage.rbl\">DynamicPage</a>",formatted)
68
+
69
+ formatted = formatter.format_page("{%Click here...@DynamicPage%}")
70
+ assert_equal("<a href=\"view/Xpday/DynamicPage.rbl\">Click here...</a>",formatted)
71
+ end
72
+
73
+
74
+
75
+ def test_pre
76
+ formatter = makeFormatter
77
+
78
+ formatted = formatter.format_page("<pre> a SomeLink AnotherLink Nolink </pre>")
79
+ assert_equal("<pre> a SomeLink AnotherLink Nolink </pre>",formatted)
80
+
81
+ formatted = formatter.format_page("<pre>\r\n a SomeLink AnotherLink Nolink \r\n</PRE>")
82
+ assert_equal("<pre>\r\n a SomeLink AnotherLink Nolink \r\n</PRE>",formatted)
83
+
84
+ formatted = formatter.format_page(" a SomeLink AnotherLink Nolink ")
85
+ assert_equal(" a <a href=\"view/Xpday/SomeLink\">SomeLink</a> <a href=\"view/Xpday/AnotherLink\">AnotherLink</a> Nolink ",formatted)
86
+
87
+ end
88
+
89
+ def test_comments
90
+ formatter = makeFormatter
91
+
92
+ string = "\r\nhello\r\nbye"
93
+ assert_equal(['hello' , 'bye'],string.strip.split("\r\n"))
94
+
95
+ input = "<!-- a SomeLink AnotherLink Nolink -->*bold*"
96
+ formatted = formatter.format_page(input)
97
+ assert_equal("<!-- a SomeLink AnotherLink Nolink --><STRONG>bold</STRONG>",formatted)
98
+ end
99
+
100
+ def test_format_page
101
+ storage = Wiki2Go::FileStorage.new(testdata,testdata('html'))
102
+
103
+ formatter = makeFormatterWithStorage(storage)
104
+
105
+ text = storage.load_page("Xpday","FrontPage")
106
+
107
+ template = storage.load_template("Xpday","view.htm")
108
+ formatted = formatter.format_page_in_template(template,text)
109
+
110
+ assert_same_file_string(testdata('expected_out.html'),scratchdata('out.html'),formatted)
111
+
112
+ end
113
+
114
+ def test_formatting_with_comments
115
+ input = <<-END_OF_TEXT
116
+ <!-- Add your name and company to the list -->
117
+ 1. Vera Peeters, Tryx, Renault Clio RWC075
118
+ 1. Pascal Van Cauwenberghe
119
+ END_OF_TEXT
120
+
121
+ expected = <<-END_OF_EXPECTED
122
+ <!-- Add your name and company to the list -->
123
+ <ol><li> Vera Peeters, Tryx, Renault Clio RWC075
124
+ <li> Pascal Van Cauwenberghe
125
+ </ol>
126
+ END_OF_EXPECTED
127
+
128
+ formatter = makeFormatter
129
+ formatted = formatter.format_page(input)
130
+ assert_equal(expected.strip,formatted.strip)
131
+ end
132
+
133
+ def test_view_link
134
+ formatter = makeFormatter
135
+ formatted = formatter.view_link("Xpday", "aPage", "aLabel")
136
+ assert_equal('<a href="view/Xpday/aPage">aLabel</a>',formatted)
137
+
138
+ end
139
+
140
+ def test_view_link_with_parameters
141
+ formatter = makeFormatter
142
+ formatted = formatter.view_version_link("Xpday", "aPage", "aLabel", { 'version' => '2' , 'user' => 'firstuser', 'firstparam' => 'value' })
143
+ assert_equal('<a href="view/Xpday/aPage?firstparam=value&user=firstuser&version=2">aLabel</a>',formatted)
144
+
145
+ end
146
+
147
+ def test_put_page
148
+ storage = Wiki2Go::FileStorage.new(testdata,testdata('html'))
149
+ formatter = makeFormatterWithStorage(storage)
150
+
151
+ text = storage.load_page("Xpday","FrontPage")
152
+
153
+ template = storage.load_template("Xpday","view.htm")
154
+ formatted = formatter.put_page_in_template(template,text)
155
+ assert_same_file_string(testdata('expected_put.html'),scratchdata('put.html'),formatted)
156
+ end
157
+
158
+ def test_ignore_tags
159
+ formatter = makeFormatter
160
+
161
+ content = tag_test_content
162
+ formatted = formatter.format_page(content)
163
+ assert_equal(tag_test_expected.strip,formatted)
164
+
165
+ end
166
+
167
+
168
+ def test_combine_links_and_formatting
169
+ formatter = makeFormatter
170
+ formatted = formatter.format_page("*{link@http://wiki2go.nayima.be}*")
171
+ assert_equal('<STRONG><a href="redirect/Xpday?url=http%3A%2F%2Fwiki2go.nayima.be" rel="nofollow" target="_blank">link</a></STRONG>',formatted)
172
+
173
+ formatted = formatter.format_page('*<a href="http://wiki2go.nayima.be">link</a>*')
174
+ assert_equal('<STRONG><a href="redirect/Xpday?url=http%3A%2F%2Fwiki2go.nayima.be" rel="nofollow" target="_blank">link</a></STRONG>',formatted)
175
+
176
+ formatted = formatter.format_page(" * *{link@http://wiki2go.nayima.be}*")
177
+ assert_equal('<ul><li> <STRONG><a href="redirect/Xpday?url=http%3A%2F%2Fwiki2go.nayima.be" rel="nofollow" target="_blank">link</a></STRONG></ul>',formatted)
178
+ end
179
+
180
+
181
+ def test_links_in_table
182
+ input = <<END_OF_INPUT
183
+ |-----------------------------------------------|
184
+ | *When* | *Where* | *What* | *Who* |
185
+ | 23/02/2005 | {Engels, Rotterdam@http://www.engels.nl/} | Check out location | |
186
+ | 13/05/2005 | MastBosch, Breda | Agile Systems annual meeting + XP Day re-kickstart | |
187
+ | 17/05/2005 21:00 | Skype | Standup | Marc, Rob, Nynke, Vera, Pascal |
188
+ | *28/06/2005* 21:00 | Skype | Standup | |
189
+ |-----------------------------------------------|
190
+ END_OF_INPUT
191
+
192
+ expected = <<END_OF_EXPECTED
193
+ <table class="wikitable" >
194
+ <tr><td> <STRONG>When</STRONG> </td><td> <STRONG>Where</STRONG> </td><td> <STRONG>What</STRONG> </td><td> <STRONG>Who</STRONG> </td></tr>
195
+ <tr><td> 23/02/2005 </td><td> <a href="redirect/Xpday?url=http%3A%2F%2Fwww.engels.nl%2F" rel="nofollow" target="_blank">Engels, Rotterdam</a> </td><td> Check out location </td><td> </td></tr>
196
+ <tr><td> 13/05/2005 </td><td> <a href="view/Xpday/MastBosch">MastBosch</a>, Breda </td><td> Agile Systems annual meeting + XP Day re-kickstart </td><td> </td></tr>
197
+ <tr><td> 17/05/2005 21:00 </td><td> Skype </td><td> Standup </td><td> Marc, Rob, Nynke, Vera, Pascal </td></tr>
198
+ <tr><td> <STRONG>28/06/2005</STRONG> 21:00 </td><td> Skype </td><td> Standup </td><td> </td></tr>
199
+ </table>
200
+ END_OF_EXPECTED
201
+
202
+ formatter = makeFormatter
203
+ formatted = formatter.format_page(input)
204
+ assert_same_content(expected.split,formatted.split)
205
+ end
206
+
207
+
208
+ def test_wiki_and_html
209
+ formatter = makeFormatter
210
+
211
+ content = content_wiki_and_html
212
+ formatted = formatter.format_page(content)
213
+ assert_equal(expected_wiki_and_html.strip,formatted)
214
+ end
215
+
216
+ def test_loads_of_tags
217
+ formatter = makeFormatter
218
+
219
+ content = lots_of_tags
220
+ formatted = formatter.format_page(content)
221
+ end
222
+
223
+ def test_paragraphs
224
+ formatter = makeFormatter
225
+
226
+ content = paragraphs_test_content
227
+ formatted = formatter.format_page(content)
228
+ assert_equal(paragraphs_test_expected.strip,formatted)
229
+
230
+ end
231
+
232
+ def content_wiki_and_html
233
+ return <<END_OF_CONTENT_WIKI_AND_HTML
234
+ * <em>Emphasis</em> added
235
+ * _Emphasis_ added
236
+ END_OF_CONTENT_WIKI_AND_HTML
237
+
238
+ end
239
+
240
+ def expected_wiki_and_html
241
+ return <<END_OF_EXPECTED_WIKI_AND_HTML
242
+ <ul><li> <em>Emphasis</em> added
243
+ <li> <EM>Emphasis</EM> added
244
+ </ul>
245
+ END_OF_EXPECTED_WIKI_AND_HTML
246
+
247
+ end
248
+
249
+
250
+ def tag_test_content
251
+ return <<-END_OF_CONTENT
252
+ This is a test of a long tag <a href="http://www.microsoft.com">
253
+ That should not be changed
254
+ END_OF_CONTENT
255
+
256
+ end
257
+
258
+ def tag_test_expected
259
+ return <<-END_OF_CONTENT
260
+ This is a test of a long tag <a href="redirect/Xpday?url=http%3A%2F%2Fwww.microsoft.com\" rel=\"nofollow\" target=\"_blank\">
261
+ That should not be changed
262
+ END_OF_CONTENT
263
+
264
+ end
265
+
266
+ def paragraphs_test_content
267
+ return <<-END_OF_CONTENT
268
+ The first line
269
+
270
+ The Second line
271
+
272
+
273
+
274
+ The Third line
275
+ END_OF_CONTENT
276
+
277
+ end
278
+
279
+ def paragraphs_test_expected
280
+ return <<END_OF_EXPECTED_CONTENT
281
+ The first line
282
+ <p>
283
+ The Second line
284
+ <p>
285
+ The Third line
286
+ END_OF_EXPECTED_CONTENT
287
+
288
+ end
289
+
290
+ def lots_of_tags
291
+ return <<-END_OF_LOADSATAGS
292
+ <p>
293
+ We regularly organize a meeting. We take care of some food and drinks.
294
+ You can meet a lot of interesting people at these meetings.
295
+ It's a nice opportunity to discuss all the aspects of XP and other {agile@http://www.agilealliance.org} methodologies.
296
+ </p>
297
+ <p>
298
+ Future meetings will be announced here and on the mailinglist and the {wiki@http://wiki.xp.be/scripts/view.pl/Xpbe/XpBeMeeting}.
299
+ </p>
300
+
301
+ <h3>XP BE MailingList</h3>
302
+ <p>
303
+ You can subscribe to the {XP BE mailing list@http://groups.yahoo.com/group/xp-be/} to discuss all things related to the use of XP in Belgium.
304
+ </p>
305
+ <p>
306
+ Lots of interesting stuff, and lots of fun guaranteed!
307
+ </p>
308
+ <h3>Meeting 18: 21/12/2004</h3>
309
+ <table>
310
+ <tr>
311
+ <td>
312
+ {http://www.belgium.be/eportal/application?origin=charterHome.jsp&event=bea.portal.framework.internal.refresh&pageid=charterDetailPage&navId=3647@logo_fod.jpg}
313
+ </td>
314
+ <td>The previous meeting was hosted by {Federal Administration of Foreign Affairs@http://www.belgium.be/eportal/application?origin=charterHome.jsp&event=bea.portal.framework.internal.refresh&pageid=charterDetailPage&navId=3647} in Brussels, on December 21st, 2004.<br><br>
315
+ The topic of the meeting was "Unit Tests as Documentation"<br>
316
+ More info on the {WIKI site@http://wiki.xp.be/scripts/view.pl/Xpbe/XpBeMeeting21122004}.<br>
317
+ </td>
318
+ </tr>
319
+ </table>
320
+
321
+ <h3>Meeting 17: 26/10/2004</h3>
322
+ <table><tr>
323
+ <td><A href= "http://www.nayima.be/" class="logo" title="Nayima">&nbsp;Nayima&nbsp;&nbsp;</A><br>
324
+ {http://www.tryx.com/@Tryx.jpg}</td>
325
+ <td>The meeting was hosted by {Tryx@http://www.tryx.com/} and {Nayima@http://www.nayima.be/} in Leuven, on October 26, 2004.<br><br>
326
+ During the meeting {Willem van den Ende@http://www.willemvandenende.com/} and {Marc Evers@http://www.xs4all.nl/~mmmevers/} will introduce {Systems Thinking@http://www.systemsthinking.net} with games and simulations.<br>
327
+ More info on the {WIKI site@href="http://wiki.xp.be/scripts/view.pl/Xpbe/XpBeMeeting260102004}.
328
+ </td></tr></table>
329
+ <br>
330
+ <h3>Meeting 16: 22/06/2004</h3>
331
+ <table ID="Table4"><tr>
332
+ <td>{href="http://www.data4s.com/@data4s.gif}</td>
333
+ <td><p>This meeting was hosted by {DATA4S@http://www.data4s.com/"} on June 22, 2004.</p>
334
+ <p>Topic was the {XP Game@xpgame}! More info on the {WIKI site@href="http://wiki.xp.be/scripts/view.pl/Xpbe/XpBeMeeting22062004}.</p></td>
335
+ </tr></table>
336
+ <br>
337
+ <h3>Meeting 15: 26/04/2004</h3>
338
+ <table ID="Table3"><tr>
339
+ <td>{http://www.egova.com@egova.jpg}</td>
340
+ <td><p>This meeting was hosted by {Egova@http://www.egova.com/} on April 26, 2004.</p>
341
+ <p>Topic is "Experiences in moving towards an XP process". More info and registration on the {WIKI site@http://wiki.xp.be/scripts/view.pl/Xpbe/XpBeMeeting26042004}.</p></td>
342
+ </tr></table>
343
+ <br>
344
+ <h3>Meeting 14: 01/03/2004</h3>
345
+ <table ID="Table1"><tr>
346
+ <td>{http://www.microsoft.be/@microsoft.gif}</td>
347
+ <td><p>This meeting was hosted by {Microsoft@http://www.microsoft.be/} on March 1st, 2004.</p>
348
+ <p>Topic was "XP in a Microsoft environment". More info on the {WIKI site@http://wiki.xp.be/scripts/view.pl/Xpbe/XpBeMeeting01032004}.</p></td>
349
+ </tr></table>
350
+ <br>
351
+ <h3>Meeting 13: 20/01/2004</h3>
352
+ <table ID="Table1"><tr>
353
+ <td>{http://www.aviapartner.aero@aviapartner.gif}</a></td>
354
+ <td><p>This meeting was hosted by {AviaPartner@http://www.aviapartner.aero/eng/} on January 20th, 2004.</p>
355
+ <p>Topic was "The effect of short(ening) releases". More info on the {WIKI site@http://wiki.xp.be/scripts/view.pl/Xpbe/XpBeMeeting20012004}.</p></td>
356
+ </tr></table>
357
+ <h3>Meeting 12: 03/11/2003</h3>
358
+ <table><tr>
359
+ <td>{http://www.ictinos.com/@ictinos_small.gif}</td>
360
+ <td><p>This meeting was be hosted by {Ictinos@http://www.ictinos.com/} on November 3rd, 2003.</p>
361
+ <p>The topic of the meeting was Unit Testing. More info on the {WIKI site@http://wiki.xp.be/scripts/view.pl/Xpbe/XpBeMeeting03112003}.</p>
362
+ </td></tr></table>
363
+ <h3>Meeting 11: 03/09/2003</h3>
364
+ <table><tr>
365
+ <td>{http://belgium.emc.com/@EMC_logo.gif}</td>
366
+ <td><p>This meeting was hosted on Wednesday September 3rd by {EMC BDG@http://belgium.emc.com/} in Mechelen. Read more about it on our {WIKI site@http://wiki.xp.be/scripts/view.pl/Xpbe/XpBeMeeting03092003}.</p>
367
+ <p>The topic was <em>{Pair Programming@http://wiki.xp.be/scripts/view.pl/Xpbe/PairProgramming}</em> and the announcement of the program of the {XP DAY Benelux@xpday} conference!</p>
368
+ </td></tr></table>
369
+ <h3>Meeting 10: 16/06/2003</h3>
370
+ <table><tr>
371
+ <td>{http://www.cronos.be/@cronos_logo.gif}</td>
372
+ <td><p>
373
+ This meeting was held on Monday June 16th 2003, hosted by {Cronos@http://www.cronos.be/}.
374
+ Read more about it on our {WIKI site@http://wiki.xp.be/scripts/view.pl/Xpbe/XpBeMeeting16062003}.
375
+ </p>
376
+ <p>The XP BE users group is two years old. Happy birthday!</p>
377
+ </td></tr></table>
378
+ <h3>Meeting 9: 30/04/2003</h3>
379
+ <table><tr>
380
+ <td>{http://www.eds.be/@eds_logo.gif}</td><td>
381
+ <p>
382
+ This meeting was held on Wednesday April 30th 2003, hosted by {EDS@http://www.eds.be/}.
383
+ Read more about it on our {WIKI site@http://wiki.xp.be/scripts/view.pl/Xpbe/XpBeMeeting30042003}.
384
+ </p>
385
+ </td></tr></table>
386
+ <h3>Meeting 8: 20/02/2003</h3>
387
+ <table><tr>
388
+ <td>{http://win-www.uia.ac.be@uia_logo.gif}</td>
389
+ <td><p>
390
+ This meeting was held on Thursday February 20th 2003, hosted by {University of Antwerp@http://win-www.uia.ac.be}.
391
+ Read more about it on our {WIKI site@http://wiki.xp.be/scripts/view.pl/Xpbe/XpBeMeeting20022003}.
392
+ </p>
393
+ </td></tr></table>
394
+ <h3>Meeting 7: 17/12/2002</h3>
395
+ <table ID="Table2"><tr>
396
+ <td>{http://www.research.philips.com/@philips_logo.gif}</td><td>
397
+ <p>
398
+ This joint meeting with the {Dutch XP Group@http://www.xpnl.org/} was hosted by {Philips Research@http://www.research.philips.com/}, on Tuesday, December 17th.
399
+ More info on the {WIKI site@http://wiki.xp.be/scripts/view.pl/Xpbe/XpBeMeeting17122002}.
400
+ </p>
401
+ </td></tr></table>
402
+ <h3>Meeting 6: 16/9/2002</h3>
403
+ <p>
404
+ The meeting was hosted by Lesire Software Engineering, on monday, September 16th.
405
+ More info on the {WIKI site@http://wiki.xp.be/scripts/view.pl/Xpbe/XpBeMeeting16092002}.
406
+ </p>
407
+
408
+ <h3>Meeting 5: 01/7/2002</h3>
409
+ <table><tr>
410
+ <td>{http://www.tryx.com/@Tryx.jpg}<br><br>
411
+ <A href= "http://www.nayima.be/" class="logo" title="Nayima">&nbsp;Nayima&nbsp;&nbsp;</A>
412
+
413
+ </td><td>
414
+ <p>
415
+ The meeting was hosted by {Tryx@http://www.tryx.com/} and {Nayima@http://www.nayima.be/} in "The Lunatic" cafe in Leuven on Monday, July 1st.
416
+ See the {WIKI site@http://wiki.xp.be/scripts/view.pl/Xpbe/XpBeMeeting01072002}.
417
+ </p>
418
+ </td></tr></table>
419
+
420
+ <h3>Meeting 4: 4/3/2002</h3>
421
+ <p>
422
+ The fourth meeting was hosted at {Europeloan Bank@http://www.europeloan.com/} on Monday, March 4th.
423
+ We dicussed the pros and cons of <em>Pair Programming</em>. For more info, see the {WIKI site@http://wiki.xp.be/scripts/view.pl/Xpbe/XpBeMeetingReport04032002}.</p>
424
+
425
+
426
+ <h3>Meeting 3: 18/12/2001</h3>
427
+ <p>
428
+ The third XP.Be meeting had presentations and discussions about Acceptance Tests. See the {WIKI site@http://wiki.xp.be/scripts/view.pl/Xpbe/XpBeMeeting18122001} for some notes and further discussion on the subject.</p>
429
+
430
+ <h3>Meeting 2: 14/09/2001</h3>
431
+ <p>
432
+ The second meeting was a very special one.
433
+ We've invited the {Dutch group@http://www.xpnl.org} to meet in Belgium this time.
434
+ It was scheduled on a Friday, so that we didn't have to look at the time...
435
+ </p>
436
+ <p>
437
+ The subject was Continuous Integration. Several people explained how this is done in their company.
438
+ </p>
439
+ <p>
440
+ Everyone can add his comments about the {meeting@http://wiki.xp.be/scripts/view.pl/Xpbe/XpBeMeeting14092001} on the WIKI site..
441
+ </p>
442
+
443
+
444
+ <h3>Meeting 1: 21/06/2001</h3>
445
+ <p>
446
+ The first meeting was a great success with 22 participants.
447
+ </p>
448
+ <p>
449
+ You can find more info on what has been discussed in the meeting on the {WIKI site@http://wiki.xp.be/scripts/view.pl/Xpbe/XpBeMeeting21062001}.
450
+ </p>
451
+ END_OF_LOADSATAGS
452
+
453
+ end
454
+
455
+ def makeFormatter
456
+ storage = MockStorage.new
457
+ storage.find_it = true
458
+ config = TestWiki2GoConfig.new
459
+ web = Wiki2Go::Web.from_page_url("http://webserver:8081/view/Xpday/Page",'view',config)
460
+ return Wiki2Go::Formatter.new(web,storage,config,false,true)
461
+ end
462
+
463
+ def makePublicFormatter
464
+ storage = MockStorage.new
465
+ storage.find_it = true
466
+ config = PublicTestWiki2GoConfig.new
467
+ web = Wiki2Go::Web.from_page_url("http://webserver:8081/view/Xpday/Page",'view',config)
468
+ return Wiki2Go::Formatter.new(web,storage,config,true,false)
469
+ end
470
+
471
+ def make_single_wiki_Formatter
472
+ storage = MockStorage.new
473
+ storage.find_it = true
474
+ config = PublicTestWiki2GoConfig.new
475
+ config.multi_wiki = false
476
+ web = Wiki2Go::Web.from_page_url("http://webserver:8081/view/Page",'view',config)
477
+ return Wiki2Go::Formatter.new(web,storage,config,true,false)
478
+ end
479
+
480
+
481
+ def makeFormatterWithStorage(storage)
482
+ config = TestWiki2GoConfig.new
483
+
484
+ web = Wiki2Go::Web.from_page_url("http://webserver:8081/view/Xpday/Page",'view',config)
485
+ return Wiki2Go::Formatter.new(web,storage,config,false,true)
486
+ end
487
+
488
+
489
+ end
490
+
491
+