Mercurial > hg > soundsoftware-site
comparison test/functional/.svn/text-base/wiki_controller_test.rb.svn-base @ 0:513646585e45
* Import Redmine trunk SVN rev 3859
author | Chris Cannam |
---|---|
date | Fri, 23 Jul 2010 15:52:44 +0100 |
parents | |
children | 94944d00e43c |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:513646585e45 |
---|---|
1 # redMine - project management software | |
2 # Copyright (C) 2006-2007 Jean-Philippe Lang | |
3 # | |
4 # This program is free software; you can redistribute it and/or | |
5 # modify it under the terms of the GNU General Public License | |
6 # as published by the Free Software Foundation; either version 2 | |
7 # of the License, or (at your option) any later version. | |
8 # | |
9 # This program is distributed in the hope that it will be useful, | |
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 # GNU General Public License for more details. | |
13 # | |
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 | |
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
17 | |
18 require File.dirname(__FILE__) + '/../test_helper' | |
19 require 'wiki_controller' | |
20 | |
21 # Re-raise errors caught by the controller. | |
22 class WikiController; def rescue_action(e) raise e end; end | |
23 | |
24 class WikiControllerTest < ActionController::TestCase | |
25 fixtures :projects, :users, :roles, :members, :member_roles, :enabled_modules, :wikis, :wiki_pages, :wiki_contents, :wiki_content_versions, :attachments | |
26 | |
27 def setup | |
28 @controller = WikiController.new | |
29 @request = ActionController::TestRequest.new | |
30 @response = ActionController::TestResponse.new | |
31 User.current = nil | |
32 end | |
33 | |
34 def test_show_start_page | |
35 get :index, :id => 'ecookbook' | |
36 assert_response :success | |
37 assert_template 'show' | |
38 assert_tag :tag => 'h1', :content => /CookBook documentation/ | |
39 | |
40 # child_pages macro | |
41 assert_tag :ul, :attributes => { :class => 'pages-hierarchy' }, | |
42 :child => { :tag => 'li', | |
43 :child => { :tag => 'a', :attributes => { :href => '/projects/ecookbook/wiki/Page_with_an_inline_image' }, | |
44 :content => 'Page with an inline image' } } | |
45 end | |
46 | |
47 def test_show_page_with_name | |
48 get :index, :id => 1, :page => 'Another_page' | |
49 assert_response :success | |
50 assert_template 'show' | |
51 assert_tag :tag => 'h1', :content => /Another page/ | |
52 # Included page with an inline image | |
53 assert_tag :tag => 'p', :content => /This is an inline image/ | |
54 assert_tag :tag => 'img', :attributes => { :src => '/attachments/download/3', | |
55 :alt => 'This is a logo' } | |
56 end | |
57 | |
58 def test_show_with_sidebar | |
59 page = Project.find(1).wiki.pages.new(:title => 'Sidebar') | |
60 page.content = WikiContent.new(:text => 'Side bar content for test_show_with_sidebar') | |
61 page.save! | |
62 | |
63 get :index, :id => 1, :page => 'Another_page' | |
64 assert_response :success | |
65 assert_tag :tag => 'div', :attributes => {:id => 'sidebar'}, | |
66 :content => /Side bar content for test_show_with_sidebar/ | |
67 end | |
68 | |
69 def test_show_unexistent_page_without_edit_right | |
70 get :index, :id => 1, :page => 'Unexistent page' | |
71 assert_response 404 | |
72 end | |
73 | |
74 def test_show_unexistent_page_with_edit_right | |
75 @request.session[:user_id] = 2 | |
76 get :index, :id => 1, :page => 'Unexistent page' | |
77 assert_response :success | |
78 assert_template 'edit' | |
79 end | |
80 | |
81 def test_create_page | |
82 @request.session[:user_id] = 2 | |
83 post :edit, :id => 1, | |
84 :page => 'New page', | |
85 :content => {:comments => 'Created the page', | |
86 :text => "h1. New page\n\nThis is a new page", | |
87 :version => 0} | |
88 assert_redirected_to :action => 'index', :id => 'ecookbook', :page => 'New_page' | |
89 page = Project.find(1).wiki.find_page('New page') | |
90 assert !page.new_record? | |
91 assert_not_nil page.content | |
92 assert_equal 'Created the page', page.content.comments | |
93 end | |
94 | |
95 def test_create_page_with_attachments | |
96 @request.session[:user_id] = 2 | |
97 assert_difference 'WikiPage.count' do | |
98 assert_difference 'Attachment.count' do | |
99 post :edit, :id => 1, | |
100 :page => 'New page', | |
101 :content => {:comments => 'Created the page', | |
102 :text => "h1. New page\n\nThis is a new page", | |
103 :version => 0}, | |
104 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}} | |
105 end | |
106 end | |
107 page = Project.find(1).wiki.find_page('New page') | |
108 assert_equal 1, page.attachments.count | |
109 assert_equal 'testfile.txt', page.attachments.first.filename | |
110 end | |
111 | |
112 def test_preview | |
113 @request.session[:user_id] = 2 | |
114 xhr :post, :preview, :id => 1, :page => 'CookBook_documentation', | |
115 :content => { :comments => '', | |
116 :text => 'this is a *previewed text*', | |
117 :version => 3 } | |
118 assert_response :success | |
119 assert_template 'common/_preview' | |
120 assert_tag :tag => 'strong', :content => /previewed text/ | |
121 end | |
122 | |
123 def test_preview_new_page | |
124 @request.session[:user_id] = 2 | |
125 xhr :post, :preview, :id => 1, :page => 'New page', | |
126 :content => { :text => 'h1. New page', | |
127 :comments => '', | |
128 :version => 0 } | |
129 assert_response :success | |
130 assert_template 'common/_preview' | |
131 assert_tag :tag => 'h1', :content => /New page/ | |
132 end | |
133 | |
134 def test_history | |
135 get :history, :id => 1, :page => 'CookBook_documentation' | |
136 assert_response :success | |
137 assert_template 'history' | |
138 assert_not_nil assigns(:versions) | |
139 assert_equal 3, assigns(:versions).size | |
140 assert_select "input[type=submit][name=commit]" | |
141 end | |
142 | |
143 def test_history_with_one_version | |
144 get :history, :id => 1, :page => 'Another_page' | |
145 assert_response :success | |
146 assert_template 'history' | |
147 assert_not_nil assigns(:versions) | |
148 assert_equal 1, assigns(:versions).size | |
149 assert_select "input[type=submit][name=commit]", false | |
150 end | |
151 | |
152 def test_diff | |
153 get :diff, :id => 1, :page => 'CookBook_documentation', :version => 2, :version_from => 1 | |
154 assert_response :success | |
155 assert_template 'diff' | |
156 assert_tag :tag => 'span', :attributes => { :class => 'diff_in'}, | |
157 :content => /updated/ | |
158 end | |
159 | |
160 def test_annotate | |
161 get :annotate, :id => 1, :page => 'CookBook_documentation', :version => 2 | |
162 assert_response :success | |
163 assert_template 'annotate' | |
164 # Line 1 | |
165 assert_tag :tag => 'tr', :child => { :tag => 'th', :attributes => {:class => 'line-num'}, :content => '1' }, | |
166 :child => { :tag => 'td', :attributes => {:class => 'author'}, :content => /John Smith/ }, | |
167 :child => { :tag => 'td', :content => /h1\. CookBook documentation/ } | |
168 # Line 2 | |
169 assert_tag :tag => 'tr', :child => { :tag => 'th', :attributes => {:class => 'line-num'}, :content => '2' }, | |
170 :child => { :tag => 'td', :attributes => {:class => 'author'}, :content => /redMine Admin/ }, | |
171 :child => { :tag => 'td', :content => /Some updated \[\[documentation\]\] here/ } | |
172 end | |
173 | |
174 def test_rename_with_redirect | |
175 @request.session[:user_id] = 2 | |
176 post :rename, :id => 1, :page => 'Another_page', | |
177 :wiki_page => { :title => 'Another renamed page', | |
178 :redirect_existing_links => 1 } | |
179 assert_redirected_to :action => 'index', :id => 'ecookbook', :page => 'Another_renamed_page' | |
180 wiki = Project.find(1).wiki | |
181 # Check redirects | |
182 assert_not_nil wiki.find_page('Another page') | |
183 assert_nil wiki.find_page('Another page', :with_redirect => false) | |
184 end | |
185 | |
186 def test_rename_without_redirect | |
187 @request.session[:user_id] = 2 | |
188 post :rename, :id => 1, :page => 'Another_page', | |
189 :wiki_page => { :title => 'Another renamed page', | |
190 :redirect_existing_links => "0" } | |
191 assert_redirected_to :action => 'index', :id => 'ecookbook', :page => 'Another_renamed_page' | |
192 wiki = Project.find(1).wiki | |
193 # Check that there's no redirects | |
194 assert_nil wiki.find_page('Another page') | |
195 end | |
196 | |
197 def test_destroy_child | |
198 @request.session[:user_id] = 2 | |
199 post :destroy, :id => 1, :page => 'Child_1' | |
200 assert_redirected_to :action => 'special', :id => 'ecookbook', :page => 'Page_index' | |
201 end | |
202 | |
203 def test_destroy_parent | |
204 @request.session[:user_id] = 2 | |
205 assert_no_difference('WikiPage.count') do | |
206 post :destroy, :id => 1, :page => 'Another_page' | |
207 end | |
208 assert_response :success | |
209 assert_template 'destroy' | |
210 end | |
211 | |
212 def test_destroy_parent_with_nullify | |
213 @request.session[:user_id] = 2 | |
214 assert_difference('WikiPage.count', -1) do | |
215 post :destroy, :id => 1, :page => 'Another_page', :todo => 'nullify' | |
216 end | |
217 assert_redirected_to :action => 'special', :id => 'ecookbook', :page => 'Page_index' | |
218 assert_nil WikiPage.find_by_id(2) | |
219 end | |
220 | |
221 def test_destroy_parent_with_cascade | |
222 @request.session[:user_id] = 2 | |
223 assert_difference('WikiPage.count', -3) do | |
224 post :destroy, :id => 1, :page => 'Another_page', :todo => 'destroy' | |
225 end | |
226 assert_redirected_to :action => 'special', :id => 'ecookbook', :page => 'Page_index' | |
227 assert_nil WikiPage.find_by_id(2) | |
228 assert_nil WikiPage.find_by_id(5) | |
229 end | |
230 | |
231 def test_destroy_parent_with_reassign | |
232 @request.session[:user_id] = 2 | |
233 assert_difference('WikiPage.count', -1) do | |
234 post :destroy, :id => 1, :page => 'Another_page', :todo => 'reassign', :reassign_to_id => 1 | |
235 end | |
236 assert_redirected_to :action => 'special', :id => 'ecookbook', :page => 'Page_index' | |
237 assert_nil WikiPage.find_by_id(2) | |
238 assert_equal WikiPage.find(1), WikiPage.find_by_id(5).parent | |
239 end | |
240 | |
241 def test_page_index | |
242 get :special, :id => 'ecookbook', :page => 'Page_index' | |
243 assert_response :success | |
244 assert_template 'special_page_index' | |
245 pages = assigns(:pages) | |
246 assert_not_nil pages | |
247 assert_equal Project.find(1).wiki.pages.size, pages.size | |
248 | |
249 assert_tag :ul, :attributes => { :class => 'pages-hierarchy' }, | |
250 :child => { :tag => 'li', :child => { :tag => 'a', :attributes => { :href => '/projects/ecookbook/wiki/CookBook_documentation' }, | |
251 :content => 'CookBook documentation' }, | |
252 :child => { :tag => 'ul', | |
253 :child => { :tag => 'li', | |
254 :child => { :tag => 'a', :attributes => { :href => '/projects/ecookbook/wiki/Page_with_an_inline_image' }, | |
255 :content => 'Page with an inline image' } } } }, | |
256 :child => { :tag => 'li', :child => { :tag => 'a', :attributes => { :href => '/projects/ecookbook/wiki/Another_page' }, | |
257 :content => 'Another page' } } | |
258 end | |
259 | |
260 def test_not_found | |
261 get :index, :id => 999 | |
262 assert_response 404 | |
263 end | |
264 | |
265 def test_protect_page | |
266 page = WikiPage.find_by_wiki_id_and_title(1, 'Another_page') | |
267 assert !page.protected? | |
268 @request.session[:user_id] = 2 | |
269 post :protect, :id => 1, :page => page.title, :protected => '1' | |
270 assert_redirected_to :action => 'index', :id => 'ecookbook', :page => 'Another_page' | |
271 assert page.reload.protected? | |
272 end | |
273 | |
274 def test_unprotect_page | |
275 page = WikiPage.find_by_wiki_id_and_title(1, 'CookBook_documentation') | |
276 assert page.protected? | |
277 @request.session[:user_id] = 2 | |
278 post :protect, :id => 1, :page => page.title, :protected => '0' | |
279 assert_redirected_to :action => 'index', :id => 'ecookbook', :page => 'CookBook_documentation' | |
280 assert !page.reload.protected? | |
281 end | |
282 | |
283 def test_show_page_with_edit_link | |
284 @request.session[:user_id] = 2 | |
285 get :index, :id => 1 | |
286 assert_response :success | |
287 assert_template 'show' | |
288 assert_tag :tag => 'a', :attributes => { :href => '/projects/1/wiki/CookBook_documentation/edit' } | |
289 end | |
290 | |
291 def test_show_page_without_edit_link | |
292 @request.session[:user_id] = 4 | |
293 get :index, :id => 1 | |
294 assert_response :success | |
295 assert_template 'show' | |
296 assert_no_tag :tag => 'a', :attributes => { :href => '/projects/1/wiki/CookBook_documentation/edit' } | |
297 end | |
298 | |
299 def test_edit_unprotected_page | |
300 # Non members can edit unprotected wiki pages | |
301 @request.session[:user_id] = 4 | |
302 get :edit, :id => 1, :page => 'Another_page' | |
303 assert_response :success | |
304 assert_template 'edit' | |
305 end | |
306 | |
307 def test_edit_protected_page_by_nonmember | |
308 # Non members can't edit protected wiki pages | |
309 @request.session[:user_id] = 4 | |
310 get :edit, :id => 1, :page => 'CookBook_documentation' | |
311 assert_response 403 | |
312 end | |
313 | |
314 def test_edit_protected_page_by_member | |
315 @request.session[:user_id] = 2 | |
316 get :edit, :id => 1, :page => 'CookBook_documentation' | |
317 assert_response :success | |
318 assert_template 'edit' | |
319 end | |
320 | |
321 def test_history_of_non_existing_page_should_return_404 | |
322 get :history, :id => 1, :page => 'Unknown_page' | |
323 assert_response 404 | |
324 end | |
325 end |