##// END OF EJS Templates
Adds a test for attached image inside a link (#4033)....
Jean-Philippe Lang -
r2848:9233a07a2355
parent child
Show More
@@ -1,471 +1,473
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 20 class ApplicationHelperTest < HelperTestCase
21 21 include ApplicationHelper
22 22 include ActionView::Helpers::TextHelper
23 23 include ActionView::Helpers::DateHelper
24 24
25 25 fixtures :projects, :roles, :enabled_modules, :users,
26 26 :repositories, :changesets,
27 27 :trackers, :issue_statuses, :issues, :versions, :documents,
28 28 :wikis, :wiki_pages, :wiki_contents,
29 29 :boards, :messages,
30 30 :attachments
31 31
32 32 def setup
33 33 super
34 34 end
35 35
36 36 def test_auto_links
37 37 to_test = {
38 38 'http://foo.bar' => '<a class="external" href="http://foo.bar">http://foo.bar</a>',
39 39 'http://foo.bar/~user' => '<a class="external" href="http://foo.bar/~user">http://foo.bar/~user</a>',
40 40 'http://foo.bar.' => '<a class="external" href="http://foo.bar">http://foo.bar</a>.',
41 41 'https://foo.bar.' => '<a class="external" href="https://foo.bar">https://foo.bar</a>.',
42 42 'This is a link: http://foo.bar.' => 'This is a link: <a class="external" href="http://foo.bar">http://foo.bar</a>.',
43 43 'A link (eg. http://foo.bar).' => 'A link (eg. <a class="external" href="http://foo.bar">http://foo.bar</a>).',
44 44 '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>.',
45 45 'http://www.foo.bar/Test_(foobar)' => '<a class="external" href="http://www.foo.bar/Test_(foobar)">http://www.foo.bar/Test_(foobar)</a>',
46 46 '(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>)',
47 47 '(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>)',
48 48 '(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 49 '(see "inline link":http://www.foo.bar/Test_(foobar))' => '(see <a href="http://www.foo.bar/Test_(foobar)" class="external">inline link</a>)',
50 50 '(see "inline link":http://www.foo.bar/Test)' => '(see <a href="http://www.foo.bar/Test" class="external">inline link</a>)',
51 51 '(see "inline link":http://www.foo.bar/Test).' => '(see <a href="http://www.foo.bar/Test" class="external">inline link</a>).',
52 52 'www.foo.bar' => '<a class="external" href="http://www.foo.bar">www.foo.bar</a>',
53 53 '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>',
54 54 'http://foo.bar/page#125' => '<a class="external" href="http://foo.bar/page#125">http://foo.bar/page#125</a>',
55 55 'http://foo@www.bar.com' => '<a class="external" href="http://foo@www.bar.com">http://foo@www.bar.com</a>',
56 56 'http://foo:bar@www.bar.com' => '<a class="external" href="http://foo:bar@www.bar.com">http://foo:bar@www.bar.com</a>',
57 57 'ftp://foo.bar' => '<a class="external" href="ftp://foo.bar">ftp://foo.bar</a>',
58 58 'ftps://foo.bar' => '<a class="external" href="ftps://foo.bar">ftps://foo.bar</a>',
59 59 'sftp://foo.bar' => '<a class="external" href="sftp://foo.bar">sftp://foo.bar</a>',
60 60 # two exclamation marks
61 61 '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>',
62 62 }
63 63 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) }
64 64 end
65 65
66 66 def test_auto_mailto
67 67 assert_equal '<p><a href="mailto:test@foo.bar" class="email">test@foo.bar</a></p>',
68 68 textilizable('test@foo.bar')
69 69 end
70 70
71 71 def test_inline_images
72 72 to_test = {
73 73 '!http://foo.bar/image.jpg!' => '<img src="http://foo.bar/image.jpg" alt="" />',
74 74 'floating !>http://foo.bar/image.jpg!' => 'floating <div style="float:right"><img src="http://foo.bar/image.jpg" alt="" /></div>',
75 75 'with class !(some-class)http://foo.bar/image.jpg!' => 'with class <img src="http://foo.bar/image.jpg" class="some-class" alt="" />',
76 76 # inline styles should be stripped
77 77 'with style !{width:100px;height100px}http://foo.bar/image.jpg!' => 'with style <img src="http://foo.bar/image.jpg" alt="" />',
78 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" />',
79 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;" />',
80 80 }
81 81 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) }
82 82 end
83 83
84 84 def test_acronyms
85 85 to_test = {
86 86 'this is an acronym: GPL(General Public License)' => 'this is an acronym: <acronym title="General Public License">GPL</acronym>',
87 87 'GPL(This is a double-quoted "title")' => '<acronym title="This is a double-quoted &quot;title&quot;">GPL</acronym>',
88 88 }
89 89 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) }
90 90
91 91 end
92 92
93 93 def test_attached_images
94 94 to_test = {
95 95 'Inline image: !logo.gif!' => 'Inline image: <img src="/attachments/download/3" title="This is a logo" alt="This is a logo" />',
96 96 'Inline image: !logo.GIF!' => 'Inline image: <img src="/attachments/download/3" title="This is a logo" alt="This is a logo" />',
97 97 'No match: !ogo.gif!' => 'No match: <img src="ogo.gif" alt="" />',
98 'No match: !ogo.GIF!' => 'No match: <img src="ogo.GIF" alt="" />'
98 'No match: !ogo.GIF!' => 'No match: <img src="ogo.GIF" alt="" />',
99 # link image
100 '!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>',
99 101 }
100 102 attachments = Attachment.find(:all)
101 103 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text, :attachments => attachments) }
102 104 end
103 105
104 106 def test_textile_external_links
105 107 to_test = {
106 108 'This is a "link":http://foo.bar' => 'This is a <a href="http://foo.bar" class="external">link</a>',
107 109 'This is an intern "link":/foo/bar' => 'This is an intern <a href="/foo/bar">link</a>',
108 110 '"link (Link title)":http://foo.bar' => '<a href="http://foo.bar" title="Link title" class="external">link</a>',
109 111 '"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>',
110 112 "This is not a \"Link\":\n\nAnother paragraph" => "This is not a \"Link\":</p>\n\n\n\t<p>Another paragraph",
111 113 # no multiline link text
112 114 "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",
113 115 # mailto link
114 116 "\"system administrator\":mailto:sysadmin@example.com?subject=redmine%20permissions" => "<a href=\"mailto:sysadmin@example.com?subject=redmine%20permissions\">system administrator</a>",
115 117 # two exclamation marks
116 118 '"a link":http://example.net/path!602815048C7B5C20!302.html' => '<a href="http://example.net/path!602815048C7B5C20!302.html" class="external">a link</a>',
117 119 }
118 120 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) }
119 121 end
120 122
121 123 def test_redmine_links
122 124 issue_link = link_to('#3', {:controller => 'issues', :action => 'show', :id => 3},
123 125 :class => 'issue', :title => 'Error 281 when updating a recipe (New)')
124 126
125 127 changeset_link = link_to('r1', {:controller => 'repositories', :action => 'revision', :id => 'ecookbook', :rev => 1},
126 128 :class => 'changeset', :title => 'My very first commit')
127 129 changeset_link2 = link_to('r2', {:controller => 'repositories', :action => 'revision', :id => 'ecookbook', :rev => 2},
128 130 :class => 'changeset', :title => 'This commit fixes #1, #2 and references #1 & #3')
129 131
130 132 document_link = link_to('Test document', {:controller => 'documents', :action => 'show', :id => 1},
131 133 :class => 'document')
132 134
133 135 version_link = link_to('1.0', {:controller => 'versions', :action => 'show', :id => 2},
134 136 :class => 'version')
135 137
136 138 message_url = {:controller => 'messages', :action => 'show', :board_id => 1, :id => 4}
137 139
138 140 source_url = {:controller => 'repositories', :action => 'entry', :id => 'ecookbook', :path => ['some', 'file']}
139 141 source_url_with_ext = {:controller => 'repositories', :action => 'entry', :id => 'ecookbook', :path => ['some', 'file.ext']}
140 142
141 143 to_test = {
142 144 # tickets
143 145 '#3, #3 and #3.' => "#{issue_link}, #{issue_link} and #{issue_link}.",
144 146 # changesets
145 147 'r1' => changeset_link,
146 148 'r1.' => "#{changeset_link}.",
147 149 'r1, r2' => "#{changeset_link}, #{changeset_link2}",
148 150 'r1,r2' => "#{changeset_link},#{changeset_link2}",
149 151 # documents
150 152 'document#1' => document_link,
151 153 'document:"Test document"' => document_link,
152 154 # versions
153 155 'version#2' => version_link,
154 156 'version:1.0' => version_link,
155 157 'version:"1.0"' => version_link,
156 158 # source
157 159 'source:/some/file' => link_to('source:/some/file', source_url, :class => 'source'),
158 160 'source:/some/file.' => link_to('source:/some/file', source_url, :class => 'source') + ".",
159 161 'source:/some/file.ext.' => link_to('source:/some/file.ext', source_url_with_ext, :class => 'source') + ".",
160 162 'source:/some/file. ' => link_to('source:/some/file', source_url, :class => 'source') + ".",
161 163 'source:/some/file.ext. ' => link_to('source:/some/file.ext', source_url_with_ext, :class => 'source') + ".",
162 164 'source:/some/file, ' => link_to('source:/some/file', source_url, :class => 'source') + ",",
163 165 'source:/some/file@52' => link_to('source:/some/file@52', source_url.merge(:rev => 52), :class => 'source'),
164 166 'source:/some/file.ext@52' => link_to('source:/some/file.ext@52', source_url_with_ext.merge(:rev => 52), :class => 'source'),
165 167 'source:/some/file#L110' => link_to('source:/some/file#L110', source_url.merge(:anchor => 'L110'), :class => 'source'),
166 168 'source:/some/file.ext#L110' => link_to('source:/some/file.ext#L110', source_url_with_ext.merge(:anchor => 'L110'), :class => 'source'),
167 169 'source:/some/file@52#L110' => link_to('source:/some/file@52#L110', source_url.merge(:rev => 52, :anchor => 'L110'), :class => 'source'),
168 170 'export:/some/file' => link_to('export:/some/file', source_url.merge(:format => 'raw'), :class => 'source download'),
169 171 # message
170 172 'message#4' => link_to('Post 2', message_url, :class => 'message'),
171 173 'message#5' => link_to('RE: post 2', message_url.merge(:anchor => 'message-5'), :class => 'message'),
172 174 # escaping
173 175 '!#3.' => '#3.',
174 176 '!r1' => 'r1',
175 177 '!document#1' => 'document#1',
176 178 '!document:"Test document"' => 'document:"Test document"',
177 179 '!version#2' => 'version#2',
178 180 '!version:1.0' => 'version:1.0',
179 181 '!version:"1.0"' => 'version:"1.0"',
180 182 '!source:/some/file' => 'source:/some/file',
181 183 # invalid expressions
182 184 'source:' => 'source:',
183 185 # url hash
184 186 "http://foo.bar/FAQ#3" => '<a class="external" href="http://foo.bar/FAQ#3">http://foo.bar/FAQ#3</a>',
185 187 }
186 188 @project = Project.find(1)
187 189 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) }
188 190 end
189 191
190 192 def test_wiki_links
191 193 to_test = {
192 194 '[[CookBook documentation]]' => '<a href="/projects/ecookbook/wiki/CookBook_documentation" class="wiki-page">CookBook documentation</a>',
193 195 '[[Another page|Page]]' => '<a href="/projects/ecookbook/wiki/Another_page" class="wiki-page">Page</a>',
194 196 # link with anchor
195 197 '[[CookBook documentation#One-section]]' => '<a href="/projects/ecookbook/wiki/CookBook_documentation#One-section" class="wiki-page">CookBook documentation</a>',
196 198 '[[Another page#anchor|Page]]' => '<a href="/projects/ecookbook/wiki/Another_page#anchor" class="wiki-page">Page</a>',
197 199 # page that doesn't exist
198 200 '[[Unknown page]]' => '<a href="/projects/ecookbook/wiki/Unknown_page" class="wiki-page new">Unknown page</a>',
199 201 '[[Unknown page|404]]' => '<a href="/projects/ecookbook/wiki/Unknown_page" class="wiki-page new">404</a>',
200 202 # link to another project wiki
201 203 '[[onlinestore:]]' => '<a href="/projects/onlinestore/wiki/" class="wiki-page">onlinestore</a>',
202 204 '[[onlinestore:|Wiki]]' => '<a href="/projects/onlinestore/wiki/" class="wiki-page">Wiki</a>',
203 205 '[[onlinestore:Start page]]' => '<a href="/projects/onlinestore/wiki/Start_page" class="wiki-page">Start page</a>',
204 206 '[[onlinestore:Start page|Text]]' => '<a href="/projects/onlinestore/wiki/Start_page" class="wiki-page">Text</a>',
205 207 '[[onlinestore:Unknown page]]' => '<a href="/projects/onlinestore/wiki/Unknown_page" class="wiki-page new">Unknown page</a>',
206 208 # striked through link
207 209 '-[[Another page|Page]]-' => '<del><a href="/projects/ecookbook/wiki/Another_page" class="wiki-page">Page</a></del>',
208 210 '-[[Another page|Page]] link-' => '<del><a href="/projects/ecookbook/wiki/Another_page" class="wiki-page">Page</a> link</del>',
209 211 # escaping
210 212 '![[Another page|Page]]' => '[[Another page|Page]]',
211 213 # project does not exist
212 214 '[[unknowproject:Start]]' => '[[unknowproject:Start]]',
213 215 '[[unknowproject:Start|Page title]]' => '[[unknowproject:Start|Page title]]',
214 216 }
215 217 @project = Project.find(1)
216 218 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) }
217 219 end
218 220
219 221 def test_html_tags
220 222 to_test = {
221 223 "<div>content</div>" => "<p>&lt;div&gt;content&lt;/div&gt;</p>",
222 224 "<div class=\"bold\">content</div>" => "<p>&lt;div class=\"bold\"&gt;content&lt;/div&gt;</p>",
223 225 "<script>some script;</script>" => "<p>&lt;script&gt;some script;&lt;/script&gt;</p>",
224 226 # do not escape pre/code tags
225 227 "<pre>\nline 1\nline2</pre>" => "<pre>\nline 1\nline2</pre>",
226 228 "<pre><code>\nline 1\nline2</code></pre>" => "<pre><code>\nline 1\nline2</code></pre>",
227 229 "<pre><div>content</div></pre>" => "<pre>&lt;div&gt;content&lt;/div&gt;</pre>",
228 230 "HTML comment: <!-- no comments -->" => "<p>HTML comment: &lt;!-- no comments --&gt;</p>",
229 231 "<!-- opening comment" => "<p>&lt;!-- opening comment</p>",
230 232 # remove attributes except class
231 233 "<pre class='foo'>some text</pre>" => "<pre class='foo'>some text</pre>",
232 234 "<pre onmouseover='alert(1)'>some text</pre>" => "<pre>some text</pre>",
233 235 }
234 236 to_test.each { |text, result| assert_equal result, textilizable(text) }
235 237 end
236 238
237 239 def test_allowed_html_tags
238 240 to_test = {
239 241 "<pre>preformatted text</pre>" => "<pre>preformatted text</pre>",
240 242 "<notextile>no *textile* formatting</notextile>" => "no *textile* formatting",
241 243 "<notextile>this is <tag>a tag</tag></notextile>" => "this is &lt;tag&gt;a tag&lt;/tag&gt;"
242 244 }
243 245 to_test.each { |text, result| assert_equal result, textilizable(text) }
244 246 end
245 247
246 248 def test_syntax_highlight
247 249 raw = <<-RAW
248 250 <pre><code class="ruby">
249 251 # Some ruby code here
250 252 </pre></code>
251 253 RAW
252 254
253 255 expected = <<-EXPECTED
254 256 <pre><code class="ruby CodeRay"><span class="no">1</span> <span class="c"># Some ruby code here</span>
255 257 </pre></code>
256 258 EXPECTED
257 259
258 260 assert_equal expected.gsub(%r{[\r\n\t]}, ''), textilizable(raw).gsub(%r{[\r\n\t]}, '')
259 261 end
260 262
261 263 def test_wiki_links_in_tables
262 264 to_test = {"|[[Page|Link title]]|[[Other Page|Other title]]|\n|Cell 21|[[Last page]]|" =>
263 265 '<tr><td><a href="/projects/ecookbook/wiki/Page" class="wiki-page new">Link title</a></td>' +
264 266 '<td><a href="/projects/ecookbook/wiki/Other_Page" class="wiki-page new">Other title</a></td>' +
265 267 '</tr><tr><td>Cell 21</td><td><a href="/projects/ecookbook/wiki/Last_page" class="wiki-page new">Last page</a></td></tr>'
266 268 }
267 269 @project = Project.find(1)
268 270 to_test.each { |text, result| assert_equal "<table>#{result}</table>", textilizable(text).gsub(/[\t\n]/, '') }
269 271 end
270 272
271 273 def test_text_formatting
272 274 to_test = {'*_+bold, italic and underline+_*' => '<strong><em><ins>bold, italic and underline</ins></em></strong>',
273 275 '(_text within parentheses_)' => '(<em>text within parentheses</em>)',
274 276 'a *Humane Web* Text Generator' => 'a <strong>Humane Web</strong> Text Generator',
275 277 '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>',
276 278 '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',
277 279 }
278 280 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) }
279 281 end
280 282
281 283 def test_wiki_horizontal_rule
282 284 assert_equal '<hr />', textilizable('---')
283 285 assert_equal '<p>Dashes: ---</p>', textilizable('Dashes: ---')
284 286 end
285 287
286 288 def test_acronym
287 289 assert_equal '<p>This is an acronym: <acronym title="American Civil Liberties Union">ACLU</acronym>.</p>',
288 290 textilizable('This is an acronym: ACLU(American Civil Liberties Union).')
289 291 end
290 292
291 293 def test_footnotes
292 294 raw = <<-RAW
293 295 This is some text[1].
294 296
295 297 fn1. This is the foot note
296 298 RAW
297 299
298 300 expected = <<-EXPECTED
299 301 <p>This is some text<sup><a href=\"#fn1\">1</a></sup>.</p>
300 302 <p id="fn1" class="footnote"><sup>1</sup> This is the foot note</p>
301 303 EXPECTED
302 304
303 305 assert_equal expected.gsub(%r{[\r\n\t]}, ''), textilizable(raw).gsub(%r{[\r\n\t]}, '')
304 306 end
305 307
306 308 def test_table_of_content
307 309 raw = <<-RAW
308 310 {{toc}}
309 311
310 312 h1. Title
311 313
312 314 Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas sed libero.
313 315
314 316 h2. Subtitle with a [[Wiki]] link
315 317
316 318 Nullam commodo metus accumsan nulla. Curabitur lobortis dui id dolor.
317 319
318 320 h2. Subtitle with [[Wiki|another Wiki]] link
319 321
320 322 h2. Subtitle with %{color:red}red text%
321 323
322 324 h1. Another title
323 325
324 326 RAW
325 327
326 328 expected = '<ul class="toc">' +
327 329 '<li class="heading1"><a href="#Title">Title</a></li>' +
328 330 '<li class="heading2"><a href="#Subtitle-with-a-Wiki-link">Subtitle with a Wiki link</a></li>' +
329 331 '<li class="heading2"><a href="#Subtitle-with-another-Wiki-link">Subtitle with another Wiki link</a></li>' +
330 332 '<li class="heading2"><a href="#Subtitle-with-red-text">Subtitle with red text</a></li>' +
331 333 '<li class="heading1"><a href="#Another-title">Another title</a></li>' +
332 334 '</ul>'
333 335
334 336 assert textilizable(raw).gsub("\n", "").include?(expected)
335 337 end
336 338
337 339 def test_blockquote
338 340 # orig raw text
339 341 raw = <<-RAW
340 342 John said:
341 343 > Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas sed libero.
342 344 > Nullam commodo metus accumsan nulla. Curabitur lobortis dui id dolor.
343 345 > * Donec odio lorem,
344 346 > * sagittis ac,
345 347 > * malesuada in,
346 348 > * adipiscing eu, dolor.
347 349 >
348 350 > >Nulla varius pulvinar diam. Proin id arcu id lorem scelerisque condimentum. Proin vehicula turpis vitae lacus.
349 351 > Proin a tellus. Nam vel neque.
350 352
351 353 He's right.
352 354 RAW
353 355
354 356 # expected html
355 357 expected = <<-EXPECTED
356 358 <p>John said:</p>
357 359 <blockquote>
358 360 Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas sed libero.
359 361 Nullam commodo metus accumsan nulla. Curabitur lobortis dui id dolor.
360 362 <ul>
361 363 <li>Donec odio lorem,</li>
362 364 <li>sagittis ac,</li>
363 365 <li>malesuada in,</li>
364 366 <li>adipiscing eu, dolor.</li>
365 367 </ul>
366 368 <blockquote>
367 369 <p>Nulla varius pulvinar diam. Proin id arcu id lorem scelerisque condimentum. Proin vehicula turpis vitae lacus.</p>
368 370 </blockquote>
369 371 <p>Proin a tellus. Nam vel neque.</p>
370 372 </blockquote>
371 373 <p>He's right.</p>
372 374 EXPECTED
373 375
374 376 assert_equal expected.gsub(%r{\s+}, ''), textilizable(raw).gsub(%r{\s+}, '')
375 377 end
376 378
377 379 def test_table
378 380 raw = <<-RAW
379 381 This is a table with empty cells:
380 382
381 383 |cell11|cell12||
382 384 |cell21||cell23|
383 385 |cell31|cell32|cell33|
384 386 RAW
385 387
386 388 expected = <<-EXPECTED
387 389 <p>This is a table with empty cells:</p>
388 390
389 391 <table>
390 392 <tr><td>cell11</td><td>cell12</td><td></td></tr>
391 393 <tr><td>cell21</td><td></td><td>cell23</td></tr>
392 394 <tr><td>cell31</td><td>cell32</td><td>cell33</td></tr>
393 395 </table>
394 396 EXPECTED
395 397
396 398 assert_equal expected.gsub(%r{\s+}, ''), textilizable(raw).gsub(%r{\s+}, '')
397 399 end
398 400
399 401 def test_table_with_line_breaks
400 402 raw = <<-RAW
401 403 This is a table with line breaks:
402 404
403 405 |cell11
404 406 continued|cell12||
405 407 |-cell21-||cell23
406 408 cell23 line2
407 409 cell23 *line3*|
408 410 |cell31|cell32
409 411 cell32 line2|cell33|
410 412
411 413 RAW
412 414
413 415 expected = <<-EXPECTED
414 416 <p>This is a table with line breaks:</p>
415 417
416 418 <table>
417 419 <tr>
418 420 <td>cell11<br />continued</td>
419 421 <td>cell12</td>
420 422 <td></td>
421 423 </tr>
422 424 <tr>
423 425 <td><del>cell21</del></td>
424 426 <td></td>
425 427 <td>cell23<br/>cell23 line2<br/>cell23 <strong>line3</strong></td>
426 428 </tr>
427 429 <tr>
428 430 <td>cell31</td>
429 431 <td>cell32<br/>cell32 line2</td>
430 432 <td>cell33</td>
431 433 </tr>
432 434 </table>
433 435 EXPECTED
434 436
435 437 assert_equal expected.gsub(%r{\s+}, ''), textilizable(raw).gsub(%r{\s+}, '')
436 438 end
437 439
438 440 def test_default_formatter
439 441 Setting.text_formatting = 'unknown'
440 442 text = 'a *link*: http://www.example.net/'
441 443 assert_equal '<p>a *link*: <a href="http://www.example.net/">http://www.example.net/</a></p>', textilizable(text)
442 444 Setting.text_formatting = 'textile'
443 445 end
444 446
445 447 def test_due_date_distance_in_words
446 448 to_test = { Date.today => 'Due in 0 days',
447 449 Date.today + 1 => 'Due in 1 day',
448 450 Date.today + 100 => 'Due in about 3 months',
449 451 Date.today + 20000 => 'Due in over 55 years',
450 452 Date.today - 1 => '1 day late',
451 453 Date.today - 100 => 'about 3 months late',
452 454 Date.today - 20000 => 'over 55 years late',
453 455 }
454 456 to_test.each do |date, expected|
455 457 assert_equal expected, due_date_distance_in_words(date)
456 458 end
457 459 end
458 460
459 461 def test_avatar
460 462 # turn on avatars
461 463 Setting.gravatar_enabled = '1'
462 464 assert avatar(User.find_by_mail('jsmith@somenet.foo')).include?(Digest::MD5.hexdigest('jsmith@somenet.foo'))
463 465 assert avatar('jsmith <jsmith@somenet.foo>').include?(Digest::MD5.hexdigest('jsmith@somenet.foo'))
464 466 assert_nil avatar('jsmith')
465 467 assert_nil avatar(nil)
466 468
467 469 # turn off avatars
468 470 Setting.gravatar_enabled = '0'
469 471 assert_nil avatar(User.find_by_mail('jsmith@somenet.foo'))
470 472 end
471 473 end
General Comments 0
You need to be logged in to leave comments. Login now