##// END OF EJS Templates
add missing fixture to ApplicationHelperTest...
Toshi MARUYAMA -
r12897:be33ac6fc02a
parent child
Show More
@@ -1,1516 +1,1517
1 1 # encoding: utf-8
2 2 #
3 3 # Redmine - project management software
4 4 # Copyright (C) 2006-2014 Jean-Philippe Lang
5 5 #
6 6 # This program is free software; you can redistribute it and/or
7 7 # modify it under the terms of the GNU General Public License
8 8 # as published by the Free Software Foundation; either version 2
9 9 # of the License, or (at your option) any later version.
10 10 #
11 11 # This program is distributed in the hope that it will be useful,
12 12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 14 # GNU General Public License for more details.
15 15 #
16 16 # You should have received a copy of the GNU General Public License
17 17 # along with this program; if not, write to the Free Software
18 18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 19
20 20 require File.expand_path('../../../test_helper', __FILE__)
21 21
22 22 class ApplicationHelperTest < ActionView::TestCase
23 23 include Redmine::I18n
24 24 include ERB::Util
25 25 include Rails.application.routes.url_helpers
26 26
27 27 fixtures :projects, :roles, :enabled_modules, :users,
28 28 :repositories, :changesets,
29 :projects_trackers,
29 30 :trackers, :issue_statuses, :issues, :versions, :documents,
30 31 :wikis, :wiki_pages, :wiki_contents,
31 32 :boards, :messages, :news,
32 33 :attachments, :enumerations
33 34
34 35 def setup
35 36 super
36 37 set_tmp_attachments_directory
37 38 @russian_test = "\xd1\x82\xd0\xb5\xd1\x81\xd1\x82"
38 39 if @russian_test.respond_to?(:force_encoding)
39 40 @russian_test.force_encoding('UTF-8')
40 41 end
41 42 end
42 43
43 44 test "#link_to_if_authorized for authorized user should allow using the :controller and :action for the target link" do
44 45 User.current = User.find_by_login('admin')
45 46
46 47 @project = Issue.first.project # Used by helper
47 48 response = link_to_if_authorized('By controller/actionr',
48 49 {:controller => 'issues', :action => 'edit', :id => Issue.first.id})
49 50 assert_match /href/, response
50 51 end
51 52
52 53 test "#link_to_if_authorized for unauthorized user should display nothing if user isn't authorized" do
53 54 User.current = User.find_by_login('dlopper')
54 55 @project = Project.find('private-child')
55 56 issue = @project.issues.first
56 57 assert !issue.visible?
57 58
58 59 response = link_to_if_authorized('Never displayed',
59 60 {:controller => 'issues', :action => 'show', :id => issue})
60 61 assert_nil response
61 62 end
62 63
63 64 def test_auto_links
64 65 to_test = {
65 66 'http://foo.bar' => '<a class="external" href="http://foo.bar">http://foo.bar</a>',
66 67 'http://foo.bar/~user' => '<a class="external" href="http://foo.bar/~user">http://foo.bar/~user</a>',
67 68 'http://foo.bar.' => '<a class="external" href="http://foo.bar">http://foo.bar</a>.',
68 69 'https://foo.bar.' => '<a class="external" href="https://foo.bar">https://foo.bar</a>.',
69 70 'This is a link: http://foo.bar.' => 'This is a link: <a class="external" href="http://foo.bar">http://foo.bar</a>.',
70 71 'A link (eg. http://foo.bar).' => 'A link (eg. <a class="external" href="http://foo.bar">http://foo.bar</a>).',
71 72 '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>.',
72 73 'http://www.foo.bar/Test_(foobar)' => '<a class="external" href="http://www.foo.bar/Test_(foobar)">http://www.foo.bar/Test_(foobar)</a>',
73 74 '(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>)',
74 75 '(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>)',
75 76 '(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>).',
76 77 '(see "inline link":http://www.foo.bar/Test_(foobar))' => '(see <a href="http://www.foo.bar/Test_(foobar)" class="external">inline link</a>)',
77 78 '(see "inline link":http://www.foo.bar/Test)' => '(see <a href="http://www.foo.bar/Test" class="external">inline link</a>)',
78 79 '(see "inline link":http://www.foo.bar/Test).' => '(see <a href="http://www.foo.bar/Test" class="external">inline link</a>).',
79 80 'www.foo.bar' => '<a class="external" href="http://www.foo.bar">www.foo.bar</a>',
80 81 '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>',
81 82 'http://foo.bar/page#125' => '<a class="external" href="http://foo.bar/page#125">http://foo.bar/page#125</a>',
82 83 'http://foo@www.bar.com' => '<a class="external" href="http://foo@www.bar.com">http://foo@www.bar.com</a>',
83 84 'http://foo:bar@www.bar.com' => '<a class="external" href="http://foo:bar@www.bar.com">http://foo:bar@www.bar.com</a>',
84 85 'ftp://foo.bar' => '<a class="external" href="ftp://foo.bar">ftp://foo.bar</a>',
85 86 'ftps://foo.bar' => '<a class="external" href="ftps://foo.bar">ftps://foo.bar</a>',
86 87 'sftp://foo.bar' => '<a class="external" href="sftp://foo.bar">sftp://foo.bar</a>',
87 88 # two exclamation marks
88 89 '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>',
89 90 # escaping
90 91 'http://foo"bar' => '<a class="external" href="http://foo&quot;bar">http://foo&quot;bar</a>',
91 92 # wrap in angle brackets
92 93 '<http://foo.bar>' => '&lt;<a class="external" href="http://foo.bar">http://foo.bar</a>&gt;',
93 94 # invalid urls
94 95 'http://' => 'http://',
95 96 'www.' => 'www.',
96 97 'test-www.bar.com' => 'test-www.bar.com',
97 98 }
98 99 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) }
99 100 end
100 101
101 102 if 'ruby'.respond_to?(:encoding)
102 103 def test_auto_links_with_non_ascii_characters
103 104 to_test = {
104 105 "http://foo.bar/#{@russian_test}" =>
105 106 %|<a class="external" href="http://foo.bar/#{@russian_test}">http://foo.bar/#{@russian_test}</a>|
106 107 }
107 108 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) }
108 109 end
109 110 else
110 111 puts 'Skipping test_auto_links_with_non_ascii_characters, unsupported ruby version'
111 112 end
112 113
113 114 def test_auto_mailto
114 115 to_test = {
115 116 'test@foo.bar' => '<a class="email" href="mailto:test@foo.bar">test@foo.bar</a>',
116 117 'test@www.foo.bar' => '<a class="email" href="mailto:test@www.foo.bar">test@www.foo.bar</a>',
117 118 }
118 119 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) }
119 120 end
120 121
121 122 def test_inline_images
122 123 to_test = {
123 124 '!http://foo.bar/image.jpg!' => '<img src="http://foo.bar/image.jpg" alt="" />',
124 125 'floating !>http://foo.bar/image.jpg!' => 'floating <div style="float:right"><img src="http://foo.bar/image.jpg" alt="" /></div>',
125 126 'with class !(some-class)http://foo.bar/image.jpg!' => 'with class <img src="http://foo.bar/image.jpg" class="some-class" alt="" />',
126 127 'with style !{width:100px;height:100px}http://foo.bar/image.jpg!' => 'with style <img src="http://foo.bar/image.jpg" style="width:100px;height:100px;" alt="" />',
127 128 '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" />',
128 129 '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;" />',
129 130 }
130 131 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) }
131 132 end
132 133
133 134 def test_inline_images_inside_tags
134 135 raw = <<-RAW
135 136 h1. !foo.png! Heading
136 137
137 138 Centered image:
138 139
139 140 p=. !bar.gif!
140 141 RAW
141 142
142 143 assert textilizable(raw).include?('<img src="foo.png" alt="" />')
143 144 assert textilizable(raw).include?('<img src="bar.gif" alt="" />')
144 145 end
145 146
146 147 def test_attached_images
147 148 to_test = {
148 149 'Inline image: !logo.gif!' => 'Inline image: <img src="/attachments/download/3/logo.gif" title="This is a logo" alt="This is a logo" />',
149 150 'Inline image: !logo.GIF!' => 'Inline image: <img src="/attachments/download/3/logo.gif" title="This is a logo" alt="This is a logo" />',
150 151 'No match: !ogo.gif!' => 'No match: <img src="ogo.gif" alt="" />',
151 152 'No match: !ogo.GIF!' => 'No match: <img src="ogo.GIF" alt="" />',
152 153 # link image
153 154 '!logo.gif!:http://foo.bar/' => '<a href="http://foo.bar/"><img src="/attachments/download/3/logo.gif" title="This is a logo" alt="This is a logo" /></a>',
154 155 }
155 156 attachments = Attachment.all
156 157 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text, :attachments => attachments) }
157 158 end
158 159
159 160 def test_attached_images_filename_extension
160 161 set_tmp_attachments_directory
161 162 a1 = Attachment.new(
162 163 :container => Issue.find(1),
163 164 :file => mock_file_with_options({:original_filename => "testtest.JPG"}),
164 165 :author => User.find(1))
165 166 assert a1.save
166 167 assert_equal "testtest.JPG", a1.filename
167 168 assert_equal "image/jpeg", a1.content_type
168 169 assert a1.image?
169 170
170 171 a2 = Attachment.new(
171 172 :container => Issue.find(1),
172 173 :file => mock_file_with_options({:original_filename => "testtest.jpeg"}),
173 174 :author => User.find(1))
174 175 assert a2.save
175 176 assert_equal "testtest.jpeg", a2.filename
176 177 assert_equal "image/jpeg", a2.content_type
177 178 assert a2.image?
178 179
179 180 a3 = Attachment.new(
180 181 :container => Issue.find(1),
181 182 :file => mock_file_with_options({:original_filename => "testtest.JPE"}),
182 183 :author => User.find(1))
183 184 assert a3.save
184 185 assert_equal "testtest.JPE", a3.filename
185 186 assert_equal "image/jpeg", a3.content_type
186 187 assert a3.image?
187 188
188 189 a4 = Attachment.new(
189 190 :container => Issue.find(1),
190 191 :file => mock_file_with_options({:original_filename => "Testtest.BMP"}),
191 192 :author => User.find(1))
192 193 assert a4.save
193 194 assert_equal "Testtest.BMP", a4.filename
194 195 assert_equal "image/x-ms-bmp", a4.content_type
195 196 assert a4.image?
196 197
197 198 to_test = {
198 199 'Inline image: !testtest.jpg!' =>
199 200 'Inline image: <img src="/attachments/download/' + a1.id.to_s + '/testtest.JPG" alt="" />',
200 201 'Inline image: !testtest.jpeg!' =>
201 202 'Inline image: <img src="/attachments/download/' + a2.id.to_s + '/testtest.jpeg" alt="" />',
202 203 'Inline image: !testtest.jpe!' =>
203 204 'Inline image: <img src="/attachments/download/' + a3.id.to_s + '/testtest.JPE" alt="" />',
204 205 'Inline image: !testtest.bmp!' =>
205 206 'Inline image: <img src="/attachments/download/' + a4.id.to_s + '/Testtest.BMP" alt="" />',
206 207 }
207 208
208 209 attachments = [a1, a2, a3, a4]
209 210 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text, :attachments => attachments) }
210 211 end
211 212
212 213 def test_attached_images_should_read_later
213 214 set_fixtures_attachments_directory
214 215 a1 = Attachment.find(16)
215 216 assert_equal "testfile.png", a1.filename
216 217 assert a1.readable?
217 218 assert (! a1.visible?(User.anonymous))
218 219 assert a1.visible?(User.find(2))
219 220 a2 = Attachment.find(17)
220 221 assert_equal "testfile.PNG", a2.filename
221 222 assert a2.readable?
222 223 assert (! a2.visible?(User.anonymous))
223 224 assert a2.visible?(User.find(2))
224 225 assert a1.created_on < a2.created_on
225 226
226 227 to_test = {
227 228 'Inline image: !testfile.png!' =>
228 229 'Inline image: <img src="/attachments/download/' + a2.id.to_s + '/testfile.PNG" alt="" />',
229 230 'Inline image: !Testfile.PNG!' =>
230 231 'Inline image: <img src="/attachments/download/' + a2.id.to_s + '/testfile.PNG" alt="" />',
231 232 }
232 233 attachments = [a1, a2]
233 234 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text, :attachments => attachments) }
234 235 set_tmp_attachments_directory
235 236 end
236 237
237 238 def test_textile_external_links
238 239 to_test = {
239 240 'This is a "link":http://foo.bar' => 'This is a <a href="http://foo.bar" class="external">link</a>',
240 241 'This is an intern "link":/foo/bar' => 'This is an intern <a href="/foo/bar">link</a>',
241 242 '"link (Link title)":http://foo.bar' => '<a href="http://foo.bar" title="Link title" class="external">link</a>',
242 243 '"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>',
243 244 "This is not a \"Link\":\n\nAnother paragraph" => "This is not a \"Link\":</p>\n\n\n\t<p>Another paragraph",
244 245 # no multiline link text
245 246 "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",
246 247 # mailto link
247 248 "\"system administrator\":mailto:sysadmin@example.com?subject=redmine%20permissions" => "<a href=\"mailto:sysadmin@example.com?subject=redmine%20permissions\">system administrator</a>",
248 249 # two exclamation marks
249 250 '"a link":http://example.net/path!602815048C7B5C20!302.html' => '<a href="http://example.net/path!602815048C7B5C20!302.html" class="external">a link</a>',
250 251 # escaping
251 252 '"test":http://foo"bar' => '<a href="http://foo&quot;bar" class="external">test</a>',
252 253 }
253 254 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) }
254 255 end
255 256
256 257 if 'ruby'.respond_to?(:encoding)
257 258 def test_textile_external_links_with_non_ascii_characters
258 259 to_test = {
259 260 %|This is a "link":http://foo.bar/#{@russian_test}| =>
260 261 %|This is a <a href="http://foo.bar/#{@russian_test}" class="external">link</a>|
261 262 }
262 263 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) }
263 264 end
264 265 else
265 266 puts 'Skipping test_textile_external_links_with_non_ascii_characters, unsupported ruby version'
266 267 end
267 268
268 269 def test_redmine_links
269 270 issue_link = link_to('#3', {:controller => 'issues', :action => 'show', :id => 3},
270 271 :class => Issue.find(3).css_classes, :title => 'Error 281 when updating a recipe (New)')
271 272 note_link = link_to('#3-14', {:controller => 'issues', :action => 'show', :id => 3, :anchor => 'note-14'},
272 273 :class => Issue.find(3).css_classes, :title => 'Error 281 when updating a recipe (New)')
273 274 note_link2 = link_to('#3#note-14', {:controller => 'issues', :action => 'show', :id => 3, :anchor => 'note-14'},
274 275 :class => Issue.find(3).css_classes, :title => 'Error 281 when updating a recipe (New)')
275 276
276 277 revision_link = link_to('r1', {:controller => 'repositories', :action => 'revision', :id => 'ecookbook', :rev => 1},
277 278 :class => 'changeset', :title => 'My very first commit do not escaping #<>&')
278 279 revision_link2 = link_to('r2', {:controller => 'repositories', :action => 'revision', :id => 'ecookbook', :rev => 2},
279 280 :class => 'changeset', :title => 'This commit fixes #1, #2 and references #1 & #3')
280 281
281 282 changeset_link2 = link_to('691322a8eb01e11fd7',
282 283 {:controller => 'repositories', :action => 'revision', :id => 'ecookbook', :rev => 1},
283 284 :class => 'changeset', :title => 'My very first commit do not escaping #<>&')
284 285
285 286 document_link = link_to('Test document', {:controller => 'documents', :action => 'show', :id => 1},
286 287 :class => 'document')
287 288
288 289 version_link = link_to('1.0', {:controller => 'versions', :action => 'show', :id => 2},
289 290 :class => 'version')
290 291
291 292 board_url = {:controller => 'boards', :action => 'show', :id => 2, :project_id => 'ecookbook'}
292 293
293 294 message_url = {:controller => 'messages', :action => 'show', :board_id => 1, :id => 4}
294 295
295 296 news_url = {:controller => 'news', :action => 'show', :id => 1}
296 297
297 298 project_url = {:controller => 'projects', :action => 'show', :id => 'subproject1'}
298 299
299 300 source_url = '/projects/ecookbook/repository/entry/some/file'
300 301 source_url_with_rev = '/projects/ecookbook/repository/revisions/52/entry/some/file'
301 302 source_url_with_ext = '/projects/ecookbook/repository/entry/some/file.ext'
302 303 source_url_with_rev_and_ext = '/projects/ecookbook/repository/revisions/52/entry/some/file.ext'
303 304 source_url_with_branch = '/projects/ecookbook/repository/revisions/branch/entry/some/file'
304 305
305 306 export_url = '/projects/ecookbook/repository/raw/some/file'
306 307 export_url_with_rev = '/projects/ecookbook/repository/revisions/52/raw/some/file'
307 308 export_url_with_ext = '/projects/ecookbook/repository/raw/some/file.ext'
308 309 export_url_with_rev_and_ext = '/projects/ecookbook/repository/revisions/52/raw/some/file.ext'
309 310 export_url_with_branch = '/projects/ecookbook/repository/revisions/branch/raw/some/file'
310 311
311 312 to_test = {
312 313 # tickets
313 314 '#3, [#3], (#3) and #3.' => "#{issue_link}, [#{issue_link}], (#{issue_link}) and #{issue_link}.",
314 315 # ticket notes
315 316 '#3-14' => note_link,
316 317 '#3#note-14' => note_link2,
317 318 # should not ignore leading zero
318 319 '#03' => '#03',
319 320 # changesets
320 321 'r1' => revision_link,
321 322 'r1.' => "#{revision_link}.",
322 323 'r1, r2' => "#{revision_link}, #{revision_link2}",
323 324 'r1,r2' => "#{revision_link},#{revision_link2}",
324 325 'commit:691322a8eb01e11fd7' => changeset_link2,
325 326 # documents
326 327 'document#1' => document_link,
327 328 'document:"Test document"' => document_link,
328 329 # versions
329 330 'version#2' => version_link,
330 331 'version:1.0' => version_link,
331 332 'version:"1.0"' => version_link,
332 333 # source
333 334 'source:some/file' => link_to('source:some/file', source_url, :class => 'source'),
334 335 'source:/some/file' => link_to('source:/some/file', source_url, :class => 'source'),
335 336 'source:/some/file.' => link_to('source:/some/file', source_url, :class => 'source') + ".",
336 337 'source:/some/file.ext.' => link_to('source:/some/file.ext', source_url_with_ext, :class => 'source') + ".",
337 338 'source:/some/file. ' => link_to('source:/some/file', source_url, :class => 'source') + ".",
338 339 'source:/some/file.ext. ' => link_to('source:/some/file.ext', source_url_with_ext, :class => 'source') + ".",
339 340 'source:/some/file, ' => link_to('source:/some/file', source_url, :class => 'source') + ",",
340 341 'source:/some/file@52' => link_to('source:/some/file@52', source_url_with_rev, :class => 'source'),
341 342 'source:/some/file@branch' => link_to('source:/some/file@branch', source_url_with_branch, :class => 'source'),
342 343 'source:/some/file.ext@52' => link_to('source:/some/file.ext@52', source_url_with_rev_and_ext, :class => 'source'),
343 344 'source:/some/file#L110' => link_to('source:/some/file#L110', source_url + "#L110", :class => 'source'),
344 345 'source:/some/file.ext#L110' => link_to('source:/some/file.ext#L110', source_url_with_ext + "#L110", :class => 'source'),
345 346 'source:/some/file@52#L110' => link_to('source:/some/file@52#L110', source_url_with_rev + "#L110", :class => 'source'),
346 347 # export
347 348 'export:/some/file' => link_to('export:/some/file', export_url, :class => 'source download'),
348 349 'export:/some/file.ext' => link_to('export:/some/file.ext', export_url_with_ext, :class => 'source download'),
349 350 'export:/some/file@52' => link_to('export:/some/file@52', export_url_with_rev, :class => 'source download'),
350 351 'export:/some/file.ext@52' => link_to('export:/some/file.ext@52', export_url_with_rev_and_ext, :class => 'source download'),
351 352 'export:/some/file@branch' => link_to('export:/some/file@branch', export_url_with_branch, :class => 'source download'),
352 353 # forum
353 354 'forum#2' => link_to('Discussion', board_url, :class => 'board'),
354 355 'forum:Discussion' => link_to('Discussion', board_url, :class => 'board'),
355 356 # message
356 357 'message#4' => link_to('Post 2', message_url, :class => 'message'),
357 358 'message#5' => link_to('RE: post 2', message_url.merge(:anchor => 'message-5', :r => 5), :class => 'message'),
358 359 # news
359 360 'news#1' => link_to('eCookbook first release !', news_url, :class => 'news'),
360 361 'news:"eCookbook first release !"' => link_to('eCookbook first release !', news_url, :class => 'news'),
361 362 # project
362 363 'project#3' => link_to('eCookbook Subproject 1', project_url, :class => 'project'),
363 364 'project:subproject1' => link_to('eCookbook Subproject 1', project_url, :class => 'project'),
364 365 'project:"eCookbook subProject 1"' => link_to('eCookbook Subproject 1', project_url, :class => 'project'),
365 366 # not found
366 367 '#0123456789' => '#0123456789',
367 368 # invalid expressions
368 369 'source:' => 'source:',
369 370 # url hash
370 371 "http://foo.bar/FAQ#3" => '<a class="external" href="http://foo.bar/FAQ#3">http://foo.bar/FAQ#3</a>',
371 372 }
372 373 @project = Project.find(1)
373 374 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text), "#{text} failed" }
374 375 end
375 376
376 377 def test_redmine_links_with_a_different_project_before_current_project
377 378 vp1 = Version.generate!(:project_id => 1, :name => '1.4.4')
378 379 vp3 = Version.generate!(:project_id => 3, :name => '1.4.4')
379 380 @project = Project.find(3)
380 381 result1 = link_to("1.4.4", "/versions/#{vp1.id}", :class => "version")
381 382 result2 = link_to("1.4.4", "/versions/#{vp3.id}", :class => "version")
382 383 assert_equal "<p>#{result1} #{result2}</p>",
383 384 textilizable("ecookbook:version:1.4.4 version:1.4.4")
384 385 end
385 386
386 387 def test_escaped_redmine_links_should_not_be_parsed
387 388 to_test = [
388 389 '#3.',
389 390 '#3-14.',
390 391 '#3#-note14.',
391 392 'r1',
392 393 'document#1',
393 394 'document:"Test document"',
394 395 'version#2',
395 396 'version:1.0',
396 397 'version:"1.0"',
397 398 'source:/some/file'
398 399 ]
399 400 @project = Project.find(1)
400 401 to_test.each { |text| assert_equal "<p>#{text}</p>", textilizable("!" + text), "#{text} failed" }
401 402 end
402 403
403 404 def test_cross_project_redmine_links
404 405 source_link = link_to('ecookbook:source:/some/file',
405 406 {:controller => 'repositories', :action => 'entry',
406 407 :id => 'ecookbook', :path => ['some', 'file']},
407 408 :class => 'source')
408 409 changeset_link = link_to('ecookbook:r2',
409 410 {:controller => 'repositories', :action => 'revision',
410 411 :id => 'ecookbook', :rev => 2},
411 412 :class => 'changeset',
412 413 :title => 'This commit fixes #1, #2 and references #1 & #3')
413 414 to_test = {
414 415 # documents
415 416 'document:"Test document"' => 'document:"Test document"',
416 417 'ecookbook:document:"Test document"' =>
417 418 link_to("Test document", "/documents/1", :class => "document"),
418 419 'invalid:document:"Test document"' => 'invalid:document:"Test document"',
419 420 # versions
420 421 'version:"1.0"' => 'version:"1.0"',
421 422 'ecookbook:version:"1.0"' =>
422 423 link_to("1.0", "/versions/2", :class => "version"),
423 424 'invalid:version:"1.0"' => 'invalid:version:"1.0"',
424 425 # changeset
425 426 'r2' => 'r2',
426 427 'ecookbook:r2' => changeset_link,
427 428 'invalid:r2' => 'invalid:r2',
428 429 # source
429 430 'source:/some/file' => 'source:/some/file',
430 431 'ecookbook:source:/some/file' => source_link,
431 432 'invalid:source:/some/file' => 'invalid:source:/some/file',
432 433 }
433 434 @project = Project.find(3)
434 435 to_test.each do |text, result|
435 436 assert_equal "<p>#{result}</p>", textilizable(text), "#{text} failed"
436 437 end
437 438 end
438 439
439 440 def test_redmine_links_by_name_should_work_with_html_escaped_characters
440 441 v = Version.generate!(:name => "Test & Show.txt", :project_id => 1)
441 442 link = link_to("Test & Show.txt", "/versions/#{v.id}", :class => "version")
442 443
443 444 @project = v.project
444 445 assert_equal "<p>#{link}</p>", textilizable('version:"Test & Show.txt"')
445 446 end
446 447
447 448 def test_link_to_issue_subject
448 449 issue = Issue.generate!(:subject => "01234567890123456789")
449 450 str = link_to_issue(issue, :truncate => 10)
450 451 result = link_to("Bug ##{issue.id}", "/issues/#{issue.id}", :class => issue.css_classes)
451 452 assert_equal "#{result}: 0123456...", str
452 453
453 454 issue = Issue.generate!(:subject => "<&>")
454 455 str = link_to_issue(issue)
455 456 result = link_to("Bug ##{issue.id}", "/issues/#{issue.id}", :class => issue.css_classes)
456 457 assert_equal "#{result}: &lt;&amp;&gt;", str
457 458
458 459 issue = Issue.generate!(:subject => "<&>0123456789012345")
459 460 str = link_to_issue(issue, :truncate => 10)
460 461 result = link_to("Bug ##{issue.id}", "/issues/#{issue.id}", :class => issue.css_classes)
461 462 assert_equal "#{result}: &lt;&amp;&gt;0123...", str
462 463 end
463 464
464 465 def test_link_to_issue_title
465 466 long_str = "0123456789" * 5
466 467
467 468 issue = Issue.generate!(:subject => "#{long_str}01234567890123456789")
468 469 str = link_to_issue(issue, :subject => false)
469 470 result = link_to("Bug ##{issue.id}", "/issues/#{issue.id}",
470 471 :class => issue.css_classes,
471 472 :title => "#{long_str}0123456...")
472 473 assert_equal result, str
473 474
474 475 issue = Issue.generate!(:subject => "<&>#{long_str}01234567890123456789")
475 476 str = link_to_issue(issue, :subject => false)
476 477 result = link_to("Bug ##{issue.id}", "/issues/#{issue.id}",
477 478 :class => issue.css_classes,
478 479 :title => "<&>#{long_str}0123...")
479 480 assert_equal result, str
480 481 end
481 482
482 483 def test_multiple_repositories_redmine_links
483 484 svn = Repository::Subversion.create!(:project_id => 1, :identifier => 'svn_repo-1', :url => 'file:///foo/hg')
484 485 Changeset.create!(:repository => svn, :committed_on => Time.now, :revision => '123')
485 486 hg = Repository::Mercurial.create!(:project_id => 1, :identifier => 'hg1', :url => '/foo/hg')
486 487 Changeset.create!(:repository => hg, :committed_on => Time.now, :revision => '123', :scmid => 'abcd')
487 488
488 489 changeset_link = link_to('r2', {:controller => 'repositories', :action => 'revision', :id => 'ecookbook', :rev => 2},
489 490 :class => 'changeset', :title => 'This commit fixes #1, #2 and references #1 & #3')
490 491 svn_changeset_link = link_to('svn_repo-1|r123', {:controller => 'repositories', :action => 'revision', :id => 'ecookbook', :repository_id => 'svn_repo-1', :rev => 123},
491 492 :class => 'changeset', :title => '')
492 493 hg_changeset_link = link_to('hg1|abcd', {:controller => 'repositories', :action => 'revision', :id => 'ecookbook', :repository_id => 'hg1', :rev => 'abcd'},
493 494 :class => 'changeset', :title => '')
494 495
495 496 source_link = link_to('source:some/file', {:controller => 'repositories', :action => 'entry', :id => 'ecookbook', :path => ['some', 'file']}, :class => 'source')
496 497 hg_source_link = link_to('source:hg1|some/file', {:controller => 'repositories', :action => 'entry', :id => 'ecookbook', :repository_id => 'hg1', :path => ['some', 'file']}, :class => 'source')
497 498
498 499 to_test = {
499 500 'r2' => changeset_link,
500 501 'svn_repo-1|r123' => svn_changeset_link,
501 502 'invalid|r123' => 'invalid|r123',
502 503 'commit:hg1|abcd' => hg_changeset_link,
503 504 'commit:invalid|abcd' => 'commit:invalid|abcd',
504 505 # source
505 506 'source:some/file' => source_link,
506 507 'source:hg1|some/file' => hg_source_link,
507 508 'source:invalid|some/file' => 'source:invalid|some/file',
508 509 }
509 510
510 511 @project = Project.find(1)
511 512 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text), "#{text} failed" }
512 513 end
513 514
514 515 def test_cross_project_multiple_repositories_redmine_links
515 516 svn = Repository::Subversion.create!(:project_id => 1, :identifier => 'svn1', :url => 'file:///foo/hg')
516 517 Changeset.create!(:repository => svn, :committed_on => Time.now, :revision => '123')
517 518 hg = Repository::Mercurial.create!(:project_id => 1, :identifier => 'hg1', :url => '/foo/hg')
518 519 Changeset.create!(:repository => hg, :committed_on => Time.now, :revision => '123', :scmid => 'abcd')
519 520
520 521 changeset_link = link_to('ecookbook:r2', {:controller => 'repositories', :action => 'revision', :id => 'ecookbook', :rev => 2},
521 522 :class => 'changeset', :title => 'This commit fixes #1, #2 and references #1 & #3')
522 523 svn_changeset_link = link_to('ecookbook:svn1|r123', {:controller => 'repositories', :action => 'revision', :id => 'ecookbook', :repository_id => 'svn1', :rev => 123},
523 524 :class => 'changeset', :title => '')
524 525 hg_changeset_link = link_to('ecookbook:hg1|abcd', {:controller => 'repositories', :action => 'revision', :id => 'ecookbook', :repository_id => 'hg1', :rev => 'abcd'},
525 526 :class => 'changeset', :title => '')
526 527
527 528 source_link = link_to('ecookbook:source:some/file', {:controller => 'repositories', :action => 'entry', :id => 'ecookbook', :path => ['some', 'file']}, :class => 'source')
528 529 hg_source_link = link_to('ecookbook:source:hg1|some/file', {:controller => 'repositories', :action => 'entry', :id => 'ecookbook', :repository_id => 'hg1', :path => ['some', 'file']}, :class => 'source')
529 530
530 531 to_test = {
531 532 'ecookbook:r2' => changeset_link,
532 533 'ecookbook:svn1|r123' => svn_changeset_link,
533 534 'ecookbook:invalid|r123' => 'ecookbook:invalid|r123',
534 535 'ecookbook:commit:hg1|abcd' => hg_changeset_link,
535 536 'ecookbook:commit:invalid|abcd' => 'ecookbook:commit:invalid|abcd',
536 537 'invalid:commit:invalid|abcd' => 'invalid:commit:invalid|abcd',
537 538 # source
538 539 'ecookbook:source:some/file' => source_link,
539 540 'ecookbook:source:hg1|some/file' => hg_source_link,
540 541 'ecookbook:source:invalid|some/file' => 'ecookbook:source:invalid|some/file',
541 542 'invalid:source:invalid|some/file' => 'invalid:source:invalid|some/file',
542 543 }
543 544
544 545 @project = Project.find(3)
545 546 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text), "#{text} failed" }
546 547 end
547 548
548 549 def test_redmine_links_git_commit
549 550 changeset_link = link_to('abcd',
550 551 {
551 552 :controller => 'repositories',
552 553 :action => 'revision',
553 554 :id => 'subproject1',
554 555 :rev => 'abcd',
555 556 },
556 557 :class => 'changeset', :title => 'test commit')
557 558 to_test = {
558 559 'commit:abcd' => changeset_link,
559 560 }
560 561 @project = Project.find(3)
561 562 r = Repository::Git.create!(:project => @project, :url => '/tmp/test/git')
562 563 assert r
563 564 c = Changeset.new(:repository => r,
564 565 :committed_on => Time.now,
565 566 :revision => 'abcd',
566 567 :scmid => 'abcd',
567 568 :comments => 'test commit')
568 569 assert( c.save )
569 570 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) }
570 571 end
571 572
572 573 # TODO: Bazaar commit id contains mail address, so it contains '@' and '_'.
573 574 def test_redmine_links_darcs_commit
574 575 changeset_link = link_to('20080308225258-98289-abcd456efg.gz',
575 576 {
576 577 :controller => 'repositories',
577 578 :action => 'revision',
578 579 :id => 'subproject1',
579 580 :rev => '123',
580 581 },
581 582 :class => 'changeset', :title => 'test commit')
582 583 to_test = {
583 584 'commit:20080308225258-98289-abcd456efg.gz' => changeset_link,
584 585 }
585 586 @project = Project.find(3)
586 587 r = Repository::Darcs.create!(
587 588 :project => @project, :url => '/tmp/test/darcs',
588 589 :log_encoding => 'UTF-8')
589 590 assert r
590 591 c = Changeset.new(:repository => r,
591 592 :committed_on => Time.now,
592 593 :revision => '123',
593 594 :scmid => '20080308225258-98289-abcd456efg.gz',
594 595 :comments => 'test commit')
595 596 assert( c.save )
596 597 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) }
597 598 end
598 599
599 600 def test_redmine_links_mercurial_commit
600 601 changeset_link_rev = link_to('r123',
601 602 {
602 603 :controller => 'repositories',
603 604 :action => 'revision',
604 605 :id => 'subproject1',
605 606 :rev => '123' ,
606 607 },
607 608 :class => 'changeset', :title => 'test commit')
608 609 changeset_link_commit = link_to('abcd',
609 610 {
610 611 :controller => 'repositories',
611 612 :action => 'revision',
612 613 :id => 'subproject1',
613 614 :rev => 'abcd' ,
614 615 },
615 616 :class => 'changeset', :title => 'test commit')
616 617 to_test = {
617 618 'r123' => changeset_link_rev,
618 619 'commit:abcd' => changeset_link_commit,
619 620 }
620 621 @project = Project.find(3)
621 622 r = Repository::Mercurial.create!(:project => @project, :url => '/tmp/test')
622 623 assert r
623 624 c = Changeset.new(:repository => r,
624 625 :committed_on => Time.now,
625 626 :revision => '123',
626 627 :scmid => 'abcd',
627 628 :comments => 'test commit')
628 629 assert( c.save )
629 630 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) }
630 631 end
631 632
632 633 def test_attachment_links
633 634 text = 'attachment:error281.txt'
634 635 result = link_to("error281.txt", "/attachments/download/1/error281.txt",
635 636 :class => "attachment")
636 637 assert_equal "<p>#{result}</p>",
637 638 textilizable(text,
638 639 :attachments => Issue.find(3).attachments),
639 640 "#{text} failed"
640 641 end
641 642
642 643 def test_attachment_link_should_link_to_latest_attachment
643 644 set_tmp_attachments_directory
644 645 a1 = Attachment.generate!(:filename => "test.txt", :created_on => 1.hour.ago)
645 646 a2 = Attachment.generate!(:filename => "test.txt")
646 647 result = link_to("test.txt", "/attachments/download/#{a2.id}/test.txt",
647 648 :class => "attachment")
648 649 assert_equal "<p>#{result}</p>",
649 650 textilizable('attachment:test.txt', :attachments => [a1, a2])
650 651 end
651 652
652 653 def test_wiki_links
653 654 russian_eacape = CGI.escape(@russian_test)
654 655 to_test = {
655 656 '[[CookBook documentation]]' =>
656 657 link_to("CookBook documentation",
657 658 "/projects/ecookbook/wiki/CookBook_documentation",
658 659 :class => "wiki-page"),
659 660 '[[Another page|Page]]' =>
660 661 link_to("Page",
661 662 "/projects/ecookbook/wiki/Another_page",
662 663 :class => "wiki-page"),
663 664 # title content should be formatted
664 665 '[[Another page|With _styled_ *title*]]' =>
665 666 link_to("With <em>styled</em> <strong>title</strong>".html_safe,
666 667 "/projects/ecookbook/wiki/Another_page",
667 668 :class => "wiki-page"),
668 669 '[[Another page|With title containing <strong>HTML entities &amp; markups</strong>]]' =>
669 670 link_to("With title containing &lt;strong&gt;HTML entities &amp; markups&lt;/strong&gt;".html_safe,
670 671 "/projects/ecookbook/wiki/Another_page",
671 672 :class => "wiki-page"),
672 673 # link with anchor
673 674 '[[CookBook documentation#One-section]]' =>
674 675 link_to("CookBook documentation",
675 676 "/projects/ecookbook/wiki/CookBook_documentation#One-section",
676 677 :class => "wiki-page"),
677 678 '[[Another page#anchor|Page]]' =>
678 679 link_to("Page",
679 680 "/projects/ecookbook/wiki/Another_page#anchor",
680 681 :class => "wiki-page"),
681 682 # UTF8 anchor
682 683 "[[Another_page##{@russian_test}|#{@russian_test}]]" =>
683 684 link_to(@russian_test,
684 685 "/projects/ecookbook/wiki/Another_page##{russian_eacape}",
685 686 :class => "wiki-page"),
686 687 # page that doesn't exist
687 688 '[[Unknown page]]' =>
688 689 link_to("Unknown page",
689 690 "/projects/ecookbook/wiki/Unknown_page",
690 691 :class => "wiki-page new"),
691 692 '[[Unknown page|404]]' =>
692 693 link_to("404",
693 694 "/projects/ecookbook/wiki/Unknown_page",
694 695 :class => "wiki-page new"),
695 696 # link to another project wiki
696 697 '[[onlinestore:]]' =>
697 698 link_to("onlinestore",
698 699 "/projects/onlinestore/wiki",
699 700 :class => "wiki-page"),
700 701 '[[onlinestore:|Wiki]]' =>
701 702 link_to("Wiki",
702 703 "/projects/onlinestore/wiki",
703 704 :class => "wiki-page"),
704 705 '[[onlinestore:Start page]]' =>
705 706 link_to("Start page",
706 707 "/projects/onlinestore/wiki/Start_page",
707 708 :class => "wiki-page"),
708 709 '[[onlinestore:Start page|Text]]' =>
709 710 link_to("Text",
710 711 "/projects/onlinestore/wiki/Start_page",
711 712 :class => "wiki-page"),
712 713 '[[onlinestore:Unknown page]]' =>
713 714 link_to("Unknown page",
714 715 "/projects/onlinestore/wiki/Unknown_page",
715 716 :class => "wiki-page new"),
716 717 # struck through link
717 718 '-[[Another page|Page]]-' =>
718 719 "<del>".html_safe +
719 720 link_to("Page",
720 721 "/projects/ecookbook/wiki/Another_page",
721 722 :class => "wiki-page").html_safe +
722 723 "</del>".html_safe,
723 724 '-[[Another page|Page]] link-' =>
724 725 "<del>".html_safe +
725 726 link_to("Page",
726 727 "/projects/ecookbook/wiki/Another_page",
727 728 :class => "wiki-page").html_safe +
728 729 " link</del>".html_safe,
729 730 # escaping
730 731 '![[Another page|Page]]' => '[[Another page|Page]]',
731 732 # project does not exist
732 733 '[[unknowproject:Start]]' => '[[unknowproject:Start]]',
733 734 '[[unknowproject:Start|Page title]]' => '[[unknowproject:Start|Page title]]',
734 735 }
735 736 @project = Project.find(1)
736 737 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) }
737 738 end
738 739
739 740 def test_wiki_links_within_local_file_generation_context
740 741 to_test = {
741 742 # link to a page
742 743 '[[CookBook documentation]]' =>
743 744 link_to("CookBook documentation", "CookBook_documentation.html",
744 745 :class => "wiki-page"),
745 746 '[[CookBook documentation|documentation]]' =>
746 747 link_to("documentation", "CookBook_documentation.html",
747 748 :class => "wiki-page"),
748 749 '[[CookBook documentation#One-section]]' =>
749 750 link_to("CookBook documentation", "CookBook_documentation.html#One-section",
750 751 :class => "wiki-page"),
751 752 '[[CookBook documentation#One-section|documentation]]' =>
752 753 link_to("documentation", "CookBook_documentation.html#One-section",
753 754 :class => "wiki-page"),
754 755 # page that doesn't exist
755 756 '[[Unknown page]]' =>
756 757 link_to("Unknown page", "Unknown_page.html",
757 758 :class => "wiki-page new"),
758 759 '[[Unknown page|404]]' =>
759 760 link_to("404", "Unknown_page.html",
760 761 :class => "wiki-page new"),
761 762 '[[Unknown page#anchor]]' =>
762 763 link_to("Unknown page", "Unknown_page.html#anchor",
763 764 :class => "wiki-page new"),
764 765 '[[Unknown page#anchor|404]]' =>
765 766 link_to("404", "Unknown_page.html#anchor",
766 767 :class => "wiki-page new"),
767 768 }
768 769 @project = Project.find(1)
769 770 to_test.each do |text, result|
770 771 assert_equal "<p>#{result}</p>", textilizable(text, :wiki_links => :local)
771 772 end
772 773 end
773 774
774 775 def test_wiki_links_within_wiki_page_context
775 776 page = WikiPage.find_by_title('Another_page' )
776 777 to_test = {
777 778 '[[CookBook documentation]]' =>
778 779 link_to("CookBook documentation",
779 780 "/projects/ecookbook/wiki/CookBook_documentation",
780 781 :class => "wiki-page"),
781 782 '[[CookBook documentation|documentation]]' =>
782 783 link_to("documentation",
783 784 "/projects/ecookbook/wiki/CookBook_documentation",
784 785 :class => "wiki-page"),
785 786 '[[CookBook documentation#One-section]]' =>
786 787 link_to("CookBook documentation",
787 788 "/projects/ecookbook/wiki/CookBook_documentation#One-section",
788 789 :class => "wiki-page"),
789 790 '[[CookBook documentation#One-section|documentation]]' =>
790 791 link_to("documentation",
791 792 "/projects/ecookbook/wiki/CookBook_documentation#One-section",
792 793 :class => "wiki-page"),
793 794 # link to the current page
794 795 '[[Another page]]' =>
795 796 link_to("Another page",
796 797 "/projects/ecookbook/wiki/Another_page",
797 798 :class => "wiki-page"),
798 799 '[[Another page|Page]]' =>
799 800 link_to("Page",
800 801 "/projects/ecookbook/wiki/Another_page",
801 802 :class => "wiki-page"),
802 803 '[[Another page#anchor]]' =>
803 804 link_to("Another page",
804 805 "#anchor",
805 806 :class => "wiki-page"),
806 807 '[[Another page#anchor|Page]]' =>
807 808 link_to("Page",
808 809 "#anchor",
809 810 :class => "wiki-page"),
810 811 # page that doesn't exist
811 812 '[[Unknown page]]' =>
812 813 link_to("Unknown page",
813 814 "/projects/ecookbook/wiki/Unknown_page?parent=Another_page",
814 815 :class => "wiki-page new"),
815 816 '[[Unknown page|404]]' =>
816 817 link_to("404",
817 818 "/projects/ecookbook/wiki/Unknown_page?parent=Another_page",
818 819 :class => "wiki-page new"),
819 820 '[[Unknown page#anchor]]' =>
820 821 link_to("Unknown page",
821 822 "/projects/ecookbook/wiki/Unknown_page?parent=Another_page#anchor",
822 823 :class => "wiki-page new"),
823 824 '[[Unknown page#anchor|404]]' =>
824 825 link_to("404",
825 826 "/projects/ecookbook/wiki/Unknown_page?parent=Another_page#anchor",
826 827 :class => "wiki-page new"),
827 828 }
828 829 @project = Project.find(1)
829 830 to_test.each do |text, result|
830 831 assert_equal "<p>#{result}</p>",
831 832 textilizable(WikiContent.new( :text => text, :page => page ), :text)
832 833 end
833 834 end
834 835
835 836 def test_wiki_links_anchor_option_should_prepend_page_title_to_href
836 837 to_test = {
837 838 # link to a page
838 839 '[[CookBook documentation]]' =>
839 840 link_to("CookBook documentation",
840 841 "#CookBook_documentation",
841 842 :class => "wiki-page"),
842 843 '[[CookBook documentation|documentation]]' =>
843 844 link_to("documentation",
844 845 "#CookBook_documentation",
845 846 :class => "wiki-page"),
846 847 '[[CookBook documentation#One-section]]' =>
847 848 link_to("CookBook documentation",
848 849 "#CookBook_documentation_One-section",
849 850 :class => "wiki-page"),
850 851 '[[CookBook documentation#One-section|documentation]]' =>
851 852 link_to("documentation",
852 853 "#CookBook_documentation_One-section",
853 854 :class => "wiki-page"),
854 855 # page that doesn't exist
855 856 '[[Unknown page]]' =>
856 857 link_to("Unknown page",
857 858 "#Unknown_page",
858 859 :class => "wiki-page new"),
859 860 '[[Unknown page|404]]' =>
860 861 link_to("404",
861 862 "#Unknown_page",
862 863 :class => "wiki-page new"),
863 864 '[[Unknown page#anchor]]' =>
864 865 link_to("Unknown page",
865 866 "#Unknown_page_anchor",
866 867 :class => "wiki-page new"),
867 868 '[[Unknown page#anchor|404]]' =>
868 869 link_to("404",
869 870 "#Unknown_page_anchor",
870 871 :class => "wiki-page new"),
871 872 }
872 873 @project = Project.find(1)
873 874 to_test.each do |text, result|
874 875 assert_equal "<p>#{result}</p>", textilizable(text, :wiki_links => :anchor)
875 876 end
876 877 end
877 878
878 879 def test_html_tags
879 880 to_test = {
880 881 "<div>content</div>" => "<p>&lt;div&gt;content&lt;/div&gt;</p>",
881 882 "<div class=\"bold\">content</div>" => "<p>&lt;div class=\"bold\"&gt;content&lt;/div&gt;</p>",
882 883 "<script>some script;</script>" => "<p>&lt;script&gt;some script;&lt;/script&gt;</p>",
883 884 # do not escape pre/code tags
884 885 "<pre>\nline 1\nline2</pre>" => "<pre>\nline 1\nline2</pre>",
885 886 "<pre><code>\nline 1\nline2</code></pre>" => "<pre><code>\nline 1\nline2</code></pre>",
886 887 "<pre><div>content</div></pre>" => "<pre>&lt;div&gt;content&lt;/div&gt;</pre>",
887 888 "HTML comment: <!-- no comments -->" => "<p>HTML comment: &lt;!-- no comments --&gt;</p>",
888 889 "<!-- opening comment" => "<p>&lt;!-- opening comment</p>",
889 890 # remove attributes except class
890 891 "<pre class='foo'>some text</pre>" => "<pre class='foo'>some text</pre>",
891 892 '<pre class="foo">some text</pre>' => '<pre class="foo">some text</pre>',
892 893 "<pre class='foo bar'>some text</pre>" => "<pre class='foo bar'>some text</pre>",
893 894 '<pre class="foo bar">some text</pre>' => '<pre class="foo bar">some text</pre>',
894 895 "<pre onmouseover='alert(1)'>some text</pre>" => "<pre>some text</pre>",
895 896 # xss
896 897 '<pre><code class=""onmouseover="alert(1)">text</code></pre>' => '<pre><code>text</code></pre>',
897 898 '<pre class=""onmouseover="alert(1)">text</pre>' => '<pre>text</pre>',
898 899 }
899 900 to_test.each { |text, result| assert_equal result, textilizable(text) }
900 901 end
901 902
902 903 def test_allowed_html_tags
903 904 to_test = {
904 905 "<pre>preformatted text</pre>" => "<pre>preformatted text</pre>",
905 906 "<notextile>no *textile* formatting</notextile>" => "no *textile* formatting",
906 907 "<notextile>this is <tag>a tag</tag></notextile>" => "this is &lt;tag&gt;a tag&lt;/tag&gt;"
907 908 }
908 909 to_test.each { |text, result| assert_equal result, textilizable(text) }
909 910 end
910 911
911 912 def test_pre_tags
912 913 raw = <<-RAW
913 914 Before
914 915
915 916 <pre>
916 917 <prepared-statement-cache-size>32</prepared-statement-cache-size>
917 918 </pre>
918 919
919 920 After
920 921 RAW
921 922
922 923 expected = <<-EXPECTED
923 924 <p>Before</p>
924 925 <pre>
925 926 &lt;prepared-statement-cache-size&gt;32&lt;/prepared-statement-cache-size&gt;
926 927 </pre>
927 928 <p>After</p>
928 929 EXPECTED
929 930
930 931 assert_equal expected.gsub(%r{[\r\n\t]}, ''), textilizable(raw).gsub(%r{[\r\n\t]}, '')
931 932 end
932 933
933 934 def test_pre_content_should_not_parse_wiki_and_redmine_links
934 935 raw = <<-RAW
935 936 [[CookBook documentation]]
936 937
937 938 #1
938 939
939 940 <pre>
940 941 [[CookBook documentation]]
941 942
942 943 #1
943 944 </pre>
944 945 RAW
945 946
946 947 result1 = link_to("CookBook documentation",
947 948 "/projects/ecookbook/wiki/CookBook_documentation",
948 949 :class => "wiki-page")
949 950 result2 = link_to('#1',
950 951 "/issues/1",
951 952 :class => Issue.find(1).css_classes,
952 953 :title => "Can't print recipes (New)")
953 954
954 955 expected = <<-EXPECTED
955 956 <p>#{result1}</p>
956 957 <p>#{result2}</p>
957 958 <pre>
958 959 [[CookBook documentation]]
959 960
960 961 #1
961 962 </pre>
962 963 EXPECTED
963 964
964 965 @project = Project.find(1)
965 966 assert_equal expected.gsub(%r{[\r\n\t]}, ''), textilizable(raw).gsub(%r{[\r\n\t]}, '')
966 967 end
967 968
968 969 def test_non_closing_pre_blocks_should_be_closed
969 970 raw = <<-RAW
970 971 <pre><code>
971 972 RAW
972 973
973 974 expected = <<-EXPECTED
974 975 <pre><code>
975 976 </code></pre>
976 977 EXPECTED
977 978
978 979 @project = Project.find(1)
979 980 assert_equal expected.gsub(%r{[\r\n\t]}, ''), textilizable(raw).gsub(%r{[\r\n\t]}, '')
980 981 end
981 982
982 983 def test_syntax_highlight
983 984 raw = <<-RAW
984 985 <pre><code class="ruby">
985 986 # Some ruby code here
986 987 </code></pre>
987 988 RAW
988 989
989 990 expected = <<-EXPECTED
990 991 <pre><code class="ruby syntaxhl"><span class=\"CodeRay\"><span class="comment"># Some ruby code here</span></span>
991 992 </code></pre>
992 993 EXPECTED
993 994
994 995 assert_equal expected.gsub(%r{[\r\n\t]}, ''), textilizable(raw).gsub(%r{[\r\n\t]}, '')
995 996 end
996 997
997 998 def test_to_path_param
998 999 assert_equal 'test1/test2', to_path_param('test1/test2')
999 1000 assert_equal 'test1/test2', to_path_param('/test1/test2/')
1000 1001 assert_equal 'test1/test2', to_path_param('//test1/test2/')
1001 1002 assert_equal nil, to_path_param('/')
1002 1003 end
1003 1004
1004 1005 def test_wiki_links_in_tables
1005 1006 text = "|[[Page|Link title]]|[[Other Page|Other title]]|\n|Cell 21|[[Last page]]|"
1006 1007 link1 = link_to("Link title", "/projects/ecookbook/wiki/Page", :class => "wiki-page new")
1007 1008 link2 = link_to("Other title", "/projects/ecookbook/wiki/Other_Page", :class => "wiki-page new")
1008 1009 link3 = link_to("Last page", "/projects/ecookbook/wiki/Last_page", :class => "wiki-page new")
1009 1010 result = "<tr><td>#{link1}</td>" +
1010 1011 "<td>#{link2}</td>" +
1011 1012 "</tr><tr><td>Cell 21</td><td>#{link3}</td></tr>"
1012 1013 @project = Project.find(1)
1013 1014 assert_equal "<table>#{result}</table>", textilizable(text).gsub(/[\t\n]/, '')
1014 1015 end
1015 1016
1016 1017 def test_text_formatting
1017 1018 to_test = {'*_+bold, italic and underline+_*' => '<strong><em><ins>bold, italic and underline</ins></em></strong>',
1018 1019 '(_text within parentheses_)' => '(<em>text within parentheses</em>)',
1019 1020 'a *Humane Web* Text Generator' => 'a <strong>Humane Web</strong> Text Generator',
1020 1021 '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>',
1021 1022 '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',
1022 1023 }
1023 1024 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) }
1024 1025 end
1025 1026
1026 1027 def test_wiki_horizontal_rule
1027 1028 assert_equal '<hr />', textilizable('---')
1028 1029 assert_equal '<p>Dashes: ---</p>', textilizable('Dashes: ---')
1029 1030 end
1030 1031
1031 1032 def test_footnotes
1032 1033 raw = <<-RAW
1033 1034 This is some text[1].
1034 1035
1035 1036 fn1. This is the foot note
1036 1037 RAW
1037 1038
1038 1039 expected = <<-EXPECTED
1039 1040 <p>This is some text<sup><a href=\"#fn1\">1</a></sup>.</p>
1040 1041 <p id="fn1" class="footnote"><sup>1</sup> This is the foot note</p>
1041 1042 EXPECTED
1042 1043
1043 1044 assert_equal expected.gsub(%r{[\r\n\t]}, ''), textilizable(raw).gsub(%r{[\r\n\t]}, '')
1044 1045 end
1045 1046
1046 1047 def test_headings
1047 1048 raw = 'h1. Some heading'
1048 1049 expected = %|<a name="Some-heading"></a>\n<h1 >Some heading<a href="#Some-heading" class="wiki-anchor">&para;</a></h1>|
1049 1050
1050 1051 assert_equal expected, textilizable(raw)
1051 1052 end
1052 1053
1053 1054 def test_headings_with_special_chars
1054 1055 # This test makes sure that the generated anchor names match the expected
1055 1056 # ones even if the heading text contains unconventional characters
1056 1057 raw = 'h1. Some heading related to version 0.5'
1057 1058 anchor = sanitize_anchor_name("Some-heading-related-to-version-0.5")
1058 1059 expected = %|<a name="#{anchor}"></a>\n<h1 >Some heading related to version 0.5<a href="##{anchor}" class="wiki-anchor">&para;</a></h1>|
1059 1060
1060 1061 assert_equal expected, textilizable(raw)
1061 1062 end
1062 1063
1063 1064 def test_headings_in_wiki_single_page_export_should_be_prepended_with_page_title
1064 1065 page = WikiPage.new( :title => 'Page Title', :wiki_id => 1 )
1065 1066 content = WikiContent.new( :text => 'h1. Some heading', :page => page )
1066 1067
1067 1068 expected = %|<a name="Page_Title_Some-heading"></a>\n<h1 >Some heading<a href="#Page_Title_Some-heading" class="wiki-anchor">&para;</a></h1>|
1068 1069
1069 1070 assert_equal expected, textilizable(content, :text, :wiki_links => :anchor )
1070 1071 end
1071 1072
1072 1073 def test_table_of_content
1073 1074 raw = <<-RAW
1074 1075 {{toc}}
1075 1076
1076 1077 h1. Title
1077 1078
1078 1079 Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas sed libero.
1079 1080
1080 1081 h2. Subtitle with a [[Wiki]] link
1081 1082
1082 1083 Nullam commodo metus accumsan nulla. Curabitur lobortis dui id dolor.
1083 1084
1084 1085 h2. Subtitle with [[Wiki|another Wiki]] link
1085 1086
1086 1087 h2. Subtitle with %{color:red}red text%
1087 1088
1088 1089 <pre>
1089 1090 some code
1090 1091 </pre>
1091 1092
1092 1093 h3. Subtitle with *some* _modifiers_
1093 1094
1094 1095 h3. Subtitle with @inline code@
1095 1096
1096 1097 h1. Another title
1097 1098
1098 1099 h3. An "Internet link":http://www.redmine.org/ inside subtitle
1099 1100
1100 1101 h2. "Project Name !/attachments/1234/logo_small.gif! !/attachments/5678/logo_2.png!":/projects/projectname/issues
1101 1102
1102 1103 RAW
1103 1104
1104 1105 expected = '<ul class="toc">' +
1105 1106 '<li><a href="#Title">Title</a>' +
1106 1107 '<ul>' +
1107 1108 '<li><a href="#Subtitle-with-a-Wiki-link">Subtitle with a Wiki link</a></li>' +
1108 1109 '<li><a href="#Subtitle-with-another-Wiki-link">Subtitle with another Wiki link</a></li>' +
1109 1110 '<li><a href="#Subtitle-with-red-text">Subtitle with red text</a>' +
1110 1111 '<ul>' +
1111 1112 '<li><a href="#Subtitle-with-some-modifiers">Subtitle with some modifiers</a></li>' +
1112 1113 '<li><a href="#Subtitle-with-inline-code">Subtitle with inline code</a></li>' +
1113 1114 '</ul>' +
1114 1115 '</li>' +
1115 1116 '</ul>' +
1116 1117 '</li>' +
1117 1118 '<li><a href="#Another-title">Another title</a>' +
1118 1119 '<ul>' +
1119 1120 '<li>' +
1120 1121 '<ul>' +
1121 1122 '<li><a href="#An-Internet-link-inside-subtitle">An Internet link inside subtitle</a></li>' +
1122 1123 '</ul>' +
1123 1124 '</li>' +
1124 1125 '<li><a href="#Project-Name">Project Name</a></li>' +
1125 1126 '</ul>' +
1126 1127 '</li>' +
1127 1128 '</ul>'
1128 1129
1129 1130 @project = Project.find(1)
1130 1131 assert textilizable(raw).gsub("\n", "").include?(expected)
1131 1132 end
1132 1133
1133 1134 def test_table_of_content_should_generate_unique_anchors
1134 1135 raw = <<-RAW
1135 1136 {{toc}}
1136 1137
1137 1138 h1. Title
1138 1139
1139 1140 h2. Subtitle
1140 1141
1141 1142 h2. Subtitle
1142 1143 RAW
1143 1144
1144 1145 expected = '<ul class="toc">' +
1145 1146 '<li><a href="#Title">Title</a>' +
1146 1147 '<ul>' +
1147 1148 '<li><a href="#Subtitle">Subtitle</a></li>' +
1148 1149 '<li><a href="#Subtitle-2">Subtitle</a></li>'
1149 1150 '</ul>'
1150 1151 '</li>' +
1151 1152 '</ul>'
1152 1153
1153 1154 @project = Project.find(1)
1154 1155 result = textilizable(raw).gsub("\n", "")
1155 1156 assert_include expected, result
1156 1157 assert_include '<a name="Subtitle">', result
1157 1158 assert_include '<a name="Subtitle-2">', result
1158 1159 end
1159 1160
1160 1161 def test_table_of_content_should_contain_included_page_headings
1161 1162 raw = <<-RAW
1162 1163 {{toc}}
1163 1164
1164 1165 h1. Included
1165 1166
1166 1167 {{include(Child_1)}}
1167 1168 RAW
1168 1169
1169 1170 expected = '<ul class="toc">' +
1170 1171 '<li><a href="#Included">Included</a></li>' +
1171 1172 '<li><a href="#Child-page-1">Child page 1</a></li>' +
1172 1173 '</ul>'
1173 1174
1174 1175 @project = Project.find(1)
1175 1176 assert textilizable(raw).gsub("\n", "").include?(expected)
1176 1177 end
1177 1178
1178 1179 def test_toc_with_textile_formatting_should_be_parsed
1179 1180 with_settings :text_formatting => 'textile' do
1180 1181 assert_select_in textilizable("{{toc}}\n\nh1. Heading"), 'ul.toc li', :text => 'Heading'
1181 1182 assert_select_in textilizable("{{<toc}}\n\nh1. Heading"), 'ul.toc.left li', :text => 'Heading'
1182 1183 assert_select_in textilizable("{{>toc}}\n\nh1. Heading"), 'ul.toc.right li', :text => 'Heading'
1183 1184 end
1184 1185 end
1185 1186
1186 1187 if Object.const_defined?(:Redcarpet)
1187 1188 def test_toc_with_markdown_formatting_should_be_parsed
1188 1189 with_settings :text_formatting => 'markdown' do
1189 1190 assert_select_in textilizable("{{toc}}\n\n# Heading"), 'ul.toc li', :text => 'Heading'
1190 1191 assert_select_in textilizable("{{<toc}}\n\n# Heading"), 'ul.toc.left li', :text => 'Heading'
1191 1192 assert_select_in textilizable("{{>toc}}\n\n# Heading"), 'ul.toc.right li', :text => 'Heading'
1192 1193 end
1193 1194 end
1194 1195 end
1195 1196
1196 1197 def test_section_edit_links
1197 1198 raw = <<-RAW
1198 1199 h1. Title
1199 1200
1200 1201 Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas sed libero.
1201 1202
1202 1203 h2. Subtitle with a [[Wiki]] link
1203 1204
1204 1205 h2. Subtitle with *some* _modifiers_
1205 1206
1206 1207 h2. Subtitle with @inline code@
1207 1208
1208 1209 <pre>
1209 1210 some code
1210 1211
1211 1212 h2. heading inside pre
1212 1213
1213 1214 <h2>html heading inside pre</h2>
1214 1215 </pre>
1215 1216
1216 1217 h2. Subtitle after pre tag
1217 1218 RAW
1218 1219
1219 1220 @project = Project.find(1)
1220 1221 set_language_if_valid 'en'
1221 1222 result = textilizable(raw, :edit_section_links => {:controller => 'wiki', :action => 'edit', :project_id => '1', :id => 'Test'}).gsub("\n", "")
1222 1223
1223 1224 # heading that contains inline code
1224 1225 assert_match Regexp.new('<div class="contextual" id="section-4" title="Edit this section">' +
1225 1226 '<a href="/projects/1/wiki/Test/edit\?section=4"><img alt="Edit" src="/images/edit.png(\?\d+)?" /></a></div>' +
1226 1227 '<a name="Subtitle-with-inline-code"></a>' +
1227 1228 '<h2 >Subtitle with <code>inline code</code><a href="#Subtitle-with-inline-code" class="wiki-anchor">&para;</a></h2>'),
1228 1229 result
1229 1230
1230 1231 # last heading
1231 1232 assert_match Regexp.new('<div class="contextual" id="section-5" title="Edit this section">' +
1232 1233 '<a href="/projects/1/wiki/Test/edit\?section=5"><img alt="Edit" src="/images/edit.png(\?\d+)?" /></a></div>' +
1233 1234 '<a name="Subtitle-after-pre-tag"></a>' +
1234 1235 '<h2 >Subtitle after pre tag<a href="#Subtitle-after-pre-tag" class="wiki-anchor">&para;</a></h2>'),
1235 1236 result
1236 1237 end
1237 1238
1238 1239 def test_default_formatter
1239 1240 with_settings :text_formatting => 'unknown' do
1240 1241 text = 'a *link*: http://www.example.net/'
1241 1242 assert_equal '<p>a *link*: <a class="external" href="http://www.example.net/">http://www.example.net/</a></p>', textilizable(text)
1242 1243 end
1243 1244 end
1244 1245
1245 1246 def test_due_date_distance_in_words
1246 1247 to_test = { Date.today => 'Due in 0 days',
1247 1248 Date.today + 1 => 'Due in 1 day',
1248 1249 Date.today + 100 => 'Due in about 3 months',
1249 1250 Date.today + 20000 => 'Due in over 54 years',
1250 1251 Date.today - 1 => '1 day late',
1251 1252 Date.today - 100 => 'about 3 months late',
1252 1253 Date.today - 20000 => 'over 54 years late',
1253 1254 }
1254 1255 ::I18n.locale = :en
1255 1256 to_test.each do |date, expected|
1256 1257 assert_equal expected, due_date_distance_in_words(date)
1257 1258 end
1258 1259 end
1259 1260
1260 1261 def test_avatar_enabled
1261 1262 with_settings :gravatar_enabled => '1' do
1262 1263 assert avatar(User.find_by_mail('jsmith@somenet.foo')).include?(Digest::MD5.hexdigest('jsmith@somenet.foo'))
1263 1264 assert avatar('jsmith <jsmith@somenet.foo>').include?(Digest::MD5.hexdigest('jsmith@somenet.foo'))
1264 1265 # Default size is 50
1265 1266 assert avatar('jsmith <jsmith@somenet.foo>').include?('size=50')
1266 1267 assert avatar('jsmith <jsmith@somenet.foo>', :size => 24).include?('size=24')
1267 1268 # Non-avatar options should be considered html options
1268 1269 assert avatar('jsmith <jsmith@somenet.foo>', :title => 'John Smith').include?('title="John Smith"')
1269 1270 # The default class of the img tag should be gravatar
1270 1271 assert avatar('jsmith <jsmith@somenet.foo>').include?('class="gravatar"')
1271 1272 assert !avatar('jsmith <jsmith@somenet.foo>', :class => 'picture').include?('class="gravatar"')
1272 1273 assert_nil avatar('jsmith')
1273 1274 assert_nil avatar(nil)
1274 1275 end
1275 1276 end
1276 1277
1277 1278 def test_avatar_disabled
1278 1279 with_settings :gravatar_enabled => '0' do
1279 1280 assert_equal '', avatar(User.find_by_mail('jsmith@somenet.foo'))
1280 1281 end
1281 1282 end
1282 1283
1283 1284 def test_link_to_user
1284 1285 user = User.find(2)
1285 1286 result = link_to("John Smith", "/users/2", :class => "user active")
1286 1287 assert_equal result, link_to_user(user)
1287 1288 end
1288 1289
1289 1290 def test_link_to_user_should_not_link_to_locked_user
1290 1291 with_current_user nil do
1291 1292 user = User.find(5)
1292 1293 assert user.locked?
1293 1294 assert_equal 'Dave2 Lopper2', link_to_user(user)
1294 1295 end
1295 1296 end
1296 1297
1297 1298 def test_link_to_user_should_link_to_locked_user_if_current_user_is_admin
1298 1299 with_current_user User.find(1) do
1299 1300 user = User.find(5)
1300 1301 assert user.locked?
1301 1302 result = link_to("Dave2 Lopper2", "/users/5", :class => "user locked")
1302 1303 assert_equal result, link_to_user(user)
1303 1304 end
1304 1305 end
1305 1306
1306 1307 def test_link_to_user_should_not_link_to_anonymous
1307 1308 user = User.anonymous
1308 1309 assert user.anonymous?
1309 1310 t = link_to_user(user)
1310 1311 assert_equal ::I18n.t(:label_user_anonymous), t
1311 1312 end
1312 1313
1313 1314 def test_link_to_attachment
1314 1315 a = Attachment.find(3)
1315 1316 assert_equal '<a href="/attachments/3/logo.gif">logo.gif</a>',
1316 1317 link_to_attachment(a)
1317 1318 assert_equal '<a href="/attachments/3/logo.gif">Text</a>',
1318 1319 link_to_attachment(a, :text => 'Text')
1319 1320 result = link_to("logo.gif", "/attachments/3/logo.gif", :class => "foo")
1320 1321 assert_equal result,
1321 1322 link_to_attachment(a, :class => 'foo')
1322 1323 assert_equal '<a href="/attachments/download/3/logo.gif">logo.gif</a>',
1323 1324 link_to_attachment(a, :download => true)
1324 1325 assert_equal '<a href="http://test.host/attachments/3/logo.gif">logo.gif</a>',
1325 1326 link_to_attachment(a, :only_path => false)
1326 1327 end
1327 1328
1328 1329 def test_thumbnail_tag
1329 1330 a = Attachment.find(3)
1330 1331 assert_equal '<a href="/attachments/3/logo.gif" title="logo.gif"><img alt="3" src="/attachments/thumbnail/3" /></a>',
1331 1332 thumbnail_tag(a)
1332 1333 end
1333 1334
1334 1335 def test_link_to_project
1335 1336 project = Project.find(1)
1336 1337 assert_equal %(<a href="/projects/ecookbook">eCookbook</a>),
1337 1338 link_to_project(project)
1338 1339 assert_equal %(<a href="/projects/ecookbook/settings">eCookbook</a>),
1339 1340 link_to_project(project, :action => 'settings')
1340 1341 assert_equal %(<a href="http://test.host/projects/ecookbook?jump=blah">eCookbook</a>),
1341 1342 link_to_project(project, {:only_path => false, :jump => 'blah'})
1342 1343 result = link_to("eCookbook", "/projects/ecookbook/settings", :class => "project")
1343 1344 assert_equal result,
1344 1345 link_to_project(project, {:action => 'settings'}, :class => "project")
1345 1346 end
1346 1347
1347 1348 def test_link_to_project_settings
1348 1349 project = Project.find(1)
1349 1350 assert_equal '<a href="/projects/ecookbook/settings">eCookbook</a>', link_to_project_settings(project)
1350 1351
1351 1352 project.status = Project::STATUS_CLOSED
1352 1353 assert_equal '<a href="/projects/ecookbook">eCookbook</a>', link_to_project_settings(project)
1353 1354
1354 1355 project.status = Project::STATUS_ARCHIVED
1355 1356 assert_equal 'eCookbook', link_to_project_settings(project)
1356 1357 end
1357 1358
1358 1359 def test_link_to_legacy_project_with_numerical_identifier_should_use_id
1359 1360 # numeric identifier are no longer allowed
1360 1361 Project.where(:id => 1).update_all(:identifier => 25)
1361 1362 assert_equal '<a href="/projects/1">eCookbook</a>',
1362 1363 link_to_project(Project.find(1))
1363 1364 end
1364 1365
1365 1366 def test_principals_options_for_select_with_users
1366 1367 User.current = nil
1367 1368 users = [User.find(2), User.find(4)]
1368 1369 assert_equal %(<option value="2">John Smith</option><option value="4">Robert Hill</option>),
1369 1370 principals_options_for_select(users)
1370 1371 end
1371 1372
1372 1373 def test_principals_options_for_select_with_selected
1373 1374 User.current = nil
1374 1375 users = [User.find(2), User.find(4)]
1375 1376 assert_equal %(<option value="2">John Smith</option><option value="4" selected="selected">Robert Hill</option>),
1376 1377 principals_options_for_select(users, User.find(4))
1377 1378 end
1378 1379
1379 1380 def test_principals_options_for_select_with_users_and_groups
1380 1381 User.current = nil
1381 1382 users = [User.find(2), Group.find(11), User.find(4), Group.find(10)]
1382 1383 assert_equal %(<option value="2">John Smith</option><option value="4">Robert Hill</option>) +
1383 1384 %(<optgroup label="Groups"><option value="10">A Team</option><option value="11">B Team</option></optgroup>),
1384 1385 principals_options_for_select(users)
1385 1386 end
1386 1387
1387 1388 def test_principals_options_for_select_with_empty_collection
1388 1389 assert_equal '', principals_options_for_select([])
1389 1390 end
1390 1391
1391 1392 def test_principals_options_for_select_should_include_me_option_when_current_user_is_in_collection
1392 1393 users = [User.find(2), User.find(4)]
1393 1394 User.current = User.find(4)
1394 1395 assert_include '<option value="4">&lt;&lt; me &gt;&gt;</option>', principals_options_for_select(users)
1395 1396 end
1396 1397
1397 1398 def test_stylesheet_link_tag_should_pick_the_default_stylesheet
1398 1399 assert_match 'href="/stylesheets/styles.css"', stylesheet_link_tag("styles")
1399 1400 end
1400 1401
1401 1402 def test_stylesheet_link_tag_for_plugin_should_pick_the_plugin_stylesheet
1402 1403 assert_match 'href="/plugin_assets/foo/stylesheets/styles.css"', stylesheet_link_tag("styles", :plugin => :foo)
1403 1404 end
1404 1405
1405 1406 def test_image_tag_should_pick_the_default_image
1406 1407 assert_match 'src="/images/image.png"', image_tag("image.png")
1407 1408 end
1408 1409
1409 1410 def test_image_tag_should_pick_the_theme_image_if_it_exists
1410 1411 theme = Redmine::Themes.themes.last
1411 1412 theme.images << 'image.png'
1412 1413
1413 1414 with_settings :ui_theme => theme.id do
1414 1415 assert_match %|src="/themes/#{theme.dir}/images/image.png"|, image_tag("image.png")
1415 1416 assert_match %|src="/images/other.png"|, image_tag("other.png")
1416 1417 end
1417 1418 ensure
1418 1419 theme.images.delete 'image.png'
1419 1420 end
1420 1421
1421 1422 def test_image_tag_sfor_plugin_should_pick_the_plugin_image
1422 1423 assert_match 'src="/plugin_assets/foo/images/image.png"', image_tag("image.png", :plugin => :foo)
1423 1424 end
1424 1425
1425 1426 def test_javascript_include_tag_should_pick_the_default_javascript
1426 1427 assert_match 'src="/javascripts/scripts.js"', javascript_include_tag("scripts")
1427 1428 end
1428 1429
1429 1430 def test_javascript_include_tag_for_plugin_should_pick_the_plugin_javascript
1430 1431 assert_match 'src="/plugin_assets/foo/javascripts/scripts.js"', javascript_include_tag("scripts", :plugin => :foo)
1431 1432 end
1432 1433
1433 1434 def test_raw_json_should_escape_closing_tags
1434 1435 s = raw_json(["<foo>bar</foo>"])
1435 1436 assert_equal '["<foo>bar<\/foo>"]', s
1436 1437 end
1437 1438
1438 1439 def test_raw_json_should_be_html_safe
1439 1440 s = raw_json(["foo"])
1440 1441 assert s.html_safe?
1441 1442 end
1442 1443
1443 1444 def test_html_title_should_app_title_if_not_set
1444 1445 assert_equal 'Redmine', html_title
1445 1446 end
1446 1447
1447 1448 def test_html_title_should_join_items
1448 1449 html_title 'Foo', 'Bar'
1449 1450 assert_equal 'Foo - Bar - Redmine', html_title
1450 1451 end
1451 1452
1452 1453 def test_html_title_should_append_current_project_name
1453 1454 @project = Project.find(1)
1454 1455 html_title 'Foo', 'Bar'
1455 1456 assert_equal 'Foo - Bar - eCookbook - Redmine', html_title
1456 1457 end
1457 1458
1458 1459 def test_title_should_return_a_h2_tag
1459 1460 assert_equal '<h2>Foo</h2>', title('Foo')
1460 1461 end
1461 1462
1462 1463 def test_title_should_set_html_title
1463 1464 title('Foo')
1464 1465 assert_equal 'Foo - Redmine', html_title
1465 1466 end
1466 1467
1467 1468 def test_title_should_turn_arrays_into_links
1468 1469 assert_equal '<h2><a href="/foo">Foo</a></h2>', title(['Foo', '/foo'])
1469 1470 assert_equal 'Foo - Redmine', html_title
1470 1471 end
1471 1472
1472 1473 def test_title_should_join_items
1473 1474 assert_equal '<h2>Foo &#187; Bar</h2>', title('Foo', 'Bar')
1474 1475 assert_equal 'Bar - Foo - Redmine', html_title
1475 1476 end
1476 1477
1477 1478 def test_favicon_path
1478 1479 assert_match %r{^/favicon\.ico}, favicon_path
1479 1480 end
1480 1481
1481 1482 def test_favicon_path_with_suburi
1482 1483 Redmine::Utils.relative_url_root = '/foo'
1483 1484 assert_match %r{^/foo/favicon\.ico}, favicon_path
1484 1485 ensure
1485 1486 Redmine::Utils.relative_url_root = ''
1486 1487 end
1487 1488
1488 1489 def test_favicon_url
1489 1490 assert_match %r{^http://test\.host/favicon\.ico}, favicon_url
1490 1491 end
1491 1492
1492 1493 def test_favicon_url_with_suburi
1493 1494 Redmine::Utils.relative_url_root = '/foo'
1494 1495 assert_match %r{^http://test\.host/foo/favicon\.ico}, favicon_url
1495 1496 ensure
1496 1497 Redmine::Utils.relative_url_root = ''
1497 1498 end
1498 1499
1499 1500 def test_truncate_single_line
1500 1501 str = "01234"
1501 1502 result = truncate_single_line_raw("#{str}\n#{str}", 10)
1502 1503 assert_equal "01234 0...", result
1503 1504 assert !result.html_safe?
1504 1505 result = truncate_single_line_raw("#{str}<&#>\n#{str}#{str}", 16)
1505 1506 assert_equal "01234<&#> 012...", result
1506 1507 assert !result.html_safe?
1507 1508 end
1508 1509
1509 1510 def test_truncate_single_line_non_ascii
1510 1511 ja = "\xe6\x97\xa5\xe6\x9c\xac\xe8\xaa\x9e"
1511 1512 ja.force_encoding('UTF-8') if ja.respond_to?(:force_encoding)
1512 1513 result = truncate_single_line_raw("#{ja}\n#{ja}\n#{ja}", 10)
1513 1514 assert_equal "#{ja} #{ja}...", result
1514 1515 assert !result.html_safe?
1515 1516 end
1516 1517 end
General Comments 0
You need to be logged in to leave comments. Login now