@@ -1,821 +1,845 | |||
|
1 | 1 | # Redmine - project management software |
|
2 | 2 | # Copyright (C) 2006-2011 Jean-Philippe Lang |
|
3 | 3 | # |
|
4 | 4 | # This program is free software; you can redistribute it and/or |
|
5 | 5 | # modify it under the terms of the GNU General Public License |
|
6 | 6 | # as published by the Free Software Foundation; either version 2 |
|
7 | 7 | # of the License, or (at your option) any later version. |
|
8 | 8 | # |
|
9 | 9 | # This program is distributed in the hope that it will be useful, |
|
10 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | # GNU General Public License for more details. |
|
13 | 13 | # |
|
14 | 14 | # You should have received a copy of the GNU General Public License |
|
15 | 15 | # along with this program; if not, write to the Free Software |
|
16 | 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
17 | 17 | |
|
18 | 18 | require File.expand_path('../../test_helper', __FILE__) |
|
19 | 19 | require 'wiki_controller' |
|
20 | 20 | |
|
21 | 21 | # Re-raise errors caught by the controller. |
|
22 | 22 | class WikiController; def rescue_action(e) raise e end; end |
|
23 | 23 | |
|
24 | 24 | class WikiControllerTest < ActionController::TestCase |
|
25 | 25 | fixtures :projects, :users, :roles, :members, :member_roles, |
|
26 | 26 | :enabled_modules, :wikis, :wiki_pages, :wiki_contents, |
|
27 | 27 | :wiki_content_versions, :attachments |
|
28 | 28 | |
|
29 | 29 | def setup |
|
30 | 30 | @controller = WikiController.new |
|
31 | 31 | @request = ActionController::TestRequest.new |
|
32 | 32 | @response = ActionController::TestResponse.new |
|
33 | 33 | User.current = nil |
|
34 | 34 | end |
|
35 | 35 | |
|
36 | 36 | def test_show_start_page |
|
37 | 37 | get :show, :project_id => 'ecookbook' |
|
38 | 38 | assert_response :success |
|
39 | 39 | assert_template 'show' |
|
40 | 40 | assert_tag :tag => 'h1', :content => /CookBook documentation/ |
|
41 | 41 | |
|
42 | 42 | # child_pages macro |
|
43 | 43 | assert_tag :ul, :attributes => { :class => 'pages-hierarchy' }, |
|
44 | 44 | :child => { :tag => 'li', |
|
45 | 45 | :child => { :tag => 'a', :attributes => { :href => '/projects/ecookbook/wiki/Page_with_an_inline_image' }, |
|
46 | 46 | :content => 'Page with an inline image' } } |
|
47 | 47 | end |
|
48 | 48 | |
|
49 | 49 | def test_export_link |
|
50 | 50 | Role.anonymous.add_permission! :export_wiki_pages |
|
51 | 51 | get :show, :project_id => 'ecookbook' |
|
52 | 52 | assert_response :success |
|
53 | 53 | assert_tag 'a', :attributes => {:href => '/projects/ecookbook/wiki/CookBook_documentation.txt'} |
|
54 | 54 | end |
|
55 | 55 | |
|
56 | 56 | def test_show_page_with_name |
|
57 | 57 | get :show, :project_id => 1, :id => 'Another_page' |
|
58 | 58 | assert_response :success |
|
59 | 59 | assert_template 'show' |
|
60 | 60 | assert_tag :tag => 'h1', :content => /Another page/ |
|
61 | 61 | # Included page with an inline image |
|
62 | 62 | assert_tag :tag => 'p', :content => /This is an inline image/ |
|
63 | 63 | assert_tag :tag => 'img', :attributes => { :src => '/attachments/download/3', |
|
64 | 64 | :alt => 'This is a logo' } |
|
65 | 65 | end |
|
66 | 66 | |
|
67 | 67 | def test_show_redirected_page |
|
68 | 68 | WikiRedirect.create!(:wiki_id => 1, :title => 'Old_title', :redirects_to => 'Another_page') |
|
69 | 69 | |
|
70 | 70 | get :show, :project_id => 'ecookbook', :id => 'Old_title' |
|
71 | 71 | assert_redirected_to '/projects/ecookbook/wiki/Another_page' |
|
72 | 72 | end |
|
73 | 73 | |
|
74 | 74 | def test_show_with_sidebar |
|
75 | 75 | page = Project.find(1).wiki.pages.new(:title => 'Sidebar') |
|
76 | 76 | page.content = WikiContent.new(:text => 'Side bar content for test_show_with_sidebar') |
|
77 | 77 | page.save! |
|
78 | 78 | |
|
79 | 79 | get :show, :project_id => 1, :id => 'Another_page' |
|
80 | 80 | assert_response :success |
|
81 | 81 | assert_tag :tag => 'div', :attributes => {:id => 'sidebar'}, |
|
82 | 82 | :content => /Side bar content for test_show_with_sidebar/ |
|
83 | 83 | end |
|
84 | 84 | |
|
85 | 85 | def test_show_should_display_section_edit_links |
|
86 | 86 | @request.session[:user_id] = 2 |
|
87 | 87 | get :show, :project_id => 1, :id => 'Page with sections' |
|
88 | 88 | assert_no_tag 'a', :attributes => { |
|
89 | 89 | :href => '/projects/ecookbook/wiki/Page_with_sections/edit?section=1' |
|
90 | 90 | } |
|
91 | 91 | assert_tag 'a', :attributes => { |
|
92 | 92 | :href => '/projects/ecookbook/wiki/Page_with_sections/edit?section=2' |
|
93 | 93 | } |
|
94 | 94 | assert_tag 'a', :attributes => { |
|
95 | 95 | :href => '/projects/ecookbook/wiki/Page_with_sections/edit?section=3' |
|
96 | 96 | } |
|
97 | 97 | end |
|
98 | 98 | |
|
99 | 99 | def test_show_current_version_should_display_section_edit_links |
|
100 | 100 | @request.session[:user_id] = 2 |
|
101 | 101 | get :show, :project_id => 1, :id => 'Page with sections', :version => 3 |
|
102 | 102 | |
|
103 | 103 | assert_tag 'a', :attributes => { |
|
104 | 104 | :href => '/projects/ecookbook/wiki/Page_with_sections/edit?section=2' |
|
105 | 105 | } |
|
106 | 106 | end |
|
107 | 107 | |
|
108 | 108 | def test_show_old_version_should_not_display_section_edit_links |
|
109 | 109 | @request.session[:user_id] = 2 |
|
110 | 110 | get :show, :project_id => 1, :id => 'Page with sections', :version => 2 |
|
111 | 111 | |
|
112 | 112 | assert_no_tag 'a', :attributes => { |
|
113 | 113 | :href => '/projects/ecookbook/wiki/Page_with_sections/edit?section=2' |
|
114 | 114 | } |
|
115 | 115 | end |
|
116 | 116 | |
|
117 | 117 | def test_show_unexistent_page_without_edit_right |
|
118 | 118 | get :show, :project_id => 1, :id => 'Unexistent page' |
|
119 | 119 | assert_response 404 |
|
120 | 120 | end |
|
121 | 121 | |
|
122 | 122 | def test_show_unexistent_page_with_edit_right |
|
123 | 123 | @request.session[:user_id] = 2 |
|
124 | 124 | get :show, :project_id => 1, :id => 'Unexistent page' |
|
125 | 125 | assert_response :success |
|
126 | 126 | assert_template 'edit' |
|
127 | 127 | end |
|
128 | 128 | |
|
129 | 129 | def test_show_unexistent_page_with_parent_should_preselect_parent |
|
130 | 130 | @request.session[:user_id] = 2 |
|
131 | 131 | get :show, :project_id => 1, :id => 'Unexistent page', :parent => 'Another_page' |
|
132 | 132 | assert_response :success |
|
133 | 133 | assert_template 'edit' |
|
134 | 134 | assert_tag 'select', :attributes => {:name => 'wiki_page[parent_id]'}, |
|
135 | 135 | :child => {:tag => 'option', :attributes => {:value => '2', :selected => 'selected'}} |
|
136 | 136 | end |
|
137 | 137 | |
|
138 | 138 | def test_show_should_not_show_history_without_permission |
|
139 | 139 | Role.anonymous.remove_permission! :view_wiki_edits |
|
140 | 140 | get :show, :project_id => 1, :id => 'Page with sections', :version => 2 |
|
141 | 141 | |
|
142 | 142 | assert_response 302 |
|
143 | 143 | end |
|
144 | 144 | |
|
145 | 145 | def test_create_page |
|
146 | 146 | @request.session[:user_id] = 2 |
|
147 | 147 | assert_difference 'WikiPage.count' do |
|
148 | 148 | assert_difference 'WikiContent.count' do |
|
149 | 149 | put :update, :project_id => 1, |
|
150 | 150 | :id => 'New page', |
|
151 | 151 | :content => {:comments => 'Created the page', |
|
152 | 152 | :text => "h1. New page\n\nThis is a new page", |
|
153 | 153 | :version => 0} |
|
154 | 154 | end |
|
155 | 155 | end |
|
156 | 156 | assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'New_page' |
|
157 | 157 | page = Project.find(1).wiki.find_page('New page') |
|
158 | 158 | assert !page.new_record? |
|
159 | 159 | assert_not_nil page.content |
|
160 | 160 | assert_nil page.parent |
|
161 | 161 | assert_equal 'Created the page', page.content.comments |
|
162 | 162 | end |
|
163 | 163 | |
|
164 | 164 | def test_create_page_with_attachments |
|
165 | 165 | @request.session[:user_id] = 2 |
|
166 | 166 | assert_difference 'WikiPage.count' do |
|
167 | 167 | assert_difference 'Attachment.count' do |
|
168 | 168 | put :update, :project_id => 1, |
|
169 | 169 | :id => 'New page', |
|
170 | 170 | :content => {:comments => 'Created the page', |
|
171 | 171 | :text => "h1. New page\n\nThis is a new page", |
|
172 | 172 | :version => 0}, |
|
173 | 173 | :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}} |
|
174 | 174 | end |
|
175 | 175 | end |
|
176 | 176 | page = Project.find(1).wiki.find_page('New page') |
|
177 | 177 | assert_equal 1, page.attachments.count |
|
178 | 178 | assert_equal 'testfile.txt', page.attachments.first.filename |
|
179 | 179 | end |
|
180 | 180 | |
|
181 | 181 | def test_create_page_with_parent |
|
182 | 182 | @request.session[:user_id] = 2 |
|
183 | 183 | assert_difference 'WikiPage.count' do |
|
184 | 184 | put :update, :project_id => 1, :id => 'New page', |
|
185 | 185 | :content => {:text => "h1. New page\n\nThis is a new page", :version => 0}, |
|
186 | 186 | :wiki_page => {:parent_id => 2} |
|
187 | 187 | end |
|
188 | 188 | page = Project.find(1).wiki.find_page('New page') |
|
189 | 189 | assert_equal WikiPage.find(2), page.parent |
|
190 | 190 | end |
|
191 | 191 | |
|
192 | 192 | def test_edit_page |
|
193 | 193 | @request.session[:user_id] = 2 |
|
194 | 194 | get :edit, :project_id => 'ecookbook', :id => 'Another_page' |
|
195 | 195 | |
|
196 | 196 | assert_response :success |
|
197 | 197 | assert_template 'edit' |
|
198 | 198 | |
|
199 | 199 | assert_tag 'textarea', |
|
200 | 200 | :attributes => { :name => 'content[text]' }, |
|
201 | 201 | :content => WikiPage.find_by_title('Another_page').content.text |
|
202 | 202 | end |
|
203 | 203 | |
|
204 | 204 | def test_edit_section |
|
205 | 205 | @request.session[:user_id] = 2 |
|
206 | 206 | get :edit, :project_id => 'ecookbook', :id => 'Page_with_sections', :section => 2 |
|
207 | 207 | |
|
208 | 208 | assert_response :success |
|
209 | 209 | assert_template 'edit' |
|
210 | 210 | |
|
211 | 211 | page = WikiPage.find_by_title('Page_with_sections') |
|
212 | 212 | section, hash = Redmine::WikiFormatting::Textile::Formatter.new(page.content.text).get_section(2) |
|
213 | 213 | |
|
214 | 214 | assert_tag 'textarea', |
|
215 | 215 | :attributes => { :name => 'content[text]' }, |
|
216 | 216 | :content => section |
|
217 | 217 | assert_tag 'input', |
|
218 | 218 | :attributes => { :name => 'section', :type => 'hidden', :value => '2' } |
|
219 | 219 | assert_tag 'input', |
|
220 | 220 | :attributes => { :name => 'section_hash', :type => 'hidden', :value => hash } |
|
221 | 221 | end |
|
222 | 222 | |
|
223 | 223 | def test_edit_invalid_section_should_respond_with_404 |
|
224 | 224 | @request.session[:user_id] = 2 |
|
225 | 225 | get :edit, :project_id => 'ecookbook', :id => 'Page_with_sections', :section => 10 |
|
226 | 226 | |
|
227 | 227 | assert_response 404 |
|
228 | 228 | end |
|
229 | 229 | |
|
230 | 230 | def test_update_page |
|
231 | 231 | @request.session[:user_id] = 2 |
|
232 | 232 | assert_no_difference 'WikiPage.count' do |
|
233 | 233 | assert_no_difference 'WikiContent.count' do |
|
234 | 234 | assert_difference 'WikiContent::Version.count' do |
|
235 | 235 | put :update, :project_id => 1, |
|
236 | 236 | :id => 'Another_page', |
|
237 | 237 | :content => { |
|
238 | 238 | :comments => "my comments", |
|
239 | 239 | :text => "edited", |
|
240 | 240 | :version => 1 |
|
241 | 241 | } |
|
242 | 242 | end |
|
243 | 243 | end |
|
244 | 244 | end |
|
245 | 245 | assert_redirected_to '/projects/ecookbook/wiki/Another_page' |
|
246 | 246 | |
|
247 | 247 | page = Wiki.find(1).pages.find_by_title('Another_page') |
|
248 | 248 | assert_equal "edited", page.content.text |
|
249 | 249 | assert_equal 2, page.content.version |
|
250 | 250 | assert_equal "my comments", page.content.comments |
|
251 | 251 | end |
|
252 | 252 | |
|
253 | 253 | def test_update_page_with_parent |
|
254 | 254 | @request.session[:user_id] = 2 |
|
255 | 255 | assert_no_difference 'WikiPage.count' do |
|
256 | 256 | assert_no_difference 'WikiContent.count' do |
|
257 | 257 | assert_difference 'WikiContent::Version.count' do |
|
258 | 258 | put :update, :project_id => 1, |
|
259 | 259 | :id => 'Another_page', |
|
260 | 260 | :content => { |
|
261 | 261 | :comments => "my comments", |
|
262 | 262 | :text => "edited", |
|
263 | 263 | :version => 1 |
|
264 | 264 | }, |
|
265 | 265 | :wiki_page => {:parent_id => '1'} |
|
266 | 266 | end |
|
267 | 267 | end |
|
268 | 268 | end |
|
269 | 269 | assert_redirected_to '/projects/ecookbook/wiki/Another_page' |
|
270 | 270 | |
|
271 | 271 | page = Wiki.find(1).pages.find_by_title('Another_page') |
|
272 | 272 | assert_equal "edited", page.content.text |
|
273 | 273 | assert_equal 2, page.content.version |
|
274 | 274 | assert_equal "my comments", page.content.comments |
|
275 | 275 | assert_equal WikiPage.find(1), page.parent |
|
276 | 276 | end |
|
277 | 277 | |
|
278 | 278 | def test_update_page_with_failure |
|
279 | 279 | @request.session[:user_id] = 2 |
|
280 | 280 | assert_no_difference 'WikiPage.count' do |
|
281 | 281 | assert_no_difference 'WikiContent.count' do |
|
282 | 282 | assert_no_difference 'WikiContent::Version.count' do |
|
283 | 283 | put :update, :project_id => 1, |
|
284 | 284 | :id => 'Another_page', |
|
285 | 285 | :content => { |
|
286 | 286 | :comments => 'a' * 300, # failure here, comment is too long |
|
287 | 287 | :text => 'edited', |
|
288 | 288 | :version => 1 |
|
289 | 289 | } |
|
290 | 290 | end |
|
291 | 291 | end |
|
292 | 292 | end |
|
293 | 293 | assert_response :success |
|
294 | 294 | assert_template 'edit' |
|
295 | 295 | |
|
296 | 296 | assert_error_tag :descendant => {:content => /Comment is too long/} |
|
297 | 297 | assert_tag :tag => 'textarea', :attributes => {:id => 'content_text'}, :content => 'edited' |
|
298 | 298 | assert_tag :tag => 'input', :attributes => {:id => 'content_version', :value => '1'} |
|
299 | 299 | end |
|
300 | 300 | |
|
301 | 301 | def test_update_page_with_parent_change_only_should_not_create_content_version |
|
302 | 302 | @request.session[:user_id] = 2 |
|
303 | 303 | assert_no_difference 'WikiPage.count' do |
|
304 | 304 | assert_no_difference 'WikiContent.count' do |
|
305 | 305 | assert_no_difference 'WikiContent::Version.count' do |
|
306 | 306 | put :update, :project_id => 1, |
|
307 | 307 | :id => 'Another_page', |
|
308 | 308 | :content => { |
|
309 | 309 | :comments => '', |
|
310 | 310 | :text => Wiki.find(1).find_page('Another_page').content.text, |
|
311 | 311 | :version => 1 |
|
312 | 312 | }, |
|
313 | 313 | :wiki_page => {:parent_id => '1'} |
|
314 | 314 | end |
|
315 | 315 | end |
|
316 | 316 | end |
|
317 | 317 | page = Wiki.find(1).pages.find_by_title('Another_page') |
|
318 | 318 | assert_equal 1, page.content.version |
|
319 | 319 | assert_equal WikiPage.find(1), page.parent |
|
320 | 320 | end |
|
321 | 321 | |
|
322 | 322 | def test_update_page_with_attachments_only_should_not_create_content_version |
|
323 | 323 | @request.session[:user_id] = 2 |
|
324 | 324 | assert_no_difference 'WikiPage.count' do |
|
325 | 325 | assert_no_difference 'WikiContent.count' do |
|
326 | 326 | assert_no_difference 'WikiContent::Version.count' do |
|
327 | 327 | assert_difference 'Attachment.count' do |
|
328 | 328 | put :update, :project_id => 1, |
|
329 | 329 | :id => 'Another_page', |
|
330 | 330 | :content => { |
|
331 | 331 | :comments => '', |
|
332 | 332 | :text => Wiki.find(1).find_page('Another_page').content.text, |
|
333 | 333 | :version => 1 |
|
334 | 334 | }, |
|
335 | 335 | :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'test file'}} |
|
336 | 336 | end |
|
337 | 337 | end |
|
338 | 338 | end |
|
339 | 339 | end |
|
340 | 340 | page = Wiki.find(1).pages.find_by_title('Another_page') |
|
341 | 341 | assert_equal 1, page.content.version |
|
342 | 342 | end |
|
343 | 343 | |
|
344 | 344 | def test_update_stale_page_should_not_raise_an_error |
|
345 | 345 | @request.session[:user_id] = 2 |
|
346 | 346 | c = Wiki.find(1).find_page('Another_page').content |
|
347 | 347 | c.text = 'Previous text' |
|
348 | 348 | c.save! |
|
349 | 349 | assert_equal 2, c.version |
|
350 | 350 | |
|
351 | 351 | assert_no_difference 'WikiPage.count' do |
|
352 | 352 | assert_no_difference 'WikiContent.count' do |
|
353 | 353 | assert_no_difference 'WikiContent::Version.count' do |
|
354 | 354 | put :update, :project_id => 1, |
|
355 | 355 | :id => 'Another_page', |
|
356 | 356 | :content => { |
|
357 | 357 | :comments => 'My comments', |
|
358 | 358 | :text => 'Text should not be lost', |
|
359 | 359 | :version => 1 |
|
360 | 360 | } |
|
361 | 361 | end |
|
362 | 362 | end |
|
363 | 363 | end |
|
364 | 364 | assert_response :success |
|
365 | 365 | assert_template 'edit' |
|
366 | 366 | assert_tag :div, |
|
367 | 367 | :attributes => { :class => /error/ }, |
|
368 | 368 | :content => /Data has been updated by another user/ |
|
369 | 369 | assert_tag 'textarea', |
|
370 | 370 | :attributes => { :name => 'content[text]' }, |
|
371 | 371 | :content => /Text should not be lost/ |
|
372 | 372 | assert_tag 'input', |
|
373 | 373 | :attributes => { :name => 'content[comments]', :value => 'My comments' } |
|
374 | 374 | |
|
375 | 375 | c.reload |
|
376 | 376 | assert_equal 'Previous text', c.text |
|
377 | 377 | assert_equal 2, c.version |
|
378 | 378 | end |
|
379 | 379 | |
|
380 | 380 | def test_update_section |
|
381 | 381 | @request.session[:user_id] = 2 |
|
382 | 382 | page = WikiPage.find_by_title('Page_with_sections') |
|
383 | 383 | section, hash = Redmine::WikiFormatting::Textile::Formatter.new(page.content.text).get_section(2) |
|
384 | 384 | text = page.content.text |
|
385 | 385 | |
|
386 | 386 | assert_no_difference 'WikiPage.count' do |
|
387 | 387 | assert_no_difference 'WikiContent.count' do |
|
388 | 388 | assert_difference 'WikiContent::Version.count' do |
|
389 | 389 | put :update, :project_id => 1, :id => 'Page_with_sections', |
|
390 | 390 | :content => { |
|
391 | 391 | :text => "New section content", |
|
392 | 392 | :version => 3 |
|
393 | 393 | }, |
|
394 | 394 | :section => 2, |
|
395 | 395 | :section_hash => hash |
|
396 | 396 | end |
|
397 | 397 | end |
|
398 | 398 | end |
|
399 | 399 | assert_redirected_to '/projects/ecookbook/wiki/Page_with_sections' |
|
400 | 400 | assert_equal Redmine::WikiFormatting::Textile::Formatter.new(text).update_section(2, "New section content"), page.reload.content.text |
|
401 | 401 | end |
|
402 | 402 | |
|
403 | 403 | def test_update_section_should_allow_stale_page_update |
|
404 | 404 | @request.session[:user_id] = 2 |
|
405 | 405 | page = WikiPage.find_by_title('Page_with_sections') |
|
406 | 406 | section, hash = Redmine::WikiFormatting::Textile::Formatter.new(page.content.text).get_section(2) |
|
407 | 407 | text = page.content.text |
|
408 | 408 | |
|
409 | 409 | assert_no_difference 'WikiPage.count' do |
|
410 | 410 | assert_no_difference 'WikiContent.count' do |
|
411 | 411 | assert_difference 'WikiContent::Version.count' do |
|
412 | 412 | put :update, :project_id => 1, :id => 'Page_with_sections', |
|
413 | 413 | :content => { |
|
414 | 414 | :text => "New section content", |
|
415 | 415 | :version => 2 # Current version is 3 |
|
416 | 416 | }, |
|
417 | 417 | :section => 2, |
|
418 | 418 | :section_hash => hash |
|
419 | 419 | end |
|
420 | 420 | end |
|
421 | 421 | end |
|
422 | 422 | assert_redirected_to '/projects/ecookbook/wiki/Page_with_sections' |
|
423 | 423 | page.reload |
|
424 | 424 | assert_equal Redmine::WikiFormatting::Textile::Formatter.new(text).update_section(2, "New section content"), page.content.text |
|
425 | 425 | assert_equal 4, page.content.version |
|
426 | 426 | end |
|
427 | 427 | |
|
428 | 428 | def test_update_section_should_not_allow_stale_section_update |
|
429 | 429 | @request.session[:user_id] = 2 |
|
430 | 430 | |
|
431 | 431 | assert_no_difference 'WikiPage.count' do |
|
432 | 432 | assert_no_difference 'WikiContent.count' do |
|
433 | 433 | assert_no_difference 'WikiContent::Version.count' do |
|
434 | 434 | put :update, :project_id => 1, :id => 'Page_with_sections', |
|
435 | 435 | :content => { |
|
436 | 436 | :comments => 'My comments', |
|
437 | 437 | :text => "Text should not be lost", |
|
438 | 438 | :version => 3 |
|
439 | 439 | }, |
|
440 | 440 | :section => 2, |
|
441 | 441 | :section_hash => Digest::MD5.hexdigest("wrong hash") |
|
442 | 442 | end |
|
443 | 443 | end |
|
444 | 444 | end |
|
445 | 445 | assert_response :success |
|
446 | 446 | assert_template 'edit' |
|
447 | 447 | assert_tag :div, |
|
448 | 448 | :attributes => { :class => /error/ }, |
|
449 | 449 | :content => /Data has been updated by another user/ |
|
450 | 450 | assert_tag 'textarea', |
|
451 | 451 | :attributes => { :name => 'content[text]' }, |
|
452 | 452 | :content => /Text should not be lost/ |
|
453 | 453 | assert_tag 'input', |
|
454 | 454 | :attributes => { :name => 'content[comments]', :value => 'My comments' } |
|
455 | 455 | end |
|
456 | 456 | |
|
457 | 457 | def test_preview |
|
458 | 458 | @request.session[:user_id] = 2 |
|
459 | 459 | xhr :post, :preview, :project_id => 1, :id => 'CookBook_documentation', |
|
460 | 460 | :content => { :comments => '', |
|
461 | 461 | :text => 'this is a *previewed text*', |
|
462 | 462 | :version => 3 } |
|
463 | 463 | assert_response :success |
|
464 | 464 | assert_template 'common/_preview' |
|
465 | 465 | assert_tag :tag => 'strong', :content => /previewed text/ |
|
466 | 466 | end |
|
467 | 467 | |
|
468 | 468 | def test_preview_new_page |
|
469 | 469 | @request.session[:user_id] = 2 |
|
470 | 470 | xhr :post, :preview, :project_id => 1, :id => 'New page', |
|
471 | 471 | :content => { :text => 'h1. New page', |
|
472 | 472 | :comments => '', |
|
473 | 473 | :version => 0 } |
|
474 | 474 | assert_response :success |
|
475 | 475 | assert_template 'common/_preview' |
|
476 | 476 | assert_tag :tag => 'h1', :content => /New page/ |
|
477 | 477 | end |
|
478 | 478 | |
|
479 | 479 | def test_history |
|
480 | 480 | get :history, :project_id => 1, :id => 'CookBook_documentation' |
|
481 | 481 | assert_response :success |
|
482 | 482 | assert_template 'history' |
|
483 | 483 | assert_not_nil assigns(:versions) |
|
484 | 484 | assert_equal 3, assigns(:versions).size |
|
485 | 485 | assert_select "input[type=submit][name=commit]" |
|
486 | 486 | end |
|
487 | 487 | |
|
488 | 488 | def test_history_with_one_version |
|
489 | 489 | get :history, :project_id => 1, :id => 'Another_page' |
|
490 | 490 | assert_response :success |
|
491 | 491 | assert_template 'history' |
|
492 | 492 | assert_not_nil assigns(:versions) |
|
493 | 493 | assert_equal 1, assigns(:versions).size |
|
494 | 494 | assert_select "input[type=submit][name=commit]", false |
|
495 | 495 | end |
|
496 | 496 | |
|
497 | 497 | def test_diff |
|
498 | 498 | get :diff, :project_id => 1, :id => 'CookBook_documentation', :version => 2, :version_from => 1 |
|
499 | 499 | assert_response :success |
|
500 | 500 | assert_template 'diff' |
|
501 | 501 | assert_tag :tag => 'span', :attributes => { :class => 'diff_in'}, |
|
502 | 502 | :content => /updated/ |
|
503 | 503 | end |
|
504 | 504 | |
|
505 | 505 | def test_annotate |
|
506 | 506 | get :annotate, :project_id => 1, :id => 'CookBook_documentation', :version => 2 |
|
507 | 507 | assert_response :success |
|
508 | 508 | assert_template 'annotate' |
|
509 | 509 | |
|
510 | 510 | # Line 1 |
|
511 | 511 | assert_tag :tag => 'tr', :child => { |
|
512 | 512 | :tag => 'th', :attributes => {:class => 'line-num'}, :content => '1', :sibling => { |
|
513 | 513 | :tag => 'td', :attributes => {:class => 'author'}, :content => /John Smith/, :sibling => { |
|
514 | 514 | :tag => 'td', :content => /h1\. CookBook documentation/ |
|
515 | 515 | } |
|
516 | 516 | } |
|
517 | 517 | } |
|
518 | 518 | |
|
519 | 519 | # Line 5 |
|
520 | 520 | assert_tag :tag => 'tr', :child => { |
|
521 | 521 | :tag => 'th', :attributes => {:class => 'line-num'}, :content => '5', :sibling => { |
|
522 | 522 | :tag => 'td', :attributes => {:class => 'author'}, :content => /redMine Admin/, :sibling => { |
|
523 | 523 | :tag => 'td', :content => /Some updated \[\[documentation\]\] here/ |
|
524 | 524 | } |
|
525 | 525 | } |
|
526 | 526 | } |
|
527 | 527 | end |
|
528 | 528 | |
|
529 | 529 | def test_get_rename |
|
530 | 530 | @request.session[:user_id] = 2 |
|
531 | 531 | get :rename, :project_id => 1, :id => 'Another_page' |
|
532 | 532 | assert_response :success |
|
533 | 533 | assert_template 'rename' |
|
534 | 534 | assert_tag 'option', |
|
535 | 535 | :attributes => {:value => ''}, |
|
536 | 536 | :content => '', |
|
537 | 537 | :parent => {:tag => 'select', :attributes => {:name => 'wiki_page[parent_id]'}} |
|
538 | 538 | assert_no_tag 'option', |
|
539 | 539 | :attributes => {:selected => 'selected'}, |
|
540 | 540 | :parent => {:tag => 'select', :attributes => {:name => 'wiki_page[parent_id]'}} |
|
541 | 541 | end |
|
542 | 542 | |
|
543 | 543 | def test_get_rename_child_page |
|
544 | 544 | @request.session[:user_id] = 2 |
|
545 | 545 | get :rename, :project_id => 1, :id => 'Child_1' |
|
546 | 546 | assert_response :success |
|
547 | 547 | assert_template 'rename' |
|
548 | 548 | assert_tag 'option', |
|
549 | 549 | :attributes => {:value => ''}, |
|
550 | 550 | :content => '', |
|
551 | 551 | :parent => {:tag => 'select', :attributes => {:name => 'wiki_page[parent_id]'}} |
|
552 | 552 | assert_tag 'option', |
|
553 | 553 | :attributes => {:value => '2', :selected => 'selected'}, |
|
554 | 554 | :content => /Another page/, |
|
555 | 555 | :parent => { |
|
556 | 556 | :tag => 'select', |
|
557 | 557 | :attributes => {:name => 'wiki_page[parent_id]'} |
|
558 | 558 | } |
|
559 | 559 | end |
|
560 | 560 | |
|
561 | 561 | def test_rename_with_redirect |
|
562 | 562 | @request.session[:user_id] = 2 |
|
563 | 563 | post :rename, :project_id => 1, :id => 'Another_page', |
|
564 | 564 | :wiki_page => { :title => 'Another renamed page', |
|
565 | 565 | :redirect_existing_links => 1 } |
|
566 | 566 | assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'Another_renamed_page' |
|
567 | 567 | wiki = Project.find(1).wiki |
|
568 | 568 | # Check redirects |
|
569 | 569 | assert_not_nil wiki.find_page('Another page') |
|
570 | 570 | assert_nil wiki.find_page('Another page', :with_redirect => false) |
|
571 | 571 | end |
|
572 | 572 | |
|
573 | 573 | def test_rename_without_redirect |
|
574 | 574 | @request.session[:user_id] = 2 |
|
575 | 575 | post :rename, :project_id => 1, :id => 'Another_page', |
|
576 | 576 | :wiki_page => { :title => 'Another renamed page', |
|
577 | 577 | :redirect_existing_links => "0" } |
|
578 | 578 | assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'Another_renamed_page' |
|
579 | 579 | wiki = Project.find(1).wiki |
|
580 | 580 | # Check that there's no redirects |
|
581 | 581 | assert_nil wiki.find_page('Another page') |
|
582 | 582 | end |
|
583 | 583 | |
|
584 | 584 | def test_rename_with_parent_assignment |
|
585 | 585 | @request.session[:user_id] = 2 |
|
586 | 586 | post :rename, :project_id => 1, :id => 'Another_page', |
|
587 | 587 | :wiki_page => { :title => 'Another page', :redirect_existing_links => "0", :parent_id => '4' } |
|
588 | 588 | assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'Another_page' |
|
589 | 589 | assert_equal WikiPage.find(4), WikiPage.find_by_title('Another_page').parent |
|
590 | 590 | end |
|
591 | 591 | |
|
592 | 592 | def test_rename_with_parent_unassignment |
|
593 | 593 | @request.session[:user_id] = 2 |
|
594 | 594 | post :rename, :project_id => 1, :id => 'Child_1', |
|
595 | 595 | :wiki_page => { :title => 'Child 1', :redirect_existing_links => "0", :parent_id => '' } |
|
596 | 596 | assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'Child_1' |
|
597 | 597 | assert_nil WikiPage.find_by_title('Child_1').parent |
|
598 | 598 | end |
|
599 | 599 | |
|
600 | 600 | def test_destroy_child |
|
601 | 601 | @request.session[:user_id] = 2 |
|
602 | 602 | delete :destroy, :project_id => 1, :id => 'Child_1' |
|
603 | 603 | assert_redirected_to :action => 'index', :project_id => 'ecookbook' |
|
604 | 604 | end |
|
605 | 605 | |
|
606 | 606 | def test_destroy_parent |
|
607 | 607 | @request.session[:user_id] = 2 |
|
608 | 608 | assert_no_difference('WikiPage.count') do |
|
609 | 609 | delete :destroy, :project_id => 1, :id => 'Another_page' |
|
610 | 610 | end |
|
611 | 611 | assert_response :success |
|
612 | 612 | assert_template 'destroy' |
|
613 | 613 | end |
|
614 | 614 | |
|
615 | 615 | def test_destroy_parent_with_nullify |
|
616 | 616 | @request.session[:user_id] = 2 |
|
617 | 617 | assert_difference('WikiPage.count', -1) do |
|
618 | 618 | delete :destroy, :project_id => 1, :id => 'Another_page', :todo => 'nullify' |
|
619 | 619 | end |
|
620 | 620 | assert_redirected_to :action => 'index', :project_id => 'ecookbook' |
|
621 | 621 | assert_nil WikiPage.find_by_id(2) |
|
622 | 622 | end |
|
623 | 623 | |
|
624 | 624 | def test_destroy_parent_with_cascade |
|
625 | 625 | @request.session[:user_id] = 2 |
|
626 | 626 | assert_difference('WikiPage.count', -3) do |
|
627 | 627 | delete :destroy, :project_id => 1, :id => 'Another_page', :todo => 'destroy' |
|
628 | 628 | end |
|
629 | 629 | assert_redirected_to :action => 'index', :project_id => 'ecookbook' |
|
630 | 630 | assert_nil WikiPage.find_by_id(2) |
|
631 | 631 | assert_nil WikiPage.find_by_id(5) |
|
632 | 632 | end |
|
633 | 633 | |
|
634 | 634 | def test_destroy_parent_with_reassign |
|
635 | 635 | @request.session[:user_id] = 2 |
|
636 | 636 | assert_difference('WikiPage.count', -1) do |
|
637 | 637 | delete :destroy, :project_id => 1, :id => 'Another_page', :todo => 'reassign', :reassign_to_id => 1 |
|
638 | 638 | end |
|
639 | 639 | assert_redirected_to :action => 'index', :project_id => 'ecookbook' |
|
640 | 640 | assert_nil WikiPage.find_by_id(2) |
|
641 | 641 | assert_equal WikiPage.find(1), WikiPage.find_by_id(5).parent |
|
642 | 642 | end |
|
643 | 643 | |
|
644 | 644 | def test_index |
|
645 | 645 | get :index, :project_id => 'ecookbook' |
|
646 | 646 | assert_response :success |
|
647 | 647 | assert_template 'index' |
|
648 | 648 | pages = assigns(:pages) |
|
649 | 649 | assert_not_nil pages |
|
650 | 650 | assert_equal Project.find(1).wiki.pages.size, pages.size |
|
651 | 651 | assert_equal pages.first.content.updated_on, pages.first.updated_on |
|
652 | 652 | |
|
653 | 653 | assert_tag :ul, :attributes => { :class => 'pages-hierarchy' }, |
|
654 | 654 | :child => { :tag => 'li', :child => { :tag => 'a', :attributes => { :href => '/projects/ecookbook/wiki/CookBook_documentation' }, |
|
655 | 655 | :content => 'CookBook documentation' }, |
|
656 | 656 | :child => { :tag => 'ul', |
|
657 | 657 | :child => { :tag => 'li', |
|
658 | 658 | :child => { :tag => 'a', :attributes => { :href => '/projects/ecookbook/wiki/Page_with_an_inline_image' }, |
|
659 | 659 | :content => 'Page with an inline image' } } } }, |
|
660 | 660 | :child => { :tag => 'li', :child => { :tag => 'a', :attributes => { :href => '/projects/ecookbook/wiki/Another_page' }, |
|
661 | 661 | :content => 'Another page' } } |
|
662 | 662 | end |
|
663 | 663 | |
|
664 | 664 | def test_index_should_include_atom_link |
|
665 | 665 | get :index, :project_id => 'ecookbook' |
|
666 | 666 | assert_tag 'a', :attributes => { :href => '/projects/ecookbook/activity.atom?show_wiki_edits=1'} |
|
667 | 667 | end |
|
668 | 668 | |
|
669 | 669 | def test_export_to_html |
|
670 | 670 | @request.session[:user_id] = 2 |
|
671 | 671 | get :export, :project_id => 'ecookbook' |
|
672 | 672 | |
|
673 | 673 | assert_response :success |
|
674 | 674 | assert_not_nil assigns(:pages) |
|
675 | 675 | assert assigns(:pages).any? |
|
676 | 676 | assert_equal "text/html", @response.content_type |
|
677 | 677 | |
|
678 | 678 | assert_select "a[name=?]", "CookBook_documentation" |
|
679 | 679 | assert_select "a[name=?]", "Another_page" |
|
680 | 680 | assert_select "a[name=?]", "Page_with_an_inline_image" |
|
681 | 681 | end |
|
682 | 682 | |
|
683 | 683 | def test_export_to_pdf |
|
684 | 684 | @request.session[:user_id] = 2 |
|
685 | 685 | get :export, :project_id => 'ecookbook', :format => 'pdf' |
|
686 | 686 | |
|
687 | 687 | assert_response :success |
|
688 | 688 | assert_not_nil assigns(:pages) |
|
689 | 689 | assert assigns(:pages).any? |
|
690 | 690 | assert_equal 'application/pdf', @response.content_type |
|
691 | 691 | assert_equal 'attachment; filename="ecookbook.pdf"', @response.headers['Content-Disposition'] |
|
692 | 692 | assert @response.body.starts_with?('%PDF') |
|
693 | 693 | end |
|
694 | 694 | |
|
695 | 695 | def test_export_without_permission_should_be_denied |
|
696 | 696 | @request.session[:user_id] = 2 |
|
697 | 697 | Role.find_by_name('Manager').remove_permission! :export_wiki_pages |
|
698 | 698 | get :export, :project_id => 'ecookbook' |
|
699 | 699 | |
|
700 | 700 | assert_response 403 |
|
701 | 701 | end |
|
702 | 702 | |
|
703 | 703 | def test_date_index |
|
704 | 704 | get :date_index, :project_id => 'ecookbook' |
|
705 | 705 | |
|
706 | 706 | assert_response :success |
|
707 | 707 | assert_template 'date_index' |
|
708 | 708 | assert_not_nil assigns(:pages) |
|
709 | 709 | assert_not_nil assigns(:pages_by_date) |
|
710 | 710 | |
|
711 | 711 | assert_tag 'a', :attributes => { :href => '/projects/ecookbook/activity.atom?show_wiki_edits=1'} |
|
712 | 712 | end |
|
713 | 713 | |
|
714 | 714 | def test_not_found |
|
715 | 715 | get :show, :project_id => 999 |
|
716 | 716 | assert_response 404 |
|
717 | 717 | end |
|
718 | 718 | |
|
719 | 719 | def test_protect_page |
|
720 | 720 | page = WikiPage.find_by_wiki_id_and_title(1, 'Another_page') |
|
721 | 721 | assert !page.protected? |
|
722 | 722 | @request.session[:user_id] = 2 |
|
723 | 723 | post :protect, :project_id => 1, :id => page.title, :protected => '1' |
|
724 | 724 | assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'Another_page' |
|
725 | 725 | assert page.reload.protected? |
|
726 | 726 | end |
|
727 | 727 | |
|
728 | 728 | def test_unprotect_page |
|
729 | 729 | page = WikiPage.find_by_wiki_id_and_title(1, 'CookBook_documentation') |
|
730 | 730 | assert page.protected? |
|
731 | 731 | @request.session[:user_id] = 2 |
|
732 | 732 | post :protect, :project_id => 1, :id => page.title, :protected => '0' |
|
733 | 733 | assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'CookBook_documentation' |
|
734 | 734 | assert !page.reload.protected? |
|
735 | 735 | end |
|
736 | 736 | |
|
737 | 737 | def test_show_page_with_edit_link |
|
738 | 738 | @request.session[:user_id] = 2 |
|
739 | 739 | get :show, :project_id => 1 |
|
740 | 740 | assert_response :success |
|
741 | 741 | assert_template 'show' |
|
742 | 742 | assert_tag :tag => 'a', :attributes => { :href => '/projects/1/wiki/CookBook_documentation/edit' } |
|
743 | 743 | end |
|
744 | 744 | |
|
745 | 745 | def test_show_page_without_edit_link |
|
746 | 746 | @request.session[:user_id] = 4 |
|
747 | 747 | get :show, :project_id => 1 |
|
748 | 748 | assert_response :success |
|
749 | 749 | assert_template 'show' |
|
750 | 750 | assert_no_tag :tag => 'a', :attributes => { :href => '/projects/1/wiki/CookBook_documentation/edit' } |
|
751 | 751 | end |
|
752 | 752 | |
|
753 | 753 | def test_show_pdf |
|
754 | 754 | @request.session[:user_id] = 2 |
|
755 | 755 | get :show, :project_id => 1, :format => 'pdf' |
|
756 | 756 | assert_response :success |
|
757 | 757 | assert_not_nil assigns(:page) |
|
758 | 758 | assert_equal 'application/pdf', @response.content_type |
|
759 | 759 | assert_equal 'attachment; filename="CookBook_documentation.pdf"', |
|
760 | 760 | @response.headers['Content-Disposition'] |
|
761 | 761 | end |
|
762 | 762 | |
|
763 | 763 | def test_show_html |
|
764 | 764 | @request.session[:user_id] = 2 |
|
765 | 765 | get :show, :project_id => 1, :format => 'html' |
|
766 | 766 | assert_response :success |
|
767 | 767 | assert_not_nil assigns(:page) |
|
768 | 768 | assert_equal 'text/html', @response.content_type |
|
769 | 769 | assert_equal 'attachment; filename="CookBook_documentation.html"', |
|
770 | 770 | @response.headers['Content-Disposition'] |
|
771 | 771 | assert_tag 'h1', :content => 'CookBook documentation' |
|
772 | 772 | end |
|
773 | 773 | |
|
774 | def test_show_versioned_html | |
|
775 | @request.session[:user_id] = 2 | |
|
776 | get :show, :project_id => 1, :format => 'html', :version => 2 | |
|
777 | assert_response :success | |
|
778 | assert_not_nil assigns(:content) | |
|
779 | assert_equal 2, assigns(:content).version | |
|
780 | assert_equal 'text/html', @response.content_type | |
|
781 | assert_equal 'attachment; filename="CookBook_documentation.html"', | |
|
782 | @response.headers['Content-Disposition'] | |
|
783 | assert_tag 'h1', :content => 'CookBook documentation' | |
|
784 | end | |
|
785 | ||
|
774 | 786 | def test_show_txt |
|
775 | 787 | @request.session[:user_id] = 2 |
|
776 | 788 | get :show, :project_id => 1, :format => 'txt' |
|
777 | 789 | assert_response :success |
|
778 | 790 | assert_not_nil assigns(:page) |
|
779 | 791 | assert_equal 'text/plain', @response.content_type |
|
780 | 792 | assert_equal 'attachment; filename="CookBook_documentation.txt"', |
|
781 | 793 | @response.headers['Content-Disposition'] |
|
782 | 794 | assert_include 'h1. CookBook documentation', @response.body |
|
783 | 795 | end |
|
784 | 796 | |
|
797 | def test_show_versioned_txt | |
|
798 | @request.session[:user_id] = 2 | |
|
799 | get :show, :project_id => 1, :format => 'txt', :version => 2 | |
|
800 | assert_response :success | |
|
801 | assert_not_nil assigns(:content) | |
|
802 | assert_equal 2, assigns(:content).version | |
|
803 | assert_equal 'text/plain', @response.content_type | |
|
804 | assert_equal 'attachment; filename="CookBook_documentation.txt"', | |
|
805 | @response.headers['Content-Disposition'] | |
|
806 | assert_include 'h1. CookBook documentation', @response.body | |
|
807 | end | |
|
808 | ||
|
785 | 809 | def test_edit_unprotected_page |
|
786 | 810 | # Non members can edit unprotected wiki pages |
|
787 | 811 | @request.session[:user_id] = 4 |
|
788 | 812 | get :edit, :project_id => 1, :id => 'Another_page' |
|
789 | 813 | assert_response :success |
|
790 | 814 | assert_template 'edit' |
|
791 | 815 | end |
|
792 | 816 | |
|
793 | 817 | def test_edit_protected_page_by_nonmember |
|
794 | 818 | # Non members can't edit protected wiki pages |
|
795 | 819 | @request.session[:user_id] = 4 |
|
796 | 820 | get :edit, :project_id => 1, :id => 'CookBook_documentation' |
|
797 | 821 | assert_response 403 |
|
798 | 822 | end |
|
799 | 823 | |
|
800 | 824 | def test_edit_protected_page_by_member |
|
801 | 825 | @request.session[:user_id] = 2 |
|
802 | 826 | get :edit, :project_id => 1, :id => 'CookBook_documentation' |
|
803 | 827 | assert_response :success |
|
804 | 828 | assert_template 'edit' |
|
805 | 829 | end |
|
806 | 830 | |
|
807 | 831 | def test_history_of_non_existing_page_should_return_404 |
|
808 | 832 | get :history, :project_id => 1, :id => 'Unknown_page' |
|
809 | 833 | assert_response 404 |
|
810 | 834 | end |
|
811 | 835 | |
|
812 | 836 | def test_add_attachment |
|
813 | 837 | @request.session[:user_id] = 2 |
|
814 | 838 | assert_difference 'Attachment.count' do |
|
815 | 839 | post :add_attachment, :project_id => 1, :id => 'CookBook_documentation', |
|
816 | 840 | :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'test file'}} |
|
817 | 841 | end |
|
818 | 842 | attachment = Attachment.first(:order => 'id DESC') |
|
819 | 843 | assert_equal Wiki.find(1).find_page('CookBook_documentation'), attachment.container |
|
820 | 844 | end |
|
821 | 845 | end |
General Comments 0
You need to be logged in to leave comments.
Login now