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