##// END OF EJS Templates
Adds a combo to select parent on wiki page rename (#5136)....
Jean-Philippe Lang -
r4261:666c54e86c2a
parent child
Show More
@@ -1,69 +1,69
1 1 # redMine - project management software
2 2 # Copyright (C) 2006-2007 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 module WikiHelper
19 19
20 20 def wiki_page_options_for_select(pages, selected = nil, parent = nil, level = 0)
21 21 s = ''
22 22 pages.select {|p| p.parent == parent}.each do |page|
23 23 attrs = "value='#{page.id}'"
24 24 attrs << " selected='selected'" if selected == page
25 25 indent = (level > 0) ? ('&nbsp;' * level * 2 + '&#187; ') : nil
26 26
27 s << "<option value='#{page.id}'>#{indent}#{h page.pretty_title}</option>\n" +
27 s << "<option #{attrs}>#{indent}#{h page.pretty_title}</option>\n" +
28 28 wiki_page_options_for_select(pages, selected, page, level + 1)
29 29 end
30 30 s
31 31 end
32 32
33 33 def html_diff(wdiff)
34 34 words = wdiff.words.collect{|word| h(word)}
35 35 words_add = 0
36 36 words_del = 0
37 37 dels = 0
38 38 del_off = 0
39 39 wdiff.diff.diffs.each do |diff|
40 40 add_at = nil
41 41 add_to = nil
42 42 del_at = nil
43 43 deleted = ""
44 44 diff.each do |change|
45 45 pos = change[1]
46 46 if change[0] == "+"
47 47 add_at = pos + dels unless add_at
48 48 add_to = pos + dels
49 49 words_add += 1
50 50 else
51 51 del_at = pos unless del_at
52 52 deleted << ' ' + h(change[2])
53 53 words_del += 1
54 54 end
55 55 end
56 56 if add_at
57 57 words[add_at] = '<span class="diff_in">' + words[add_at]
58 58 words[add_to] = words[add_to] + '</span>'
59 59 end
60 60 if del_at
61 61 words.insert del_at - del_off + dels + words_add, '<span class="diff_out">' + deleted + '</span>'
62 62 dels += 1
63 63 del_off += words_del
64 64 words_del = 0
65 65 end
66 66 end
67 67 simple_format_without_paragraph(words.join(' '))
68 68 end
69 69 end
@@ -1,12 +1,12
1 1 <h2><%= l(:button_rename) %>: <%= @original_title %></h2>
2 2
3 3 <%= error_messages_for 'page' %>
4 4
5 5 <% labelled_tabular_form_for :wiki_page, @page, :url => { :action => 'rename' } do |f| %>
6 6 <div class="box">
7 7 <p><%= f.text_field :title, :required => true, :size => 100 %></p>
8 8 <p><%= f.check_box :redirect_existing_links %></p>
9 <p><%= f.text_field :parent_title, :size => 100 %></p>
9 <p><%= f.select :parent_id, "<option value=''></option>" + wiki_page_options_for_select(@wiki.pages.all(:include => :parent) - @page.self_and_descendants, @page.parent), :label => :field_parent_title %></p>
10 10 </div>
11 11 <%= submit_tag l(:button_rename) %>
12 12 <% end %>
@@ -1,365 +1,413
1 1 # redMine - project management software
2 2 # Copyright (C) 2006-2007 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.dirname(__FILE__) + '/../test_helper'
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 47 def test_show_page_with_name
48 48 get :show, :project_id => 1, :id => 'Another_page'
49 49 assert_response :success
50 50 assert_template 'show'
51 51 assert_tag :tag => 'h1', :content => /Another page/
52 52 # Included page with an inline image
53 53 assert_tag :tag => 'p', :content => /This is an inline image/
54 54 assert_tag :tag => 'img', :attributes => { :src => '/attachments/download/3',
55 55 :alt => 'This is a logo' }
56 56 end
57 57
58 58 def test_show_with_sidebar
59 59 page = Project.find(1).wiki.pages.new(:title => 'Sidebar')
60 60 page.content = WikiContent.new(:text => 'Side bar content for test_show_with_sidebar')
61 61 page.save!
62 62
63 63 get :show, :project_id => 1, :id => 'Another_page'
64 64 assert_response :success
65 65 assert_tag :tag => 'div', :attributes => {:id => 'sidebar'},
66 66 :content => /Side bar content for test_show_with_sidebar/
67 67 end
68 68
69 69 def test_show_unexistent_page_without_edit_right
70 70 get :show, :project_id => 1, :id => 'Unexistent page'
71 71 assert_response 404
72 72 end
73 73
74 74 def test_show_unexistent_page_with_edit_right
75 75 @request.session[:user_id] = 2
76 76 get :show, :project_id => 1, :id => 'Unexistent page'
77 77 assert_response :success
78 78 assert_template 'edit'
79 79 end
80 80
81 81 def test_create_page
82 82 @request.session[:user_id] = 2
83 83 put :update, :project_id => 1,
84 84 :id => 'New page',
85 85 :content => {:comments => 'Created the page',
86 86 :text => "h1. New page\n\nThis is a new page",
87 87 :version => 0}
88 88 assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'New_page'
89 89 page = Project.find(1).wiki.find_page('New page')
90 90 assert !page.new_record?
91 91 assert_not_nil page.content
92 92 assert_equal 'Created the page', page.content.comments
93 93 end
94 94
95 95 def test_create_page_with_attachments
96 96 @request.session[:user_id] = 2
97 97 assert_difference 'WikiPage.count' do
98 98 assert_difference 'Attachment.count' do
99 99 put :update, :project_id => 1,
100 100 :id => 'New page',
101 101 :content => {:comments => 'Created the page',
102 102 :text => "h1. New page\n\nThis is a new page",
103 103 :version => 0},
104 104 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}}
105 105 end
106 106 end
107 107 page = Project.find(1).wiki.find_page('New page')
108 108 assert_equal 1, page.attachments.count
109 109 assert_equal 'testfile.txt', page.attachments.first.filename
110 110 end
111 111
112 112 def test_preview
113 113 @request.session[:user_id] = 2
114 114 xhr :post, :preview, :project_id => 1, :id => 'CookBook_documentation',
115 115 :content => { :comments => '',
116 116 :text => 'this is a *previewed text*',
117 117 :version => 3 }
118 118 assert_response :success
119 119 assert_template 'common/_preview'
120 120 assert_tag :tag => 'strong', :content => /previewed text/
121 121 end
122 122
123 123 def test_preview_new_page
124 124 @request.session[:user_id] = 2
125 125 xhr :post, :preview, :project_id => 1, :id => 'New page',
126 126 :content => { :text => 'h1. New page',
127 127 :comments => '',
128 128 :version => 0 }
129 129 assert_response :success
130 130 assert_template 'common/_preview'
131 131 assert_tag :tag => 'h1', :content => /New page/
132 132 end
133 133
134 134 def test_history
135 135 get :history, :project_id => 1, :id => 'CookBook_documentation'
136 136 assert_response :success
137 137 assert_template 'history'
138 138 assert_not_nil assigns(:versions)
139 139 assert_equal 3, assigns(:versions).size
140 140 assert_select "input[type=submit][name=commit]"
141 141 end
142 142
143 143 def test_history_with_one_version
144 144 get :history, :project_id => 1, :id => 'Another_page'
145 145 assert_response :success
146 146 assert_template 'history'
147 147 assert_not_nil assigns(:versions)
148 148 assert_equal 1, assigns(:versions).size
149 149 assert_select "input[type=submit][name=commit]", false
150 150 end
151 151
152 152 def test_diff
153 153 get :diff, :project_id => 1, :id => 'CookBook_documentation', :version => 2, :version_from => 1
154 154 assert_response :success
155 155 assert_template 'diff'
156 156 assert_tag :tag => 'span', :attributes => { :class => 'diff_in'},
157 157 :content => /updated/
158 158 end
159 159
160 160 def test_annotate
161 161 get :annotate, :project_id => 1, :id => 'CookBook_documentation', :version => 2
162 162 assert_response :success
163 163 assert_template 'annotate'
164 164 # Line 1
165 165 assert_tag :tag => 'tr', :child => { :tag => 'th', :attributes => {:class => 'line-num'}, :content => '1' },
166 166 :child => { :tag => 'td', :attributes => {:class => 'author'}, :content => /John Smith/ },
167 167 :child => { :tag => 'td', :content => /h1\. CookBook documentation/ }
168 168 # Line 2
169 169 assert_tag :tag => 'tr', :child => { :tag => 'th', :attributes => {:class => 'line-num'}, :content => '2' },
170 170 :child => { :tag => 'td', :attributes => {:class => 'author'}, :content => /redMine Admin/ },
171 171 :child => { :tag => 'td', :content => /Some updated \[\[documentation\]\] here/ }
172 172 end
173
174 def test_get_rename
175 @request.session[:user_id] = 2
176 get :rename, :project_id => 1, :id => 'Another_page'
177 assert_response :success
178 assert_template 'rename'
179 assert_tag 'option',
180 :attributes => {:value => ''},
181 :content => '',
182 :parent => {:tag => 'select', :attributes => {:name => 'wiki_page[parent_id]'}}
183 assert_no_tag 'option',
184 :attributes => {:selected => 'selected'},
185 :parent => {:tag => 'select', :attributes => {:name => 'wiki_page[parent_id]'}}
186 end
187
188 def test_get_rename_child_page
189 @request.session[:user_id] = 2
190 get :rename, :project_id => 1, :id => 'Child_1'
191 assert_response :success
192 assert_template 'rename'
193 assert_tag 'option',
194 :attributes => {:value => ''},
195 :content => '',
196 :parent => {:tag => 'select', :attributes => {:name => 'wiki_page[parent_id]'}}
197 assert_tag 'option',
198 :attributes => {:value => '2', :selected => 'selected'},
199 :content => /Another page/,
200 :parent => {
201 :tag => 'select',
202 :attributes => {:name => 'wiki_page[parent_id]'}
203 }
204 end
173 205
174 206 def test_rename_with_redirect
175 207 @request.session[:user_id] = 2
176 208 post :rename, :project_id => 1, :id => 'Another_page',
177 209 :wiki_page => { :title => 'Another renamed page',
178 210 :redirect_existing_links => 1 }
179 211 assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'Another_renamed_page'
180 212 wiki = Project.find(1).wiki
181 213 # Check redirects
182 214 assert_not_nil wiki.find_page('Another page')
183 215 assert_nil wiki.find_page('Another page', :with_redirect => false)
184 216 end
185 217
186 218 def test_rename_without_redirect
187 219 @request.session[:user_id] = 2
188 220 post :rename, :project_id => 1, :id => 'Another_page',
189 221 :wiki_page => { :title => 'Another renamed page',
190 222 :redirect_existing_links => "0" }
191 223 assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'Another_renamed_page'
192 224 wiki = Project.find(1).wiki
193 225 # Check that there's no redirects
194 226 assert_nil wiki.find_page('Another page')
195 227 end
196 228
229 def test_rename_with_parent_assignment
230 @request.session[:user_id] = 2
231 post :rename, :project_id => 1, :id => 'Another_page',
232 :wiki_page => { :title => 'Another page', :redirect_existing_links => "0", :parent_id => '4' }
233 assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'Another_page'
234 assert_equal WikiPage.find(4), WikiPage.find_by_title('Another_page').parent
235 end
236
237 def test_rename_with_parent_unassignment
238 @request.session[:user_id] = 2
239 post :rename, :project_id => 1, :id => 'Child_1',
240 :wiki_page => { :title => 'Child 1', :redirect_existing_links => "0", :parent_id => '' }
241 assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'Child_1'
242 assert_nil WikiPage.find_by_title('Child_1').parent
243 end
244
197 245 def test_destroy_child
198 246 @request.session[:user_id] = 2
199 247 delete :destroy, :project_id => 1, :id => 'Child_1'
200 248 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
201 249 end
202 250
203 251 def test_destroy_parent
204 252 @request.session[:user_id] = 2
205 253 assert_no_difference('WikiPage.count') do
206 254 delete :destroy, :project_id => 1, :id => 'Another_page'
207 255 end
208 256 assert_response :success
209 257 assert_template 'destroy'
210 258 end
211 259
212 260 def test_destroy_parent_with_nullify
213 261 @request.session[:user_id] = 2
214 262 assert_difference('WikiPage.count', -1) do
215 263 delete :destroy, :project_id => 1, :id => 'Another_page', :todo => 'nullify'
216 264 end
217 265 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
218 266 assert_nil WikiPage.find_by_id(2)
219 267 end
220 268
221 269 def test_destroy_parent_with_cascade
222 270 @request.session[:user_id] = 2
223 271 assert_difference('WikiPage.count', -3) do
224 272 delete :destroy, :project_id => 1, :id => 'Another_page', :todo => 'destroy'
225 273 end
226 274 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
227 275 assert_nil WikiPage.find_by_id(2)
228 276 assert_nil WikiPage.find_by_id(5)
229 277 end
230 278
231 279 def test_destroy_parent_with_reassign
232 280 @request.session[:user_id] = 2
233 281 assert_difference('WikiPage.count', -1) do
234 282 delete :destroy, :project_id => 1, :id => 'Another_page', :todo => 'reassign', :reassign_to_id => 1
235 283 end
236 284 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
237 285 assert_nil WikiPage.find_by_id(2)
238 286 assert_equal WikiPage.find(1), WikiPage.find_by_id(5).parent
239 287 end
240 288
241 289 def test_index
242 290 get :index, :project_id => 'ecookbook'
243 291 assert_response :success
244 292 assert_template 'index'
245 293 pages = assigns(:pages)
246 294 assert_not_nil pages
247 295 assert_equal Project.find(1).wiki.pages.size, pages.size
248 296
249 297 assert_tag :ul, :attributes => { :class => 'pages-hierarchy' },
250 298 :child => { :tag => 'li', :child => { :tag => 'a', :attributes => { :href => '/projects/ecookbook/wiki/CookBook_documentation' },
251 299 :content => 'CookBook documentation' },
252 300 :child => { :tag => 'ul',
253 301 :child => { :tag => 'li',
254 302 :child => { :tag => 'a', :attributes => { :href => '/projects/ecookbook/wiki/Page_with_an_inline_image' },
255 303 :content => 'Page with an inline image' } } } },
256 304 :child => { :tag => 'li', :child => { :tag => 'a', :attributes => { :href => '/projects/ecookbook/wiki/Another_page' },
257 305 :content => 'Another page' } }
258 306 end
259 307
260 308 context "GET :export" do
261 309 context "with an authorized user to export the wiki" do
262 310 setup do
263 311 @request.session[:user_id] = 2
264 312 get :export, :project_id => 'ecookbook'
265 313 end
266 314
267 315 should_respond_with :success
268 316 should_assign_to :pages
269 317 should_respond_with_content_type "text/html"
270 318 should "export all of the wiki pages to a single html file" do
271 319 assert_select "a[name=?]", "CookBook_documentation"
272 320 assert_select "a[name=?]", "Another_page"
273 321 assert_select "a[name=?]", "Page_with_an_inline_image"
274 322 end
275 323
276 324 end
277 325
278 326 context "with an unauthorized user" do
279 327 setup do
280 328 get :export, :project_id => 'ecookbook'
281 329
282 330 should_respond_with :redirect
283 331 should_redirect_to('wiki index') { {:action => 'show', :project_id => @project, :id => nil} }
284 332 end
285 333 end
286 334 end
287 335
288 336 context "GET :date_index" do
289 337 setup do
290 338 get :date_index, :project_id => 'ecookbook'
291 339 end
292 340
293 341 should_respond_with :success
294 342 should_assign_to :pages
295 343 should_assign_to :pages_by_date
296 344 should_render_template 'wiki/date_index'
297 345
298 346 end
299 347
300 348 def test_not_found
301 349 get :show, :project_id => 999
302 350 assert_response 404
303 351 end
304 352
305 353 def test_protect_page
306 354 page = WikiPage.find_by_wiki_id_and_title(1, 'Another_page')
307 355 assert !page.protected?
308 356 @request.session[:user_id] = 2
309 357 post :protect, :project_id => 1, :id => page.title, :protected => '1'
310 358 assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'Another_page'
311 359 assert page.reload.protected?
312 360 end
313 361
314 362 def test_unprotect_page
315 363 page = WikiPage.find_by_wiki_id_and_title(1, 'CookBook_documentation')
316 364 assert page.protected?
317 365 @request.session[:user_id] = 2
318 366 post :protect, :project_id => 1, :id => page.title, :protected => '0'
319 367 assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'CookBook_documentation'
320 368 assert !page.reload.protected?
321 369 end
322 370
323 371 def test_show_page_with_edit_link
324 372 @request.session[:user_id] = 2
325 373 get :show, :project_id => 1
326 374 assert_response :success
327 375 assert_template 'show'
328 376 assert_tag :tag => 'a', :attributes => { :href => '/projects/1/wiki/CookBook_documentation/edit' }
329 377 end
330 378
331 379 def test_show_page_without_edit_link
332 380 @request.session[:user_id] = 4
333 381 get :show, :project_id => 1
334 382 assert_response :success
335 383 assert_template 'show'
336 384 assert_no_tag :tag => 'a', :attributes => { :href => '/projects/1/wiki/CookBook_documentation/edit' }
337 385 end
338 386
339 387 def test_edit_unprotected_page
340 388 # Non members can edit unprotected wiki pages
341 389 @request.session[:user_id] = 4
342 390 get :edit, :project_id => 1, :id => 'Another_page'
343 391 assert_response :success
344 392 assert_template 'edit'
345 393 end
346 394
347 395 def test_edit_protected_page_by_nonmember
348 396 # Non members can't edit protected wiki pages
349 397 @request.session[:user_id] = 4
350 398 get :edit, :project_id => 1, :id => 'CookBook_documentation'
351 399 assert_response 403
352 400 end
353 401
354 402 def test_edit_protected_page_by_member
355 403 @request.session[:user_id] = 2
356 404 get :edit, :project_id => 1, :id => 'CookBook_documentation'
357 405 assert_response :success
358 406 assert_template 'edit'
359 407 end
360 408
361 409 def test_history_of_non_existing_page_should_return_404
362 410 get :history, :project_id => 1, :id => 'Unknown_page'
363 411 assert_response 404
364 412 end
365 413 end
General Comments 0
You need to be logged in to leave comments. Login now