@@ -1,342 +1,342 | |||
|
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, :repositories, :changesets, :trackers, :issue_statuses, :issues, :documents, :versions, :wikis, :wiki_pages, :wiki_contents, :roles, :enabled_modules |
|
24 | 24 | |
|
25 | 25 | def setup |
|
26 | 26 | super |
|
27 | 27 | end |
|
28 | 28 | |
|
29 | 29 | def test_auto_links |
|
30 | 30 | to_test = { |
|
31 | 31 | 'http://foo.bar' => '<a class="external" href="http://foo.bar">http://foo.bar</a>', |
|
32 | 32 | 'http://foo.bar/~user' => '<a class="external" href="http://foo.bar/~user">http://foo.bar/~user</a>', |
|
33 | 33 | 'http://foo.bar.' => '<a class="external" href="http://foo.bar">http://foo.bar</a>.', |
|
34 | 34 | 'This is a link: http://foo.bar.' => 'This is a link: <a class="external" href="http://foo.bar">http://foo.bar</a>.', |
|
35 | 35 | 'A link (eg. http://foo.bar).' => 'A link (eg. <a class="external" href="http://foo.bar">http://foo.bar</a>).', |
|
36 | 36 | '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>.', |
|
37 | 37 | 'www.foo.bar' => '<a class="external" href="http://www.foo.bar">www.foo.bar</a>', |
|
38 | 38 | 'http://foo.bar/page?p=1&t=z&s=' => '<a class="external" href="http://foo.bar/page?p=1&t=z&s=">http://foo.bar/page?p=1&t=z&s=</a>', |
|
39 | 39 | 'http://foo.bar/page#125' => '<a class="external" href="http://foo.bar/page#125">http://foo.bar/page#125</a>', |
|
40 | 40 | 'http://foo@www.bar.com' => '<a class="external" href="http://foo@www.bar.com">http://foo@www.bar.com</a>', |
|
41 | 41 | 'ftp://foo.bar' => '<a class="external" href="ftp://foo.bar">ftp://foo.bar</a>', |
|
42 | 42 | } |
|
43 | 43 | to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) } |
|
44 | 44 | end |
|
45 | 45 | |
|
46 | 46 | def test_auto_mailto |
|
47 | 47 | assert_equal '<p><a href="mailto:test@foo.bar" class="email">test@foo.bar</a></p>', |
|
48 | 48 | textilizable('test@foo.bar') |
|
49 | 49 | end |
|
50 | 50 | |
|
51 | 51 | def test_inline_images |
|
52 | 52 | to_test = { |
|
53 | 53 | '!http://foo.bar/image.jpg!' => '<img src="http://foo.bar/image.jpg" alt="" />', |
|
54 | 54 | 'floating !>http://foo.bar/image.jpg!' => 'floating <div style="float:right"><img src="http://foo.bar/image.jpg" alt="" /></div>', |
|
55 | 55 | 'with class !(some-class)http://foo.bar/image.jpg!' => 'with class <img src="http://foo.bar/image.jpg" class="some-class" alt="" />', |
|
56 | 56 | 'with style !{width:100px;height100px}http://foo.bar/image.jpg!' => 'with style <img src="http://foo.bar/image.jpg" style="width:100px;height100px;" alt="" />', |
|
57 | 57 | } |
|
58 | 58 | to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) } |
|
59 | 59 | end |
|
60 | 60 | |
|
61 | 61 | def test_textile_external_links |
|
62 | 62 | to_test = { |
|
63 | 63 | 'This is a "link":http://foo.bar' => 'This is a <a href="http://foo.bar" class="external">link</a>', |
|
64 | 64 | 'This is an intern "link":/foo/bar' => 'This is an intern <a href="/foo/bar">link</a>', |
|
65 | 65 | '"link (Link title)":http://foo.bar' => '<a href="http://foo.bar" title="Link title" class="external">link</a>', |
|
66 | 66 | "This is not a \"Link\":\n\nAnother paragraph" => "This is not a \"Link\":</p>\n\n\n\t<p>Another paragraph", |
|
67 | 67 | # no multiline link text |
|
68 | 68 | "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" |
|
69 | 69 | } |
|
70 | 70 | to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) } |
|
71 | 71 | end |
|
72 | 72 | |
|
73 | 73 | def test_redmine_links |
|
74 | 74 | issue_link = link_to('#3', {:controller => 'issues', :action => 'show', :id => 3}, |
|
75 | 75 | :class => 'issue', :title => 'Error 281 when updating a recipe (New)') |
|
76 | 76 | |
|
77 | 77 | changeset_link = link_to('r1', {:controller => 'repositories', :action => 'revision', :id => 'ecookbook', :rev => 1}, |
|
78 | 78 | :class => 'changeset', :title => 'My very first commit') |
|
79 | 79 | |
|
80 | 80 | document_link = link_to('Test document', {:controller => 'documents', :action => 'show', :id => 1}, |
|
81 | 81 | :class => 'document') |
|
82 | 82 | |
|
83 | 83 | version_link = link_to('1.0', {:controller => 'versions', :action => 'show', :id => 2}, |
|
84 | 84 | :class => 'version') |
|
85 | 85 | |
|
86 | 86 | source_url = {:controller => 'repositories', :action => 'entry', :id => 'ecookbook', :path => ['some', 'file']} |
|
87 | 87 | source_url_with_ext = {:controller => 'repositories', :action => 'entry', :id => 'ecookbook', :path => ['some', 'file.ext']} |
|
88 | 88 | |
|
89 | 89 | to_test = { |
|
90 | 90 | # tickets |
|
91 | 91 | '#3, #3 and #3.' => "#{issue_link}, #{issue_link} and #{issue_link}.", |
|
92 | 92 | # changesets |
|
93 | 93 | 'r1' => changeset_link, |
|
94 | 94 | # documents |
|
95 | 95 | 'document#1' => document_link, |
|
96 | 96 | 'document:"Test document"' => document_link, |
|
97 | 97 | # versions |
|
98 | 98 | 'version#2' => version_link, |
|
99 | 99 | 'version:1.0' => version_link, |
|
100 | 100 | 'version:"1.0"' => version_link, |
|
101 | 101 | # source |
|
102 | 102 | 'source:/some/file' => link_to('source:/some/file', source_url, :class => 'source'), |
|
103 | 103 | 'source:/some/file.' => link_to('source:/some/file', source_url, :class => 'source') + ".", |
|
104 | 104 | 'source:/some/file.ext.' => link_to('source:/some/file.ext', source_url_with_ext, :class => 'source') + ".", |
|
105 | 105 | 'source:/some/file. ' => link_to('source:/some/file', source_url, :class => 'source') + ".", |
|
106 | 106 | 'source:/some/file.ext. ' => link_to('source:/some/file.ext', source_url_with_ext, :class => 'source') + ".", |
|
107 | 107 | 'source:/some/file, ' => link_to('source:/some/file', source_url, :class => 'source') + ",", |
|
108 | 108 | 'source:/some/file@52' => link_to('source:/some/file@52', source_url.merge(:rev => 52), :class => 'source'), |
|
109 | 109 | 'source:/some/file.ext@52' => link_to('source:/some/file.ext@52', source_url_with_ext.merge(:rev => 52), :class => 'source'), |
|
110 | 110 | 'source:/some/file#L110' => link_to('source:/some/file#L110', source_url.merge(:anchor => 'L110'), :class => 'source'), |
|
111 | 111 | 'source:/some/file.ext#L110' => link_to('source:/some/file.ext#L110', source_url_with_ext.merge(:anchor => 'L110'), :class => 'source'), |
|
112 | 112 | 'source:/some/file@52#L110' => link_to('source:/some/file@52#L110', source_url.merge(:rev => 52, :anchor => 'L110'), :class => 'source'), |
|
113 | 113 | 'export:/some/file' => link_to('export:/some/file', source_url.merge(:format => 'raw'), :class => 'source download'), |
|
114 | 114 | # escaping |
|
115 | 115 | '!#3.' => '#3.', |
|
116 | 116 | '!r1' => 'r1', |
|
117 | 117 | '!document#1' => 'document#1', |
|
118 | 118 | '!document:"Test document"' => 'document:"Test document"', |
|
119 | 119 | '!version#2' => 'version#2', |
|
120 | 120 | '!version:1.0' => 'version:1.0', |
|
121 | 121 | '!version:"1.0"' => 'version:"1.0"', |
|
122 | 122 | '!source:/some/file' => 'source:/some/file', |
|
123 | 123 | # invalid expressions |
|
124 | 124 | 'source:' => 'source:', |
|
125 | 125 | # url hash |
|
126 | 126 | "http://foo.bar/FAQ#3" => '<a class="external" href="http://foo.bar/FAQ#3">http://foo.bar/FAQ#3</a>', |
|
127 | 127 | } |
|
128 | 128 | @project = Project.find(1) |
|
129 | 129 | to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) } |
|
130 | 130 | end |
|
131 | 131 | |
|
132 | 132 | def test_wiki_links |
|
133 | 133 | to_test = { |
|
134 | 134 | '[[CookBook documentation]]' => '<a href="/wiki/ecookbook/CookBook_documentation" class="wiki-page">CookBook documentation</a>', |
|
135 | 135 | '[[Another page|Page]]' => '<a href="/wiki/ecookbook/Another_page" class="wiki-page">Page</a>', |
|
136 | 136 | # page that doesn't exist |
|
137 | 137 | '[[Unknown page]]' => '<a href="/wiki/ecookbook/Unknown_page" class="wiki-page new">Unknown page</a>', |
|
138 | 138 | '[[Unknown page|404]]' => '<a href="/wiki/ecookbook/Unknown_page" class="wiki-page new">404</a>', |
|
139 | 139 | # link to another project wiki |
|
140 | 140 | '[[onlinestore:]]' => '<a href="/wiki/onlinestore/" class="wiki-page">onlinestore</a>', |
|
141 | 141 | '[[onlinestore:|Wiki]]' => '<a href="/wiki/onlinestore/" class="wiki-page">Wiki</a>', |
|
142 | 142 | '[[onlinestore:Start page]]' => '<a href="/wiki/onlinestore/Start_page" class="wiki-page">Start page</a>', |
|
143 | 143 | '[[onlinestore:Start page|Text]]' => '<a href="/wiki/onlinestore/Start_page" class="wiki-page">Text</a>', |
|
144 | 144 | '[[onlinestore:Unknown page]]' => '<a href="/wiki/onlinestore/Unknown_page" class="wiki-page new">Unknown page</a>', |
|
145 | 145 | # striked through link |
|
146 | 146 | '-[[Another page|Page]]-' => '<del><a href="/wiki/ecookbook/Another_page" class="wiki-page">Page</a></del>', |
|
147 | 147 | # escaping |
|
148 | 148 | '![[Another page|Page]]' => '[[Another page|Page]]', |
|
149 | 149 | } |
|
150 | 150 | @project = Project.find(1) |
|
151 | 151 | to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) } |
|
152 | 152 | end |
|
153 | 153 | |
|
154 | 154 | def test_html_tags |
|
155 | 155 | to_test = { |
|
156 | 156 | "<div>content</div>" => "<p><div>content</div></p>", |
|
157 | 157 | "<div class=\"bold\">content</div>" => "<p><div class=\"bold\">content</div></p>", |
|
158 | 158 | "<script>some script;</script>" => "<p><script>some script;</script></p>", |
|
159 | 159 | # do not escape pre/code tags |
|
160 | 160 | "<pre>\nline 1\nline2</pre>" => "<pre>\nline 1\nline2</pre>", |
|
161 | 161 | "<pre><code>\nline 1\nline2</code></pre>" => "<pre><code>\nline 1\nline2</code></pre>", |
|
162 | 162 | "<pre><div>content</div></pre>" => "<pre><div>content</div></pre>", |
|
163 | 163 | "HTML comment: <!-- no comments -->" => "<p>HTML comment: <!-- no comments --></p>", |
|
164 | 164 | "<!-- opening comment" => "<p><!-- opening comment</p>" |
|
165 | 165 | } |
|
166 | 166 | to_test.each { |text, result| assert_equal result, textilizable(text) } |
|
167 | 167 | end |
|
168 | 168 | |
|
169 | 169 | def test_allowed_html_tags |
|
170 | 170 | to_test = { |
|
171 | 171 | "<pre>preformatted text</pre>" => "<pre>preformatted text</pre>", |
|
172 | 172 | "<notextile>no *textile* formatting</notextile>" => "no *textile* formatting", |
|
173 | 173 | } |
|
174 | 174 | to_test.each { |text, result| assert_equal result, textilizable(text) } |
|
175 | 175 | end |
|
176 | 176 | |
|
177 | 177 | def test_wiki_links_in_tables |
|
178 | 178 | to_test = {"|[[Page|Link title]]|[[Other Page|Other title]]|\n|Cell 21|[[Last page]]|" => |
|
179 | 179 | '<tr><td><a href="/wiki/ecookbook/Page" class="wiki-page new">Link title</a></td>' + |
|
180 | 180 | '<td><a href="/wiki/ecookbook/Other_Page" class="wiki-page new">Other title</a></td>' + |
|
181 | 181 | '</tr><tr><td>Cell 21</td><td><a href="/wiki/ecookbook/Last_page" class="wiki-page new">Last page</a></td></tr>' |
|
182 | 182 | } |
|
183 | 183 | @project = Project.find(1) |
|
184 | 184 | to_test.each { |text, result| assert_equal "<table>#{result}</table>", textilizable(text).gsub(/[\t\n]/, '') } |
|
185 | 185 | end |
|
186 | 186 | |
|
187 | 187 | def test_text_formatting |
|
188 | 188 | to_test = {'*_+bold, italic and underline+_*' => '<strong><em><ins>bold, italic and underline</ins></em></strong>', |
|
189 | 189 | '(_text within parentheses_)' => '(<em>text within parentheses</em>)' |
|
190 | 190 | } |
|
191 | 191 | to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) } |
|
192 | 192 | end |
|
193 | 193 | |
|
194 | 194 | def test_wiki_horizontal_rule |
|
195 | 195 | assert_equal '<hr />', textilizable('---') |
|
196 | 196 | assert_equal '<p>Dashes: ---</p>', textilizable('Dashes: ---') |
|
197 | 197 | end |
|
198 | 198 | |
|
199 | 199 | def test_table_of_content |
|
200 | 200 | raw = <<-RAW |
|
201 | 201 | {{toc}} |
|
202 | 202 | |
|
203 | 203 | h1. Title |
|
204 | 204 | |
|
205 | 205 | Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas sed libero. |
|
206 | 206 | |
|
207 | 207 | h2. Subtitle |
|
208 | 208 | |
|
209 | 209 | Nullam commodo metus accumsan nulla. Curabitur lobortis dui id dolor. |
|
210 | 210 | |
|
211 | 211 | h2. Subtitle with %{color:red}red text% |
|
212 | 212 | |
|
213 | 213 | h1. Another title |
|
214 | 214 | |
|
215 | 215 | RAW |
|
216 | 216 | |
|
217 |
expected = '< |
|
|
218 |
'< |
|
|
219 |
'< |
|
|
220 |
'< |
|
|
221 |
'< |
|
|
222 |
'</ |
|
|
217 | expected = '<ul class="toc">' + | |
|
218 | '<li class="heading1"><a href="#1">Title</a></li>' + | |
|
219 | '<li class="heading2"><a href="#2">Subtitle</a></li>' + | |
|
220 | '<li class="heading2"><a href="#3">Subtitle with red text</a></li>' + | |
|
221 | '<li class="heading1"><a href="#4">Another title</a></li>' + | |
|
222 | '</ul>' | |
|
223 | 223 | |
|
224 | assert textilizable(raw).include?(expected) | |
|
224 | assert textilizable(raw).gsub("\n", "").include?(expected) | |
|
225 | 225 | end |
|
226 | 226 | |
|
227 | 227 | def test_blockquote |
|
228 | 228 | # orig raw text |
|
229 | 229 | raw = <<-RAW |
|
230 | 230 | John said: |
|
231 | 231 | > Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas sed libero. |
|
232 | 232 | > Nullam commodo metus accumsan nulla. Curabitur lobortis dui id dolor. |
|
233 | 233 | > * Donec odio lorem, |
|
234 | 234 | > * sagittis ac, |
|
235 | 235 | > * malesuada in, |
|
236 | 236 | > * adipiscing eu, dolor. |
|
237 | 237 | > |
|
238 | 238 | > >Nulla varius pulvinar diam. Proin id arcu id lorem scelerisque condimentum. Proin vehicula turpis vitae lacus. |
|
239 | 239 | > Proin a tellus. Nam vel neque. |
|
240 | 240 | |
|
241 | 241 | He's right. |
|
242 | 242 | RAW |
|
243 | 243 | |
|
244 | 244 | # expected html |
|
245 | 245 | expected = <<-EXPECTED |
|
246 | 246 | <p>John said:</p> |
|
247 | 247 | <blockquote> |
|
248 | 248 | Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas sed libero. |
|
249 | 249 | Nullam commodo metus accumsan nulla. Curabitur lobortis dui id dolor. |
|
250 | 250 | <ul> |
|
251 | 251 | <li>Donec odio lorem,</li> |
|
252 | 252 | <li>sagittis ac,</li> |
|
253 | 253 | <li>malesuada in,</li> |
|
254 | 254 | <li>adipiscing eu, dolor.</li> |
|
255 | 255 | </ul> |
|
256 | 256 | <blockquote> |
|
257 | 257 | <p>Nulla varius pulvinar diam. Proin id arcu id lorem scelerisque condimentum. Proin vehicula turpis vitae lacus.</p> |
|
258 | 258 | </blockquote> |
|
259 | 259 | <p>Proin a tellus. Nam vel neque.</p> |
|
260 | 260 | </blockquote> |
|
261 | 261 | <p>He's right.</p> |
|
262 | 262 | EXPECTED |
|
263 | 263 | |
|
264 | 264 | assert_equal expected.gsub(%r{\s+}, ''), textilizable(raw).gsub(%r{\s+}, '') |
|
265 | 265 | end |
|
266 | 266 | |
|
267 | 267 | def test_table |
|
268 | 268 | raw = <<-RAW |
|
269 | 269 | This is a table with empty cells: |
|
270 | 270 | |
|
271 | 271 | |cell11|cell12|| |
|
272 | 272 | |cell21||cell23| |
|
273 | 273 | |cell31|cell32|cell33| |
|
274 | 274 | RAW |
|
275 | 275 | |
|
276 | 276 | expected = <<-EXPECTED |
|
277 | 277 | <p>This is a table with empty cells:</p> |
|
278 | 278 | |
|
279 | 279 | <table> |
|
280 | 280 | <tr><td>cell11</td><td>cell12</td><td></td></tr> |
|
281 | 281 | <tr><td>cell21</td><td></td><td>cell23</td></tr> |
|
282 | 282 | <tr><td>cell31</td><td>cell32</td><td>cell33</td></tr> |
|
283 | 283 | </table> |
|
284 | 284 | EXPECTED |
|
285 | 285 | |
|
286 | 286 | assert_equal expected.gsub(%r{\s+}, ''), textilizable(raw).gsub(%r{\s+}, '') |
|
287 | 287 | end |
|
288 | 288 | |
|
289 | 289 | def test_macro_hello_world |
|
290 | 290 | text = "{{hello_world}}" |
|
291 | 291 | assert textilizable(text).match(/Hello world!/) |
|
292 | 292 | # escaping |
|
293 | 293 | text = "!{{hello_world}}" |
|
294 | 294 | assert_equal '<p>{{hello_world}}</p>', textilizable(text) |
|
295 | 295 | end |
|
296 | 296 | |
|
297 | 297 | def test_macro_include |
|
298 | 298 | @project = Project.find(1) |
|
299 | 299 | # include a page of the current project wiki |
|
300 | 300 | text = "{{include(Another page)}}" |
|
301 | 301 | assert textilizable(text).match(/This is a link to a ticket/) |
|
302 | 302 | |
|
303 | 303 | @project = nil |
|
304 | 304 | # include a page of a specific project wiki |
|
305 | 305 | text = "{{include(ecookbook:Another page)}}" |
|
306 | 306 | assert textilizable(text).match(/This is a link to a ticket/) |
|
307 | 307 | |
|
308 | 308 | text = "{{include(ecookbook:)}}" |
|
309 | 309 | assert textilizable(text).match(/CookBook documentation/) |
|
310 | 310 | |
|
311 | 311 | text = "{{include(unknowidentifier:somepage)}}" |
|
312 | 312 | assert textilizable(text).match(/Unknow project/) |
|
313 | 313 | end |
|
314 | 314 | |
|
315 | 315 | def test_date_format_default |
|
316 | 316 | today = Date.today |
|
317 | 317 | Setting.date_format = '' |
|
318 | 318 | assert_equal l_date(today), format_date(today) |
|
319 | 319 | end |
|
320 | 320 | |
|
321 | 321 | def test_date_format |
|
322 | 322 | today = Date.today |
|
323 | 323 | Setting.date_format = '%d %m %Y' |
|
324 | 324 | assert_equal today.strftime('%d %m %Y'), format_date(today) |
|
325 | 325 | end |
|
326 | 326 | |
|
327 | 327 | def test_time_format_default |
|
328 | 328 | now = Time.now |
|
329 | 329 | Setting.date_format = '' |
|
330 | 330 | Setting.time_format = '' |
|
331 | 331 | assert_equal l_datetime(now), format_time(now) |
|
332 | 332 | assert_equal l_time(now), format_time(now, false) |
|
333 | 333 | end |
|
334 | 334 | |
|
335 | 335 | def test_time_format |
|
336 | 336 | now = Time.now |
|
337 | 337 | Setting.date_format = '%d %m %Y' |
|
338 | 338 | Setting.time_format = '%H %M' |
|
339 | 339 | assert_equal now.strftime('%d %m %Y %H %M'), format_time(now) |
|
340 | 340 | assert_equal now.strftime('%H %M'), format_time(now, false) |
|
341 | 341 | end |
|
342 | 342 | end |
General Comments 0
You need to be logged in to leave comments.
Login now