##// END OF EJS Templates
Merged r4063 from trunk....
Eric Davis -
r4019:5a639173ded5
parent child
Show More
@@ -1,612 +1,609
1 1 # Redmine - project management software
2 2 # Copyright (C) 2006-2009 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
6 6 # as published by the Free Software Foundation; either version 2
7 7 # of the License, or (at your option) any later version.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18 require File.dirname(__FILE__) + '/../../test_helper'
19 19
20 class ApplicationHelperTest < HelperTestCase
21 include ApplicationHelper
22 include ActionView::Helpers::TextHelper
23 include ActionView::Helpers::DateHelper
20 class ApplicationHelperTest < ActionView::TestCase
24 21
25 22 fixtures :projects, :roles, :enabled_modules, :users,
26 23 :repositories, :changesets,
27 24 :trackers, :issue_statuses, :issues, :versions, :documents,
28 25 :wikis, :wiki_pages, :wiki_contents,
29 26 :boards, :messages,
30 27 :attachments,
31 28 :enumerations
32 29
33 30 def setup
34 31 super
35 32 end
36 33
37 34 def test_auto_links
38 35 to_test = {
39 36 'http://foo.bar' => '<a class="external" href="http://foo.bar">http://foo.bar</a>',
40 37 'http://foo.bar/~user' => '<a class="external" href="http://foo.bar/~user">http://foo.bar/~user</a>',
41 38 'http://foo.bar.' => '<a class="external" href="http://foo.bar">http://foo.bar</a>.',
42 39 'https://foo.bar.' => '<a class="external" href="https://foo.bar">https://foo.bar</a>.',
43 40 'This is a link: http://foo.bar.' => 'This is a link: <a class="external" href="http://foo.bar">http://foo.bar</a>.',
44 41 'A link (eg. http://foo.bar).' => 'A link (eg. <a class="external" href="http://foo.bar">http://foo.bar</a>).',
45 42 'http://foo.bar/foo.bar#foo.bar.' => '<a class="external" href="http://foo.bar/foo.bar#foo.bar">http://foo.bar/foo.bar#foo.bar</a>.',
46 43 'http://www.foo.bar/Test_(foobar)' => '<a class="external" href="http://www.foo.bar/Test_(foobar)">http://www.foo.bar/Test_(foobar)</a>',
47 44 '(see inline link : http://www.foo.bar/Test_(foobar))' => '(see inline link : <a class="external" href="http://www.foo.bar/Test_(foobar)">http://www.foo.bar/Test_(foobar)</a>)',
48 45 '(see inline link : http://www.foo.bar/Test)' => '(see inline link : <a class="external" href="http://www.foo.bar/Test">http://www.foo.bar/Test</a>)',
49 46 '(see inline link : http://www.foo.bar/Test).' => '(see inline link : <a class="external" href="http://www.foo.bar/Test">http://www.foo.bar/Test</a>).',
50 47 '(see "inline link":http://www.foo.bar/Test_(foobar))' => '(see <a href="http://www.foo.bar/Test_(foobar)" class="external">inline link</a>)',
51 48 '(see "inline link":http://www.foo.bar/Test)' => '(see <a href="http://www.foo.bar/Test" class="external">inline link</a>)',
52 49 '(see "inline link":http://www.foo.bar/Test).' => '(see <a href="http://www.foo.bar/Test" class="external">inline link</a>).',
53 50 'www.foo.bar' => '<a class="external" href="http://www.foo.bar">www.foo.bar</a>',
54 51 'http://foo.bar/page?p=1&t=z&s=' => '<a class="external" href="http://foo.bar/page?p=1&#38;t=z&#38;s=">http://foo.bar/page?p=1&#38;t=z&#38;s=</a>',
55 52 'http://foo.bar/page#125' => '<a class="external" href="http://foo.bar/page#125">http://foo.bar/page#125</a>',
56 53 'http://foo@www.bar.com' => '<a class="external" href="http://foo@www.bar.com">http://foo@www.bar.com</a>',
57 54 'http://foo:bar@www.bar.com' => '<a class="external" href="http://foo:bar@www.bar.com">http://foo:bar@www.bar.com</a>',
58 55 'ftp://foo.bar' => '<a class="external" href="ftp://foo.bar">ftp://foo.bar</a>',
59 56 'ftps://foo.bar' => '<a class="external" href="ftps://foo.bar">ftps://foo.bar</a>',
60 57 'sftp://foo.bar' => '<a class="external" href="sftp://foo.bar">sftp://foo.bar</a>',
61 58 # two exclamation marks
62 59 'http://example.net/path!602815048C7B5C20!302.html' => '<a class="external" href="http://example.net/path!602815048C7B5C20!302.html">http://example.net/path!602815048C7B5C20!302.html</a>',
63 60 # escaping
64 61 'http://foo"bar' => '<a class="external" href="http://foo&quot;bar">http://foo"bar</a>',
65 62 }
66 63 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) }
67 64 end
68 65
69 66 def test_auto_mailto
70 67 assert_equal '<p><a class="email" href="mailto:test@foo.bar">test@foo.bar</a></p>',
71 68 textilizable('test@foo.bar')
72 69 end
73 70
74 71 def test_inline_images
75 72 to_test = {
76 73 '!http://foo.bar/image.jpg!' => '<img src="http://foo.bar/image.jpg" alt="" />',
77 74 'floating !>http://foo.bar/image.jpg!' => 'floating <div style="float:right"><img src="http://foo.bar/image.jpg" alt="" /></div>',
78 75 'with class !(some-class)http://foo.bar/image.jpg!' => 'with class <img src="http://foo.bar/image.jpg" class="some-class" alt="" />',
79 76 # inline styles should be stripped
80 77 'with style !{width:100px;height100px}http://foo.bar/image.jpg!' => 'with style <img src="http://foo.bar/image.jpg" alt="" />',
81 78 'with title !http://foo.bar/image.jpg(This is a title)!' => 'with title <img src="http://foo.bar/image.jpg" title="This is a title" alt="This is a title" />',
82 79 'with title !http://foo.bar/image.jpg(This is a double-quoted "title")!' => 'with title <img src="http://foo.bar/image.jpg" title="This is a double-quoted &quot;title&quot;" alt="This is a double-quoted &quot;title&quot;" />',
83 80 }
84 81 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) }
85 82 end
86 83
87 84 def test_inline_images_inside_tags
88 85 raw = <<-RAW
89 86 h1. !foo.png! Heading
90 87
91 88 Centered image:
92 89
93 90 p=. !bar.gif!
94 91 RAW
95 92
96 93 assert textilizable(raw).include?('<img src="foo.png" alt="" />')
97 94 assert textilizable(raw).include?('<img src="bar.gif" alt="" />')
98 95 end
99 96
100 97 def test_acronyms
101 98 to_test = {
102 99 'this is an acronym: GPL(General Public License)' => 'this is an acronym: <acronym title="General Public License">GPL</acronym>',
103 100 'GPL(This is a double-quoted "title")' => '<acronym title="This is a double-quoted &quot;title&quot;">GPL</acronym>',
104 101 }
105 102 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) }
106 103
107 104 end
108 105
109 106 def test_attached_images
110 107 to_test = {
111 108 'Inline image: !logo.gif!' => 'Inline image: <img src="/attachments/download/3" title="This is a logo" alt="This is a logo" />',
112 109 'Inline image: !logo.GIF!' => 'Inline image: <img src="/attachments/download/3" title="This is a logo" alt="This is a logo" />',
113 110 'No match: !ogo.gif!' => 'No match: <img src="ogo.gif" alt="" />',
114 111 'No match: !ogo.GIF!' => 'No match: <img src="ogo.GIF" alt="" />',
115 112 # link image
116 113 '!logo.gif!:http://foo.bar/' => '<a href="http://foo.bar/"><img src="/attachments/download/3" title="This is a logo" alt="This is a logo" /></a>',
117 114 }
118 115 attachments = Attachment.find(:all)
119 116 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text, :attachments => attachments) }
120 117 end
121 118
122 119 def test_textile_external_links
123 120 to_test = {
124 121 'This is a "link":http://foo.bar' => 'This is a <a href="http://foo.bar" class="external">link</a>',
125 122 'This is an intern "link":/foo/bar' => 'This is an intern <a href="/foo/bar">link</a>',
126 123 '"link (Link title)":http://foo.bar' => '<a href="http://foo.bar" title="Link title" class="external">link</a>',
127 124 '"link (Link title with "double-quotes")":http://foo.bar' => '<a href="http://foo.bar" title="Link title with &quot;double-quotes&quot;" class="external">link</a>',
128 125 "This is not a \"Link\":\n\nAnother paragraph" => "This is not a \"Link\":</p>\n\n\n\t<p>Another paragraph",
129 126 # no multiline link text
130 127 "This is a double quote \"on the first line\nand another on a second line\":test" => "This is a double quote \"on the first line<br />and another on a second line\":test",
131 128 # mailto link
132 129 "\"system administrator\":mailto:sysadmin@example.com?subject=redmine%20permissions" => "<a href=\"mailto:sysadmin@example.com?subject=redmine%20permissions\">system administrator</a>",
133 130 # two exclamation marks
134 131 '"a link":http://example.net/path!602815048C7B5C20!302.html' => '<a href="http://example.net/path!602815048C7B5C20!302.html" class="external">a link</a>',
135 132 # escaping
136 133 '"test":http://foo"bar' => '<a href="http://foo&quot;bar" class="external">test</a>',
137 134 }
138 135 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) }
139 136 end
140 137
141 138 def test_redmine_links
142 139 issue_link = link_to('#3', {:controller => 'issues', :action => 'show', :id => 3},
143 140 :class => 'issue status-1 priority-1 overdue', :title => 'Error 281 when updating a recipe (New)')
144 141
145 142 changeset_link = link_to('r1', {:controller => 'repositories', :action => 'revision', :id => 'ecookbook', :rev => 1},
146 143 :class => 'changeset', :title => 'My very first commit')
147 144 changeset_link2 = link_to('r2', {:controller => 'repositories', :action => 'revision', :id => 'ecookbook', :rev => 2},
148 145 :class => 'changeset', :title => 'This commit fixes #1, #2 and references #1 & #3')
149 146
150 147 document_link = link_to('Test document', {:controller => 'documents', :action => 'show', :id => 1},
151 148 :class => 'document')
152 149
153 150 version_link = link_to('1.0', {:controller => 'versions', :action => 'show', :id => 2},
154 151 :class => 'version')
155 152
156 153 message_url = {:controller => 'messages', :action => 'show', :board_id => 1, :id => 4}
157 154
158 155 project_url = {:controller => 'projects', :action => 'show', :id => 'subproject1'}
159 156
160 157 source_url = {:controller => 'repositories', :action => 'entry', :id => 'ecookbook', :path => ['some', 'file']}
161 158 source_url_with_ext = {:controller => 'repositories', :action => 'entry', :id => 'ecookbook', :path => ['some', 'file.ext']}
162 159
163 160 to_test = {
164 161 # tickets
165 162 '#3, [#3], (#3) and #3.' => "#{issue_link}, [#{issue_link}], (#{issue_link}) and #{issue_link}.",
166 163 # changesets
167 164 'r1' => changeset_link,
168 165 'r1.' => "#{changeset_link}.",
169 166 'r1, r2' => "#{changeset_link}, #{changeset_link2}",
170 167 'r1,r2' => "#{changeset_link},#{changeset_link2}",
171 168 # documents
172 169 'document#1' => document_link,
173 170 'document:"Test document"' => document_link,
174 171 # versions
175 172 'version#2' => version_link,
176 173 'version:1.0' => version_link,
177 174 'version:"1.0"' => version_link,
178 175 # source
179 176 'source:/some/file' => link_to('source:/some/file', source_url, :class => 'source'),
180 177 'source:/some/file.' => link_to('source:/some/file', source_url, :class => 'source') + ".",
181 178 'source:/some/file.ext.' => link_to('source:/some/file.ext', source_url_with_ext, :class => 'source') + ".",
182 179 'source:/some/file. ' => link_to('source:/some/file', source_url, :class => 'source') + ".",
183 180 'source:/some/file.ext. ' => link_to('source:/some/file.ext', source_url_with_ext, :class => 'source') + ".",
184 181 'source:/some/file, ' => link_to('source:/some/file', source_url, :class => 'source') + ",",
185 182 'source:/some/file@52' => link_to('source:/some/file@52', source_url.merge(:rev => 52), :class => 'source'),
186 183 'source:/some/file.ext@52' => link_to('source:/some/file.ext@52', source_url_with_ext.merge(:rev => 52), :class => 'source'),
187 184 'source:/some/file#L110' => link_to('source:/some/file#L110', source_url.merge(:anchor => 'L110'), :class => 'source'),
188 185 'source:/some/file.ext#L110' => link_to('source:/some/file.ext#L110', source_url_with_ext.merge(:anchor => 'L110'), :class => 'source'),
189 186 'source:/some/file@52#L110' => link_to('source:/some/file@52#L110', source_url.merge(:rev => 52, :anchor => 'L110'), :class => 'source'),
190 187 'export:/some/file' => link_to('export:/some/file', source_url.merge(:format => 'raw'), :class => 'source download'),
191 188 # message
192 189 'message#4' => link_to('Post 2', message_url, :class => 'message'),
193 190 'message#5' => link_to('RE: post 2', message_url.merge(:anchor => 'message-5'), :class => 'message'),
194 191 # project
195 192 'project#3' => link_to('eCookbook Subproject 1', project_url, :class => 'project'),
196 193 'project:subproject1' => link_to('eCookbook Subproject 1', project_url, :class => 'project'),
197 194 'project:"eCookbook subProject 1"' => link_to('eCookbook Subproject 1', project_url, :class => 'project'),
198 195 # escaping
199 196 '!#3.' => '#3.',
200 197 '!r1' => 'r1',
201 198 '!document#1' => 'document#1',
202 199 '!document:"Test document"' => 'document:"Test document"',
203 200 '!version#2' => 'version#2',
204 201 '!version:1.0' => 'version:1.0',
205 202 '!version:"1.0"' => 'version:"1.0"',
206 203 '!source:/some/file' => 'source:/some/file',
207 204 # not found
208 205 '#0123456789' => '#0123456789',
209 206 # invalid expressions
210 207 'source:' => 'source:',
211 208 # url hash
212 209 "http://foo.bar/FAQ#3" => '<a class="external" href="http://foo.bar/FAQ#3">http://foo.bar/FAQ#3</a>',
213 210 }
214 211 @project = Project.find(1)
215 212 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text), "#{text} failed" }
216 213 end
217 214
218 215 def test_attachment_links
219 216 attachment_link = link_to('error281.txt', {:controller => 'attachments', :action => 'download', :id => '1'}, :class => 'attachment')
220 217 to_test = {
221 218 'attachment:error281.txt' => attachment_link
222 219 }
223 220 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text, :attachments => Issue.find(3).attachments), "#{text} failed" }
224 221 end
225 222
226 223 def test_wiki_links
227 224 to_test = {
228 225 '[[CookBook documentation]]' => '<a href="/projects/ecookbook/wiki/CookBook_documentation" class="wiki-page">CookBook documentation</a>',
229 226 '[[Another page|Page]]' => '<a href="/projects/ecookbook/wiki/Another_page" class="wiki-page">Page</a>',
230 227 # link with anchor
231 228 '[[CookBook documentation#One-section]]' => '<a href="/projects/ecookbook/wiki/CookBook_documentation#One-section" class="wiki-page">CookBook documentation</a>',
232 229 '[[Another page#anchor|Page]]' => '<a href="/projects/ecookbook/wiki/Another_page#anchor" class="wiki-page">Page</a>',
233 230 # page that doesn't exist
234 231 '[[Unknown page]]' => '<a href="/projects/ecookbook/wiki/Unknown_page" class="wiki-page new">Unknown page</a>',
235 232 '[[Unknown page|404]]' => '<a href="/projects/ecookbook/wiki/Unknown_page" class="wiki-page new">404</a>',
236 233 # link to another project wiki
237 234 '[[onlinestore:]]' => '<a href="/projects/onlinestore/wiki/" class="wiki-page">onlinestore</a>',
238 235 '[[onlinestore:|Wiki]]' => '<a href="/projects/onlinestore/wiki/" class="wiki-page">Wiki</a>',
239 236 '[[onlinestore:Start page]]' => '<a href="/projects/onlinestore/wiki/Start_page" class="wiki-page">Start page</a>',
240 237 '[[onlinestore:Start page|Text]]' => '<a href="/projects/onlinestore/wiki/Start_page" class="wiki-page">Text</a>',
241 238 '[[onlinestore:Unknown page]]' => '<a href="/projects/onlinestore/wiki/Unknown_page" class="wiki-page new">Unknown page</a>',
242 239 # striked through link
243 240 '-[[Another page|Page]]-' => '<del><a href="/projects/ecookbook/wiki/Another_page" class="wiki-page">Page</a></del>',
244 241 '-[[Another page|Page]] link-' => '<del><a href="/projects/ecookbook/wiki/Another_page" class="wiki-page">Page</a> link</del>',
245 242 # escaping
246 243 '![[Another page|Page]]' => '[[Another page|Page]]',
247 244 # project does not exist
248 245 '[[unknowproject:Start]]' => '[[unknowproject:Start]]',
249 246 '[[unknowproject:Start|Page title]]' => '[[unknowproject:Start|Page title]]',
250 247 }
251 248 @project = Project.find(1)
252 249 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) }
253 250 end
254 251
255 252 def test_html_tags
256 253 to_test = {
257 254 "<div>content</div>" => "<p>&lt;div&gt;content&lt;/div&gt;</p>",
258 255 "<div class=\"bold\">content</div>" => "<p>&lt;div class=\"bold\"&gt;content&lt;/div&gt;</p>",
259 256 "<script>some script;</script>" => "<p>&lt;script&gt;some script;&lt;/script&gt;</p>",
260 257 # do not escape pre/code tags
261 258 "<pre>\nline 1\nline2</pre>" => "<pre>\nline 1\nline2</pre>",
262 259 "<pre><code>\nline 1\nline2</code></pre>" => "<pre><code>\nline 1\nline2</code></pre>",
263 260 "<pre><div>content</div></pre>" => "<pre>&lt;div&gt;content&lt;/div&gt;</pre>",
264 261 "HTML comment: <!-- no comments -->" => "<p>HTML comment: &lt;!-- no comments --&gt;</p>",
265 262 "<!-- opening comment" => "<p>&lt;!-- opening comment</p>",
266 263 # remove attributes except class
267 264 "<pre class='foo'>some text</pre>" => "<pre class='foo'>some text</pre>",
268 265 "<pre onmouseover='alert(1)'>some text</pre>" => "<pre>some text</pre>",
269 266 }
270 267 to_test.each { |text, result| assert_equal result, textilizable(text) }
271 268 end
272 269
273 270 def test_allowed_html_tags
274 271 to_test = {
275 272 "<pre>preformatted text</pre>" => "<pre>preformatted text</pre>",
276 273 "<notextile>no *textile* formatting</notextile>" => "no *textile* formatting",
277 274 "<notextile>this is <tag>a tag</tag></notextile>" => "this is &lt;tag&gt;a tag&lt;/tag&gt;"
278 275 }
279 276 to_test.each { |text, result| assert_equal result, textilizable(text) }
280 277 end
281 278
282 279 def test_pre_tags
283 280 raw = <<-RAW
284 281 Before
285 282
286 283 <pre>
287 284 <prepared-statement-cache-size>32</prepared-statement-cache-size>
288 285 </pre>
289 286
290 287 After
291 288 RAW
292 289
293 290 expected = <<-EXPECTED
294 291 <p>Before</p>
295 292 <pre>
296 293 &lt;prepared-statement-cache-size&gt;32&lt;/prepared-statement-cache-size&gt;
297 294 </pre>
298 295 <p>After</p>
299 296 EXPECTED
300 297
301 298 assert_equal expected.gsub(%r{[\r\n\t]}, ''), textilizable(raw).gsub(%r{[\r\n\t]}, '')
302 299 end
303 300
304 301 def test_pre_content_should_not_parse_wiki_and_redmine_links
305 302 raw = <<-RAW
306 303 [[CookBook documentation]]
307 304
308 305 #1
309 306
310 307 <pre>
311 308 [[CookBook documentation]]
312 309
313 310 #1
314 311 </pre>
315 312 RAW
316 313
317 314 expected = <<-EXPECTED
318 315 <p><a href="/projects/ecookbook/wiki/CookBook_documentation" class="wiki-page">CookBook documentation</a></p>
319 316 <p><a href="/issues/1" class="issue status-1 priority-1" title="Can't print recipes (New)">#1</a></p>
320 317 <pre>
321 318 [[CookBook documentation]]
322 319
323 320 #1
324 321 </pre>
325 322 EXPECTED
326 323
327 324 @project = Project.find(1)
328 325 assert_equal expected.gsub(%r{[\r\n\t]}, ''), textilizable(raw).gsub(%r{[\r\n\t]}, '')
329 326 end
330 327
331 328 def test_non_closing_pre_blocks_should_be_closed
332 329 raw = <<-RAW
333 330 <pre><code>
334 331 RAW
335 332
336 333 expected = <<-EXPECTED
337 334 <pre><code>
338 335 </code></pre>
339 336 EXPECTED
340 337
341 338 @project = Project.find(1)
342 339 assert_equal expected.gsub(%r{[\r\n\t]}, ''), textilizable(raw).gsub(%r{[\r\n\t]}, '')
343 340 end
344 341
345 342 def test_syntax_highlight
346 343 raw = <<-RAW
347 344 <pre><code class="ruby">
348 345 # Some ruby code here
349 346 </code></pre>
350 347 RAW
351 348
352 349 expected = <<-EXPECTED
353 350 <pre><code class="ruby syntaxhl"><span class=\"CodeRay\"><span class="no">1</span> <span class="c"># Some ruby code here</span></span>
354 351 </code></pre>
355 352 EXPECTED
356 353
357 354 assert_equal expected.gsub(%r{[\r\n\t]}, ''), textilizable(raw).gsub(%r{[\r\n\t]}, '')
358 355 end
359 356
360 357 def test_wiki_links_in_tables
361 358 to_test = {"|[[Page|Link title]]|[[Other Page|Other title]]|\n|Cell 21|[[Last page]]|" =>
362 359 '<tr><td><a href="/projects/ecookbook/wiki/Page" class="wiki-page new">Link title</a></td>' +
363 360 '<td><a href="/projects/ecookbook/wiki/Other_Page" class="wiki-page new">Other title</a></td>' +
364 361 '</tr><tr><td>Cell 21</td><td><a href="/projects/ecookbook/wiki/Last_page" class="wiki-page new">Last page</a></td></tr>'
365 362 }
366 363 @project = Project.find(1)
367 364 to_test.each { |text, result| assert_equal "<table>#{result}</table>", textilizable(text).gsub(/[\t\n]/, '') }
368 365 end
369 366
370 367 def test_text_formatting
371 368 to_test = {'*_+bold, italic and underline+_*' => '<strong><em><ins>bold, italic and underline</ins></em></strong>',
372 369 '(_text within parentheses_)' => '(<em>text within parentheses</em>)',
373 370 'a *Humane Web* Text Generator' => 'a <strong>Humane Web</strong> Text Generator',
374 371 'a H *umane* W *eb* T *ext* G *enerator*' => 'a H <strong>umane</strong> W <strong>eb</strong> T <strong>ext</strong> G <strong>enerator</strong>',
375 372 'a *H* umane *W* eb *T* ext *G* enerator' => 'a <strong>H</strong> umane <strong>W</strong> eb <strong>T</strong> ext <strong>G</strong> enerator',
376 373 }
377 374 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) }
378 375 end
379 376
380 377 def test_wiki_horizontal_rule
381 378 assert_equal '<hr />', textilizable('---')
382 379 assert_equal '<p>Dashes: ---</p>', textilizable('Dashes: ---')
383 380 end
384 381
385 382 def test_acronym
386 383 assert_equal '<p>This is an acronym: <acronym title="American Civil Liberties Union">ACLU</acronym>.</p>',
387 384 textilizable('This is an acronym: ACLU(American Civil Liberties Union).')
388 385 end
389 386
390 387 def test_footnotes
391 388 raw = <<-RAW
392 389 This is some text[1].
393 390
394 391 fn1. This is the foot note
395 392 RAW
396 393
397 394 expected = <<-EXPECTED
398 395 <p>This is some text<sup><a href=\"#fn1\">1</a></sup>.</p>
399 396 <p id="fn1" class="footnote"><sup>1</sup> This is the foot note</p>
400 397 EXPECTED
401 398
402 399 assert_equal expected.gsub(%r{[\r\n\t]}, ''), textilizable(raw).gsub(%r{[\r\n\t]}, '')
403 400 end
404 401
405 402 def test_table_of_content
406 403 raw = <<-RAW
407 404 {{toc}}
408 405
409 406 h1. Title
410 407
411 408 Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas sed libero.
412 409
413 410 h2. Subtitle with a [[Wiki]] link
414 411
415 412 Nullam commodo metus accumsan nulla. Curabitur lobortis dui id dolor.
416 413
417 414 h2. Subtitle with [[Wiki|another Wiki]] link
418 415
419 416 h2. Subtitle with %{color:red}red text%
420 417
421 418 h1. Another title
422 419
423 420 h2. An "Internet link":http://www.redmine.org/ inside subtitle
424 421
425 422 h2. "Project Name !/attachments/1234/logo_small.gif! !/attachments/5678/logo_2.png!":/projects/projectname/issues
426 423
427 424 RAW
428 425
429 426 expected = '<ul class="toc">' +
430 427 '<li class="heading1"><a href="#Title">Title</a></li>' +
431 428 '<li class="heading2"><a href="#Subtitle-with-a-Wiki-link">Subtitle with a Wiki link</a></li>' +
432 429 '<li class="heading2"><a href="#Subtitle-with-another-Wiki-link">Subtitle with another Wiki link</a></li>' +
433 430 '<li class="heading2"><a href="#Subtitle-with-red-text">Subtitle with red text</a></li>' +
434 431 '<li class="heading1"><a href="#Another-title">Another title</a></li>' +
435 432 '<li class="heading2"><a href="#An-Internet-link-inside-subtitle">An Internet link inside subtitle</a></li>' +
436 433 '<li class="heading2"><a href="#Project-Name">Project Name</a></li>' +
437 434 '</ul>'
438 435
439 436 assert textilizable(raw).gsub("\n", "").include?(expected)
440 437 end
441 438
442 439 def test_blockquote
443 440 # orig raw text
444 441 raw = <<-RAW
445 442 John said:
446 443 > Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas sed libero.
447 444 > Nullam commodo metus accumsan nulla. Curabitur lobortis dui id dolor.
448 445 > * Donec odio lorem,
449 446 > * sagittis ac,
450 447 > * malesuada in,
451 448 > * adipiscing eu, dolor.
452 449 >
453 450 > >Nulla varius pulvinar diam. Proin id arcu id lorem scelerisque condimentum. Proin vehicula turpis vitae lacus.
454 451 > Proin a tellus. Nam vel neque.
455 452
456 453 He's right.
457 454 RAW
458 455
459 456 # expected html
460 457 expected = <<-EXPECTED
461 458 <p>John said:</p>
462 459 <blockquote>
463 460 Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas sed libero.
464 461 Nullam commodo metus accumsan nulla. Curabitur lobortis dui id dolor.
465 462 <ul>
466 463 <li>Donec odio lorem,</li>
467 464 <li>sagittis ac,</li>
468 465 <li>malesuada in,</li>
469 466 <li>adipiscing eu, dolor.</li>
470 467 </ul>
471 468 <blockquote>
472 469 <p>Nulla varius pulvinar diam. Proin id arcu id lorem scelerisque condimentum. Proin vehicula turpis vitae lacus.</p>
473 470 </blockquote>
474 471 <p>Proin a tellus. Nam vel neque.</p>
475 472 </blockquote>
476 473 <p>He's right.</p>
477 474 EXPECTED
478 475
479 476 assert_equal expected.gsub(%r{\s+}, ''), textilizable(raw).gsub(%r{\s+}, '')
480 477 end
481 478
482 479 def test_table
483 480 raw = <<-RAW
484 481 This is a table with empty cells:
485 482
486 483 |cell11|cell12||
487 484 |cell21||cell23|
488 485 |cell31|cell32|cell33|
489 486 RAW
490 487
491 488 expected = <<-EXPECTED
492 489 <p>This is a table with empty cells:</p>
493 490
494 491 <table>
495 492 <tr><td>cell11</td><td>cell12</td><td></td></tr>
496 493 <tr><td>cell21</td><td></td><td>cell23</td></tr>
497 494 <tr><td>cell31</td><td>cell32</td><td>cell33</td></tr>
498 495 </table>
499 496 EXPECTED
500 497
501 498 assert_equal expected.gsub(%r{\s+}, ''), textilizable(raw).gsub(%r{\s+}, '')
502 499 end
503 500
504 501 def test_table_with_line_breaks
505 502 raw = <<-RAW
506 503 This is a table with line breaks:
507 504
508 505 |cell11
509 506 continued|cell12||
510 507 |-cell21-||cell23
511 508 cell23 line2
512 509 cell23 *line3*|
513 510 |cell31|cell32
514 511 cell32 line2|cell33|
515 512
516 513 RAW
517 514
518 515 expected = <<-EXPECTED
519 516 <p>This is a table with line breaks:</p>
520 517
521 518 <table>
522 519 <tr>
523 520 <td>cell11<br />continued</td>
524 521 <td>cell12</td>
525 522 <td></td>
526 523 </tr>
527 524 <tr>
528 525 <td><del>cell21</del></td>
529 526 <td></td>
530 527 <td>cell23<br/>cell23 line2<br/>cell23 <strong>line3</strong></td>
531 528 </tr>
532 529 <tr>
533 530 <td>cell31</td>
534 531 <td>cell32<br/>cell32 line2</td>
535 532 <td>cell33</td>
536 533 </tr>
537 534 </table>
538 535 EXPECTED
539 536
540 537 assert_equal expected.gsub(%r{\s+}, ''), textilizable(raw).gsub(%r{\s+}, '')
541 538 end
542 539
543 540 def test_textile_should_not_mangle_brackets
544 541 assert_equal '<p>[msg1][msg2]</p>', textilizable('[msg1][msg2]')
545 542 end
546 543
547 544 def test_default_formatter
548 545 Setting.text_formatting = 'unknown'
549 546 text = 'a *link*: http://www.example.net/'
550 547 assert_equal '<p>a *link*: <a href="http://www.example.net/">http://www.example.net/</a></p>', textilizable(text)
551 548 Setting.text_formatting = 'textile'
552 549 end
553 550
554 551 def test_due_date_distance_in_words
555 552 to_test = { Date.today => 'Due in 0 days',
556 553 Date.today + 1 => 'Due in 1 day',
557 554 Date.today + 100 => 'Due in about 3 months',
558 555 Date.today + 20000 => 'Due in over 54 years',
559 556 Date.today - 1 => '1 day late',
560 557 Date.today - 100 => 'about 3 months late',
561 558 Date.today - 20000 => 'over 54 years late',
562 559 }
563 560 to_test.each do |date, expected|
564 561 assert_equal expected, due_date_distance_in_words(date)
565 562 end
566 563 end
567 564
568 565 def test_avatar
569 566 # turn on avatars
570 567 Setting.gravatar_enabled = '1'
571 568 assert avatar(User.find_by_mail('jsmith@somenet.foo')).include?(Digest::MD5.hexdigest('jsmith@somenet.foo'))
572 569 assert avatar('jsmith <jsmith@somenet.foo>').include?(Digest::MD5.hexdigest('jsmith@somenet.foo'))
573 570 assert_nil avatar('jsmith')
574 571 assert_nil avatar(nil)
575 572
576 573 # turn off avatars
577 574 Setting.gravatar_enabled = '0'
578 575 assert_nil avatar(User.find_by_mail('jsmith@somenet.foo'))
579 576 end
580 577
581 578 def test_link_to_user
582 579 user = User.find(2)
583 580 t = link_to_user(user)
584 581 assert_equal "<a href=\"/users/2\">#{ user.name }</a>", t
585 582 end
586 583
587 584 def test_link_to_user_should_not_link_to_locked_user
588 585 user = User.find(5)
589 586 assert user.locked?
590 587 t = link_to_user(user)
591 588 assert_equal user.name, t
592 589 end
593 590
594 591 def test_link_to_user_should_not_link_to_anonymous
595 592 user = User.anonymous
596 593 assert user.anonymous?
597 594 t = link_to_user(user)
598 595 assert_equal ::I18n.t(:label_user_anonymous), t
599 596 end
600 597
601 598 def test_link_to_project
602 599 project = Project.find(1)
603 600 assert_equal %(<a href="/projects/ecookbook">eCookbook</a>),
604 601 link_to_project(project)
605 602 assert_equal %(<a href="/projects/ecookbook/settings">eCookbook</a>),
606 603 link_to_project(project, :action => 'settings')
607 604 assert_equal %(<a href="http://test.host/projects/ecookbook?jump=blah">eCookbook</a>),
608 605 link_to_project(project, {:only_path => false, :jump => 'blah'})
609 606 assert_equal %(<a href="/projects/ecookbook/settings" class="project">eCookbook</a>),
610 607 link_to_project(project, {:action => 'settings'}, :class => "project")
611 608 end
612 609 end
General Comments 0
You need to be logged in to leave comments. Login now