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