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