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