##// END OF EJS Templates
Merged r7971 from trunk (#9682)....
Jean-Philippe Lang -
r7996:d19a0b70e0c3
parent child
Show More
@@ -1,61 +1,61
1 1 <div class="contextual">
2 2 <% if @editable %>
3 3 <%= link_to_if_authorized(l(:button_edit), {:action => 'edit', :id => @page.title}, :class => 'icon icon-edit', :accesskey => accesskey(:edit)) if @content.version == @page.content.version %>
4 4 <%= watcher_tag(@page, User.current) %>
5 5 <%= link_to_if_authorized(l(:button_lock), {:action => 'protect', :id => @page.title, :protected => 1}, :method => :post, :class => 'icon icon-lock') if !@page.protected? %>
6 6 <%= link_to_if_authorized(l(:button_unlock), {:action => 'protect', :id => @page.title, :protected => 0}, :method => :post, :class => 'icon icon-unlock') if @page.protected? %>
7 7 <%= link_to_if_authorized(l(:button_rename), {:action => 'rename', :id => @page.title}, :class => 'icon icon-move') if @content.version == @page.content.version %>
8 8 <%= link_to_if_authorized(l(:button_delete), {:action => 'destroy', :id => @page.title}, :method => :delete, :confirm => l(:text_are_you_sure), :class => 'icon icon-del') %>
9 9 <%= link_to_if_authorized(l(:button_rollback), {:action => 'edit', :id => @page.title, :version => @content.version }, :class => 'icon icon-cancel') if @content.version < @page.content.version %>
10 10 <% end %>
11 11 <%= link_to_if_authorized(l(:label_history), {:action => 'history', :id => @page.title}, :class => 'icon icon-history') %>
12 12 </div>
13 13
14 14 <%= breadcrumb(@page.ancestors.reverse.collect {|parent| link_to h(parent.pretty_title), {:id => parent.title, :project_id => parent.project}}) %>
15 15
16 16 <% if @content.version != @page.content.version %>
17 17 <p>
18 18 <%= link_to(('&#171; ' + l(:label_previous)), :action => 'show', :id => @page.title, :project_id => @page.project, :version => (@content.version - 1)) + " - " if @content.version > 1 %>
19 19 <%= "#{l(:label_version)} #{@content.version}/#{@page.content.version}" %>
20 20 <%= '(' + link_to('diff', :controller => 'wiki', :action => 'diff', :id => @page.title, :project_id => @page.project, :version => @content.version) + ')' if @content.version > 1 %> -
21 21 <%= link_to((l(:label_next) + ' &#187;'), :action => 'show', :id => @page.title, :project_id => @page.project, :version => (@content.version + 1)) + " - " if @content.version < @page.content.version %>
22 22 <%= link_to(l(:label_current_version), :action => 'show', :id => @page.title, :project_id => @page.project) %>
23 23 <br />
24 24 <em><%= @content.author ? @content.author.name : "anonyme" %>, <%= format_time(@content.updated_on) %> </em><br />
25 25 <%=h @content.comments %>
26 26 </p>
27 27 <hr />
28 28 <% end %>
29 29
30 30 <%= render(:partial => "wiki/content", :locals => {:content => @content}) %>
31 31
32 32 <%= link_to_attachments @page %>
33 33
34 34 <% if @editable && authorize_for('wiki', 'add_attachment') %>
35 35 <div id="wiki_add_attachment">
36 36 <p><%= link_to l(:label_attachment_new), {}, :onclick => "Element.show('add_attachment_form'); Element.hide(this); Element.scrollTo('add_attachment_form'); return false;",
37 37 :id => 'attach_files_link' %></p>
38 38 <% form_tag({ :controller => 'wiki', :action => 'add_attachment', :project_id => @project, :id => @page.title }, :multipart => true, :id => "add_attachment_form", :style => "display:none;") do %>
39 39 <div class="box">
40 40 <p><%= render :partial => 'attachments/form' %></p>
41 41 </div>
42 42 <%= submit_tag l(:button_add) %>
43 43 <%= link_to l(:button_cancel), {}, :onclick => "Element.hide('add_attachment_form'); Element.show('attach_files_link'); return false;" %>
44 44 <% end %>
45 45 </div>
46 46 <% end %>
47 47
48 48 <% other_formats_links do |f| %>
49 <%= f.link_to 'HTML', :url => {:id => @page.title, :version => @content.version} %>
50 <%= f.link_to 'TXT', :url => {:id => @page.title, :version => @content.version} %>
49 <%= f.link_to 'HTML', :url => {:id => @page.title, :version => params[:version]} %>
50 <%= f.link_to 'TXT', :url => {:id => @page.title, :version => params[:version]} %>
51 51 <% end if User.current.allowed_to?(:export_wiki_pages, @project) %>
52 52
53 53 <% content_for :header_tags do %>
54 54 <%= stylesheet_link_tag 'scm' %>
55 55 <% end %>
56 56
57 57 <% content_for :sidebar do %>
58 58 <%= render :partial => 'sidebar' %>
59 59 <% end %>
60 60
61 61 <% html_title @page.pretty_title %>
@@ -1,521 +1,528
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, :enabled_modules, :wikis, :wiki_pages, :wiki_contents, :wiki_content_versions, :attachments
26 26
27 27 def setup
28 28 @controller = WikiController.new
29 29 @request = ActionController::TestRequest.new
30 30 @response = ActionController::TestResponse.new
31 31 User.current = nil
32 32 end
33 33
34 34 def test_show_start_page
35 35 get :show, :project_id => 'ecookbook'
36 36 assert_response :success
37 37 assert_template 'show'
38 38 assert_tag :tag => 'h1', :content => /CookBook documentation/
39 39
40 40 # child_pages macro
41 41 assert_tag :ul, :attributes => { :class => 'pages-hierarchy' },
42 42 :child => { :tag => 'li',
43 43 :child => { :tag => 'a', :attributes => { :href => '/projects/ecookbook/wiki/Page_with_an_inline_image' },
44 44 :content => 'Page with an inline image' } }
45 45 end
46 46
47 def test_export_link
48 Role.anonymous.add_permission! :export_wiki_pages
49 get :show, :project_id => 'ecookbook'
50 assert_response :success
51 assert_tag 'a', :attributes => {:href => '/projects/ecookbook/wiki/CookBook_documentation.txt'}
52 end
53
47 54 def test_show_page_with_name
48 55 get :show, :project_id => 1, :id => 'Another_page'
49 56 assert_response :success
50 57 assert_template 'show'
51 58 assert_tag :tag => 'h1', :content => /Another page/
52 59 # Included page with an inline image
53 60 assert_tag :tag => 'p', :content => /This is an inline image/
54 61 assert_tag :tag => 'img', :attributes => { :src => '/attachments/download/3',
55 62 :alt => 'This is a logo' }
56 63 end
57 64
58 65 def test_show_redirected_page
59 66 WikiRedirect.create!(:wiki_id => 1, :title => 'Old_title', :redirects_to => 'Another_page')
60 67
61 68 get :show, :project_id => 'ecookbook', :id => 'Old_title'
62 69 assert_redirected_to '/projects/ecookbook/wiki/Another_page'
63 70 end
64 71
65 72 def test_show_with_sidebar
66 73 page = Project.find(1).wiki.pages.new(:title => 'Sidebar')
67 74 page.content = WikiContent.new(:text => 'Side bar content for test_show_with_sidebar')
68 75 page.save!
69 76
70 77 get :show, :project_id => 1, :id => 'Another_page'
71 78 assert_response :success
72 79 assert_tag :tag => 'div', :attributes => {:id => 'sidebar'},
73 80 :content => /Side bar content for test_show_with_sidebar/
74 81 end
75 82
76 83 def test_show_unexistent_page_without_edit_right
77 84 get :show, :project_id => 1, :id => 'Unexistent page'
78 85 assert_response 404
79 86 end
80 87
81 88 def test_show_unexistent_page_with_edit_right
82 89 @request.session[:user_id] = 2
83 90 get :show, :project_id => 1, :id => 'Unexistent page'
84 91 assert_response :success
85 92 assert_template 'edit'
86 93 end
87 94
88 95 def test_create_page
89 96 @request.session[:user_id] = 2
90 97 put :update, :project_id => 1,
91 98 :id => 'New page',
92 99 :content => {:comments => 'Created the page',
93 100 :text => "h1. New page\n\nThis is a new page",
94 101 :version => 0}
95 102 assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'New_page'
96 103 page = Project.find(1).wiki.find_page('New page')
97 104 assert !page.new_record?
98 105 assert_not_nil page.content
99 106 assert_equal 'Created the page', page.content.comments
100 107 end
101 108
102 109 def test_create_page_with_attachments
103 110 @request.session[:user_id] = 2
104 111 assert_difference 'WikiPage.count' do
105 112 assert_difference 'Attachment.count' do
106 113 put :update, :project_id => 1,
107 114 :id => 'New page',
108 115 :content => {:comments => 'Created the page',
109 116 :text => "h1. New page\n\nThis is a new page",
110 117 :version => 0},
111 118 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}}
112 119 end
113 120 end
114 121 page = Project.find(1).wiki.find_page('New page')
115 122 assert_equal 1, page.attachments.count
116 123 assert_equal 'testfile.txt', page.attachments.first.filename
117 124 end
118 125
119 126 def test_update_page
120 127 @request.session[:user_id] = 2
121 128 assert_no_difference 'WikiPage.count' do
122 129 assert_no_difference 'WikiContent.count' do
123 130 assert_difference 'WikiContent::Version.count' do
124 131 put :update, :project_id => 1,
125 132 :id => 'Another_page',
126 133 :content => {
127 134 :comments => "my comments",
128 135 :text => "edited",
129 136 :version => 1
130 137 }
131 138 end
132 139 end
133 140 end
134 141 assert_redirected_to '/projects/ecookbook/wiki/Another_page'
135 142
136 143 page = Wiki.find(1).pages.find_by_title('Another_page')
137 144 assert_equal "edited", page.content.text
138 145 assert_equal 2, page.content.version
139 146 assert_equal "my comments", page.content.comments
140 147 end
141 148
142 149 def test_update_page_with_failure
143 150 @request.session[:user_id] = 2
144 151 assert_no_difference 'WikiPage.count' do
145 152 assert_no_difference 'WikiContent.count' do
146 153 assert_no_difference 'WikiContent::Version.count' do
147 154 put :update, :project_id => 1,
148 155 :id => 'Another_page',
149 156 :content => {
150 157 :comments => 'a' * 300, # failure here, comment is too long
151 158 :text => 'edited',
152 159 :version => 1
153 160 }
154 161 end
155 162 end
156 163 end
157 164 assert_response :success
158 165 assert_template 'edit'
159 166
160 167 assert_error_tag :descendant => {:content => /Comment is too long/}
161 168 assert_tag :tag => 'textarea', :attributes => {:id => 'content_text'}, :content => 'edited'
162 169 assert_tag :tag => 'input', :attributes => {:id => 'content_version', :value => '1'}
163 170 end
164 171
165 172 def test_update_stale_page_should_not_raise_an_error
166 173 @request.session[:user_id] = 2
167 174 c = Wiki.find(1).find_page('Another_page').content
168 175 c.text = 'Previous text'
169 176 c.save!
170 177 assert_equal 2, c.version
171 178
172 179 assert_no_difference 'WikiPage.count' do
173 180 assert_no_difference 'WikiContent.count' do
174 181 assert_no_difference 'WikiContent::Version.count' do
175 182 put :update, :project_id => 1,
176 183 :id => 'Another_page',
177 184 :content => {
178 185 :comments => 'My comments',
179 186 :text => 'Text should not be lost',
180 187 :version => 1
181 188 }
182 189 end
183 190 end
184 191 end
185 192 assert_response :success
186 193 assert_template 'edit'
187 194 assert_tag :div,
188 195 :attributes => { :class => /error/ },
189 196 :content => /Data has been updated by another user/
190 197 assert_tag 'textarea',
191 198 :attributes => { :name => 'content[text]' },
192 199 :content => /Text should not be lost/
193 200 assert_tag 'input',
194 201 :attributes => { :name => 'content[comments]', :value => 'My comments' }
195 202
196 203 c.reload
197 204 assert_equal 'Previous text', c.text
198 205 assert_equal 2, c.version
199 206 end
200 207
201 208 def test_preview
202 209 @request.session[:user_id] = 2
203 210 xhr :post, :preview, :project_id => 1, :id => 'CookBook_documentation',
204 211 :content => { :comments => '',
205 212 :text => 'this is a *previewed text*',
206 213 :version => 3 }
207 214 assert_response :success
208 215 assert_template 'common/_preview'
209 216 assert_tag :tag => 'strong', :content => /previewed text/
210 217 end
211 218
212 219 def test_preview_new_page
213 220 @request.session[:user_id] = 2
214 221 xhr :post, :preview, :project_id => 1, :id => 'New page',
215 222 :content => { :text => 'h1. New page',
216 223 :comments => '',
217 224 :version => 0 }
218 225 assert_response :success
219 226 assert_template 'common/_preview'
220 227 assert_tag :tag => 'h1', :content => /New page/
221 228 end
222 229
223 230 def test_history
224 231 get :history, :project_id => 1, :id => 'CookBook_documentation'
225 232 assert_response :success
226 233 assert_template 'history'
227 234 assert_not_nil assigns(:versions)
228 235 assert_equal 3, assigns(:versions).size
229 236 assert_select "input[type=submit][name=commit]"
230 237 end
231 238
232 239 def test_history_with_one_version
233 240 get :history, :project_id => 1, :id => 'Another_page'
234 241 assert_response :success
235 242 assert_template 'history'
236 243 assert_not_nil assigns(:versions)
237 244 assert_equal 1, assigns(:versions).size
238 245 assert_select "input[type=submit][name=commit]", false
239 246 end
240 247
241 248 def test_diff
242 249 get :diff, :project_id => 1, :id => 'CookBook_documentation', :version => 2, :version_from => 1
243 250 assert_response :success
244 251 assert_template 'diff'
245 252 assert_tag :tag => 'span', :attributes => { :class => 'diff_in'},
246 253 :content => /updated/
247 254 end
248 255
249 256 def test_annotate
250 257 get :annotate, :project_id => 1, :id => 'CookBook_documentation', :version => 2
251 258 assert_response :success
252 259 assert_template 'annotate'
253 260
254 261 # Line 1
255 262 assert_tag :tag => 'tr', :child => {
256 263 :tag => 'th', :attributes => {:class => 'line-num'}, :content => '1', :sibling => {
257 264 :tag => 'td', :attributes => {:class => 'author'}, :content => /John Smith/, :sibling => {
258 265 :tag => 'td', :content => /h1\. CookBook documentation/
259 266 }
260 267 }
261 268 }
262 269
263 270 # Line 5
264 271 assert_tag :tag => 'tr', :child => {
265 272 :tag => 'th', :attributes => {:class => 'line-num'}, :content => '5', :sibling => {
266 273 :tag => 'td', :attributes => {:class => 'author'}, :content => /redMine Admin/, :sibling => {
267 274 :tag => 'td', :content => /Some updated \[\[documentation\]\] here/
268 275 }
269 276 }
270 277 }
271 278 end
272 279
273 280 def test_get_rename
274 281 @request.session[:user_id] = 2
275 282 get :rename, :project_id => 1, :id => 'Another_page'
276 283 assert_response :success
277 284 assert_template 'rename'
278 285 assert_tag 'option',
279 286 :attributes => {:value => ''},
280 287 :content => '',
281 288 :parent => {:tag => 'select', :attributes => {:name => 'wiki_page[parent_id]'}}
282 289 assert_no_tag 'option',
283 290 :attributes => {:selected => 'selected'},
284 291 :parent => {:tag => 'select', :attributes => {:name => 'wiki_page[parent_id]'}}
285 292 end
286 293
287 294 def test_get_rename_child_page
288 295 @request.session[:user_id] = 2
289 296 get :rename, :project_id => 1, :id => 'Child_1'
290 297 assert_response :success
291 298 assert_template 'rename'
292 299 assert_tag 'option',
293 300 :attributes => {:value => ''},
294 301 :content => '',
295 302 :parent => {:tag => 'select', :attributes => {:name => 'wiki_page[parent_id]'}}
296 303 assert_tag 'option',
297 304 :attributes => {:value => '2', :selected => 'selected'},
298 305 :content => /Another page/,
299 306 :parent => {
300 307 :tag => 'select',
301 308 :attributes => {:name => 'wiki_page[parent_id]'}
302 309 }
303 310 end
304 311
305 312 def test_rename_with_redirect
306 313 @request.session[:user_id] = 2
307 314 post :rename, :project_id => 1, :id => 'Another_page',
308 315 :wiki_page => { :title => 'Another renamed page',
309 316 :redirect_existing_links => 1 }
310 317 assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'Another_renamed_page'
311 318 wiki = Project.find(1).wiki
312 319 # Check redirects
313 320 assert_not_nil wiki.find_page('Another page')
314 321 assert_nil wiki.find_page('Another page', :with_redirect => false)
315 322 end
316 323
317 324 def test_rename_without_redirect
318 325 @request.session[:user_id] = 2
319 326 post :rename, :project_id => 1, :id => 'Another_page',
320 327 :wiki_page => { :title => 'Another renamed page',
321 328 :redirect_existing_links => "0" }
322 329 assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'Another_renamed_page'
323 330 wiki = Project.find(1).wiki
324 331 # Check that there's no redirects
325 332 assert_nil wiki.find_page('Another page')
326 333 end
327 334
328 335 def test_rename_with_parent_assignment
329 336 @request.session[:user_id] = 2
330 337 post :rename, :project_id => 1, :id => 'Another_page',
331 338 :wiki_page => { :title => 'Another page', :redirect_existing_links => "0", :parent_id => '4' }
332 339 assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'Another_page'
333 340 assert_equal WikiPage.find(4), WikiPage.find_by_title('Another_page').parent
334 341 end
335 342
336 343 def test_rename_with_parent_unassignment
337 344 @request.session[:user_id] = 2
338 345 post :rename, :project_id => 1, :id => 'Child_1',
339 346 :wiki_page => { :title => 'Child 1', :redirect_existing_links => "0", :parent_id => '' }
340 347 assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'Child_1'
341 348 assert_nil WikiPage.find_by_title('Child_1').parent
342 349 end
343 350
344 351 def test_destroy_child
345 352 @request.session[:user_id] = 2
346 353 delete :destroy, :project_id => 1, :id => 'Child_1'
347 354 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
348 355 end
349 356
350 357 def test_destroy_parent
351 358 @request.session[:user_id] = 2
352 359 assert_no_difference('WikiPage.count') do
353 360 delete :destroy, :project_id => 1, :id => 'Another_page'
354 361 end
355 362 assert_response :success
356 363 assert_template 'destroy'
357 364 end
358 365
359 366 def test_destroy_parent_with_nullify
360 367 @request.session[:user_id] = 2
361 368 assert_difference('WikiPage.count', -1) do
362 369 delete :destroy, :project_id => 1, :id => 'Another_page', :todo => 'nullify'
363 370 end
364 371 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
365 372 assert_nil WikiPage.find_by_id(2)
366 373 end
367 374
368 375 def test_destroy_parent_with_cascade
369 376 @request.session[:user_id] = 2
370 377 assert_difference('WikiPage.count', -3) do
371 378 delete :destroy, :project_id => 1, :id => 'Another_page', :todo => 'destroy'
372 379 end
373 380 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
374 381 assert_nil WikiPage.find_by_id(2)
375 382 assert_nil WikiPage.find_by_id(5)
376 383 end
377 384
378 385 def test_destroy_parent_with_reassign
379 386 @request.session[:user_id] = 2
380 387 assert_difference('WikiPage.count', -1) do
381 388 delete :destroy, :project_id => 1, :id => 'Another_page', :todo => 'reassign', :reassign_to_id => 1
382 389 end
383 390 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
384 391 assert_nil WikiPage.find_by_id(2)
385 392 assert_equal WikiPage.find(1), WikiPage.find_by_id(5).parent
386 393 end
387 394
388 395 def test_index
389 396 get :index, :project_id => 'ecookbook'
390 397 assert_response :success
391 398 assert_template 'index'
392 399 pages = assigns(:pages)
393 400 assert_not_nil pages
394 401 assert_equal Project.find(1).wiki.pages.size, pages.size
395 402 assert_equal pages.first.content.updated_on, pages.first.updated_on
396 403
397 404 assert_tag :ul, :attributes => { :class => 'pages-hierarchy' },
398 405 :child => { :tag => 'li', :child => { :tag => 'a', :attributes => { :href => '/projects/ecookbook/wiki/CookBook_documentation' },
399 406 :content => 'CookBook documentation' },
400 407 :child => { :tag => 'ul',
401 408 :child => { :tag => 'li',
402 409 :child => { :tag => 'a', :attributes => { :href => '/projects/ecookbook/wiki/Page_with_an_inline_image' },
403 410 :content => 'Page with an inline image' } } } },
404 411 :child => { :tag => 'li', :child => { :tag => 'a', :attributes => { :href => '/projects/ecookbook/wiki/Another_page' },
405 412 :content => 'Another page' } }
406 413 end
407 414
408 415 def test_index_should_include_atom_link
409 416 get :index, :project_id => 'ecookbook'
410 417 assert_tag 'a', :attributes => { :href => '/projects/ecookbook/activity.atom?show_wiki_edits=1'}
411 418 end
412 419
413 420 context "GET :export" do
414 421 context "with an authorized user to export the wiki" do
415 422 setup do
416 423 @request.session[:user_id] = 2
417 424 get :export, :project_id => 'ecookbook'
418 425 end
419 426
420 427 should_respond_with :success
421 428 should_assign_to :pages
422 429 should_respond_with_content_type "text/html"
423 430 should "export all of the wiki pages to a single html file" do
424 431 assert_select "a[name=?]", "CookBook_documentation"
425 432 assert_select "a[name=?]", "Another_page"
426 433 assert_select "a[name=?]", "Page_with_an_inline_image"
427 434 end
428 435
429 436 end
430 437
431 438 context "with an unauthorized user" do
432 439 setup do
433 440 get :export, :project_id => 'ecookbook'
434 441
435 442 should_respond_with :redirect
436 443 should_redirect_to('wiki index') { {:action => 'show', :project_id => @project, :id => nil} }
437 444 end
438 445 end
439 446 end
440 447
441 448 context "GET :date_index" do
442 449 setup do
443 450 get :date_index, :project_id => 'ecookbook'
444 451 end
445 452
446 453 should_respond_with :success
447 454 should_assign_to :pages
448 455 should_assign_to :pages_by_date
449 456 should_render_template 'wiki/date_index'
450 457
451 458 should "include atom link" do
452 459 assert_tag 'a', :attributes => { :href => '/projects/ecookbook/activity.atom?show_wiki_edits=1'}
453 460 end
454 461 end
455 462
456 463 def test_not_found
457 464 get :show, :project_id => 999
458 465 assert_response 404
459 466 end
460 467
461 468 def test_protect_page
462 469 page = WikiPage.find_by_wiki_id_and_title(1, 'Another_page')
463 470 assert !page.protected?
464 471 @request.session[:user_id] = 2
465 472 post :protect, :project_id => 1, :id => page.title, :protected => '1'
466 473 assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'Another_page'
467 474 assert page.reload.protected?
468 475 end
469 476
470 477 def test_unprotect_page
471 478 page = WikiPage.find_by_wiki_id_and_title(1, 'CookBook_documentation')
472 479 assert page.protected?
473 480 @request.session[:user_id] = 2
474 481 post :protect, :project_id => 1, :id => page.title, :protected => '0'
475 482 assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'CookBook_documentation'
476 483 assert !page.reload.protected?
477 484 end
478 485
479 486 def test_show_page_with_edit_link
480 487 @request.session[:user_id] = 2
481 488 get :show, :project_id => 1
482 489 assert_response :success
483 490 assert_template 'show'
484 491 assert_tag :tag => 'a', :attributes => { :href => '/projects/1/wiki/CookBook_documentation/edit' }
485 492 end
486 493
487 494 def test_show_page_without_edit_link
488 495 @request.session[:user_id] = 4
489 496 get :show, :project_id => 1
490 497 assert_response :success
491 498 assert_template 'show'
492 499 assert_no_tag :tag => 'a', :attributes => { :href => '/projects/1/wiki/CookBook_documentation/edit' }
493 500 end
494 501
495 502 def test_edit_unprotected_page
496 503 # Non members can edit unprotected wiki pages
497 504 @request.session[:user_id] = 4
498 505 get :edit, :project_id => 1, :id => 'Another_page'
499 506 assert_response :success
500 507 assert_template 'edit'
501 508 end
502 509
503 510 def test_edit_protected_page_by_nonmember
504 511 # Non members can't edit protected wiki pages
505 512 @request.session[:user_id] = 4
506 513 get :edit, :project_id => 1, :id => 'CookBook_documentation'
507 514 assert_response 403
508 515 end
509 516
510 517 def test_edit_protected_page_by_member
511 518 @request.session[:user_id] = 2
512 519 get :edit, :project_id => 1, :id => 'CookBook_documentation'
513 520 assert_response :success
514 521 assert_template 'edit'
515 522 end
516 523
517 524 def test_history_of_non_existing_page_should_return_404
518 525 get :history, :project_id => 1, :id => 'Unknown_page'
519 526 assert_response 404
520 527 end
521 528 end
General Comments 0
You need to be logged in to leave comments. Login now