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