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