Chris@0
|
1 # redMine - project management software
|
Chris@0
|
2 # Copyright (C) 2006-2007 Jean-Philippe Lang
|
Chris@0
|
3 #
|
Chris@0
|
4 # This program is free software; you can redistribute it and/or
|
Chris@0
|
5 # modify it under the terms of the GNU General Public License
|
Chris@0
|
6 # as published by the Free Software Foundation; either version 2
|
Chris@0
|
7 # of the License, or (at your option) any later version.
|
Chris@0
|
8 #
|
Chris@0
|
9 # This program is distributed in the hope that it will be useful,
|
Chris@0
|
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
|
Chris@0
|
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
Chris@0
|
12 # GNU General Public License for more details.
|
Chris@0
|
13 #
|
Chris@0
|
14 # You should have received a copy of the GNU General Public License
|
Chris@0
|
15 # along with this program; if not, write to the Free Software
|
Chris@0
|
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
Chris@0
|
17
|
Chris@117
|
18 require File.expand_path('../../test_helper', __FILE__)
|
Chris@0
|
19 require 'wiki_controller'
|
Chris@0
|
20
|
Chris@0
|
21 # Re-raise errors caught by the controller.
|
Chris@0
|
22 class WikiController; def rescue_action(e) raise e end; end
|
Chris@0
|
23
|
Chris@0
|
24 class WikiControllerTest < ActionController::TestCase
|
Chris@0
|
25 fixtures :projects, :users, :roles, :members, :member_roles, :enabled_modules, :wikis, :wiki_pages, :wiki_contents, :wiki_content_versions, :attachments
|
Chris@0
|
26
|
Chris@0
|
27 def setup
|
Chris@0
|
28 @controller = WikiController.new
|
Chris@0
|
29 @request = ActionController::TestRequest.new
|
Chris@0
|
30 @response = ActionController::TestResponse.new
|
Chris@0
|
31 User.current = nil
|
Chris@0
|
32 end
|
Chris@0
|
33
|
Chris@0
|
34 def test_show_start_page
|
chris@37
|
35 get :show, :project_id => 'ecookbook'
|
Chris@0
|
36 assert_response :success
|
Chris@0
|
37 assert_template 'show'
|
Chris@0
|
38 assert_tag :tag => 'h1', :content => /CookBook documentation/
|
Chris@0
|
39
|
Chris@0
|
40 # child_pages macro
|
Chris@0
|
41 assert_tag :ul, :attributes => { :class => 'pages-hierarchy' },
|
Chris@0
|
42 :child => { :tag => 'li',
|
Chris@0
|
43 :child => { :tag => 'a', :attributes => { :href => '/projects/ecookbook/wiki/Page_with_an_inline_image' },
|
Chris@0
|
44 :content => 'Page with an inline image' } }
|
Chris@0
|
45 end
|
Chris@0
|
46
|
Chris@0
|
47 def test_show_page_with_name
|
chris@37
|
48 get :show, :project_id => 1, :id => 'Another_page'
|
Chris@0
|
49 assert_response :success
|
Chris@0
|
50 assert_template 'show'
|
Chris@0
|
51 assert_tag :tag => 'h1', :content => /Another page/
|
Chris@0
|
52 # Included page with an inline image
|
Chris@0
|
53 assert_tag :tag => 'p', :content => /This is an inline image/
|
Chris@0
|
54 assert_tag :tag => 'img', :attributes => { :src => '/attachments/download/3',
|
Chris@0
|
55 :alt => 'This is a logo' }
|
Chris@0
|
56 end
|
Chris@0
|
57
|
Chris@0
|
58 def test_show_with_sidebar
|
Chris@0
|
59 page = Project.find(1).wiki.pages.new(:title => 'Sidebar')
|
Chris@0
|
60 page.content = WikiContent.new(:text => 'Side bar content for test_show_with_sidebar')
|
Chris@0
|
61 page.save!
|
Chris@0
|
62
|
chris@37
|
63 get :show, :project_id => 1, :id => 'Another_page'
|
Chris@0
|
64 assert_response :success
|
Chris@0
|
65 assert_tag :tag => 'div', :attributes => {:id => 'sidebar'},
|
Chris@0
|
66 :content => /Side bar content for test_show_with_sidebar/
|
Chris@0
|
67 end
|
Chris@0
|
68
|
Chris@0
|
69 def test_show_unexistent_page_without_edit_right
|
chris@37
|
70 get :show, :project_id => 1, :id => 'Unexistent page'
|
Chris@0
|
71 assert_response 404
|
Chris@0
|
72 end
|
Chris@0
|
73
|
Chris@0
|
74 def test_show_unexistent_page_with_edit_right
|
Chris@0
|
75 @request.session[:user_id] = 2
|
chris@37
|
76 get :show, :project_id => 1, :id => 'Unexistent page'
|
Chris@0
|
77 assert_response :success
|
Chris@0
|
78 assert_template 'edit'
|
Chris@0
|
79 end
|
Chris@0
|
80
|
Chris@0
|
81 def test_create_page
|
Chris@0
|
82 @request.session[:user_id] = 2
|
chris@37
|
83 put :update, :project_id => 1,
|
chris@37
|
84 :id => 'New page',
|
Chris@0
|
85 :content => {:comments => 'Created the page',
|
Chris@0
|
86 :text => "h1. New page\n\nThis is a new page",
|
Chris@0
|
87 :version => 0}
|
chris@37
|
88 assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'New_page'
|
Chris@0
|
89 page = Project.find(1).wiki.find_page('New page')
|
Chris@0
|
90 assert !page.new_record?
|
Chris@0
|
91 assert_not_nil page.content
|
Chris@0
|
92 assert_equal 'Created the page', page.content.comments
|
Chris@0
|
93 end
|
Chris@0
|
94
|
Chris@0
|
95 def test_create_page_with_attachments
|
Chris@0
|
96 @request.session[:user_id] = 2
|
Chris@0
|
97 assert_difference 'WikiPage.count' do
|
Chris@0
|
98 assert_difference 'Attachment.count' do
|
chris@37
|
99 put :update, :project_id => 1,
|
chris@37
|
100 :id => 'New page',
|
Chris@0
|
101 :content => {:comments => 'Created the page',
|
Chris@0
|
102 :text => "h1. New page\n\nThis is a new page",
|
Chris@0
|
103 :version => 0},
|
Chris@0
|
104 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}}
|
Chris@0
|
105 end
|
Chris@0
|
106 end
|
Chris@0
|
107 page = Project.find(1).wiki.find_page('New page')
|
Chris@0
|
108 assert_equal 1, page.attachments.count
|
Chris@0
|
109 assert_equal 'testfile.txt', page.attachments.first.filename
|
Chris@0
|
110 end
|
Chris@117
|
111
|
Chris@117
|
112 def test_update_page
|
Chris@117
|
113 @request.session[:user_id] = 2
|
Chris@117
|
114 assert_no_difference 'WikiPage.count' do
|
Chris@117
|
115 assert_no_difference 'WikiContent.count' do
|
Chris@117
|
116 assert_difference 'WikiContent::Version.count' do
|
Chris@117
|
117 put :update, :project_id => 1,
|
Chris@117
|
118 :id => 'Another_page',
|
Chris@117
|
119 :content => {
|
Chris@117
|
120 :comments => "my comments",
|
Chris@117
|
121 :text => "edited",
|
Chris@117
|
122 :version => 1
|
Chris@117
|
123 }
|
Chris@117
|
124 end
|
Chris@117
|
125 end
|
Chris@117
|
126 end
|
Chris@117
|
127 assert_redirected_to '/projects/ecookbook/wiki/Another_page'
|
Chris@117
|
128
|
Chris@117
|
129 page = Wiki.find(1).pages.find_by_title('Another_page')
|
Chris@117
|
130 assert_equal "edited", page.content.text
|
Chris@117
|
131 assert_equal 2, page.content.version
|
Chris@117
|
132 assert_equal "my comments", page.content.comments
|
Chris@117
|
133 end
|
Chris@117
|
134
|
Chris@117
|
135 def test_update_page_with_failure
|
Chris@117
|
136 @request.session[:user_id] = 2
|
Chris@117
|
137 assert_no_difference 'WikiPage.count' do
|
Chris@117
|
138 assert_no_difference 'WikiContent.count' do
|
Chris@117
|
139 assert_no_difference 'WikiContent::Version.count' do
|
Chris@117
|
140 put :update, :project_id => 1,
|
Chris@117
|
141 :id => 'Another_page',
|
Chris@117
|
142 :content => {
|
Chris@117
|
143 :comments => 'a' * 300, # failure here, comment is too long
|
Chris@117
|
144 :text => 'edited',
|
Chris@117
|
145 :version => 1
|
Chris@117
|
146 }
|
Chris@117
|
147 end
|
Chris@117
|
148 end
|
Chris@117
|
149 end
|
Chris@117
|
150 assert_response :success
|
Chris@117
|
151 assert_template 'edit'
|
Chris@117
|
152
|
Chris@117
|
153 assert_error_tag :descendant => {:content => /Comment is too long/}
|
Chris@117
|
154 assert_tag :tag => 'textarea', :attributes => {:id => 'content_text'}, :content => 'edited'
|
Chris@117
|
155 assert_tag :tag => 'input', :attributes => {:id => 'content_version', :value => '1'}
|
Chris@117
|
156 end
|
Chris@0
|
157
|
Chris@0
|
158 def test_preview
|
Chris@0
|
159 @request.session[:user_id] = 2
|
chris@37
|
160 xhr :post, :preview, :project_id => 1, :id => 'CookBook_documentation',
|
Chris@0
|
161 :content => { :comments => '',
|
Chris@0
|
162 :text => 'this is a *previewed text*',
|
Chris@0
|
163 :version => 3 }
|
Chris@0
|
164 assert_response :success
|
Chris@0
|
165 assert_template 'common/_preview'
|
Chris@0
|
166 assert_tag :tag => 'strong', :content => /previewed text/
|
Chris@0
|
167 end
|
Chris@0
|
168
|
Chris@0
|
169 def test_preview_new_page
|
Chris@0
|
170 @request.session[:user_id] = 2
|
chris@37
|
171 xhr :post, :preview, :project_id => 1, :id => 'New page',
|
Chris@0
|
172 :content => { :text => 'h1. New page',
|
Chris@0
|
173 :comments => '',
|
Chris@0
|
174 :version => 0 }
|
Chris@0
|
175 assert_response :success
|
Chris@0
|
176 assert_template 'common/_preview'
|
Chris@0
|
177 assert_tag :tag => 'h1', :content => /New page/
|
Chris@0
|
178 end
|
Chris@0
|
179
|
Chris@0
|
180 def test_history
|
chris@37
|
181 get :history, :project_id => 1, :id => 'CookBook_documentation'
|
Chris@0
|
182 assert_response :success
|
Chris@0
|
183 assert_template 'history'
|
Chris@0
|
184 assert_not_nil assigns(:versions)
|
Chris@0
|
185 assert_equal 3, assigns(:versions).size
|
Chris@0
|
186 assert_select "input[type=submit][name=commit]"
|
Chris@0
|
187 end
|
Chris@0
|
188
|
Chris@0
|
189 def test_history_with_one_version
|
chris@37
|
190 get :history, :project_id => 1, :id => 'Another_page'
|
Chris@0
|
191 assert_response :success
|
Chris@0
|
192 assert_template 'history'
|
Chris@0
|
193 assert_not_nil assigns(:versions)
|
Chris@0
|
194 assert_equal 1, assigns(:versions).size
|
Chris@0
|
195 assert_select "input[type=submit][name=commit]", false
|
Chris@0
|
196 end
|
Chris@0
|
197
|
Chris@0
|
198 def test_diff
|
chris@37
|
199 get :diff, :project_id => 1, :id => 'CookBook_documentation', :version => 2, :version_from => 1
|
Chris@0
|
200 assert_response :success
|
Chris@0
|
201 assert_template 'diff'
|
Chris@0
|
202 assert_tag :tag => 'span', :attributes => { :class => 'diff_in'},
|
Chris@0
|
203 :content => /updated/
|
Chris@0
|
204 end
|
Chris@0
|
205
|
Chris@0
|
206 def test_annotate
|
chris@37
|
207 get :annotate, :project_id => 1, :id => 'CookBook_documentation', :version => 2
|
Chris@0
|
208 assert_response :success
|
Chris@0
|
209 assert_template 'annotate'
|
Chris@0
|
210 # Line 1
|
Chris@0
|
211 assert_tag :tag => 'tr', :child => { :tag => 'th', :attributes => {:class => 'line-num'}, :content => '1' },
|
Chris@0
|
212 :child => { :tag => 'td', :attributes => {:class => 'author'}, :content => /John Smith/ },
|
Chris@0
|
213 :child => { :tag => 'td', :content => /h1\. CookBook documentation/ }
|
Chris@0
|
214 # Line 2
|
Chris@0
|
215 assert_tag :tag => 'tr', :child => { :tag => 'th', :attributes => {:class => 'line-num'}, :content => '2' },
|
Chris@0
|
216 :child => { :tag => 'td', :attributes => {:class => 'author'}, :content => /redMine Admin/ },
|
Chris@0
|
217 :child => { :tag => 'td', :content => /Some updated \[\[documentation\]\] here/ }
|
Chris@0
|
218 end
|
chris@37
|
219
|
chris@37
|
220 def test_get_rename
|
chris@37
|
221 @request.session[:user_id] = 2
|
chris@37
|
222 get :rename, :project_id => 1, :id => 'Another_page'
|
chris@37
|
223 assert_response :success
|
chris@37
|
224 assert_template 'rename'
|
chris@37
|
225 assert_tag 'option',
|
chris@37
|
226 :attributes => {:value => ''},
|
chris@37
|
227 :content => '',
|
chris@37
|
228 :parent => {:tag => 'select', :attributes => {:name => 'wiki_page[parent_id]'}}
|
chris@37
|
229 assert_no_tag 'option',
|
chris@37
|
230 :attributes => {:selected => 'selected'},
|
chris@37
|
231 :parent => {:tag => 'select', :attributes => {:name => 'wiki_page[parent_id]'}}
|
chris@37
|
232 end
|
chris@37
|
233
|
chris@37
|
234 def test_get_rename_child_page
|
chris@37
|
235 @request.session[:user_id] = 2
|
chris@37
|
236 get :rename, :project_id => 1, :id => 'Child_1'
|
chris@37
|
237 assert_response :success
|
chris@37
|
238 assert_template 'rename'
|
chris@37
|
239 assert_tag 'option',
|
chris@37
|
240 :attributes => {:value => ''},
|
chris@37
|
241 :content => '',
|
chris@37
|
242 :parent => {:tag => 'select', :attributes => {:name => 'wiki_page[parent_id]'}}
|
chris@37
|
243 assert_tag 'option',
|
chris@37
|
244 :attributes => {:value => '2', :selected => 'selected'},
|
chris@37
|
245 :content => /Another page/,
|
chris@37
|
246 :parent => {
|
chris@37
|
247 :tag => 'select',
|
chris@37
|
248 :attributes => {:name => 'wiki_page[parent_id]'}
|
chris@37
|
249 }
|
chris@37
|
250 end
|
Chris@0
|
251
|
Chris@0
|
252 def test_rename_with_redirect
|
Chris@0
|
253 @request.session[:user_id] = 2
|
chris@37
|
254 post :rename, :project_id => 1, :id => 'Another_page',
|
Chris@0
|
255 :wiki_page => { :title => 'Another renamed page',
|
Chris@0
|
256 :redirect_existing_links => 1 }
|
chris@37
|
257 assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'Another_renamed_page'
|
Chris@0
|
258 wiki = Project.find(1).wiki
|
Chris@0
|
259 # Check redirects
|
Chris@0
|
260 assert_not_nil wiki.find_page('Another page')
|
Chris@0
|
261 assert_nil wiki.find_page('Another page', :with_redirect => false)
|
Chris@0
|
262 end
|
Chris@0
|
263
|
Chris@0
|
264 def test_rename_without_redirect
|
Chris@0
|
265 @request.session[:user_id] = 2
|
chris@37
|
266 post :rename, :project_id => 1, :id => 'Another_page',
|
Chris@0
|
267 :wiki_page => { :title => 'Another renamed page',
|
Chris@0
|
268 :redirect_existing_links => "0" }
|
chris@37
|
269 assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'Another_renamed_page'
|
Chris@0
|
270 wiki = Project.find(1).wiki
|
Chris@0
|
271 # Check that there's no redirects
|
Chris@0
|
272 assert_nil wiki.find_page('Another page')
|
Chris@0
|
273 end
|
Chris@0
|
274
|
chris@37
|
275 def test_rename_with_parent_assignment
|
chris@37
|
276 @request.session[:user_id] = 2
|
chris@37
|
277 post :rename, :project_id => 1, :id => 'Another_page',
|
chris@37
|
278 :wiki_page => { :title => 'Another page', :redirect_existing_links => "0", :parent_id => '4' }
|
chris@37
|
279 assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'Another_page'
|
chris@37
|
280 assert_equal WikiPage.find(4), WikiPage.find_by_title('Another_page').parent
|
chris@37
|
281 end
|
chris@37
|
282
|
chris@37
|
283 def test_rename_with_parent_unassignment
|
chris@37
|
284 @request.session[:user_id] = 2
|
chris@37
|
285 post :rename, :project_id => 1, :id => 'Child_1',
|
chris@37
|
286 :wiki_page => { :title => 'Child 1', :redirect_existing_links => "0", :parent_id => '' }
|
chris@37
|
287 assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'Child_1'
|
chris@37
|
288 assert_nil WikiPage.find_by_title('Child_1').parent
|
chris@37
|
289 end
|
chris@37
|
290
|
Chris@0
|
291 def test_destroy_child
|
Chris@0
|
292 @request.session[:user_id] = 2
|
chris@37
|
293 delete :destroy, :project_id => 1, :id => 'Child_1'
|
chris@37
|
294 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
|
Chris@0
|
295 end
|
Chris@0
|
296
|
Chris@0
|
297 def test_destroy_parent
|
Chris@0
|
298 @request.session[:user_id] = 2
|
Chris@0
|
299 assert_no_difference('WikiPage.count') do
|
chris@37
|
300 delete :destroy, :project_id => 1, :id => 'Another_page'
|
Chris@0
|
301 end
|
Chris@0
|
302 assert_response :success
|
Chris@0
|
303 assert_template 'destroy'
|
Chris@0
|
304 end
|
Chris@0
|
305
|
Chris@0
|
306 def test_destroy_parent_with_nullify
|
Chris@0
|
307 @request.session[:user_id] = 2
|
Chris@0
|
308 assert_difference('WikiPage.count', -1) do
|
chris@37
|
309 delete :destroy, :project_id => 1, :id => 'Another_page', :todo => 'nullify'
|
Chris@0
|
310 end
|
chris@37
|
311 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
|
Chris@0
|
312 assert_nil WikiPage.find_by_id(2)
|
Chris@0
|
313 end
|
Chris@0
|
314
|
Chris@0
|
315 def test_destroy_parent_with_cascade
|
Chris@0
|
316 @request.session[:user_id] = 2
|
Chris@0
|
317 assert_difference('WikiPage.count', -3) do
|
chris@37
|
318 delete :destroy, :project_id => 1, :id => 'Another_page', :todo => 'destroy'
|
Chris@0
|
319 end
|
chris@37
|
320 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
|
Chris@0
|
321 assert_nil WikiPage.find_by_id(2)
|
Chris@0
|
322 assert_nil WikiPage.find_by_id(5)
|
Chris@0
|
323 end
|
Chris@0
|
324
|
Chris@0
|
325 def test_destroy_parent_with_reassign
|
Chris@0
|
326 @request.session[:user_id] = 2
|
Chris@0
|
327 assert_difference('WikiPage.count', -1) do
|
chris@37
|
328 delete :destroy, :project_id => 1, :id => 'Another_page', :todo => 'reassign', :reassign_to_id => 1
|
Chris@0
|
329 end
|
chris@37
|
330 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
|
Chris@0
|
331 assert_nil WikiPage.find_by_id(2)
|
Chris@0
|
332 assert_equal WikiPage.find(1), WikiPage.find_by_id(5).parent
|
Chris@0
|
333 end
|
Chris@0
|
334
|
chris@37
|
335 def test_index
|
chris@37
|
336 get :index, :project_id => 'ecookbook'
|
Chris@0
|
337 assert_response :success
|
chris@37
|
338 assert_template 'index'
|
Chris@0
|
339 pages = assigns(:pages)
|
Chris@0
|
340 assert_not_nil pages
|
Chris@0
|
341 assert_equal Project.find(1).wiki.pages.size, pages.size
|
Chris@0
|
342
|
Chris@0
|
343 assert_tag :ul, :attributes => { :class => 'pages-hierarchy' },
|
Chris@0
|
344 :child => { :tag => 'li', :child => { :tag => 'a', :attributes => { :href => '/projects/ecookbook/wiki/CookBook_documentation' },
|
Chris@0
|
345 :content => 'CookBook documentation' },
|
Chris@0
|
346 :child => { :tag => 'ul',
|
Chris@0
|
347 :child => { :tag => 'li',
|
Chris@0
|
348 :child => { :tag => 'a', :attributes => { :href => '/projects/ecookbook/wiki/Page_with_an_inline_image' },
|
Chris@0
|
349 :content => 'Page with an inline image' } } } },
|
Chris@0
|
350 :child => { :tag => 'li', :child => { :tag => 'a', :attributes => { :href => '/projects/ecookbook/wiki/Another_page' },
|
Chris@0
|
351 :content => 'Another page' } }
|
Chris@0
|
352 end
|
chris@37
|
353
|
chris@37
|
354 context "GET :export" do
|
chris@37
|
355 context "with an authorized user to export the wiki" do
|
chris@37
|
356 setup do
|
chris@37
|
357 @request.session[:user_id] = 2
|
chris@37
|
358 get :export, :project_id => 'ecookbook'
|
chris@37
|
359 end
|
chris@37
|
360
|
chris@37
|
361 should_respond_with :success
|
chris@37
|
362 should_assign_to :pages
|
chris@37
|
363 should_respond_with_content_type "text/html"
|
chris@37
|
364 should "export all of the wiki pages to a single html file" do
|
chris@37
|
365 assert_select "a[name=?]", "CookBook_documentation"
|
chris@37
|
366 assert_select "a[name=?]", "Another_page"
|
chris@37
|
367 assert_select "a[name=?]", "Page_with_an_inline_image"
|
chris@37
|
368 end
|
chris@37
|
369
|
chris@37
|
370 end
|
chris@37
|
371
|
chris@37
|
372 context "with an unauthorized user" do
|
chris@37
|
373 setup do
|
chris@37
|
374 get :export, :project_id => 'ecookbook'
|
chris@37
|
375
|
chris@37
|
376 should_respond_with :redirect
|
chris@37
|
377 should_redirect_to('wiki index') { {:action => 'show', :project_id => @project, :id => nil} }
|
chris@37
|
378 end
|
chris@37
|
379 end
|
chris@37
|
380 end
|
chris@37
|
381
|
chris@37
|
382 context "GET :date_index" do
|
chris@37
|
383 setup do
|
chris@37
|
384 get :date_index, :project_id => 'ecookbook'
|
chris@37
|
385 end
|
chris@37
|
386
|
chris@37
|
387 should_respond_with :success
|
chris@37
|
388 should_assign_to :pages
|
chris@37
|
389 should_assign_to :pages_by_date
|
chris@37
|
390 should_render_template 'wiki/date_index'
|
chris@37
|
391
|
chris@37
|
392 end
|
Chris@0
|
393
|
Chris@0
|
394 def test_not_found
|
chris@37
|
395 get :show, :project_id => 999
|
Chris@0
|
396 assert_response 404
|
Chris@0
|
397 end
|
Chris@0
|
398
|
Chris@0
|
399 def test_protect_page
|
Chris@0
|
400 page = WikiPage.find_by_wiki_id_and_title(1, 'Another_page')
|
Chris@0
|
401 assert !page.protected?
|
Chris@0
|
402 @request.session[:user_id] = 2
|
chris@37
|
403 post :protect, :project_id => 1, :id => page.title, :protected => '1'
|
chris@37
|
404 assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'Another_page'
|
Chris@0
|
405 assert page.reload.protected?
|
Chris@0
|
406 end
|
Chris@0
|
407
|
Chris@0
|
408 def test_unprotect_page
|
Chris@0
|
409 page = WikiPage.find_by_wiki_id_and_title(1, 'CookBook_documentation')
|
Chris@0
|
410 assert page.protected?
|
Chris@0
|
411 @request.session[:user_id] = 2
|
chris@37
|
412 post :protect, :project_id => 1, :id => page.title, :protected => '0'
|
chris@37
|
413 assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'CookBook_documentation'
|
Chris@0
|
414 assert !page.reload.protected?
|
Chris@0
|
415 end
|
Chris@0
|
416
|
Chris@0
|
417 def test_show_page_with_edit_link
|
Chris@0
|
418 @request.session[:user_id] = 2
|
chris@37
|
419 get :show, :project_id => 1
|
Chris@0
|
420 assert_response :success
|
Chris@0
|
421 assert_template 'show'
|
Chris@0
|
422 assert_tag :tag => 'a', :attributes => { :href => '/projects/1/wiki/CookBook_documentation/edit' }
|
Chris@0
|
423 end
|
Chris@0
|
424
|
Chris@0
|
425 def test_show_page_without_edit_link
|
Chris@0
|
426 @request.session[:user_id] = 4
|
chris@37
|
427 get :show, :project_id => 1
|
Chris@0
|
428 assert_response :success
|
Chris@0
|
429 assert_template 'show'
|
Chris@0
|
430 assert_no_tag :tag => 'a', :attributes => { :href => '/projects/1/wiki/CookBook_documentation/edit' }
|
Chris@0
|
431 end
|
Chris@0
|
432
|
Chris@0
|
433 def test_edit_unprotected_page
|
Chris@0
|
434 # Non members can edit unprotected wiki pages
|
Chris@0
|
435 @request.session[:user_id] = 4
|
chris@37
|
436 get :edit, :project_id => 1, :id => 'Another_page'
|
Chris@0
|
437 assert_response :success
|
Chris@0
|
438 assert_template 'edit'
|
Chris@0
|
439 end
|
Chris@0
|
440
|
Chris@0
|
441 def test_edit_protected_page_by_nonmember
|
Chris@0
|
442 # Non members can't edit protected wiki pages
|
Chris@0
|
443 @request.session[:user_id] = 4
|
chris@37
|
444 get :edit, :project_id => 1, :id => 'CookBook_documentation'
|
Chris@0
|
445 assert_response 403
|
Chris@0
|
446 end
|
Chris@0
|
447
|
Chris@0
|
448 def test_edit_protected_page_by_member
|
Chris@0
|
449 @request.session[:user_id] = 2
|
chris@37
|
450 get :edit, :project_id => 1, :id => 'CookBook_documentation'
|
Chris@0
|
451 assert_response :success
|
Chris@0
|
452 assert_template 'edit'
|
Chris@0
|
453 end
|
Chris@0
|
454
|
Chris@0
|
455 def test_history_of_non_existing_page_should_return_404
|
chris@37
|
456 get :history, :project_id => 1, :id => 'Unknown_page'
|
Chris@0
|
457 assert_response 404
|
Chris@0
|
458 end
|
Chris@0
|
459 end
|