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