Mercurial > hg > soundsoftware-site
comparison .svn/pristine/f4/f4a618fa8832b4a871286e474a6e7c3dd200647e.svn-base @ 1296:038ba2d95de8 redmine-2.2
Fix redmine-2.2 branch update (add missing svn files)
author | Chris Cannam |
---|---|
date | Fri, 14 Jun 2013 09:05:06 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
1294:3e4c3460b6ca | 1296:038ba2d95de8 |
---|---|
1 # Redmine - project management software | |
2 # Copyright (C) 2006-2012 Jean-Philippe Lang | |
3 # | |
4 # This program is free software; you can redistribute it and/or | |
5 # modify it under the terms of the GNU General Public License | |
6 # as published by the Free Software Foundation; either version 2 | |
7 # of the License, or (at your option) any later version. | |
8 # | |
9 # This program is distributed in the hope that it will be useful, | |
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 # GNU General Public License for more details. | |
13 # | |
14 # You should have received a copy of the GNU General Public License | |
15 # along with this program; if not, write to the Free Software | |
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
17 | |
18 require File.expand_path('../../../../../test_helper', __FILE__) | |
19 | |
20 class Redmine::WikiFormatting::MacrosTest < ActionView::TestCase | |
21 include ApplicationHelper | |
22 include ActionView::Helpers::TextHelper | |
23 include ActionView::Helpers::SanitizeHelper | |
24 include ERB::Util | |
25 extend ActionView::Helpers::SanitizeHelper::ClassMethods | |
26 | |
27 fixtures :projects, :roles, :enabled_modules, :users, | |
28 :repositories, :changesets, | |
29 :trackers, :issue_statuses, :issues, | |
30 :versions, :documents, | |
31 :wikis, :wiki_pages, :wiki_contents, | |
32 :boards, :messages, | |
33 :attachments | |
34 | |
35 def setup | |
36 super | |
37 @project = nil | |
38 end | |
39 | |
40 def teardown | |
41 end | |
42 | |
43 def test_macro_registration | |
44 Redmine::WikiFormatting::Macros.register do | |
45 macro :foo do |obj, args| | |
46 "Foo: #{args.size} (#{args.join(',')}) (#{args.class.name})" | |
47 end | |
48 end | |
49 | |
50 assert_equal '<p>Foo: 0 () (Array)</p>', textilizable("{{foo}}") | |
51 assert_equal '<p>Foo: 0 () (Array)</p>', textilizable("{{foo()}}") | |
52 assert_equal '<p>Foo: 1 (arg1) (Array)</p>', textilizable("{{foo(arg1)}}") | |
53 assert_equal '<p>Foo: 2 (arg1,arg2) (Array)</p>', textilizable("{{foo(arg1, arg2)}}") | |
54 end | |
55 | |
56 def test_macro_registration_parse_args_set_to_false_should_disable_arguments_parsing | |
57 Redmine::WikiFormatting::Macros.register do | |
58 macro :bar, :parse_args => false do |obj, args| | |
59 "Bar: (#{args}) (#{args.class.name})" | |
60 end | |
61 end | |
62 | |
63 assert_equal '<p>Bar: (args, more args) (String)</p>', textilizable("{{bar(args, more args)}}") | |
64 assert_equal '<p>Bar: () (String)</p>', textilizable("{{bar}}") | |
65 assert_equal '<p>Bar: () (String)</p>', textilizable("{{bar()}}") | |
66 end | |
67 | |
68 def test_macro_registration_with_3_args_should_receive_text_argument | |
69 Redmine::WikiFormatting::Macros.register do | |
70 macro :baz do |obj, args, text| | |
71 "Baz: (#{args.join(',')}) (#{text.class.name}) (#{text})" | |
72 end | |
73 end | |
74 | |
75 assert_equal "<p>Baz: () (NilClass) ()</p>", textilizable("{{baz}}") | |
76 assert_equal "<p>Baz: () (NilClass) ()</p>", textilizable("{{baz()}}") | |
77 assert_equal "<p>Baz: () (String) (line1\nline2)</p>", textilizable("{{baz()\nline1\nline2\n}}") | |
78 assert_equal "<p>Baz: (arg1,arg2) (String) (line1\nline2)</p>", textilizable("{{baz(arg1, arg2)\nline1\nline2\n}}") | |
79 end | |
80 | |
81 def test_multiple_macros_on_the_same_line | |
82 Redmine::WikiFormatting::Macros.macro :foo do |obj, args| | |
83 args.any? ? "args: #{args.join(',')}" : "no args" | |
84 end | |
85 | |
86 assert_equal '<p>no args no args</p>', textilizable("{{foo}} {{foo}}") | |
87 assert_equal '<p>args: a,b no args</p>', textilizable("{{foo(a,b)}} {{foo}}") | |
88 assert_equal '<p>args: a,b args: c,d</p>', textilizable("{{foo(a,b)}} {{foo(c,d)}}") | |
89 assert_equal '<p>no args args: c,d</p>', textilizable("{{foo}} {{foo(c,d)}}") | |
90 end | |
91 | |
92 def test_macro_should_receive_the_object_as_argument_when_with_object_and_attribute | |
93 issue = Issue.find(1) | |
94 issue.description = "{{hello_world}}" | |
95 assert_equal '<p>Hello world! Object: Issue, Called with no argument and no block of text.</p>', textilizable(issue, :description) | |
96 end | |
97 | |
98 def test_macro_should_receive_the_object_as_argument_when_called_with_object_option | |
99 text = "{{hello_world}}" | |
100 assert_equal '<p>Hello world! Object: Issue, Called with no argument and no block of text.</p>', textilizable(text, :object => Issue.find(1)) | |
101 end | |
102 | |
103 def test_extract_macro_options_should_with_args | |
104 options = extract_macro_options(["arg1", "arg2"], :foo, :size) | |
105 assert_equal([["arg1", "arg2"], {}], options) | |
106 end | |
107 | |
108 def test_extract_macro_options_should_with_options | |
109 options = extract_macro_options(["foo=bar", "size=2"], :foo, :size) | |
110 assert_equal([[], {:foo => "bar", :size => "2"}], options) | |
111 end | |
112 | |
113 def test_extract_macro_options_should_with_args_and_options | |
114 options = extract_macro_options(["arg1", "arg2", "foo=bar", "size=2"], :foo, :size) | |
115 assert_equal([["arg1", "arg2"], {:foo => "bar", :size => "2"}], options) | |
116 end | |
117 | |
118 def test_extract_macro_options_should_parse_options_lazily | |
119 options = extract_macro_options(["params=x=1&y=2"], :params) | |
120 assert_equal([[], {:params => "x=1&y=2"}], options) | |
121 end | |
122 | |
123 def test_macro_exception_should_be_displayed | |
124 Redmine::WikiFormatting::Macros.macro :exception do |obj, args| | |
125 raise "My message" | |
126 end | |
127 | |
128 text = "{{exception}}" | |
129 assert_include '<div class="flash error">Error executing the <strong>exception</strong> macro (My message)</div>', textilizable(text) | |
130 end | |
131 | |
132 def test_macro_arguments_should_not_be_parsed_by_formatters | |
133 text = '{{hello_world(http://www.redmine.org, #1)}}' | |
134 assert_include 'Arguments: http://www.redmine.org, #1', textilizable(text) | |
135 end | |
136 | |
137 def test_exclamation_mark_should_not_run_macros | |
138 text = "!{{hello_world}}" | |
139 assert_equal '<p>{{hello_world}}</p>', textilizable(text) | |
140 end | |
141 | |
142 def test_exclamation_mark_should_escape_macros | |
143 text = "!{{hello_world(<tag>)}}" | |
144 assert_equal '<p>{{hello_world(<tag>)}}</p>', textilizable(text) | |
145 end | |
146 | |
147 def test_unknown_macros_should_not_be_replaced | |
148 text = "{{unknown}}" | |
149 assert_equal '<p>{{unknown}}</p>', textilizable(text) | |
150 end | |
151 | |
152 def test_unknown_macros_should_parsed_as_text | |
153 text = "{{unknown(*test*)}}" | |
154 assert_equal '<p>{{unknown(<strong>test</strong>)}}</p>', textilizable(text) | |
155 end | |
156 | |
157 def test_unknown_macros_should_be_escaped | |
158 text = "{{unknown(<tag>)}}" | |
159 assert_equal '<p>{{unknown(<tag>)}}</p>', textilizable(text) | |
160 end | |
161 | |
162 def test_html_safe_macro_output_should_not_be_escaped | |
163 Redmine::WikiFormatting::Macros.macro :safe_macro do |obj, args| | |
164 "<tag>".html_safe | |
165 end | |
166 assert_equal '<p><tag></p>', textilizable("{{safe_macro}}") | |
167 end | |
168 | |
169 def test_macro_hello_world | |
170 text = "{{hello_world}}" | |
171 assert textilizable(text).match(/Hello world!/) | |
172 end | |
173 | |
174 def test_macro_hello_world_should_escape_arguments | |
175 text = "{{hello_world(<tag>)}}" | |
176 assert_include 'Arguments: <tag>', textilizable(text) | |
177 end | |
178 | |
179 def test_macro_macro_list | |
180 text = "{{macro_list}}" | |
181 assert_match %r{<code>hello_world</code>}, textilizable(text) | |
182 end | |
183 | |
184 def test_macro_include | |
185 @project = Project.find(1) | |
186 # include a page of the current project wiki | |
187 text = "{{include(Another page)}}" | |
188 assert_include 'This is a link to a ticket', textilizable(text) | |
189 | |
190 @project = nil | |
191 # include a page of a specific project wiki | |
192 text = "{{include(ecookbook:Another page)}}" | |
193 assert_include 'This is a link to a ticket', textilizable(text) | |
194 | |
195 text = "{{include(ecookbook:)}}" | |
196 assert_include 'CookBook documentation', textilizable(text) | |
197 | |
198 text = "{{include(unknowidentifier:somepage)}}" | |
199 assert_include 'Page not found', textilizable(text) | |
200 end | |
201 | |
202 def test_macro_collapse | |
203 text = "{{collapse\n*Collapsed* block of text\n}}" | |
204 result = textilizable(text) | |
205 | |
206 assert_select_in result, 'div.collapsed-text' | |
207 assert_select_in result, 'strong', :text => 'Collapsed' | |
208 assert_select_in result, 'a.collapsible.collapsed', :text => 'Show' | |
209 assert_select_in result, 'a.collapsible', :text => 'Hide' | |
210 end | |
211 | |
212 def test_macro_collapse_with_one_arg | |
213 text = "{{collapse(Example)\n*Collapsed* block of text\n}}" | |
214 result = textilizable(text) | |
215 | |
216 assert_select_in result, 'div.collapsed-text' | |
217 assert_select_in result, 'strong', :text => 'Collapsed' | |
218 assert_select_in result, 'a.collapsible.collapsed', :text => 'Example' | |
219 assert_select_in result, 'a.collapsible', :text => 'Example' | |
220 end | |
221 | |
222 def test_macro_collapse_with_two_args | |
223 text = "{{collapse(Show example, Hide example)\n*Collapsed* block of text\n}}" | |
224 result = textilizable(text) | |
225 | |
226 assert_select_in result, 'div.collapsed-text' | |
227 assert_select_in result, 'strong', :text => 'Collapsed' | |
228 assert_select_in result, 'a.collapsible.collapsed', :text => 'Show example' | |
229 assert_select_in result, 'a.collapsible', :text => 'Hide example' | |
230 end | |
231 | |
232 def test_macro_child_pages | |
233 expected = "<p><ul class=\"pages-hierarchy\">\n" + | |
234 "<li><a href=\"/projects/ecookbook/wiki/Child_1\">Child 1</a>\n" + | |
235 "<ul class=\"pages-hierarchy\">\n<li><a href=\"/projects/ecookbook/wiki/Child_1_1\">Child 1 1</a></li>\n</ul>\n</li>\n" + | |
236 "<li><a href=\"/projects/ecookbook/wiki/Child_2\">Child 2</a></li>\n" + | |
237 "</ul>\n</p>" | |
238 | |
239 @project = Project.find(1) | |
240 # child pages of the current wiki page | |
241 assert_equal expected, textilizable("{{child_pages}}", :object => WikiPage.find(2).content) | |
242 # child pages of another page | |
243 assert_equal expected, textilizable("{{child_pages(Another_page)}}", :object => WikiPage.find(1).content) | |
244 | |
245 @project = Project.find(2) | |
246 assert_equal expected, textilizable("{{child_pages(ecookbook:Another_page)}}", :object => WikiPage.find(1).content) | |
247 end | |
248 | |
249 def test_macro_child_pages_with_parent_option | |
250 expected = "<p><ul class=\"pages-hierarchy\">\n" + | |
251 "<li><a href=\"/projects/ecookbook/wiki/Another_page\">Another page</a>\n" + | |
252 "<ul class=\"pages-hierarchy\">\n" + | |
253 "<li><a href=\"/projects/ecookbook/wiki/Child_1\">Child 1</a>\n" + | |
254 "<ul class=\"pages-hierarchy\">\n<li><a href=\"/projects/ecookbook/wiki/Child_1_1\">Child 1 1</a></li>\n</ul>\n</li>\n" + | |
255 "<li><a href=\"/projects/ecookbook/wiki/Child_2\">Child 2</a></li>\n" + | |
256 "</ul>\n</li>\n</ul>\n</p>" | |
257 | |
258 @project = Project.find(1) | |
259 # child pages of the current wiki page | |
260 assert_equal expected, textilizable("{{child_pages(parent=1)}}", :object => WikiPage.find(2).content) | |
261 # child pages of another page | |
262 assert_equal expected, textilizable("{{child_pages(Another_page, parent=1)}}", :object => WikiPage.find(1).content) | |
263 | |
264 @project = Project.find(2) | |
265 assert_equal expected, textilizable("{{child_pages(ecookbook:Another_page, parent=1)}}", :object => WikiPage.find(1).content) | |
266 end | |
267 | |
268 def test_macro_child_pages_with_depth_option | |
269 expected = "<p><ul class=\"pages-hierarchy\">\n" + | |
270 "<li><a href=\"/projects/ecookbook/wiki/Child_1\">Child 1</a></li>\n" + | |
271 "<li><a href=\"/projects/ecookbook/wiki/Child_2\">Child 2</a></li>\n" + | |
272 "</ul>\n</p>" | |
273 | |
274 @project = Project.find(1) | |
275 assert_equal expected, textilizable("{{child_pages(depth=1)}}", :object => WikiPage.find(2).content) | |
276 end | |
277 | |
278 def test_macro_child_pages_without_wiki_page_should_fail | |
279 assert_match /can be called from wiki pages only/, textilizable("{{child_pages}}") | |
280 end | |
281 | |
282 def test_macro_thumbnail | |
283 assert_equal '<p><a href="/attachments/17" class="thumbnail" title="testfile.PNG"><img alt="testfile.PNG" src="/attachments/thumbnail/17" /></a></p>', | |
284 textilizable("{{thumbnail(testfile.png)}}", :object => Issue.find(14)) | |
285 end | |
286 | |
287 def test_macro_thumbnail_with_size | |
288 assert_equal '<p><a href="/attachments/17" class="thumbnail" title="testfile.PNG"><img alt="testfile.PNG" src="/attachments/thumbnail/17/200" /></a></p>', | |
289 textilizable("{{thumbnail(testfile.png, size=200)}}", :object => Issue.find(14)) | |
290 end | |
291 | |
292 def test_macro_thumbnail_with_title | |
293 assert_equal '<p><a href="/attachments/17" class="thumbnail" title="Cool image"><img alt="testfile.PNG" src="/attachments/thumbnail/17" /></a></p>', | |
294 textilizable("{{thumbnail(testfile.png, title=Cool image)}}", :object => Issue.find(14)) | |
295 end | |
296 | |
297 def test_macro_thumbnail_with_invalid_filename_should_fail | |
298 assert_include 'test.png not found', | |
299 textilizable("{{thumbnail(test.png)}}", :object => Issue.find(14)) | |
300 end | |
301 | |
302 def test_macros_should_not_be_executed_in_pre_tags | |
303 text = <<-RAW | |
304 {{hello_world(foo)}} | |
305 | |
306 <pre> | |
307 {{hello_world(pre)}} | |
308 !{{hello_world(pre)}} | |
309 </pre> | |
310 | |
311 {{hello_world(bar)}} | |
312 RAW | |
313 | |
314 expected = <<-EXPECTED | |
315 <p>Hello world! Object: NilClass, Arguments: foo and no block of text.</p> | |
316 | |
317 <pre> | |
318 {{hello_world(pre)}} | |
319 !{{hello_world(pre)}} | |
320 </pre> | |
321 | |
322 <p>Hello world! Object: NilClass, Arguments: bar and no block of text.</p> | |
323 EXPECTED | |
324 | |
325 assert_equal expected.gsub(%r{[\r\n\t]}, ''), textilizable(text).gsub(%r{[\r\n\t]}, '') | |
326 end | |
327 | |
328 def test_macros_should_be_escaped_in_pre_tags | |
329 text = "<pre>{{hello_world(<tag>)}}</pre>" | |
330 assert_equal "<pre>{{hello_world(<tag>)}}</pre>", textilizable(text) | |
331 end | |
332 | |
333 def test_macros_should_not_mangle_next_macros_outputs | |
334 text = '{{macro(2)}} !{{macro(2)}} {{hello_world(foo)}}' | |
335 assert_equal '<p>{{macro(2)}} {{macro(2)}} Hello world! Object: NilClass, Arguments: foo and no block of text.</p>', textilizable(text) | |
336 end | |
337 | |
338 def test_macros_with_text_should_not_mangle_following_macros | |
339 text = <<-RAW | |
340 {{hello_world | |
341 Line of text | |
342 }} | |
343 | |
344 {{hello_world | |
345 Another line of text | |
346 }} | |
347 RAW | |
348 | |
349 expected = <<-EXPECTED | |
350 <p>Hello world! Object: NilClass, Called with no argument and a 12 bytes long block of text.</p> | |
351 <p>Hello world! Object: NilClass, Called with no argument and a 20 bytes long block of text.</p> | |
352 EXPECTED | |
353 | |
354 assert_equal expected.gsub(%r{[\r\n\t]}, ''), textilizable(text).gsub(%r{[\r\n\t]}, '') | |
355 end | |
356 end |