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