Chris@1115
|
1 # encoding: utf-8
|
Chris@1115
|
2 #
|
Chris@0
|
3 # Redmine - project management software
|
Chris@1115
|
4 # Copyright (C) 2006-2012 Jean-Philippe Lang
|
Chris@0
|
5 #
|
Chris@0
|
6 # This program is free software; you can redistribute it and/or
|
Chris@0
|
7 # modify it under the terms of the GNU General Public License
|
Chris@0
|
8 # as published by the Free Software Foundation; either version 2
|
Chris@0
|
9 # of the License, or (at your option) any later version.
|
Chris@441
|
10 #
|
Chris@0
|
11 # This program is distributed in the hope that it will be useful,
|
Chris@0
|
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
|
Chris@0
|
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
Chris@0
|
14 # GNU General Public License for more details.
|
Chris@441
|
15 #
|
Chris@0
|
16 # You should have received a copy of the GNU General Public License
|
Chris@0
|
17 # along with this program; if not, write to the Free Software
|
Chris@0
|
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
Chris@0
|
19
|
Chris@119
|
20 require File.expand_path('../../../test_helper', __FILE__)
|
Chris@0
|
21
|
chris@22
|
22 class ApplicationHelperTest < ActionView::TestCase
|
Chris@1115
|
23 include ERB::Util
|
Chris@1115
|
24
|
Chris@0
|
25 fixtures :projects, :roles, :enabled_modules, :users,
|
Chris@909
|
26 :repositories, :changesets,
|
Chris@909
|
27 :trackers, :issue_statuses, :issues, :versions, :documents,
|
Chris@909
|
28 :wikis, :wiki_pages, :wiki_contents,
|
Chris@909
|
29 :boards, :messages, :news,
|
Chris@909
|
30 :attachments, :enumerations
|
Chris@0
|
31
|
Chris@0
|
32 def setup
|
Chris@0
|
33 super
|
Chris@909
|
34 set_tmp_attachments_directory
|
Chris@0
|
35 end
|
chris@22
|
36
|
chris@22
|
37 context "#link_to_if_authorized" do
|
chris@22
|
38 context "authorized user" do
|
chris@22
|
39 should "be tested"
|
chris@22
|
40 end
|
Chris@441
|
41
|
chris@22
|
42 context "unauthorized user" do
|
chris@22
|
43 should "be tested"
|
chris@22
|
44 end
|
Chris@441
|
45
|
chris@22
|
46 should "allow using the :controller and :action for the target link" do
|
chris@22
|
47 User.current = User.find_by_login('admin')
|
chris@22
|
48
|
chris@22
|
49 @project = Issue.first.project # Used by helper
|
chris@22
|
50 response = link_to_if_authorized("By controller/action",
|
chris@22
|
51 {:controller => 'issues', :action => 'edit', :id => Issue.first.id})
|
chris@22
|
52 assert_match /href/, response
|
chris@22
|
53 end
|
Chris@441
|
54
|
chris@22
|
55 end
|
Chris@441
|
56
|
Chris@0
|
57 def test_auto_links
|
Chris@0
|
58 to_test = {
|
Chris@0
|
59 'http://foo.bar' => '<a class="external" href="http://foo.bar">http://foo.bar</a>',
|
Chris@0
|
60 'http://foo.bar/~user' => '<a class="external" href="http://foo.bar/~user">http://foo.bar/~user</a>',
|
Chris@0
|
61 'http://foo.bar.' => '<a class="external" href="http://foo.bar">http://foo.bar</a>.',
|
Chris@0
|
62 'https://foo.bar.' => '<a class="external" href="https://foo.bar">https://foo.bar</a>.',
|
Chris@0
|
63 'This is a link: http://foo.bar.' => 'This is a link: <a class="external" href="http://foo.bar">http://foo.bar</a>.',
|
Chris@0
|
64 'A link (eg. http://foo.bar).' => 'A link (eg. <a class="external" href="http://foo.bar">http://foo.bar</a>).',
|
Chris@0
|
65 '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>.',
|
Chris@0
|
66 'http://www.foo.bar/Test_(foobar)' => '<a class="external" href="http://www.foo.bar/Test_(foobar)">http://www.foo.bar/Test_(foobar)</a>',
|
Chris@0
|
67 '(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>)',
|
Chris@0
|
68 '(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>)',
|
Chris@0
|
69 '(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>).',
|
Chris@0
|
70 '(see "inline link":http://www.foo.bar/Test_(foobar))' => '(see <a href="http://www.foo.bar/Test_(foobar)" class="external">inline link</a>)',
|
Chris@0
|
71 '(see "inline link":http://www.foo.bar/Test)' => '(see <a href="http://www.foo.bar/Test" class="external">inline link</a>)',
|
Chris@0
|
72 '(see "inline link":http://www.foo.bar/Test).' => '(see <a href="http://www.foo.bar/Test" class="external">inline link</a>).',
|
Chris@0
|
73 'www.foo.bar' => '<a class="external" href="http://www.foo.bar">www.foo.bar</a>',
|
Chris@0
|
74 '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>',
|
Chris@0
|
75 'http://foo.bar/page#125' => '<a class="external" href="http://foo.bar/page#125">http://foo.bar/page#125</a>',
|
Chris@0
|
76 'http://foo@www.bar.com' => '<a class="external" href="http://foo@www.bar.com">http://foo@www.bar.com</a>',
|
Chris@0
|
77 'http://foo:bar@www.bar.com' => '<a class="external" href="http://foo:bar@www.bar.com">http://foo:bar@www.bar.com</a>',
|
Chris@0
|
78 'ftp://foo.bar' => '<a class="external" href="ftp://foo.bar">ftp://foo.bar</a>',
|
Chris@0
|
79 'ftps://foo.bar' => '<a class="external" href="ftps://foo.bar">ftps://foo.bar</a>',
|
Chris@0
|
80 'sftp://foo.bar' => '<a class="external" href="sftp://foo.bar">sftp://foo.bar</a>',
|
Chris@0
|
81 # two exclamation marks
|
Chris@0
|
82 '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>',
|
Chris@0
|
83 # escaping
|
Chris@1115
|
84 'http://foo"bar' => '<a class="external" href="http://foo"bar">http://foo"bar</a>',
|
chris@37
|
85 # wrap in angle brackets
|
chris@37
|
86 '<http://foo.bar>' => '<<a class="external" href="http://foo.bar">http://foo.bar</a>>'
|
Chris@0
|
87 }
|
Chris@0
|
88 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) }
|
Chris@0
|
89 end
|
Chris@441
|
90
|
Chris@1115
|
91 if 'ruby'.respond_to?(:encoding)
|
Chris@1115
|
92 def test_auto_links_with_non_ascii_characters
|
Chris@1115
|
93 to_test = {
|
Chris@1115
|
94 'http://foo.bar/тест' => '<a class="external" href="http://foo.bar/тест">http://foo.bar/тест</a>'
|
Chris@1115
|
95 }
|
Chris@1115
|
96 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) }
|
Chris@1115
|
97 end
|
Chris@1115
|
98 else
|
Chris@1115
|
99 puts 'Skipping test_auto_links_with_non_ascii_characters, unsupported ruby version'
|
Chris@1115
|
100 end
|
Chris@1115
|
101
|
Chris@0
|
102 def test_auto_mailto
|
Chris@441
|
103 assert_equal '<p><a class="email" href="mailto:test@foo.bar">test@foo.bar</a></p>',
|
Chris@0
|
104 textilizable('test@foo.bar')
|
Chris@0
|
105 end
|
Chris@441
|
106
|
Chris@0
|
107 def test_inline_images
|
Chris@0
|
108 to_test = {
|
Chris@0
|
109 '!http://foo.bar/image.jpg!' => '<img src="http://foo.bar/image.jpg" alt="" />',
|
Chris@0
|
110 'floating !>http://foo.bar/image.jpg!' => 'floating <div style="float:right"><img src="http://foo.bar/image.jpg" alt="" /></div>',
|
Chris@0
|
111 'with class !(some-class)http://foo.bar/image.jpg!' => 'with class <img src="http://foo.bar/image.jpg" class="some-class" alt="" />',
|
Chris@1115
|
112 '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="" />',
|
Chris@0
|
113 '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" />',
|
Chris@0
|
114 '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"" />',
|
Chris@0
|
115 }
|
Chris@0
|
116 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) }
|
Chris@0
|
117 end
|
Chris@441
|
118
|
Chris@0
|
119 def test_inline_images_inside_tags
|
Chris@0
|
120 raw = <<-RAW
|
Chris@0
|
121 h1. !foo.png! Heading
|
Chris@0
|
122
|
Chris@0
|
123 Centered image:
|
Chris@0
|
124
|
Chris@0
|
125 p=. !bar.gif!
|
Chris@0
|
126 RAW
|
Chris@0
|
127
|
Chris@0
|
128 assert textilizable(raw).include?('<img src="foo.png" alt="" />')
|
Chris@0
|
129 assert textilizable(raw).include?('<img src="bar.gif" alt="" />')
|
Chris@0
|
130 end
|
Chris@441
|
131
|
Chris@0
|
132 def test_attached_images
|
Chris@0
|
133 to_test = {
|
Chris@0
|
134 'Inline image: !logo.gif!' => 'Inline image: <img src="/attachments/download/3" title="This is a logo" alt="This is a logo" />',
|
Chris@0
|
135 'Inline image: !logo.GIF!' => 'Inline image: <img src="/attachments/download/3" title="This is a logo" alt="This is a logo" />',
|
Chris@0
|
136 'No match: !ogo.gif!' => 'No match: <img src="ogo.gif" alt="" />',
|
Chris@0
|
137 'No match: !ogo.GIF!' => 'No match: <img src="ogo.GIF" alt="" />',
|
Chris@0
|
138 # link image
|
Chris@0
|
139 '!logo.gif!:http://foo.bar/' => '<a href="http://foo.bar/"><img src="/attachments/download/3" title="This is a logo" alt="This is a logo" /></a>',
|
Chris@0
|
140 }
|
Chris@0
|
141 attachments = Attachment.find(:all)
|
Chris@0
|
142 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text, :attachments => attachments) }
|
Chris@0
|
143 end
|
Chris@441
|
144
|
Chris@909
|
145 def test_attached_images_filename_extension
|
Chris@909
|
146 set_tmp_attachments_directory
|
Chris@909
|
147 a1 = Attachment.new(
|
Chris@909
|
148 :container => Issue.find(1),
|
Chris@909
|
149 :file => mock_file_with_options({:original_filename => "testtest.JPG"}),
|
Chris@909
|
150 :author => User.find(1))
|
Chris@909
|
151 assert a1.save
|
Chris@909
|
152 assert_equal "testtest.JPG", a1.filename
|
Chris@909
|
153 assert_equal "image/jpeg", a1.content_type
|
Chris@909
|
154 assert a1.image?
|
Chris@909
|
155
|
Chris@909
|
156 a2 = Attachment.new(
|
Chris@909
|
157 :container => Issue.find(1),
|
Chris@909
|
158 :file => mock_file_with_options({:original_filename => "testtest.jpeg"}),
|
Chris@909
|
159 :author => User.find(1))
|
Chris@909
|
160 assert a2.save
|
Chris@909
|
161 assert_equal "testtest.jpeg", a2.filename
|
Chris@909
|
162 assert_equal "image/jpeg", a2.content_type
|
Chris@909
|
163 assert a2.image?
|
Chris@909
|
164
|
Chris@909
|
165 a3 = Attachment.new(
|
Chris@909
|
166 :container => Issue.find(1),
|
Chris@909
|
167 :file => mock_file_with_options({:original_filename => "testtest.JPE"}),
|
Chris@909
|
168 :author => User.find(1))
|
Chris@909
|
169 assert a3.save
|
Chris@909
|
170 assert_equal "testtest.JPE", a3.filename
|
Chris@909
|
171 assert_equal "image/jpeg", a3.content_type
|
Chris@909
|
172 assert a3.image?
|
Chris@909
|
173
|
Chris@909
|
174 a4 = Attachment.new(
|
Chris@909
|
175 :container => Issue.find(1),
|
Chris@909
|
176 :file => mock_file_with_options({:original_filename => "Testtest.BMP"}),
|
Chris@909
|
177 :author => User.find(1))
|
Chris@909
|
178 assert a4.save
|
Chris@909
|
179 assert_equal "Testtest.BMP", a4.filename
|
Chris@909
|
180 assert_equal "image/x-ms-bmp", a4.content_type
|
Chris@909
|
181 assert a4.image?
|
Chris@909
|
182
|
Chris@909
|
183 to_test = {
|
Chris@909
|
184 'Inline image: !testtest.jpg!' =>
|
Chris@909
|
185 'Inline image: <img src="/attachments/download/' + a1.id.to_s + '" alt="" />',
|
Chris@909
|
186 'Inline image: !testtest.jpeg!' =>
|
Chris@909
|
187 'Inline image: <img src="/attachments/download/' + a2.id.to_s + '" alt="" />',
|
Chris@909
|
188 'Inline image: !testtest.jpe!' =>
|
Chris@909
|
189 'Inline image: <img src="/attachments/download/' + a3.id.to_s + '" alt="" />',
|
Chris@909
|
190 'Inline image: !testtest.bmp!' =>
|
Chris@909
|
191 'Inline image: <img src="/attachments/download/' + a4.id.to_s + '" alt="" />',
|
Chris@909
|
192 }
|
Chris@909
|
193
|
Chris@909
|
194 attachments = [a1, a2, a3, a4]
|
Chris@909
|
195 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text, :attachments => attachments) }
|
Chris@909
|
196 end
|
Chris@909
|
197
|
Chris@909
|
198 def test_attached_images_should_read_later
|
Chris@1115
|
199 set_fixtures_attachments_directory
|
Chris@909
|
200 a1 = Attachment.find(16)
|
Chris@909
|
201 assert_equal "testfile.png", a1.filename
|
Chris@909
|
202 assert a1.readable?
|
Chris@909
|
203 assert (! a1.visible?(User.anonymous))
|
Chris@909
|
204 assert a1.visible?(User.find(2))
|
Chris@909
|
205 a2 = Attachment.find(17)
|
Chris@909
|
206 assert_equal "testfile.PNG", a2.filename
|
Chris@909
|
207 assert a2.readable?
|
Chris@909
|
208 assert (! a2.visible?(User.anonymous))
|
Chris@909
|
209 assert a2.visible?(User.find(2))
|
Chris@909
|
210 assert a1.created_on < a2.created_on
|
Chris@909
|
211
|
Chris@909
|
212 to_test = {
|
Chris@909
|
213 'Inline image: !testfile.png!' =>
|
Chris@909
|
214 'Inline image: <img src="/attachments/download/' + a2.id.to_s + '" alt="" />',
|
Chris@909
|
215 'Inline image: !Testfile.PNG!' =>
|
Chris@909
|
216 'Inline image: <img src="/attachments/download/' + a2.id.to_s + '" alt="" />',
|
Chris@909
|
217 }
|
Chris@909
|
218 attachments = [a1, a2]
|
Chris@909
|
219 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text, :attachments => attachments) }
|
Chris@909
|
220 set_tmp_attachments_directory
|
Chris@909
|
221 end
|
Chris@909
|
222
|
Chris@0
|
223 def test_textile_external_links
|
Chris@0
|
224 to_test = {
|
Chris@0
|
225 'This is a "link":http://foo.bar' => 'This is a <a href="http://foo.bar" class="external">link</a>',
|
Chris@0
|
226 'This is an intern "link":/foo/bar' => 'This is an intern <a href="/foo/bar">link</a>',
|
Chris@0
|
227 '"link (Link title)":http://foo.bar' => '<a href="http://foo.bar" title="Link title" class="external">link</a>',
|
Chris@0
|
228 '"link (Link title with "double-quotes")":http://foo.bar' => '<a href="http://foo.bar" title="Link title with "double-quotes"" class="external">link</a>',
|
Chris@0
|
229 "This is not a \"Link\":\n\nAnother paragraph" => "This is not a \"Link\":</p>\n\n\n\t<p>Another paragraph",
|
Chris@0
|
230 # no multiline link text
|
Chris@0
|
231 "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",
|
Chris@0
|
232 # mailto link
|
Chris@0
|
233 "\"system administrator\":mailto:sysadmin@example.com?subject=redmine%20permissions" => "<a href=\"mailto:sysadmin@example.com?subject=redmine%20permissions\">system administrator</a>",
|
Chris@0
|
234 # two exclamation marks
|
Chris@0
|
235 '"a link":http://example.net/path!602815048C7B5C20!302.html' => '<a href="http://example.net/path!602815048C7B5C20!302.html" class="external">a link</a>',
|
Chris@0
|
236 # escaping
|
Chris@0
|
237 '"test":http://foo"bar' => '<a href="http://foo"bar" class="external">test</a>',
|
Chris@0
|
238 }
|
Chris@0
|
239 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) }
|
Chris@0
|
240 end
|
Chris@119
|
241
|
Chris@1115
|
242 if 'ruby'.respond_to?(:encoding)
|
Chris@1115
|
243 def test_textile_external_links_with_non_ascii_characters
|
Chris@1115
|
244 to_test = {
|
Chris@1115
|
245 'This is a "link":http://foo.bar/тест' => 'This is a <a href="http://foo.bar/тест" class="external">link</a>'
|
Chris@1115
|
246 }
|
Chris@1115
|
247 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) }
|
Chris@1115
|
248 end
|
Chris@1115
|
249 else
|
Chris@1115
|
250 puts 'Skipping test_textile_external_links_with_non_ascii_characters, unsupported ruby version'
|
Chris@1115
|
251 end
|
Chris@1115
|
252
|
Chris@0
|
253 def test_redmine_links
|
Chris@441
|
254 issue_link = link_to('#3', {:controller => 'issues', :action => 'show', :id => 3},
|
Chris@1115
|
255 :class => 'issue status-1 priority-4 priority-lowest overdue', :title => 'Error 281 when updating a recipe (New)')
|
Chris@1115
|
256 note_link = link_to('#3', {:controller => 'issues', :action => 'show', :id => 3, :anchor => 'note-14'},
|
Chris@1115
|
257 :class => 'issue status-1 priority-4 priority-lowest overdue', :title => 'Error 281 when updating a recipe (New)')
|
Chris@441
|
258
|
Chris@0
|
259 changeset_link = link_to('r1', {:controller => 'repositories', :action => 'revision', :id => 'ecookbook', :rev => 1},
|
Chris@0
|
260 :class => 'changeset', :title => 'My very first commit')
|
Chris@0
|
261 changeset_link2 = link_to('r2', {:controller => 'repositories', :action => 'revision', :id => 'ecookbook', :rev => 2},
|
Chris@0
|
262 :class => 'changeset', :title => 'This commit fixes #1, #2 and references #1 & #3')
|
Chris@441
|
263
|
Chris@0
|
264 document_link = link_to('Test document', {:controller => 'documents', :action => 'show', :id => 1},
|
Chris@0
|
265 :class => 'document')
|
Chris@441
|
266
|
Chris@0
|
267 version_link = link_to('1.0', {:controller => 'versions', :action => 'show', :id => 2},
|
Chris@0
|
268 :class => 'version')
|
Chris@0
|
269
|
Chris@909
|
270 board_url = {:controller => 'boards', :action => 'show', :id => 2, :project_id => 'ecookbook'}
|
Chris@909
|
271
|
Chris@0
|
272 message_url = {:controller => 'messages', :action => 'show', :board_id => 1, :id => 4}
|
Chris@909
|
273
|
Chris@909
|
274 news_url = {:controller => 'news', :action => 'show', :id => 1}
|
Chris@441
|
275
|
Chris@0
|
276 project_url = {:controller => 'projects', :action => 'show', :id => 'subproject1'}
|
Chris@441
|
277
|
Chris@1115
|
278 source_url = '/projects/ecookbook/repository/entry/some/file'
|
Chris@1115
|
279 source_url_with_rev = '/projects/ecookbook/repository/revisions/52/entry/some/file'
|
Chris@1115
|
280 source_url_with_ext = '/projects/ecookbook/repository/entry/some/file.ext'
|
Chris@1115
|
281 source_url_with_rev_and_ext = '/projects/ecookbook/repository/revisions/52/entry/some/file.ext'
|
Chris@1115
|
282
|
Chris@1115
|
283 export_url = '/projects/ecookbook/repository/raw/some/file'
|
Chris@1115
|
284 export_url_with_rev = '/projects/ecookbook/repository/revisions/52/raw/some/file'
|
Chris@1115
|
285 export_url_with_ext = '/projects/ecookbook/repository/raw/some/file.ext'
|
Chris@1115
|
286 export_url_with_rev_and_ext = '/projects/ecookbook/repository/revisions/52/raw/some/file.ext'
|
Chris@441
|
287
|
Chris@0
|
288 to_test = {
|
Chris@0
|
289 # tickets
|
Chris@0
|
290 '#3, [#3], (#3) and #3.' => "#{issue_link}, [#{issue_link}], (#{issue_link}) and #{issue_link}.",
|
Chris@1115
|
291 # ticket notes
|
Chris@1115
|
292 '#3-14' => note_link,
|
Chris@1115
|
293 '#3#note-14' => note_link,
|
Chris@1115
|
294 # should not ignore leading zero
|
Chris@1115
|
295 '#03' => '#03',
|
Chris@0
|
296 # changesets
|
Chris@0
|
297 'r1' => changeset_link,
|
Chris@0
|
298 'r1.' => "#{changeset_link}.",
|
Chris@0
|
299 'r1, r2' => "#{changeset_link}, #{changeset_link2}",
|
Chris@0
|
300 'r1,r2' => "#{changeset_link},#{changeset_link2}",
|
Chris@0
|
301 # documents
|
Chris@0
|
302 'document#1' => document_link,
|
Chris@0
|
303 'document:"Test document"' => document_link,
|
Chris@0
|
304 # versions
|
Chris@0
|
305 'version#2' => version_link,
|
Chris@0
|
306 'version:1.0' => version_link,
|
Chris@0
|
307 'version:"1.0"' => version_link,
|
Chris@0
|
308 # source
|
Chris@1115
|
309 'source:some/file' => link_to('source:some/file', source_url, :class => 'source'),
|
Chris@0
|
310 'source:/some/file' => link_to('source:/some/file', source_url, :class => 'source'),
|
Chris@0
|
311 'source:/some/file.' => link_to('source:/some/file', source_url, :class => 'source') + ".",
|
Chris@0
|
312 'source:/some/file.ext.' => link_to('source:/some/file.ext', source_url_with_ext, :class => 'source') + ".",
|
Chris@0
|
313 'source:/some/file. ' => link_to('source:/some/file', source_url, :class => 'source') + ".",
|
Chris@0
|
314 'source:/some/file.ext. ' => link_to('source:/some/file.ext', source_url_with_ext, :class => 'source') + ".",
|
Chris@0
|
315 'source:/some/file, ' => link_to('source:/some/file', source_url, :class => 'source') + ",",
|
Chris@1115
|
316 'source:/some/file@52' => link_to('source:/some/file@52', source_url_with_rev, :class => 'source'),
|
Chris@1115
|
317 'source:/some/file.ext@52' => link_to('source:/some/file.ext@52', source_url_with_rev_and_ext, :class => 'source'),
|
Chris@1115
|
318 'source:/some/file#L110' => link_to('source:/some/file#L110', source_url + "#L110", :class => 'source'),
|
Chris@1115
|
319 'source:/some/file.ext#L110' => link_to('source:/some/file.ext#L110', source_url_with_ext + "#L110", :class => 'source'),
|
Chris@1115
|
320 'source:/some/file@52#L110' => link_to('source:/some/file@52#L110', source_url_with_rev + "#L110", :class => 'source'),
|
Chris@1115
|
321 # export
|
Chris@1115
|
322 'export:/some/file' => link_to('export:/some/file', export_url, :class => 'source download'),
|
Chris@1115
|
323 'export:/some/file.ext' => link_to('export:/some/file.ext', export_url_with_ext, :class => 'source download'),
|
Chris@1115
|
324 'export:/some/file@52' => link_to('export:/some/file@52', export_url_with_rev, :class => 'source download'),
|
Chris@1115
|
325 'export:/some/file.ext@52' => link_to('export:/some/file.ext@52', export_url_with_rev_and_ext, :class => 'source download'),
|
Chris@909
|
326 # forum
|
Chris@909
|
327 'forum#2' => link_to('Discussion', board_url, :class => 'board'),
|
Chris@909
|
328 'forum:Discussion' => link_to('Discussion', board_url, :class => 'board'),
|
Chris@0
|
329 # message
|
Chris@0
|
330 'message#4' => link_to('Post 2', message_url, :class => 'message'),
|
Chris@210
|
331 'message#5' => link_to('RE: post 2', message_url.merge(:anchor => 'message-5', :r => 5), :class => 'message'),
|
Chris@909
|
332 # news
|
Chris@909
|
333 'news#1' => link_to('eCookbook first release !', news_url, :class => 'news'),
|
Chris@909
|
334 'news:"eCookbook first release !"' => link_to('eCookbook first release !', news_url, :class => 'news'),
|
Chris@0
|
335 # project
|
Chris@0
|
336 'project#3' => link_to('eCookbook Subproject 1', project_url, :class => 'project'),
|
Chris@0
|
337 'project:subproject1' => link_to('eCookbook Subproject 1', project_url, :class => 'project'),
|
Chris@0
|
338 'project:"eCookbook subProject 1"' => link_to('eCookbook Subproject 1', project_url, :class => 'project'),
|
Chris@0
|
339 # not found
|
Chris@0
|
340 '#0123456789' => '#0123456789',
|
Chris@0
|
341 # invalid expressions
|
Chris@0
|
342 'source:' => 'source:',
|
Chris@0
|
343 # url hash
|
Chris@0
|
344 "http://foo.bar/FAQ#3" => '<a class="external" href="http://foo.bar/FAQ#3">http://foo.bar/FAQ#3</a>',
|
Chris@0
|
345 }
|
Chris@0
|
346 @project = Project.find(1)
|
Chris@0
|
347 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text), "#{text} failed" }
|
Chris@0
|
348 end
|
Chris@441
|
349
|
Chris@1294
|
350 def test_redmine_links_with_a_different_project_before_current_project
|
Chris@1294
|
351 vp1 = Version.generate!(:project_id => 1, :name => '1.4.4')
|
Chris@1294
|
352 vp3 = Version.generate!(:project_id => 3, :name => '1.4.4')
|
Chris@1294
|
353
|
Chris@1294
|
354 @project = Project.find(3)
|
Chris@1294
|
355 assert_equal %(<p><a href="/versions/#{vp1.id}" class="version">1.4.4</a> <a href="/versions/#{vp3.id}" class="version">1.4.4</a></p>),
|
Chris@1294
|
356 textilizable("ecookbook:version:1.4.4 version:1.4.4")
|
Chris@1294
|
357 end
|
Chris@1294
|
358
|
Chris@1115
|
359 def test_escaped_redmine_links_should_not_be_parsed
|
Chris@1115
|
360 to_test = [
|
Chris@1115
|
361 '#3.',
|
Chris@1115
|
362 '#3-14.',
|
Chris@1115
|
363 '#3#-note14.',
|
Chris@1115
|
364 'r1',
|
Chris@1115
|
365 'document#1',
|
Chris@1115
|
366 'document:"Test document"',
|
Chris@1115
|
367 'version#2',
|
Chris@1115
|
368 'version:1.0',
|
Chris@1115
|
369 'version:"1.0"',
|
Chris@1115
|
370 'source:/some/file'
|
Chris@1115
|
371 ]
|
Chris@1115
|
372 @project = Project.find(1)
|
Chris@1115
|
373 to_test.each { |text| assert_equal "<p>#{text}</p>", textilizable("!" + text), "#{text} failed" }
|
Chris@1115
|
374 end
|
Chris@1115
|
375
|
Chris@210
|
376 def test_cross_project_redmine_links
|
Chris@210
|
377 source_link = link_to('ecookbook:source:/some/file', {:controller => 'repositories', :action => 'entry', :id => 'ecookbook', :path => ['some', 'file']},
|
Chris@210
|
378 :class => 'source')
|
Chris@441
|
379
|
Chris@210
|
380 changeset_link = link_to('ecookbook:r2', {:controller => 'repositories', :action => 'revision', :id => 'ecookbook', :rev => 2},
|
Chris@210
|
381 :class => 'changeset', :title => 'This commit fixes #1, #2 and references #1 & #3')
|
Chris@441
|
382
|
Chris@210
|
383 to_test = {
|
Chris@210
|
384 # documents
|
Chris@210
|
385 'document:"Test document"' => 'document:"Test document"',
|
Chris@210
|
386 'ecookbook:document:"Test document"' => '<a href="/documents/1" class="document">Test document</a>',
|
Chris@210
|
387 'invalid:document:"Test document"' => 'invalid:document:"Test document"',
|
Chris@210
|
388 # versions
|
Chris@210
|
389 'version:"1.0"' => 'version:"1.0"',
|
Chris@909
|
390 'ecookbook:version:"1.0"' => '<a href="/versions/2" class="version">1.0</a>',
|
Chris@210
|
391 'invalid:version:"1.0"' => 'invalid:version:"1.0"',
|
Chris@210
|
392 # changeset
|
Chris@210
|
393 'r2' => 'r2',
|
Chris@210
|
394 'ecookbook:r2' => changeset_link,
|
Chris@210
|
395 'invalid:r2' => 'invalid:r2',
|
Chris@210
|
396 # source
|
Chris@210
|
397 'source:/some/file' => 'source:/some/file',
|
Chris@210
|
398 'ecookbook:source:/some/file' => source_link,
|
Chris@210
|
399 'invalid:source:/some/file' => 'invalid:source:/some/file',
|
Chris@210
|
400 }
|
Chris@210
|
401 @project = Project.find(3)
|
Chris@210
|
402 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text), "#{text} failed" }
|
Chris@210
|
403 end
|
Chris@119
|
404
|
Chris@1115
|
405 def test_multiple_repositories_redmine_links
|
Chris@1294
|
406 svn = Repository::Subversion.create!(:project_id => 1, :identifier => 'svn_repo-1', :url => 'file:///foo/hg')
|
Chris@1115
|
407 Changeset.create!(:repository => svn, :committed_on => Time.now, :revision => '123')
|
Chris@1115
|
408 hg = Repository::Mercurial.create!(:project_id => 1, :identifier => 'hg1', :url => '/foo/hg')
|
Chris@1115
|
409 Changeset.create!(:repository => hg, :committed_on => Time.now, :revision => '123', :scmid => 'abcd')
|
Chris@1115
|
410
|
Chris@1115
|
411 changeset_link = link_to('r2', {:controller => 'repositories', :action => 'revision', :id => 'ecookbook', :rev => 2},
|
Chris@1115
|
412 :class => 'changeset', :title => 'This commit fixes #1, #2 and references #1 & #3')
|
Chris@1294
|
413 svn_changeset_link = link_to('svn_repo-1|r123', {:controller => 'repositories', :action => 'revision', :id => 'ecookbook', :repository_id => 'svn_repo-1', :rev => 123},
|
Chris@1115
|
414 :class => 'changeset', :title => '')
|
Chris@1115
|
415 hg_changeset_link = link_to('hg1|abcd', {:controller => 'repositories', :action => 'revision', :id => 'ecookbook', :repository_id => 'hg1', :rev => 'abcd'},
|
Chris@1115
|
416 :class => 'changeset', :title => '')
|
Chris@1115
|
417
|
Chris@1115
|
418 source_link = link_to('source:some/file', {:controller => 'repositories', :action => 'entry', :id => 'ecookbook', :path => ['some', 'file']}, :class => 'source')
|
Chris@1115
|
419 hg_source_link = link_to('source:hg1|some/file', {:controller => 'repositories', :action => 'entry', :id => 'ecookbook', :repository_id => 'hg1', :path => ['some', 'file']}, :class => 'source')
|
Chris@1115
|
420
|
Chris@1115
|
421 to_test = {
|
Chris@1115
|
422 'r2' => changeset_link,
|
Chris@1294
|
423 'svn_repo-1|r123' => svn_changeset_link,
|
Chris@1115
|
424 'invalid|r123' => 'invalid|r123',
|
Chris@1115
|
425 'commit:hg1|abcd' => hg_changeset_link,
|
Chris@1115
|
426 'commit:invalid|abcd' => 'commit:invalid|abcd',
|
Chris@1115
|
427 # source
|
Chris@1115
|
428 'source:some/file' => source_link,
|
Chris@1115
|
429 'source:hg1|some/file' => hg_source_link,
|
Chris@1115
|
430 'source:invalid|some/file' => 'source:invalid|some/file',
|
Chris@1115
|
431 }
|
Chris@1115
|
432
|
Chris@1115
|
433 @project = Project.find(1)
|
Chris@1115
|
434 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text), "#{text} failed" }
|
Chris@1115
|
435 end
|
Chris@1115
|
436
|
Chris@1115
|
437 def test_cross_project_multiple_repositories_redmine_links
|
Chris@1115
|
438 svn = Repository::Subversion.create!(:project_id => 1, :identifier => 'svn1', :url => 'file:///foo/hg')
|
Chris@1115
|
439 Changeset.create!(:repository => svn, :committed_on => Time.now, :revision => '123')
|
Chris@1115
|
440 hg = Repository::Mercurial.create!(:project_id => 1, :identifier => 'hg1', :url => '/foo/hg')
|
Chris@1115
|
441 Changeset.create!(:repository => hg, :committed_on => Time.now, :revision => '123', :scmid => 'abcd')
|
Chris@1115
|
442
|
Chris@1115
|
443 changeset_link = link_to('ecookbook:r2', {:controller => 'repositories', :action => 'revision', :id => 'ecookbook', :rev => 2},
|
Chris@1115
|
444 :class => 'changeset', :title => 'This commit fixes #1, #2 and references #1 & #3')
|
Chris@1115
|
445 svn_changeset_link = link_to('ecookbook:svn1|r123', {:controller => 'repositories', :action => 'revision', :id => 'ecookbook', :repository_id => 'svn1', :rev => 123},
|
Chris@1115
|
446 :class => 'changeset', :title => '')
|
Chris@1115
|
447 hg_changeset_link = link_to('ecookbook:hg1|abcd', {:controller => 'repositories', :action => 'revision', :id => 'ecookbook', :repository_id => 'hg1', :rev => 'abcd'},
|
Chris@1115
|
448 :class => 'changeset', :title => '')
|
Chris@1115
|
449
|
Chris@1115
|
450 source_link = link_to('ecookbook:source:some/file', {:controller => 'repositories', :action => 'entry', :id => 'ecookbook', :path => ['some', 'file']}, :class => 'source')
|
Chris@1115
|
451 hg_source_link = link_to('ecookbook:source:hg1|some/file', {:controller => 'repositories', :action => 'entry', :id => 'ecookbook', :repository_id => 'hg1', :path => ['some', 'file']}, :class => 'source')
|
Chris@1115
|
452
|
Chris@1115
|
453 to_test = {
|
Chris@1115
|
454 'ecookbook:r2' => changeset_link,
|
Chris@1115
|
455 'ecookbook:svn1|r123' => svn_changeset_link,
|
Chris@1115
|
456 'ecookbook:invalid|r123' => 'ecookbook:invalid|r123',
|
Chris@1115
|
457 'ecookbook:commit:hg1|abcd' => hg_changeset_link,
|
Chris@1115
|
458 'ecookbook:commit:invalid|abcd' => 'ecookbook:commit:invalid|abcd',
|
Chris@1115
|
459 'invalid:commit:invalid|abcd' => 'invalid:commit:invalid|abcd',
|
Chris@1115
|
460 # source
|
Chris@1115
|
461 'ecookbook:source:some/file' => source_link,
|
Chris@1115
|
462 'ecookbook:source:hg1|some/file' => hg_source_link,
|
Chris@1115
|
463 'ecookbook:source:invalid|some/file' => 'ecookbook:source:invalid|some/file',
|
Chris@1115
|
464 'invalid:source:invalid|some/file' => 'invalid:source:invalid|some/file',
|
Chris@1115
|
465 }
|
Chris@1115
|
466
|
Chris@1115
|
467 @project = Project.find(3)
|
Chris@1115
|
468 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text), "#{text} failed" }
|
Chris@1115
|
469 end
|
Chris@1115
|
470
|
Chris@119
|
471 def test_redmine_links_git_commit
|
Chris@119
|
472 changeset_link = link_to('abcd',
|
Chris@119
|
473 {
|
Chris@119
|
474 :controller => 'repositories',
|
Chris@119
|
475 :action => 'revision',
|
Chris@119
|
476 :id => 'subproject1',
|
Chris@119
|
477 :rev => 'abcd',
|
Chris@119
|
478 },
|
Chris@119
|
479 :class => 'changeset', :title => 'test commit')
|
Chris@119
|
480 to_test = {
|
Chris@119
|
481 'commit:abcd' => changeset_link,
|
Chris@119
|
482 }
|
Chris@119
|
483 @project = Project.find(3)
|
Chris@119
|
484 r = Repository::Git.create!(:project => @project, :url => '/tmp/test/git')
|
Chris@119
|
485 assert r
|
Chris@119
|
486 c = Changeset.new(:repository => r,
|
Chris@119
|
487 :committed_on => Time.now,
|
Chris@119
|
488 :revision => 'abcd',
|
Chris@119
|
489 :scmid => 'abcd',
|
Chris@119
|
490 :comments => 'test commit')
|
Chris@119
|
491 assert( c.save )
|
Chris@119
|
492 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) }
|
Chris@119
|
493 end
|
Chris@119
|
494
|
Chris@119
|
495 # TODO: Bazaar commit id contains mail address, so it contains '@' and '_'.
|
Chris@119
|
496 def test_redmine_links_darcs_commit
|
Chris@119
|
497 changeset_link = link_to('20080308225258-98289-abcd456efg.gz',
|
Chris@119
|
498 {
|
Chris@119
|
499 :controller => 'repositories',
|
Chris@119
|
500 :action => 'revision',
|
Chris@119
|
501 :id => 'subproject1',
|
Chris@119
|
502 :rev => '123',
|
Chris@119
|
503 },
|
Chris@119
|
504 :class => 'changeset', :title => 'test commit')
|
Chris@119
|
505 to_test = {
|
Chris@119
|
506 'commit:20080308225258-98289-abcd456efg.gz' => changeset_link,
|
Chris@119
|
507 }
|
Chris@119
|
508 @project = Project.find(3)
|
Chris@245
|
509 r = Repository::Darcs.create!(
|
Chris@245
|
510 :project => @project, :url => '/tmp/test/darcs',
|
Chris@245
|
511 :log_encoding => 'UTF-8')
|
Chris@119
|
512 assert r
|
Chris@119
|
513 c = Changeset.new(:repository => r,
|
Chris@119
|
514 :committed_on => Time.now,
|
Chris@119
|
515 :revision => '123',
|
Chris@119
|
516 :scmid => '20080308225258-98289-abcd456efg.gz',
|
Chris@119
|
517 :comments => 'test commit')
|
Chris@119
|
518 assert( c.save )
|
Chris@119
|
519 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) }
|
Chris@119
|
520 end
|
Chris@119
|
521
|
Chris@119
|
522 def test_redmine_links_mercurial_commit
|
Chris@119
|
523 changeset_link_rev = link_to('r123',
|
Chris@119
|
524 {
|
Chris@119
|
525 :controller => 'repositories',
|
Chris@119
|
526 :action => 'revision',
|
Chris@119
|
527 :id => 'subproject1',
|
Chris@119
|
528 :rev => '123' ,
|
Chris@119
|
529 },
|
Chris@119
|
530 :class => 'changeset', :title => 'test commit')
|
Chris@119
|
531 changeset_link_commit = link_to('abcd',
|
Chris@119
|
532 {
|
Chris@119
|
533 :controller => 'repositories',
|
Chris@119
|
534 :action => 'revision',
|
Chris@119
|
535 :id => 'subproject1',
|
Chris@119
|
536 :rev => 'abcd' ,
|
Chris@119
|
537 },
|
Chris@119
|
538 :class => 'changeset', :title => 'test commit')
|
Chris@119
|
539 to_test = {
|
Chris@119
|
540 'r123' => changeset_link_rev,
|
Chris@119
|
541 'commit:abcd' => changeset_link_commit,
|
Chris@119
|
542 }
|
Chris@119
|
543 @project = Project.find(3)
|
Chris@119
|
544 r = Repository::Mercurial.create!(:project => @project, :url => '/tmp/test')
|
Chris@119
|
545 assert r
|
Chris@119
|
546 c = Changeset.new(:repository => r,
|
Chris@119
|
547 :committed_on => Time.now,
|
Chris@119
|
548 :revision => '123',
|
Chris@119
|
549 :scmid => 'abcd',
|
Chris@119
|
550 :comments => 'test commit')
|
Chris@119
|
551 assert( c.save )
|
Chris@119
|
552 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) }
|
Chris@119
|
553 end
|
Chris@119
|
554
|
Chris@0
|
555 def test_attachment_links
|
Chris@0
|
556 attachment_link = link_to('error281.txt', {:controller => 'attachments', :action => 'download', :id => '1'}, :class => 'attachment')
|
Chris@0
|
557 to_test = {
|
Chris@0
|
558 'attachment:error281.txt' => attachment_link
|
Chris@0
|
559 }
|
Chris@0
|
560 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text, :attachments => Issue.find(3).attachments), "#{text} failed" }
|
Chris@0
|
561 end
|
Chris@441
|
562
|
Chris@1294
|
563 def test_attachment_link_should_link_to_latest_attachment
|
Chris@1294
|
564 set_tmp_attachments_directory
|
Chris@1294
|
565 a1 = Attachment.generate!(:filename => "test.txt", :created_on => 1.hour.ago)
|
Chris@1294
|
566 a2 = Attachment.generate!(:filename => "test.txt")
|
Chris@1294
|
567
|
Chris@1294
|
568 assert_equal %(<p><a href="/attachments/download/#{a2.id}" class="attachment">test.txt</a></p>),
|
Chris@1294
|
569 textilizable('attachment:test.txt', :attachments => [a1, a2])
|
Chris@1294
|
570 end
|
Chris@1294
|
571
|
Chris@0
|
572 def test_wiki_links
|
Chris@0
|
573 to_test = {
|
Chris@0
|
574 '[[CookBook documentation]]' => '<a href="/projects/ecookbook/wiki/CookBook_documentation" class="wiki-page">CookBook documentation</a>',
|
Chris@0
|
575 '[[Another page|Page]]' => '<a href="/projects/ecookbook/wiki/Another_page" class="wiki-page">Page</a>',
|
Chris@909
|
576 # title content should be formatted
|
Chris@909
|
577 '[[Another page|With _styled_ *title*]]' => '<a href="/projects/ecookbook/wiki/Another_page" class="wiki-page">With <em>styled</em> <strong>title</strong></a>',
|
Chris@909
|
578 '[[Another page|With title containing <strong>HTML entities & markups</strong>]]' => '<a href="/projects/ecookbook/wiki/Another_page" class="wiki-page">With title containing <strong>HTML entities & markups</strong></a>',
|
Chris@0
|
579 # link with anchor
|
Chris@0
|
580 '[[CookBook documentation#One-section]]' => '<a href="/projects/ecookbook/wiki/CookBook_documentation#One-section" class="wiki-page">CookBook documentation</a>',
|
Chris@0
|
581 '[[Another page#anchor|Page]]' => '<a href="/projects/ecookbook/wiki/Another_page#anchor" class="wiki-page">Page</a>',
|
Chris@1115
|
582 # UTF8 anchor
|
Chris@1115
|
583 '[[Another_page#Тест|Тест]]' => %|<a href="/projects/ecookbook/wiki/Another_page##{CGI.escape 'Тест'}" class="wiki-page">Тест</a>|,
|
Chris@0
|
584 # page that doesn't exist
|
Chris@0
|
585 '[[Unknown page]]' => '<a href="/projects/ecookbook/wiki/Unknown_page" class="wiki-page new">Unknown page</a>',
|
Chris@0
|
586 '[[Unknown page|404]]' => '<a href="/projects/ecookbook/wiki/Unknown_page" class="wiki-page new">404</a>',
|
Chris@0
|
587 # link to another project wiki
|
chris@37
|
588 '[[onlinestore:]]' => '<a href="/projects/onlinestore/wiki" class="wiki-page">onlinestore</a>',
|
chris@37
|
589 '[[onlinestore:|Wiki]]' => '<a href="/projects/onlinestore/wiki" class="wiki-page">Wiki</a>',
|
Chris@0
|
590 '[[onlinestore:Start page]]' => '<a href="/projects/onlinestore/wiki/Start_page" class="wiki-page">Start page</a>',
|
Chris@0
|
591 '[[onlinestore:Start page|Text]]' => '<a href="/projects/onlinestore/wiki/Start_page" class="wiki-page">Text</a>',
|
Chris@0
|
592 '[[onlinestore:Unknown page]]' => '<a href="/projects/onlinestore/wiki/Unknown_page" class="wiki-page new">Unknown page</a>',
|
Chris@0
|
593 # striked through link
|
Chris@0
|
594 '-[[Another page|Page]]-' => '<del><a href="/projects/ecookbook/wiki/Another_page" class="wiki-page">Page</a></del>',
|
Chris@0
|
595 '-[[Another page|Page]] link-' => '<del><a href="/projects/ecookbook/wiki/Another_page" class="wiki-page">Page</a> link</del>',
|
Chris@0
|
596 # escaping
|
Chris@0
|
597 '![[Another page|Page]]' => '[[Another page|Page]]',
|
Chris@0
|
598 # project does not exist
|
Chris@0
|
599 '[[unknowproject:Start]]' => '[[unknowproject:Start]]',
|
Chris@0
|
600 '[[unknowproject:Start|Page title]]' => '[[unknowproject:Start|Page title]]',
|
Chris@0
|
601 }
|
Chris@909
|
602
|
Chris@0
|
603 @project = Project.find(1)
|
Chris@0
|
604 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) }
|
Chris@0
|
605 end
|
Chris@441
|
606
|
Chris@909
|
607 def test_wiki_links_within_local_file_generation_context
|
Chris@909
|
608
|
Chris@909
|
609 to_test = {
|
Chris@909
|
610 # link to a page
|
Chris@909
|
611 '[[CookBook documentation]]' => '<a href="CookBook_documentation.html" class="wiki-page">CookBook documentation</a>',
|
Chris@909
|
612 '[[CookBook documentation|documentation]]' => '<a href="CookBook_documentation.html" class="wiki-page">documentation</a>',
|
Chris@909
|
613 '[[CookBook documentation#One-section]]' => '<a href="CookBook_documentation.html#One-section" class="wiki-page">CookBook documentation</a>',
|
Chris@909
|
614 '[[CookBook documentation#One-section|documentation]]' => '<a href="CookBook_documentation.html#One-section" class="wiki-page">documentation</a>',
|
Chris@909
|
615 # page that doesn't exist
|
Chris@909
|
616 '[[Unknown page]]' => '<a href="Unknown_page.html" class="wiki-page new">Unknown page</a>',
|
Chris@909
|
617 '[[Unknown page|404]]' => '<a href="Unknown_page.html" class="wiki-page new">404</a>',
|
Chris@909
|
618 '[[Unknown page#anchor]]' => '<a href="Unknown_page.html#anchor" class="wiki-page new">Unknown page</a>',
|
Chris@909
|
619 '[[Unknown page#anchor|404]]' => '<a href="Unknown_page.html#anchor" class="wiki-page new">404</a>',
|
Chris@909
|
620 }
|
Chris@909
|
621
|
Chris@909
|
622 @project = Project.find(1)
|
Chris@909
|
623
|
Chris@909
|
624 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text, :wiki_links => :local) }
|
Chris@909
|
625 end
|
Chris@909
|
626
|
Chris@1115
|
627 def test_wiki_links_within_wiki_page_context
|
Chris@1115
|
628
|
Chris@1115
|
629 page = WikiPage.find_by_title('Another_page' )
|
Chris@1115
|
630
|
Chris@1115
|
631 to_test = {
|
Chris@1115
|
632 # link to another page
|
Chris@1115
|
633 '[[CookBook documentation]]' => '<a href="/projects/ecookbook/wiki/CookBook_documentation" class="wiki-page">CookBook documentation</a>',
|
Chris@1115
|
634 '[[CookBook documentation|documentation]]' => '<a href="/projects/ecookbook/wiki/CookBook_documentation" class="wiki-page">documentation</a>',
|
Chris@1115
|
635 '[[CookBook documentation#One-section]]' => '<a href="/projects/ecookbook/wiki/CookBook_documentation#One-section" class="wiki-page">CookBook documentation</a>',
|
Chris@1115
|
636 '[[CookBook documentation#One-section|documentation]]' => '<a href="/projects/ecookbook/wiki/CookBook_documentation#One-section" class="wiki-page">documentation</a>',
|
Chris@1115
|
637 # link to the current page
|
Chris@1115
|
638 '[[Another page]]' => '<a href="/projects/ecookbook/wiki/Another_page" class="wiki-page">Another page</a>',
|
Chris@1115
|
639 '[[Another page|Page]]' => '<a href="/projects/ecookbook/wiki/Another_page" class="wiki-page">Page</a>',
|
Chris@1115
|
640 '[[Another page#anchor]]' => '<a href="#anchor" class="wiki-page">Another page</a>',
|
Chris@1115
|
641 '[[Another page#anchor|Page]]' => '<a href="#anchor" class="wiki-page">Page</a>',
|
Chris@1115
|
642 # page that doesn't exist
|
Chris@1115
|
643 '[[Unknown page]]' => '<a href="/projects/ecookbook/wiki/Unknown_page?parent=Another_page" class="wiki-page new">Unknown page</a>',
|
Chris@1115
|
644 '[[Unknown page|404]]' => '<a href="/projects/ecookbook/wiki/Unknown_page?parent=Another_page" class="wiki-page new">404</a>',
|
Chris@1115
|
645 '[[Unknown page#anchor]]' => '<a href="/projects/ecookbook/wiki/Unknown_page?parent=Another_page#anchor" class="wiki-page new">Unknown page</a>',
|
Chris@1115
|
646 '[[Unknown page#anchor|404]]' => '<a href="/projects/ecookbook/wiki/Unknown_page?parent=Another_page#anchor" class="wiki-page new">404</a>',
|
Chris@1115
|
647 }
|
Chris@1115
|
648
|
Chris@1115
|
649 @project = Project.find(1)
|
Chris@1115
|
650
|
Chris@1115
|
651 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(WikiContent.new( :text => text, :page => page ), :text) }
|
Chris@1115
|
652 end
|
Chris@1115
|
653
|
Chris@1115
|
654 def test_wiki_links_anchor_option_should_prepend_page_title_to_href
|
Chris@1115
|
655
|
Chris@1115
|
656 to_test = {
|
Chris@1115
|
657 # link to a page
|
Chris@1115
|
658 '[[CookBook documentation]]' => '<a href="#CookBook_documentation" class="wiki-page">CookBook documentation</a>',
|
Chris@1115
|
659 '[[CookBook documentation|documentation]]' => '<a href="#CookBook_documentation" class="wiki-page">documentation</a>',
|
Chris@1115
|
660 '[[CookBook documentation#One-section]]' => '<a href="#CookBook_documentation_One-section" class="wiki-page">CookBook documentation</a>',
|
Chris@1115
|
661 '[[CookBook documentation#One-section|documentation]]' => '<a href="#CookBook_documentation_One-section" class="wiki-page">documentation</a>',
|
Chris@1115
|
662 # page that doesn't exist
|
Chris@1115
|
663 '[[Unknown page]]' => '<a href="#Unknown_page" class="wiki-page new">Unknown page</a>',
|
Chris@1115
|
664 '[[Unknown page|404]]' => '<a href="#Unknown_page" class="wiki-page new">404</a>',
|
Chris@1115
|
665 '[[Unknown page#anchor]]' => '<a href="#Unknown_page_anchor" class="wiki-page new">Unknown page</a>',
|
Chris@1115
|
666 '[[Unknown page#anchor|404]]' => '<a href="#Unknown_page_anchor" class="wiki-page new">404</a>',
|
Chris@1115
|
667 }
|
Chris@1115
|
668
|
Chris@1115
|
669 @project = Project.find(1)
|
Chris@1115
|
670
|
Chris@1115
|
671 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text, :wiki_links => :anchor) }
|
Chris@1115
|
672 end
|
Chris@1115
|
673
|
Chris@0
|
674 def test_html_tags
|
Chris@0
|
675 to_test = {
|
Chris@0
|
676 "<div>content</div>" => "<p><div>content</div></p>",
|
Chris@0
|
677 "<div class=\"bold\">content</div>" => "<p><div class=\"bold\">content</div></p>",
|
Chris@0
|
678 "<script>some script;</script>" => "<p><script>some script;</script></p>",
|
Chris@0
|
679 # do not escape pre/code tags
|
Chris@0
|
680 "<pre>\nline 1\nline2</pre>" => "<pre>\nline 1\nline2</pre>",
|
Chris@0
|
681 "<pre><code>\nline 1\nline2</code></pre>" => "<pre><code>\nline 1\nline2</code></pre>",
|
Chris@0
|
682 "<pre><div>content</div></pre>" => "<pre><div>content</div></pre>",
|
Chris@0
|
683 "HTML comment: <!-- no comments -->" => "<p>HTML comment: <!-- no comments --></p>",
|
Chris@0
|
684 "<!-- opening comment" => "<p><!-- opening comment</p>",
|
Chris@0
|
685 # remove attributes except class
|
Chris@0
|
686 "<pre class='foo'>some text</pre>" => "<pre class='foo'>some text</pre>",
|
Chris@119
|
687 '<pre class="foo">some text</pre>' => '<pre class="foo">some text</pre>',
|
Chris@119
|
688 "<pre class='foo bar'>some text</pre>" => "<pre class='foo bar'>some text</pre>",
|
Chris@119
|
689 '<pre class="foo bar">some text</pre>' => '<pre class="foo bar">some text</pre>',
|
Chris@0
|
690 "<pre onmouseover='alert(1)'>some text</pre>" => "<pre>some text</pre>",
|
Chris@119
|
691 # xss
|
Chris@119
|
692 '<pre><code class=""onmouseover="alert(1)">text</code></pre>' => '<pre><code>text</code></pre>',
|
Chris@119
|
693 '<pre class=""onmouseover="alert(1)">text</pre>' => '<pre>text</pre>',
|
Chris@0
|
694 }
|
Chris@0
|
695 to_test.each { |text, result| assert_equal result, textilizable(text) }
|
Chris@0
|
696 end
|
Chris@441
|
697
|
Chris@0
|
698 def test_allowed_html_tags
|
Chris@0
|
699 to_test = {
|
Chris@0
|
700 "<pre>preformatted text</pre>" => "<pre>preformatted text</pre>",
|
Chris@0
|
701 "<notextile>no *textile* formatting</notextile>" => "no *textile* formatting",
|
Chris@0
|
702 "<notextile>this is <tag>a tag</tag></notextile>" => "this is <tag>a tag</tag>"
|
Chris@0
|
703 }
|
Chris@0
|
704 to_test.each { |text, result| assert_equal result, textilizable(text) }
|
Chris@0
|
705 end
|
Chris@441
|
706
|
Chris@0
|
707 def test_pre_tags
|
Chris@0
|
708 raw = <<-RAW
|
Chris@0
|
709 Before
|
Chris@0
|
710
|
Chris@0
|
711 <pre>
|
Chris@0
|
712 <prepared-statement-cache-size>32</prepared-statement-cache-size>
|
Chris@0
|
713 </pre>
|
Chris@0
|
714
|
Chris@0
|
715 After
|
Chris@0
|
716 RAW
|
Chris@0
|
717
|
Chris@0
|
718 expected = <<-EXPECTED
|
Chris@0
|
719 <p>Before</p>
|
Chris@0
|
720 <pre>
|
Chris@0
|
721 <prepared-statement-cache-size>32</prepared-statement-cache-size>
|
Chris@0
|
722 </pre>
|
Chris@0
|
723 <p>After</p>
|
Chris@0
|
724 EXPECTED
|
Chris@441
|
725
|
Chris@0
|
726 assert_equal expected.gsub(%r{[\r\n\t]}, ''), textilizable(raw).gsub(%r{[\r\n\t]}, '')
|
Chris@0
|
727 end
|
Chris@441
|
728
|
Chris@0
|
729 def test_pre_content_should_not_parse_wiki_and_redmine_links
|
Chris@0
|
730 raw = <<-RAW
|
Chris@0
|
731 [[CookBook documentation]]
|
Chris@0
|
732
|
Chris@0
|
733 #1
|
Chris@0
|
734
|
Chris@0
|
735 <pre>
|
Chris@0
|
736 [[CookBook documentation]]
|
Chris@0
|
737
|
Chris@0
|
738 #1
|
Chris@0
|
739 </pre>
|
Chris@0
|
740 RAW
|
Chris@0
|
741
|
Chris@0
|
742 expected = <<-EXPECTED
|
Chris@0
|
743 <p><a href="/projects/ecookbook/wiki/CookBook_documentation" class="wiki-page">CookBook documentation</a></p>
|
Chris@1115
|
744 <p><a href="/issues/1" class="issue status-1 priority-4 priority-lowest" title="Can't print recipes (New)">#1</a></p>
|
Chris@0
|
745 <pre>
|
Chris@0
|
746 [[CookBook documentation]]
|
Chris@0
|
747
|
Chris@0
|
748 #1
|
Chris@0
|
749 </pre>
|
Chris@0
|
750 EXPECTED
|
Chris@441
|
751
|
Chris@0
|
752 @project = Project.find(1)
|
Chris@0
|
753 assert_equal expected.gsub(%r{[\r\n\t]}, ''), textilizable(raw).gsub(%r{[\r\n\t]}, '')
|
Chris@0
|
754 end
|
Chris@441
|
755
|
Chris@0
|
756 def test_non_closing_pre_blocks_should_be_closed
|
Chris@0
|
757 raw = <<-RAW
|
Chris@0
|
758 <pre><code>
|
Chris@0
|
759 RAW
|
Chris@0
|
760
|
Chris@0
|
761 expected = <<-EXPECTED
|
Chris@0
|
762 <pre><code>
|
Chris@0
|
763 </code></pre>
|
Chris@0
|
764 EXPECTED
|
Chris@441
|
765
|
Chris@0
|
766 @project = Project.find(1)
|
Chris@0
|
767 assert_equal expected.gsub(%r{[\r\n\t]}, ''), textilizable(raw).gsub(%r{[\r\n\t]}, '')
|
Chris@0
|
768 end
|
Chris@441
|
769
|
Chris@0
|
770 def test_syntax_highlight
|
Chris@0
|
771 raw = <<-RAW
|
Chris@0
|
772 <pre><code class="ruby">
|
Chris@0
|
773 # Some ruby code here
|
Chris@0
|
774 </code></pre>
|
Chris@0
|
775 RAW
|
Chris@0
|
776
|
Chris@0
|
777 expected = <<-EXPECTED
|
Chris@1115
|
778 <pre><code class="ruby syntaxhl"><span class=\"CodeRay\"><span class="comment"># Some ruby code here</span></span>
|
Chris@0
|
779 </code></pre>
|
Chris@0
|
780 EXPECTED
|
Chris@0
|
781
|
Chris@0
|
782 assert_equal expected.gsub(%r{[\r\n\t]}, ''), textilizable(raw).gsub(%r{[\r\n\t]}, '')
|
Chris@0
|
783 end
|
Chris@441
|
784
|
Chris@1115
|
785 def test_to_path_param
|
Chris@1115
|
786 assert_equal 'test1/test2', to_path_param('test1/test2')
|
Chris@1115
|
787 assert_equal 'test1/test2', to_path_param('/test1/test2/')
|
Chris@1115
|
788 assert_equal 'test1/test2', to_path_param('//test1/test2/')
|
Chris@1115
|
789 assert_equal nil, to_path_param('/')
|
Chris@1115
|
790 end
|
Chris@1115
|
791
|
Chris@0
|
792 def test_wiki_links_in_tables
|
Chris@0
|
793 to_test = {"|[[Page|Link title]]|[[Other Page|Other title]]|\n|Cell 21|[[Last page]]|" =>
|
Chris@0
|
794 '<tr><td><a href="/projects/ecookbook/wiki/Page" class="wiki-page new">Link title</a></td>' +
|
Chris@0
|
795 '<td><a href="/projects/ecookbook/wiki/Other_Page" class="wiki-page new">Other title</a></td>' +
|
Chris@0
|
796 '</tr><tr><td>Cell 21</td><td><a href="/projects/ecookbook/wiki/Last_page" class="wiki-page new">Last page</a></td></tr>'
|
Chris@0
|
797 }
|
Chris@0
|
798 @project = Project.find(1)
|
Chris@0
|
799 to_test.each { |text, result| assert_equal "<table>#{result}</table>", textilizable(text).gsub(/[\t\n]/, '') }
|
Chris@0
|
800 end
|
Chris@441
|
801
|
Chris@0
|
802 def test_text_formatting
|
Chris@0
|
803 to_test = {'*_+bold, italic and underline+_*' => '<strong><em><ins>bold, italic and underline</ins></em></strong>',
|
Chris@0
|
804 '(_text within parentheses_)' => '(<em>text within parentheses</em>)',
|
Chris@0
|
805 'a *Humane Web* Text Generator' => 'a <strong>Humane Web</strong> Text Generator',
|
Chris@0
|
806 '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>',
|
Chris@0
|
807 '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',
|
Chris@0
|
808 }
|
Chris@0
|
809 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) }
|
Chris@0
|
810 end
|
Chris@441
|
811
|
Chris@0
|
812 def test_wiki_horizontal_rule
|
Chris@0
|
813 assert_equal '<hr />', textilizable('---')
|
Chris@0
|
814 assert_equal '<p>Dashes: ---</p>', textilizable('Dashes: ---')
|
Chris@0
|
815 end
|
Chris@441
|
816
|
Chris@0
|
817 def test_footnotes
|
Chris@0
|
818 raw = <<-RAW
|
Chris@0
|
819 This is some text[1].
|
Chris@0
|
820
|
Chris@0
|
821 fn1. This is the foot note
|
Chris@0
|
822 RAW
|
Chris@0
|
823
|
Chris@0
|
824 expected = <<-EXPECTED
|
Chris@0
|
825 <p>This is some text<sup><a href=\"#fn1\">1</a></sup>.</p>
|
Chris@0
|
826 <p id="fn1" class="footnote"><sup>1</sup> This is the foot note</p>
|
Chris@0
|
827 EXPECTED
|
Chris@0
|
828
|
Chris@0
|
829 assert_equal expected.gsub(%r{[\r\n\t]}, ''), textilizable(raw).gsub(%r{[\r\n\t]}, '')
|
Chris@0
|
830 end
|
Chris@441
|
831
|
Chris@441
|
832 def test_headings
|
Chris@441
|
833 raw = 'h1. Some heading'
|
Chris@441
|
834 expected = %|<a name="Some-heading"></a>\n<h1 >Some heading<a href="#Some-heading" class="wiki-anchor">¶</a></h1>|
|
Chris@441
|
835
|
Chris@441
|
836 assert_equal expected, textilizable(raw)
|
Chris@441
|
837 end
|
Chris@441
|
838
|
Chris@909
|
839 def test_headings_with_special_chars
|
Chris@909
|
840 # This test makes sure that the generated anchor names match the expected
|
Chris@909
|
841 # ones even if the heading text contains unconventional characters
|
Chris@909
|
842 raw = 'h1. Some heading related to version 0.5'
|
Chris@909
|
843 anchor = sanitize_anchor_name("Some-heading-related-to-version-0.5")
|
Chris@909
|
844 expected = %|<a name="#{anchor}"></a>\n<h1 >Some heading related to version 0.5<a href="##{anchor}" class="wiki-anchor">¶</a></h1>|
|
Chris@909
|
845
|
Chris@909
|
846 assert_equal expected, textilizable(raw)
|
Chris@909
|
847 end
|
Chris@909
|
848
|
Chris@909
|
849 def test_headings_in_wiki_single_page_export_should_be_prepended_with_page_title
|
Chris@1115
|
850 page = WikiPage.new( :title => 'Page Title', :wiki_id => 1 )
|
Chris@1115
|
851 content = WikiContent.new( :text => 'h1. Some heading', :page => page )
|
Chris@909
|
852
|
Chris@909
|
853 expected = %|<a name="Page_Title_Some-heading"></a>\n<h1 >Some heading<a href="#Page_Title_Some-heading" class="wiki-anchor">¶</a></h1>|
|
Chris@909
|
854
|
Chris@909
|
855 assert_equal expected, textilizable(content, :text, :wiki_links => :anchor )
|
Chris@909
|
856 end
|
Chris@909
|
857
|
Chris@0
|
858 def test_table_of_content
|
Chris@0
|
859 raw = <<-RAW
|
Chris@0
|
860 {{toc}}
|
Chris@0
|
861
|
Chris@0
|
862 h1. Title
|
Chris@0
|
863
|
Chris@0
|
864 Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas sed libero.
|
Chris@0
|
865
|
Chris@0
|
866 h2. Subtitle with a [[Wiki]] link
|
Chris@0
|
867
|
Chris@0
|
868 Nullam commodo metus accumsan nulla. Curabitur lobortis dui id dolor.
|
Chris@0
|
869
|
Chris@0
|
870 h2. Subtitle with [[Wiki|another Wiki]] link
|
Chris@0
|
871
|
Chris@0
|
872 h2. Subtitle with %{color:red}red text%
|
Chris@119
|
873
|
Chris@119
|
874 <pre>
|
Chris@119
|
875 some code
|
Chris@119
|
876 </pre>
|
Chris@119
|
877
|
chris@37
|
878 h3. Subtitle with *some* _modifiers_
|
Chris@0
|
879
|
Chris@929
|
880 h3. Subtitle with @inline code@
|
Chris@929
|
881
|
Chris@0
|
882 h1. Another title
|
Chris@0
|
883
|
chris@37
|
884 h3. An "Internet link":http://www.redmine.org/ inside subtitle
|
Chris@0
|
885
|
Chris@0
|
886 h2. "Project Name !/attachments/1234/logo_small.gif! !/attachments/5678/logo_2.png!":/projects/projectname/issues
|
Chris@0
|
887
|
Chris@0
|
888 RAW
|
Chris@0
|
889
|
chris@37
|
890 expected = '<ul class="toc">' +
|
chris@37
|
891 '<li><a href="#Title">Title</a>' +
|
chris@37
|
892 '<ul>' +
|
Chris@441
|
893 '<li><a href="#Subtitle-with-a-Wiki-link">Subtitle with a Wiki link</a></li>' +
|
Chris@441
|
894 '<li><a href="#Subtitle-with-another-Wiki-link">Subtitle with another Wiki link</a></li>' +
|
chris@37
|
895 '<li><a href="#Subtitle-with-red-text">Subtitle with red text</a>' +
|
chris@37
|
896 '<ul>' +
|
chris@37
|
897 '<li><a href="#Subtitle-with-some-modifiers">Subtitle with some modifiers</a></li>' +
|
Chris@929
|
898 '<li><a href="#Subtitle-with-inline-code">Subtitle with inline code</a></li>' +
|
chris@37
|
899 '</ul>' +
|
chris@37
|
900 '</li>' +
|
chris@37
|
901 '</ul>' +
|
chris@37
|
902 '</li>' +
|
chris@37
|
903 '<li><a href="#Another-title">Another title</a>' +
|
chris@37
|
904 '<ul>' +
|
chris@37
|
905 '<li>' +
|
chris@37
|
906 '<ul>' +
|
chris@37
|
907 '<li><a href="#An-Internet-link-inside-subtitle">An Internet link inside subtitle</a></li>' +
|
chris@37
|
908 '</ul>' +
|
chris@37
|
909 '</li>' +
|
chris@37
|
910 '<li><a href="#Project-Name">Project Name</a></li>' +
|
chris@37
|
911 '</ul>' +
|
chris@37
|
912 '</li>' +
|
Chris@0
|
913 '</ul>'
|
Chris@0
|
914
|
chris@37
|
915 @project = Project.find(1)
|
Chris@909
|
916 assert textilizable(raw).gsub("\n", "").include?(expected)
|
chris@37
|
917 end
|
Chris@441
|
918
|
Chris@929
|
919 def test_table_of_content_should_generate_unique_anchors
|
Chris@929
|
920 raw = <<-RAW
|
Chris@929
|
921 {{toc}}
|
Chris@929
|
922
|
Chris@929
|
923 h1. Title
|
Chris@929
|
924
|
Chris@929
|
925 h2. Subtitle
|
Chris@929
|
926
|
Chris@929
|
927 h2. Subtitle
|
Chris@929
|
928 RAW
|
Chris@929
|
929
|
Chris@929
|
930 expected = '<ul class="toc">' +
|
Chris@929
|
931 '<li><a href="#Title">Title</a>' +
|
Chris@929
|
932 '<ul>' +
|
Chris@929
|
933 '<li><a href="#Subtitle">Subtitle</a></li>' +
|
Chris@929
|
934 '<li><a href="#Subtitle-2">Subtitle</a></li>'
|
Chris@929
|
935 '</ul>'
|
Chris@929
|
936 '</li>' +
|
Chris@929
|
937 '</ul>'
|
Chris@929
|
938
|
Chris@929
|
939 @project = Project.find(1)
|
Chris@929
|
940 result = textilizable(raw).gsub("\n", "")
|
Chris@929
|
941 assert_include expected, result
|
Chris@929
|
942 assert_include '<a name="Subtitle">', result
|
Chris@929
|
943 assert_include '<a name="Subtitle-2">', result
|
Chris@929
|
944 end
|
Chris@929
|
945
|
chris@37
|
946 def test_table_of_content_should_contain_included_page_headings
|
chris@37
|
947 raw = <<-RAW
|
chris@37
|
948 {{toc}}
|
chris@37
|
949
|
chris@37
|
950 h1. Included
|
chris@37
|
951
|
chris@37
|
952 {{include(Child_1)}}
|
chris@37
|
953 RAW
|
chris@37
|
954
|
chris@37
|
955 expected = '<ul class="toc">' +
|
chris@37
|
956 '<li><a href="#Included">Included</a></li>' +
|
Chris@441
|
957 '<li><a href="#Child-page-1">Child page 1</a></li>' +
|
chris@37
|
958 '</ul>'
|
chris@37
|
959
|
chris@37
|
960 @project = Project.find(1)
|
Chris@0
|
961 assert textilizable(raw).gsub("\n", "").include?(expected)
|
Chris@0
|
962 end
|
Chris@0
|
963
|
Chris@929
|
964 def test_section_edit_links
|
Chris@929
|
965 raw = <<-RAW
|
Chris@929
|
966 h1. Title
|
Chris@929
|
967
|
Chris@929
|
968 Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas sed libero.
|
Chris@929
|
969
|
Chris@929
|
970 h2. Subtitle with a [[Wiki]] link
|
Chris@929
|
971
|
Chris@929
|
972 h2. Subtitle with *some* _modifiers_
|
Chris@929
|
973
|
Chris@929
|
974 h2. Subtitle with @inline code@
|
Chris@929
|
975
|
Chris@929
|
976 <pre>
|
Chris@929
|
977 some code
|
Chris@929
|
978
|
Chris@929
|
979 h2. heading inside pre
|
Chris@929
|
980
|
Chris@929
|
981 <h2>html heading inside pre</h2>
|
Chris@929
|
982 </pre>
|
Chris@929
|
983
|
Chris@929
|
984 h2. Subtitle after pre tag
|
Chris@929
|
985 RAW
|
Chris@929
|
986
|
Chris@929
|
987 @project = Project.find(1)
|
Chris@929
|
988 set_language_if_valid 'en'
|
Chris@929
|
989 result = textilizable(raw, :edit_section_links => {:controller => 'wiki', :action => 'edit', :project_id => '1', :id => 'Test'}).gsub("\n", "")
|
Chris@929
|
990
|
Chris@929
|
991 # heading that contains inline code
|
Chris@929
|
992 assert_match Regexp.new('<div class="contextual" title="Edit this section">' +
|
Chris@929
|
993 '<a href="/projects/1/wiki/Test/edit\?section=4"><img alt="Edit" src="/images/edit.png(\?\d+)?" /></a></div>' +
|
Chris@929
|
994 '<a name="Subtitle-with-inline-code"></a>' +
|
Chris@929
|
995 '<h2 >Subtitle with <code>inline code</code><a href="#Subtitle-with-inline-code" class="wiki-anchor">¶</a></h2>'),
|
Chris@929
|
996 result
|
Chris@929
|
997
|
Chris@929
|
998 # last heading
|
Chris@929
|
999 assert_match Regexp.new('<div class="contextual" title="Edit this section">' +
|
Chris@929
|
1000 '<a href="/projects/1/wiki/Test/edit\?section=5"><img alt="Edit" src="/images/edit.png(\?\d+)?" /></a></div>' +
|
Chris@929
|
1001 '<a name="Subtitle-after-pre-tag"></a>' +
|
Chris@929
|
1002 '<h2 >Subtitle after pre tag<a href="#Subtitle-after-pre-tag" class="wiki-anchor">¶</a></h2>'),
|
Chris@929
|
1003 result
|
Chris@929
|
1004 end
|
Chris@929
|
1005
|
Chris@0
|
1006 def test_default_formatter
|
Chris@1115
|
1007 with_settings :text_formatting => 'unknown' do
|
Chris@1115
|
1008 text = 'a *link*: http://www.example.net/'
|
Chris@1115
|
1009 assert_equal '<p>a *link*: <a class="external" href="http://www.example.net/">http://www.example.net/</a></p>', textilizable(text)
|
Chris@1115
|
1010 end
|
Chris@0
|
1011 end
|
Chris@441
|
1012
|
Chris@0
|
1013 def test_due_date_distance_in_words
|
Chris@0
|
1014 to_test = { Date.today => 'Due in 0 days',
|
Chris@0
|
1015 Date.today + 1 => 'Due in 1 day',
|
Chris@0
|
1016 Date.today + 100 => 'Due in about 3 months',
|
Chris@0
|
1017 Date.today + 20000 => 'Due in over 54 years',
|
Chris@0
|
1018 Date.today - 1 => '1 day late',
|
Chris@0
|
1019 Date.today - 100 => 'about 3 months late',
|
Chris@0
|
1020 Date.today - 20000 => 'over 54 years late',
|
Chris@0
|
1021 }
|
Chris@119
|
1022 ::I18n.locale = :en
|
Chris@0
|
1023 to_test.each do |date, expected|
|
Chris@0
|
1024 assert_equal expected, due_date_distance_in_words(date)
|
Chris@0
|
1025 end
|
Chris@0
|
1026 end
|
Chris@441
|
1027
|
Chris@1115
|
1028 def test_avatar_enabled
|
Chris@1115
|
1029 with_settings :gravatar_enabled => '1' do
|
Chris@1115
|
1030 assert avatar(User.find_by_mail('jsmith@somenet.foo')).include?(Digest::MD5.hexdigest('jsmith@somenet.foo'))
|
Chris@1115
|
1031 assert avatar('jsmith <jsmith@somenet.foo>').include?(Digest::MD5.hexdigest('jsmith@somenet.foo'))
|
Chris@1115
|
1032 # Default size is 50
|
Chris@1115
|
1033 assert avatar('jsmith <jsmith@somenet.foo>').include?('size=50')
|
Chris@1115
|
1034 assert avatar('jsmith <jsmith@somenet.foo>', :size => 24).include?('size=24')
|
Chris@1115
|
1035 # Non-avatar options should be considered html options
|
Chris@1115
|
1036 assert avatar('jsmith <jsmith@somenet.foo>', :title => 'John Smith').include?('title="John Smith"')
|
Chris@1115
|
1037 # The default class of the img tag should be gravatar
|
Chris@1115
|
1038 assert avatar('jsmith <jsmith@somenet.foo>').include?('class="gravatar"')
|
Chris@1115
|
1039 assert !avatar('jsmith <jsmith@somenet.foo>', :class => 'picture').include?('class="gravatar"')
|
Chris@1115
|
1040 assert_nil avatar('jsmith')
|
Chris@1115
|
1041 assert_nil avatar(nil)
|
Chris@1115
|
1042 end
|
Chris@1115
|
1043 end
|
Chris@441
|
1044
|
Chris@1115
|
1045 def test_avatar_disabled
|
Chris@1115
|
1046 with_settings :gravatar_enabled => '0' do
|
Chris@1115
|
1047 assert_equal '', avatar(User.find_by_mail('jsmith@somenet.foo'))
|
Chris@1115
|
1048 end
|
Chris@0
|
1049 end
|
Chris@441
|
1050
|
Chris@0
|
1051 def test_link_to_user
|
Chris@0
|
1052 user = User.find(2)
|
Chris@1115
|
1053 assert_equal '<a href="/users/2" class="user active">John Smith</a>', link_to_user(user)
|
Chris@0
|
1054 end
|
Chris@441
|
1055
|
Chris@0
|
1056 def test_link_to_user_should_not_link_to_locked_user
|
Chris@1115
|
1057 with_current_user nil do
|
Chris@1115
|
1058 user = User.find(5)
|
Chris@1115
|
1059 assert user.locked?
|
Chris@1115
|
1060 assert_equal 'Dave2 Lopper2', link_to_user(user)
|
Chris@1115
|
1061 end
|
Chris@1115
|
1062 end
|
Chris@1115
|
1063
|
Chris@1115
|
1064 def test_link_to_user_should_link_to_locked_user_if_current_user_is_admin
|
Chris@1115
|
1065 with_current_user User.find(1) do
|
Chris@1115
|
1066 user = User.find(5)
|
Chris@1115
|
1067 assert user.locked?
|
Chris@1115
|
1068 assert_equal '<a href="/users/5" class="user locked">Dave2 Lopper2</a>', link_to_user(user)
|
Chris@1115
|
1069 end
|
Chris@0
|
1070 end
|
Chris@441
|
1071
|
Chris@0
|
1072 def test_link_to_user_should_not_link_to_anonymous
|
Chris@0
|
1073 user = User.anonymous
|
Chris@0
|
1074 assert user.anonymous?
|
Chris@0
|
1075 t = link_to_user(user)
|
Chris@0
|
1076 assert_equal ::I18n.t(:label_user_anonymous), t
|
Chris@0
|
1077 end
|
Chris@14
|
1078
|
Chris@14
|
1079 def test_link_to_project
|
Chris@14
|
1080 project = Project.find(1)
|
Chris@14
|
1081 assert_equal %(<a href="/projects/ecookbook">eCookbook</a>),
|
Chris@14
|
1082 link_to_project(project)
|
Chris@14
|
1083 assert_equal %(<a href="/projects/ecookbook/settings">eCookbook</a>),
|
Chris@14
|
1084 link_to_project(project, :action => 'settings')
|
Chris@14
|
1085 assert_equal %(<a href="http://test.host/projects/ecookbook?jump=blah">eCookbook</a>),
|
Chris@14
|
1086 link_to_project(project, {:only_path => false, :jump => 'blah'})
|
Chris@14
|
1087 assert_equal %(<a href="/projects/ecookbook/settings" class="project">eCookbook</a>),
|
Chris@14
|
1088 link_to_project(project, {:action => 'settings'}, :class => "project")
|
Chris@14
|
1089 end
|
Chris@909
|
1090
|
Chris@929
|
1091 def test_link_to_legacy_project_with_numerical_identifier_should_use_id
|
Chris@929
|
1092 # numeric identifier are no longer allowed
|
Chris@929
|
1093 Project.update_all "identifier=25", "id=1"
|
Chris@929
|
1094
|
Chris@929
|
1095 assert_equal '<a href="/projects/1">eCookbook</a>',
|
Chris@929
|
1096 link_to_project(Project.find(1))
|
Chris@929
|
1097 end
|
Chris@929
|
1098
|
Chris@909
|
1099 def test_principals_options_for_select_with_users
|
Chris@1115
|
1100 User.current = nil
|
Chris@909
|
1101 users = [User.find(2), User.find(4)]
|
Chris@909
|
1102 assert_equal %(<option value="2">John Smith</option><option value="4">Robert Hill</option>),
|
Chris@909
|
1103 principals_options_for_select(users)
|
Chris@909
|
1104 end
|
Chris@909
|
1105
|
Chris@909
|
1106 def test_principals_options_for_select_with_selected
|
Chris@1115
|
1107 User.current = nil
|
Chris@909
|
1108 users = [User.find(2), User.find(4)]
|
Chris@909
|
1109 assert_equal %(<option value="2">John Smith</option><option value="4" selected="selected">Robert Hill</option>),
|
Chris@909
|
1110 principals_options_for_select(users, User.find(4))
|
Chris@909
|
1111 end
|
Chris@909
|
1112
|
Chris@909
|
1113 def test_principals_options_for_select_with_users_and_groups
|
Chris@1115
|
1114 User.current = nil
|
Chris@909
|
1115 users = [User.find(2), Group.find(11), User.find(4), Group.find(10)]
|
Chris@909
|
1116 assert_equal %(<option value="2">John Smith</option><option value="4">Robert Hill</option>) +
|
Chris@909
|
1117 %(<optgroup label="Groups"><option value="10">A Team</option><option value="11">B Team</option></optgroup>),
|
Chris@909
|
1118 principals_options_for_select(users)
|
Chris@909
|
1119 end
|
Chris@909
|
1120
|
Chris@909
|
1121 def test_principals_options_for_select_with_empty_collection
|
Chris@909
|
1122 assert_equal '', principals_options_for_select([])
|
Chris@909
|
1123 end
|
Chris@1115
|
1124
|
Chris@1115
|
1125 def test_principals_options_for_select_should_include_me_option_when_current_user_is_in_collection
|
Chris@1115
|
1126 users = [User.find(2), User.find(4)]
|
Chris@1115
|
1127 User.current = User.find(4)
|
Chris@1115
|
1128 assert_include '<option value="4"><< me >></option>', principals_options_for_select(users)
|
Chris@1115
|
1129 end
|
Chris@1115
|
1130
|
Chris@1115
|
1131 def test_stylesheet_link_tag_should_pick_the_default_stylesheet
|
Chris@1115
|
1132 assert_match 'href="/stylesheets/styles.css"', stylesheet_link_tag("styles")
|
Chris@1115
|
1133 end
|
Chris@1115
|
1134
|
Chris@1115
|
1135 def test_stylesheet_link_tag_for_plugin_should_pick_the_plugin_stylesheet
|
Chris@1115
|
1136 assert_match 'href="/plugin_assets/foo/stylesheets/styles.css"', stylesheet_link_tag("styles", :plugin => :foo)
|
Chris@1115
|
1137 end
|
Chris@1115
|
1138
|
Chris@1115
|
1139 def test_image_tag_should_pick_the_default_image
|
Chris@1115
|
1140 assert_match 'src="/images/image.png"', image_tag("image.png")
|
Chris@1115
|
1141 end
|
Chris@1115
|
1142
|
Chris@1115
|
1143 def test_image_tag_should_pick_the_theme_image_if_it_exists
|
Chris@1115
|
1144 theme = Redmine::Themes.themes.last
|
Chris@1115
|
1145 theme.images << 'image.png'
|
Chris@1115
|
1146
|
Chris@1115
|
1147 with_settings :ui_theme => theme.id do
|
Chris@1115
|
1148 assert_match %|src="/themes/#{theme.dir}/images/image.png"|, image_tag("image.png")
|
Chris@1115
|
1149 assert_match %|src="/images/other.png"|, image_tag("other.png")
|
Chris@1115
|
1150 end
|
Chris@1115
|
1151 ensure
|
Chris@1115
|
1152 theme.images.delete 'image.png'
|
Chris@1115
|
1153 end
|
Chris@1115
|
1154
|
Chris@1115
|
1155 def test_image_tag_sfor_plugin_should_pick_the_plugin_image
|
Chris@1115
|
1156 assert_match 'src="/plugin_assets/foo/images/image.png"', image_tag("image.png", :plugin => :foo)
|
Chris@1115
|
1157 end
|
Chris@1115
|
1158
|
Chris@1115
|
1159 def test_javascript_include_tag_should_pick_the_default_javascript
|
Chris@1115
|
1160 assert_match 'src="/javascripts/scripts.js"', javascript_include_tag("scripts")
|
Chris@1115
|
1161 end
|
Chris@1115
|
1162
|
Chris@1115
|
1163 def test_javascript_include_tag_for_plugin_should_pick_the_plugin_javascript
|
Chris@1115
|
1164 assert_match 'src="/plugin_assets/foo/javascripts/scripts.js"', javascript_include_tag("scripts", :plugin => :foo)
|
Chris@1115
|
1165 end
|
Chris@1115
|
1166
|
Chris@1115
|
1167 def test_per_page_links_should_show_usefull_values
|
Chris@1115
|
1168 set_language_if_valid 'en'
|
Chris@1115
|
1169 stubs(:link_to).returns("[link]")
|
Chris@1115
|
1170
|
Chris@1115
|
1171 with_settings :per_page_options => '10, 25, 50, 100' do
|
Chris@1115
|
1172 assert_nil per_page_links(10, 3)
|
Chris@1115
|
1173 assert_nil per_page_links(25, 3)
|
Chris@1115
|
1174 assert_equal "Per page: 10, [link]", per_page_links(10, 22)
|
Chris@1115
|
1175 assert_equal "Per page: [link], 25", per_page_links(25, 22)
|
Chris@1115
|
1176 assert_equal "Per page: [link], [link], 50", per_page_links(50, 22)
|
Chris@1115
|
1177 assert_equal "Per page: [link], 25, [link]", per_page_links(25, 26)
|
Chris@1115
|
1178 assert_equal "Per page: [link], 25, [link], [link]", per_page_links(25, 120)
|
Chris@1115
|
1179 end
|
Chris@1115
|
1180 end
|
Chris@0
|
1181 end
|