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