@@ -1,69 +1,69 | |||
|
1 | 1 | <div class="contextual"> |
|
2 | 2 | <% if @editable %> |
|
3 | 3 | <%= link_to_if_authorized(l(:button_edit), {:action => 'edit', :id => @page.title}, :class => 'icon icon-edit', :accesskey => accesskey(:edit)) if @content.version == @page.content.version %> |
|
4 | 4 | <%= watcher_tag(@page, User.current) %> |
|
5 | 5 | <%= link_to_if_authorized(l(:button_lock), {:action => 'protect', :id => @page.title, :protected => 1}, :method => :post, :class => 'icon icon-lock') if !@page.protected? %> |
|
6 | 6 | <%= link_to_if_authorized(l(:button_unlock), {:action => 'protect', :id => @page.title, :protected => 0}, :method => :post, :class => 'icon icon-unlock') if @page.protected? %> |
|
7 | 7 | <%= link_to_if_authorized(l(:button_rename), {:action => 'rename', :id => @page.title}, :class => 'icon icon-move') if @content.version == @page.content.version %> |
|
8 | 8 | <%= link_to_if_authorized(l(:button_delete), {:action => 'destroy', :id => @page.title}, :method => :delete, :confirm => l(:text_are_you_sure), :class => 'icon icon-del') %> |
|
9 | 9 | <%= link_to_if_authorized(l(:button_rollback), {:action => 'edit', :id => @page.title, :version => @content.version }, :class => 'icon icon-cancel') if @content.version < @page.content.version %> |
|
10 | 10 | <% end %> |
|
11 | 11 | <%= link_to_if_authorized(l(:label_history), {:action => 'history', :id => @page.title}, :class => 'icon icon-history') %> |
|
12 | 12 | </div> |
|
13 | 13 | |
|
14 | 14 | <%= wiki_page_breadcrumb(@page) %> |
|
15 | 15 | |
|
16 | 16 | <% if @content.version != @page.content.version %> |
|
17 | 17 | <p> |
|
18 | 18 | <%= link_to(("\xc2\xab " + l(:label_previous)), |
|
19 | 19 | :action => 'show', :id => @page.title, :project_id => @page.project, |
|
20 | 20 | :version => (@content.version - 1)) + " - " if @content.version > 1 %> |
|
21 | 21 | <%= "#{l(:label_version)} #{@content.version}/#{@page.content.version}" %> |
|
22 | 22 | <%= '(' + link_to(l(:label_diff), :controller => 'wiki', :action => 'diff', |
|
23 | 23 | :id => @page.title, :project_id => @page.project, |
|
24 | 24 | :version => @content.version) + ')' if @content.version > 1 %> - |
|
25 | 25 | <%= link_to((l(:label_next) + " \xc2\xbb"), :action => 'show', |
|
26 | 26 | :id => @page.title, :project_id => @page.project, |
|
27 | 27 | :version => (@content.version + 1)) + " - " if @content.version < @page.content.version %> |
|
28 | 28 | <%= link_to(l(:label_current_version), :action => 'show', :id => @page.title, :project_id => @page.project) %> |
|
29 | 29 | <br /> |
|
30 | 30 | <em><%= @content.author ? link_to_user(@content.author) : l(:label_user_anonymous) |
|
31 | 31 | %>, <%= format_time(@content.updated_on) %> </em><br /> |
|
32 | 32 | <%=h @content.comments %> |
|
33 | 33 | </p> |
|
34 | 34 | <hr /> |
|
35 | 35 | <% end %> |
|
36 | 36 | |
|
37 | 37 | <%= render(:partial => "wiki/content", :locals => {:content => @content}) %> |
|
38 | 38 | |
|
39 | 39 | <%= link_to_attachments @page %> |
|
40 | 40 | |
|
41 | 41 | <% if @editable && authorize_for('wiki', 'add_attachment') %> |
|
42 | 42 | <div id="wiki_add_attachment"> |
|
43 | 43 | <p><%= link_to l(:label_attachment_new), {}, :onclick => "Element.show('add_attachment_form'); Element.hide(this); Element.scrollTo('add_attachment_form'); return false;", |
|
44 | 44 | :id => 'attach_files_link' %></p> |
|
45 | 45 | <% form_tag({ :controller => 'wiki', :action => 'add_attachment', :project_id => @project, :id => @page.title }, :multipart => true, :id => "add_attachment_form", :style => "display:none;") do %> |
|
46 | 46 | <div class="box"> |
|
47 | 47 | <p><%= render :partial => 'attachments/form' %></p> |
|
48 | 48 | </div> |
|
49 | 49 | <%= submit_tag l(:button_add) %> |
|
50 | 50 | <%= link_to l(:button_cancel), {}, :onclick => "Element.hide('add_attachment_form'); Element.show('attach_files_link'); return false;" %> |
|
51 | 51 | <% end %> |
|
52 | 52 | </div> |
|
53 | 53 | <% end %> |
|
54 | 54 | |
|
55 | 55 | <% other_formats_links do |f| %> |
|
56 |
<%= f.link_to 'PDF', :url => {:id => @page.title, :version => |
|
|
57 |
<%= f.link_to 'HTML', :url => {:id => @page.title, :version => |
|
|
58 |
<%= f.link_to 'TXT', :url => {:id => @page.title, :version => |
|
|
56 | <%= f.link_to 'PDF', :url => {:id => @page.title, :version => params[:version]} %> | |
|
57 | <%= f.link_to 'HTML', :url => {:id => @page.title, :version => params[:version]} %> | |
|
58 | <%= f.link_to 'TXT', :url => {:id => @page.title, :version => params[:version]} %> | |
|
59 | 59 | <% end if User.current.allowed_to?(:export_wiki_pages, @project) %> |
|
60 | 60 | |
|
61 | 61 | <% content_for :header_tags do %> |
|
62 | 62 | <%= stylesheet_link_tag 'scm' %> |
|
63 | 63 | <% end %> |
|
64 | 64 | |
|
65 | 65 | <% content_for :sidebar do %> |
|
66 | 66 | <%= render :partial => 'sidebar' %> |
|
67 | 67 | <% end %> |
|
68 | 68 | |
|
69 | 69 | <% html_title @page.pretty_title %> |
@@ -1,700 +1,707 | |||
|
1 | 1 | # Redmine - project management software |
|
2 | 2 | # Copyright (C) 2006-2011 Jean-Philippe Lang |
|
3 | 3 | # |
|
4 | 4 | # This program is free software; you can redistribute it and/or |
|
5 | 5 | # modify it under the terms of the GNU General Public License |
|
6 | 6 | # as published by the Free Software Foundation; either version 2 |
|
7 | 7 | # of the License, or (at your option) any later version. |
|
8 | 8 | # |
|
9 | 9 | # This program is distributed in the hope that it will be useful, |
|
10 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | # GNU General Public License for more details. |
|
13 | 13 | # |
|
14 | 14 | # You should have received a copy of the GNU General Public License |
|
15 | 15 | # along with this program; if not, write to the Free Software |
|
16 | 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
17 | 17 | |
|
18 | 18 | require File.expand_path('../../test_helper', __FILE__) |
|
19 | 19 | require 'wiki_controller' |
|
20 | 20 | |
|
21 | 21 | # Re-raise errors caught by the controller. |
|
22 | 22 | class WikiController; def rescue_action(e) raise e end; end |
|
23 | 23 | |
|
24 | 24 | class WikiControllerTest < ActionController::TestCase |
|
25 | 25 | fixtures :projects, :users, :roles, :members, :member_roles, |
|
26 | 26 | :enabled_modules, :wikis, :wiki_pages, :wiki_contents, |
|
27 | 27 | :wiki_content_versions, :attachments |
|
28 | 28 | |
|
29 | 29 | def setup |
|
30 | 30 | @controller = WikiController.new |
|
31 | 31 | @request = ActionController::TestRequest.new |
|
32 | 32 | @response = ActionController::TestResponse.new |
|
33 | 33 | User.current = nil |
|
34 | 34 | end |
|
35 | 35 | |
|
36 | 36 | def test_show_start_page |
|
37 | 37 | get :show, :project_id => 'ecookbook' |
|
38 | 38 | assert_response :success |
|
39 | 39 | assert_template 'show' |
|
40 | 40 | assert_tag :tag => 'h1', :content => /CookBook documentation/ |
|
41 | 41 | |
|
42 | 42 | # child_pages macro |
|
43 | 43 | assert_tag :ul, :attributes => { :class => 'pages-hierarchy' }, |
|
44 | 44 | :child => { :tag => 'li', |
|
45 | 45 | :child => { :tag => 'a', :attributes => { :href => '/projects/ecookbook/wiki/Page_with_an_inline_image' }, |
|
46 | 46 | :content => 'Page with an inline image' } } |
|
47 | 47 | end |
|
48 | 48 | |
|
49 | def test_export_link | |
|
50 | Role.anonymous.add_permission! :export_wiki_pages | |
|
51 | get :show, :project_id => 'ecookbook' | |
|
52 | assert_response :success | |
|
53 | assert_tag 'a', :attributes => {:href => '/projects/ecookbook/wiki/CookBook_documentation.txt'} | |
|
54 | end | |
|
55 | ||
|
49 | 56 | def test_show_page_with_name |
|
50 | 57 | get :show, :project_id => 1, :id => 'Another_page' |
|
51 | 58 | assert_response :success |
|
52 | 59 | assert_template 'show' |
|
53 | 60 | assert_tag :tag => 'h1', :content => /Another page/ |
|
54 | 61 | # Included page with an inline image |
|
55 | 62 | assert_tag :tag => 'p', :content => /This is an inline image/ |
|
56 | 63 | assert_tag :tag => 'img', :attributes => { :src => '/attachments/download/3', |
|
57 | 64 | :alt => 'This is a logo' } |
|
58 | 65 | end |
|
59 | 66 | |
|
60 | 67 | def test_show_redirected_page |
|
61 | 68 | WikiRedirect.create!(:wiki_id => 1, :title => 'Old_title', :redirects_to => 'Another_page') |
|
62 | 69 | |
|
63 | 70 | get :show, :project_id => 'ecookbook', :id => 'Old_title' |
|
64 | 71 | assert_redirected_to '/projects/ecookbook/wiki/Another_page' |
|
65 | 72 | end |
|
66 | 73 | |
|
67 | 74 | def test_show_with_sidebar |
|
68 | 75 | page = Project.find(1).wiki.pages.new(:title => 'Sidebar') |
|
69 | 76 | page.content = WikiContent.new(:text => 'Side bar content for test_show_with_sidebar') |
|
70 | 77 | page.save! |
|
71 | 78 | |
|
72 | 79 | get :show, :project_id => 1, :id => 'Another_page' |
|
73 | 80 | assert_response :success |
|
74 | 81 | assert_tag :tag => 'div', :attributes => {:id => 'sidebar'}, |
|
75 | 82 | :content => /Side bar content for test_show_with_sidebar/ |
|
76 | 83 | end |
|
77 | 84 | |
|
78 | 85 | def test_show_unexistent_page_without_edit_right |
|
79 | 86 | get :show, :project_id => 1, :id => 'Unexistent page' |
|
80 | 87 | assert_response 404 |
|
81 | 88 | end |
|
82 | 89 | |
|
83 | 90 | def test_show_should_display_section_edit_links |
|
84 | 91 | @request.session[:user_id] = 2 |
|
85 | 92 | get :show, :project_id => 1, :id => 'Page with sections' |
|
86 | 93 | assert_no_tag 'a', :attributes => { |
|
87 | 94 | :href => '/projects/ecookbook/wiki/Page_with_sections/edit?section=1' |
|
88 | 95 | } |
|
89 | 96 | assert_tag 'a', :attributes => { |
|
90 | 97 | :href => '/projects/ecookbook/wiki/Page_with_sections/edit?section=2' |
|
91 | 98 | } |
|
92 | 99 | assert_tag 'a', :attributes => { |
|
93 | 100 | :href => '/projects/ecookbook/wiki/Page_with_sections/edit?section=3' |
|
94 | 101 | } |
|
95 | 102 | end |
|
96 | 103 | |
|
97 | 104 | def test_show_current_version_should_display_section_edit_links |
|
98 | 105 | @request.session[:user_id] = 2 |
|
99 | 106 | get :show, :project_id => 1, :id => 'Page with sections', :version => 3 |
|
100 | 107 | |
|
101 | 108 | assert_tag 'a', :attributes => { |
|
102 | 109 | :href => '/projects/ecookbook/wiki/Page_with_sections/edit?section=2' |
|
103 | 110 | } |
|
104 | 111 | end |
|
105 | 112 | |
|
106 | 113 | def test_show_old_version_should_not_display_section_edit_links |
|
107 | 114 | @request.session[:user_id] = 2 |
|
108 | 115 | get :show, :project_id => 1, :id => 'Page with sections', :version => 2 |
|
109 | 116 | |
|
110 | 117 | assert_no_tag 'a', :attributes => { |
|
111 | 118 | :href => '/projects/ecookbook/wiki/Page_with_sections/edit?section=2' |
|
112 | 119 | } |
|
113 | 120 | end |
|
114 | 121 | |
|
115 | 122 | def test_show_unexistent_page_with_edit_right |
|
116 | 123 | @request.session[:user_id] = 2 |
|
117 | 124 | get :show, :project_id => 1, :id => 'Unexistent page' |
|
118 | 125 | assert_response :success |
|
119 | 126 | assert_template 'edit' |
|
120 | 127 | end |
|
121 | 128 | |
|
122 | 129 | def test_create_page |
|
123 | 130 | @request.session[:user_id] = 2 |
|
124 | 131 | put :update, :project_id => 1, |
|
125 | 132 | :id => 'New page', |
|
126 | 133 | :content => {:comments => 'Created the page', |
|
127 | 134 | :text => "h1. New page\n\nThis is a new page", |
|
128 | 135 | :version => 0} |
|
129 | 136 | assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'New_page' |
|
130 | 137 | page = Project.find(1).wiki.find_page('New page') |
|
131 | 138 | assert !page.new_record? |
|
132 | 139 | assert_not_nil page.content |
|
133 | 140 | assert_equal 'Created the page', page.content.comments |
|
134 | 141 | end |
|
135 | 142 | |
|
136 | 143 | def test_create_page_with_attachments |
|
137 | 144 | @request.session[:user_id] = 2 |
|
138 | 145 | assert_difference 'WikiPage.count' do |
|
139 | 146 | assert_difference 'Attachment.count' do |
|
140 | 147 | put :update, :project_id => 1, |
|
141 | 148 | :id => 'New page', |
|
142 | 149 | :content => {:comments => 'Created the page', |
|
143 | 150 | :text => "h1. New page\n\nThis is a new page", |
|
144 | 151 | :version => 0}, |
|
145 | 152 | :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}} |
|
146 | 153 | end |
|
147 | 154 | end |
|
148 | 155 | page = Project.find(1).wiki.find_page('New page') |
|
149 | 156 | assert_equal 1, page.attachments.count |
|
150 | 157 | assert_equal 'testfile.txt', page.attachments.first.filename |
|
151 | 158 | end |
|
152 | 159 | |
|
153 | 160 | def test_edit_page |
|
154 | 161 | @request.session[:user_id] = 2 |
|
155 | 162 | get :edit, :project_id => 'ecookbook', :id => 'Another_page' |
|
156 | 163 | |
|
157 | 164 | assert_response :success |
|
158 | 165 | assert_template 'edit' |
|
159 | 166 | |
|
160 | 167 | assert_tag 'textarea', |
|
161 | 168 | :attributes => { :name => 'content[text]' }, |
|
162 | 169 | :content => WikiPage.find_by_title('Another_page').content.text |
|
163 | 170 | end |
|
164 | 171 | |
|
165 | 172 | def test_edit_section |
|
166 | 173 | @request.session[:user_id] = 2 |
|
167 | 174 | get :edit, :project_id => 'ecookbook', :id => 'Page_with_sections', :section => 2 |
|
168 | 175 | |
|
169 | 176 | assert_response :success |
|
170 | 177 | assert_template 'edit' |
|
171 | 178 | |
|
172 | 179 | page = WikiPage.find_by_title('Page_with_sections') |
|
173 | 180 | section, hash = Redmine::WikiFormatting::Textile::Formatter.new(page.content.text).get_section(2) |
|
174 | 181 | |
|
175 | 182 | assert_tag 'textarea', |
|
176 | 183 | :attributes => { :name => 'content[text]' }, |
|
177 | 184 | :content => section |
|
178 | 185 | assert_tag 'input', |
|
179 | 186 | :attributes => { :name => 'section', :type => 'hidden', :value => '2' } |
|
180 | 187 | assert_tag 'input', |
|
181 | 188 | :attributes => { :name => 'section_hash', :type => 'hidden', :value => hash } |
|
182 | 189 | end |
|
183 | 190 | |
|
184 | 191 | def test_edit_invalid_section_should_respond_with_404 |
|
185 | 192 | @request.session[:user_id] = 2 |
|
186 | 193 | get :edit, :project_id => 'ecookbook', :id => 'Page_with_sections', :section => 10 |
|
187 | 194 | |
|
188 | 195 | assert_response 404 |
|
189 | 196 | end |
|
190 | 197 | |
|
191 | 198 | def test_update_page |
|
192 | 199 | @request.session[:user_id] = 2 |
|
193 | 200 | assert_no_difference 'WikiPage.count' do |
|
194 | 201 | assert_no_difference 'WikiContent.count' do |
|
195 | 202 | assert_difference 'WikiContent::Version.count' do |
|
196 | 203 | put :update, :project_id => 1, |
|
197 | 204 | :id => 'Another_page', |
|
198 | 205 | :content => { |
|
199 | 206 | :comments => "my comments", |
|
200 | 207 | :text => "edited", |
|
201 | 208 | :version => 1 |
|
202 | 209 | } |
|
203 | 210 | end |
|
204 | 211 | end |
|
205 | 212 | end |
|
206 | 213 | assert_redirected_to '/projects/ecookbook/wiki/Another_page' |
|
207 | 214 | |
|
208 | 215 | page = Wiki.find(1).pages.find_by_title('Another_page') |
|
209 | 216 | assert_equal "edited", page.content.text |
|
210 | 217 | assert_equal 2, page.content.version |
|
211 | 218 | assert_equal "my comments", page.content.comments |
|
212 | 219 | end |
|
213 | 220 | |
|
214 | 221 | def test_update_page_with_failure |
|
215 | 222 | @request.session[:user_id] = 2 |
|
216 | 223 | assert_no_difference 'WikiPage.count' do |
|
217 | 224 | assert_no_difference 'WikiContent.count' do |
|
218 | 225 | assert_no_difference 'WikiContent::Version.count' do |
|
219 | 226 | put :update, :project_id => 1, |
|
220 | 227 | :id => 'Another_page', |
|
221 | 228 | :content => { |
|
222 | 229 | :comments => 'a' * 300, # failure here, comment is too long |
|
223 | 230 | :text => 'edited', |
|
224 | 231 | :version => 1 |
|
225 | 232 | } |
|
226 | 233 | end |
|
227 | 234 | end |
|
228 | 235 | end |
|
229 | 236 | assert_response :success |
|
230 | 237 | assert_template 'edit' |
|
231 | 238 | |
|
232 | 239 | assert_error_tag :descendant => {:content => /Comment is too long/} |
|
233 | 240 | assert_tag :tag => 'textarea', :attributes => {:id => 'content_text'}, :content => 'edited' |
|
234 | 241 | assert_tag :tag => 'input', :attributes => {:id => 'content_version', :value => '1'} |
|
235 | 242 | end |
|
236 | 243 | |
|
237 | 244 | def test_update_stale_page_should_not_raise_an_error |
|
238 | 245 | @request.session[:user_id] = 2 |
|
239 | 246 | c = Wiki.find(1).find_page('Another_page').content |
|
240 | 247 | c.text = 'Previous text' |
|
241 | 248 | c.save! |
|
242 | 249 | assert_equal 2, c.version |
|
243 | 250 | |
|
244 | 251 | assert_no_difference 'WikiPage.count' do |
|
245 | 252 | assert_no_difference 'WikiContent.count' do |
|
246 | 253 | assert_no_difference 'WikiContent::Version.count' do |
|
247 | 254 | put :update, :project_id => 1, |
|
248 | 255 | :id => 'Another_page', |
|
249 | 256 | :content => { |
|
250 | 257 | :comments => 'My comments', |
|
251 | 258 | :text => 'Text should not be lost', |
|
252 | 259 | :version => 1 |
|
253 | 260 | } |
|
254 | 261 | end |
|
255 | 262 | end |
|
256 | 263 | end |
|
257 | 264 | assert_response :success |
|
258 | 265 | assert_template 'edit' |
|
259 | 266 | assert_tag :div, |
|
260 | 267 | :attributes => { :class => /error/ }, |
|
261 | 268 | :content => /Data has been updated by another user/ |
|
262 | 269 | assert_tag 'textarea', |
|
263 | 270 | :attributes => { :name => 'content[text]' }, |
|
264 | 271 | :content => /Text should not be lost/ |
|
265 | 272 | assert_tag 'input', |
|
266 | 273 | :attributes => { :name => 'content[comments]', :value => 'My comments' } |
|
267 | 274 | |
|
268 | 275 | c.reload |
|
269 | 276 | assert_equal 'Previous text', c.text |
|
270 | 277 | assert_equal 2, c.version |
|
271 | 278 | end |
|
272 | 279 | |
|
273 | 280 | def test_update_section |
|
274 | 281 | @request.session[:user_id] = 2 |
|
275 | 282 | page = WikiPage.find_by_title('Page_with_sections') |
|
276 | 283 | section, hash = Redmine::WikiFormatting::Textile::Formatter.new(page.content.text).get_section(2) |
|
277 | 284 | text = page.content.text |
|
278 | 285 | |
|
279 | 286 | assert_no_difference 'WikiPage.count' do |
|
280 | 287 | assert_no_difference 'WikiContent.count' do |
|
281 | 288 | assert_difference 'WikiContent::Version.count' do |
|
282 | 289 | put :update, :project_id => 1, :id => 'Page_with_sections', |
|
283 | 290 | :content => { |
|
284 | 291 | :text => "New section content", |
|
285 | 292 | :version => 3 |
|
286 | 293 | }, |
|
287 | 294 | :section => 2, |
|
288 | 295 | :section_hash => hash |
|
289 | 296 | end |
|
290 | 297 | end |
|
291 | 298 | end |
|
292 | 299 | assert_redirected_to '/projects/ecookbook/wiki/Page_with_sections' |
|
293 | 300 | assert_equal Redmine::WikiFormatting::Textile::Formatter.new(text).update_section(2, "New section content"), page.reload.content.text |
|
294 | 301 | end |
|
295 | 302 | |
|
296 | 303 | def test_update_section_should_allow_stale_page_update |
|
297 | 304 | @request.session[:user_id] = 2 |
|
298 | 305 | page = WikiPage.find_by_title('Page_with_sections') |
|
299 | 306 | section, hash = Redmine::WikiFormatting::Textile::Formatter.new(page.content.text).get_section(2) |
|
300 | 307 | text = page.content.text |
|
301 | 308 | |
|
302 | 309 | assert_no_difference 'WikiPage.count' do |
|
303 | 310 | assert_no_difference 'WikiContent.count' do |
|
304 | 311 | assert_difference 'WikiContent::Version.count' do |
|
305 | 312 | put :update, :project_id => 1, :id => 'Page_with_sections', |
|
306 | 313 | :content => { |
|
307 | 314 | :text => "New section content", |
|
308 | 315 | :version => 2 # Current version is 3 |
|
309 | 316 | }, |
|
310 | 317 | :section => 2, |
|
311 | 318 | :section_hash => hash |
|
312 | 319 | end |
|
313 | 320 | end |
|
314 | 321 | end |
|
315 | 322 | assert_redirected_to '/projects/ecookbook/wiki/Page_with_sections' |
|
316 | 323 | page.reload |
|
317 | 324 | assert_equal Redmine::WikiFormatting::Textile::Formatter.new(text).update_section(2, "New section content"), page.content.text |
|
318 | 325 | assert_equal 4, page.content.version |
|
319 | 326 | end |
|
320 | 327 | |
|
321 | 328 | def test_update_section_should_not_allow_stale_section_update |
|
322 | 329 | @request.session[:user_id] = 2 |
|
323 | 330 | |
|
324 | 331 | assert_no_difference 'WikiPage.count' do |
|
325 | 332 | assert_no_difference 'WikiContent.count' do |
|
326 | 333 | assert_no_difference 'WikiContent::Version.count' do |
|
327 | 334 | put :update, :project_id => 1, :id => 'Page_with_sections', |
|
328 | 335 | :content => { |
|
329 | 336 | :comments => 'My comments', |
|
330 | 337 | :text => "Text should not be lost", |
|
331 | 338 | :version => 3 |
|
332 | 339 | }, |
|
333 | 340 | :section => 2, |
|
334 | 341 | :section_hash => Digest::MD5.hexdigest("wrong hash") |
|
335 | 342 | end |
|
336 | 343 | end |
|
337 | 344 | end |
|
338 | 345 | assert_response :success |
|
339 | 346 | assert_template 'edit' |
|
340 | 347 | assert_tag :div, |
|
341 | 348 | :attributes => { :class => /error/ }, |
|
342 | 349 | :content => /Data has been updated by another user/ |
|
343 | 350 | assert_tag 'textarea', |
|
344 | 351 | :attributes => { :name => 'content[text]' }, |
|
345 | 352 | :content => /Text should not be lost/ |
|
346 | 353 | assert_tag 'input', |
|
347 | 354 | :attributes => { :name => 'content[comments]', :value => 'My comments' } |
|
348 | 355 | end |
|
349 | 356 | |
|
350 | 357 | def test_preview |
|
351 | 358 | @request.session[:user_id] = 2 |
|
352 | 359 | xhr :post, :preview, :project_id => 1, :id => 'CookBook_documentation', |
|
353 | 360 | :content => { :comments => '', |
|
354 | 361 | :text => 'this is a *previewed text*', |
|
355 | 362 | :version => 3 } |
|
356 | 363 | assert_response :success |
|
357 | 364 | assert_template 'common/_preview' |
|
358 | 365 | assert_tag :tag => 'strong', :content => /previewed text/ |
|
359 | 366 | end |
|
360 | 367 | |
|
361 | 368 | def test_preview_new_page |
|
362 | 369 | @request.session[:user_id] = 2 |
|
363 | 370 | xhr :post, :preview, :project_id => 1, :id => 'New page', |
|
364 | 371 | :content => { :text => 'h1. New page', |
|
365 | 372 | :comments => '', |
|
366 | 373 | :version => 0 } |
|
367 | 374 | assert_response :success |
|
368 | 375 | assert_template 'common/_preview' |
|
369 | 376 | assert_tag :tag => 'h1', :content => /New page/ |
|
370 | 377 | end |
|
371 | 378 | |
|
372 | 379 | def test_history |
|
373 | 380 | get :history, :project_id => 1, :id => 'CookBook_documentation' |
|
374 | 381 | assert_response :success |
|
375 | 382 | assert_template 'history' |
|
376 | 383 | assert_not_nil assigns(:versions) |
|
377 | 384 | assert_equal 3, assigns(:versions).size |
|
378 | 385 | assert_select "input[type=submit][name=commit]" |
|
379 | 386 | end |
|
380 | 387 | |
|
381 | 388 | def test_history_with_one_version |
|
382 | 389 | get :history, :project_id => 1, :id => 'Another_page' |
|
383 | 390 | assert_response :success |
|
384 | 391 | assert_template 'history' |
|
385 | 392 | assert_not_nil assigns(:versions) |
|
386 | 393 | assert_equal 1, assigns(:versions).size |
|
387 | 394 | assert_select "input[type=submit][name=commit]", false |
|
388 | 395 | end |
|
389 | 396 | |
|
390 | 397 | def test_diff |
|
391 | 398 | get :diff, :project_id => 1, :id => 'CookBook_documentation', :version => 2, :version_from => 1 |
|
392 | 399 | assert_response :success |
|
393 | 400 | assert_template 'diff' |
|
394 | 401 | assert_tag :tag => 'span', :attributes => { :class => 'diff_in'}, |
|
395 | 402 | :content => /updated/ |
|
396 | 403 | end |
|
397 | 404 | |
|
398 | 405 | def test_annotate |
|
399 | 406 | get :annotate, :project_id => 1, :id => 'CookBook_documentation', :version => 2 |
|
400 | 407 | assert_response :success |
|
401 | 408 | assert_template 'annotate' |
|
402 | 409 | |
|
403 | 410 | # Line 1 |
|
404 | 411 | assert_tag :tag => 'tr', :child => { |
|
405 | 412 | :tag => 'th', :attributes => {:class => 'line-num'}, :content => '1', :sibling => { |
|
406 | 413 | :tag => 'td', :attributes => {:class => 'author'}, :content => /John Smith/, :sibling => { |
|
407 | 414 | :tag => 'td', :content => /h1\. CookBook documentation/ |
|
408 | 415 | } |
|
409 | 416 | } |
|
410 | 417 | } |
|
411 | 418 | |
|
412 | 419 | # Line 5 |
|
413 | 420 | assert_tag :tag => 'tr', :child => { |
|
414 | 421 | :tag => 'th', :attributes => {:class => 'line-num'}, :content => '5', :sibling => { |
|
415 | 422 | :tag => 'td', :attributes => {:class => 'author'}, :content => /redMine Admin/, :sibling => { |
|
416 | 423 | :tag => 'td', :content => /Some updated \[\[documentation\]\] here/ |
|
417 | 424 | } |
|
418 | 425 | } |
|
419 | 426 | } |
|
420 | 427 | end |
|
421 | 428 | |
|
422 | 429 | def test_get_rename |
|
423 | 430 | @request.session[:user_id] = 2 |
|
424 | 431 | get :rename, :project_id => 1, :id => 'Another_page' |
|
425 | 432 | assert_response :success |
|
426 | 433 | assert_template 'rename' |
|
427 | 434 | assert_tag 'option', |
|
428 | 435 | :attributes => {:value => ''}, |
|
429 | 436 | :content => '', |
|
430 | 437 | :parent => {:tag => 'select', :attributes => {:name => 'wiki_page[parent_id]'}} |
|
431 | 438 | assert_no_tag 'option', |
|
432 | 439 | :attributes => {:selected => 'selected'}, |
|
433 | 440 | :parent => {:tag => 'select', :attributes => {:name => 'wiki_page[parent_id]'}} |
|
434 | 441 | end |
|
435 | 442 | |
|
436 | 443 | def test_get_rename_child_page |
|
437 | 444 | @request.session[:user_id] = 2 |
|
438 | 445 | get :rename, :project_id => 1, :id => 'Child_1' |
|
439 | 446 | assert_response :success |
|
440 | 447 | assert_template 'rename' |
|
441 | 448 | assert_tag 'option', |
|
442 | 449 | :attributes => {:value => ''}, |
|
443 | 450 | :content => '', |
|
444 | 451 | :parent => {:tag => 'select', :attributes => {:name => 'wiki_page[parent_id]'}} |
|
445 | 452 | assert_tag 'option', |
|
446 | 453 | :attributes => {:value => '2', :selected => 'selected'}, |
|
447 | 454 | :content => /Another page/, |
|
448 | 455 | :parent => { |
|
449 | 456 | :tag => 'select', |
|
450 | 457 | :attributes => {:name => 'wiki_page[parent_id]'} |
|
451 | 458 | } |
|
452 | 459 | end |
|
453 | 460 | |
|
454 | 461 | def test_rename_with_redirect |
|
455 | 462 | @request.session[:user_id] = 2 |
|
456 | 463 | post :rename, :project_id => 1, :id => 'Another_page', |
|
457 | 464 | :wiki_page => { :title => 'Another renamed page', |
|
458 | 465 | :redirect_existing_links => 1 } |
|
459 | 466 | assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'Another_renamed_page' |
|
460 | 467 | wiki = Project.find(1).wiki |
|
461 | 468 | # Check redirects |
|
462 | 469 | assert_not_nil wiki.find_page('Another page') |
|
463 | 470 | assert_nil wiki.find_page('Another page', :with_redirect => false) |
|
464 | 471 | end |
|
465 | 472 | |
|
466 | 473 | def test_rename_without_redirect |
|
467 | 474 | @request.session[:user_id] = 2 |
|
468 | 475 | post :rename, :project_id => 1, :id => 'Another_page', |
|
469 | 476 | :wiki_page => { :title => 'Another renamed page', |
|
470 | 477 | :redirect_existing_links => "0" } |
|
471 | 478 | assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'Another_renamed_page' |
|
472 | 479 | wiki = Project.find(1).wiki |
|
473 | 480 | # Check that there's no redirects |
|
474 | 481 | assert_nil wiki.find_page('Another page') |
|
475 | 482 | end |
|
476 | 483 | |
|
477 | 484 | def test_rename_with_parent_assignment |
|
478 | 485 | @request.session[:user_id] = 2 |
|
479 | 486 | post :rename, :project_id => 1, :id => 'Another_page', |
|
480 | 487 | :wiki_page => { :title => 'Another page', :redirect_existing_links => "0", :parent_id => '4' } |
|
481 | 488 | assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'Another_page' |
|
482 | 489 | assert_equal WikiPage.find(4), WikiPage.find_by_title('Another_page').parent |
|
483 | 490 | end |
|
484 | 491 | |
|
485 | 492 | def test_rename_with_parent_unassignment |
|
486 | 493 | @request.session[:user_id] = 2 |
|
487 | 494 | post :rename, :project_id => 1, :id => 'Child_1', |
|
488 | 495 | :wiki_page => { :title => 'Child 1', :redirect_existing_links => "0", :parent_id => '' } |
|
489 | 496 | assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'Child_1' |
|
490 | 497 | assert_nil WikiPage.find_by_title('Child_1').parent |
|
491 | 498 | end |
|
492 | 499 | |
|
493 | 500 | def test_destroy_child |
|
494 | 501 | @request.session[:user_id] = 2 |
|
495 | 502 | delete :destroy, :project_id => 1, :id => 'Child_1' |
|
496 | 503 | assert_redirected_to :action => 'index', :project_id => 'ecookbook' |
|
497 | 504 | end |
|
498 | 505 | |
|
499 | 506 | def test_destroy_parent |
|
500 | 507 | @request.session[:user_id] = 2 |
|
501 | 508 | assert_no_difference('WikiPage.count') do |
|
502 | 509 | delete :destroy, :project_id => 1, :id => 'Another_page' |
|
503 | 510 | end |
|
504 | 511 | assert_response :success |
|
505 | 512 | assert_template 'destroy' |
|
506 | 513 | end |
|
507 | 514 | |
|
508 | 515 | def test_destroy_parent_with_nullify |
|
509 | 516 | @request.session[:user_id] = 2 |
|
510 | 517 | assert_difference('WikiPage.count', -1) do |
|
511 | 518 | delete :destroy, :project_id => 1, :id => 'Another_page', :todo => 'nullify' |
|
512 | 519 | end |
|
513 | 520 | assert_redirected_to :action => 'index', :project_id => 'ecookbook' |
|
514 | 521 | assert_nil WikiPage.find_by_id(2) |
|
515 | 522 | end |
|
516 | 523 | |
|
517 | 524 | def test_destroy_parent_with_cascade |
|
518 | 525 | @request.session[:user_id] = 2 |
|
519 | 526 | assert_difference('WikiPage.count', -3) do |
|
520 | 527 | delete :destroy, :project_id => 1, :id => 'Another_page', :todo => 'destroy' |
|
521 | 528 | end |
|
522 | 529 | assert_redirected_to :action => 'index', :project_id => 'ecookbook' |
|
523 | 530 | assert_nil WikiPage.find_by_id(2) |
|
524 | 531 | assert_nil WikiPage.find_by_id(5) |
|
525 | 532 | end |
|
526 | 533 | |
|
527 | 534 | def test_destroy_parent_with_reassign |
|
528 | 535 | @request.session[:user_id] = 2 |
|
529 | 536 | assert_difference('WikiPage.count', -1) do |
|
530 | 537 | delete :destroy, :project_id => 1, :id => 'Another_page', :todo => 'reassign', :reassign_to_id => 1 |
|
531 | 538 | end |
|
532 | 539 | assert_redirected_to :action => 'index', :project_id => 'ecookbook' |
|
533 | 540 | assert_nil WikiPage.find_by_id(2) |
|
534 | 541 | assert_equal WikiPage.find(1), WikiPage.find_by_id(5).parent |
|
535 | 542 | end |
|
536 | 543 | |
|
537 | 544 | def test_index |
|
538 | 545 | get :index, :project_id => 'ecookbook' |
|
539 | 546 | assert_response :success |
|
540 | 547 | assert_template 'index' |
|
541 | 548 | pages = assigns(:pages) |
|
542 | 549 | assert_not_nil pages |
|
543 | 550 | assert_equal Project.find(1).wiki.pages.size, pages.size |
|
544 | 551 | assert_equal pages.first.content.updated_on, pages.first.updated_on |
|
545 | 552 | |
|
546 | 553 | assert_tag :ul, :attributes => { :class => 'pages-hierarchy' }, |
|
547 | 554 | :child => { :tag => 'li', :child => { :tag => 'a', :attributes => { :href => '/projects/ecookbook/wiki/CookBook_documentation' }, |
|
548 | 555 | :content => 'CookBook documentation' }, |
|
549 | 556 | :child => { :tag => 'ul', |
|
550 | 557 | :child => { :tag => 'li', |
|
551 | 558 | :child => { :tag => 'a', :attributes => { :href => '/projects/ecookbook/wiki/Page_with_an_inline_image' }, |
|
552 | 559 | :content => 'Page with an inline image' } } } }, |
|
553 | 560 | :child => { :tag => 'li', :child => { :tag => 'a', :attributes => { :href => '/projects/ecookbook/wiki/Another_page' }, |
|
554 | 561 | :content => 'Another page' } } |
|
555 | 562 | end |
|
556 | 563 | |
|
557 | 564 | def test_index_should_include_atom_link |
|
558 | 565 | get :index, :project_id => 'ecookbook' |
|
559 | 566 | assert_tag 'a', :attributes => { :href => '/projects/ecookbook/activity.atom?show_wiki_edits=1'} |
|
560 | 567 | end |
|
561 | 568 | |
|
562 | 569 | context "GET :export" do |
|
563 | 570 | context "with an authorized user to export the wiki" do |
|
564 | 571 | setup do |
|
565 | 572 | @request.session[:user_id] = 2 |
|
566 | 573 | get :export, :project_id => 'ecookbook' |
|
567 | 574 | end |
|
568 | 575 | |
|
569 | 576 | should_respond_with :success |
|
570 | 577 | should_assign_to :pages |
|
571 | 578 | should_respond_with_content_type "text/html" |
|
572 | 579 | should "export all of the wiki pages to a single html file" do |
|
573 | 580 | assert_select "a[name=?]", "CookBook_documentation" |
|
574 | 581 | assert_select "a[name=?]", "Another_page" |
|
575 | 582 | assert_select "a[name=?]", "Page_with_an_inline_image" |
|
576 | 583 | end |
|
577 | 584 | |
|
578 | 585 | end |
|
579 | 586 | |
|
580 | 587 | context "with an unauthorized user" do |
|
581 | 588 | setup do |
|
582 | 589 | get :export, :project_id => 'ecookbook' |
|
583 | 590 | |
|
584 | 591 | should_respond_with :redirect |
|
585 | 592 | should_redirect_to('wiki index') { {:action => 'show', :project_id => @project, :id => nil} } |
|
586 | 593 | end |
|
587 | 594 | end |
|
588 | 595 | end |
|
589 | 596 | |
|
590 | 597 | context "GET :date_index" do |
|
591 | 598 | setup do |
|
592 | 599 | get :date_index, :project_id => 'ecookbook' |
|
593 | 600 | end |
|
594 | 601 | |
|
595 | 602 | should_respond_with :success |
|
596 | 603 | should_assign_to :pages |
|
597 | 604 | should_assign_to :pages_by_date |
|
598 | 605 | should_render_template 'wiki/date_index' |
|
599 | 606 | |
|
600 | 607 | should "include atom link" do |
|
601 | 608 | assert_tag 'a', :attributes => { :href => '/projects/ecookbook/activity.atom?show_wiki_edits=1'} |
|
602 | 609 | end |
|
603 | 610 | end |
|
604 | 611 | |
|
605 | 612 | def test_not_found |
|
606 | 613 | get :show, :project_id => 999 |
|
607 | 614 | assert_response 404 |
|
608 | 615 | end |
|
609 | 616 | |
|
610 | 617 | def test_protect_page |
|
611 | 618 | page = WikiPage.find_by_wiki_id_and_title(1, 'Another_page') |
|
612 | 619 | assert !page.protected? |
|
613 | 620 | @request.session[:user_id] = 2 |
|
614 | 621 | post :protect, :project_id => 1, :id => page.title, :protected => '1' |
|
615 | 622 | assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'Another_page' |
|
616 | 623 | assert page.reload.protected? |
|
617 | 624 | end |
|
618 | 625 | |
|
619 | 626 | def test_unprotect_page |
|
620 | 627 | page = WikiPage.find_by_wiki_id_and_title(1, 'CookBook_documentation') |
|
621 | 628 | assert page.protected? |
|
622 | 629 | @request.session[:user_id] = 2 |
|
623 | 630 | post :protect, :project_id => 1, :id => page.title, :protected => '0' |
|
624 | 631 | assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'CookBook_documentation' |
|
625 | 632 | assert !page.reload.protected? |
|
626 | 633 | end |
|
627 | 634 | |
|
628 | 635 | def test_show_page_with_edit_link |
|
629 | 636 | @request.session[:user_id] = 2 |
|
630 | 637 | get :show, :project_id => 1 |
|
631 | 638 | assert_response :success |
|
632 | 639 | assert_template 'show' |
|
633 | 640 | assert_tag :tag => 'a', :attributes => { :href => '/projects/1/wiki/CookBook_documentation/edit' } |
|
634 | 641 | end |
|
635 | 642 | |
|
636 | 643 | def test_show_page_without_edit_link |
|
637 | 644 | @request.session[:user_id] = 4 |
|
638 | 645 | get :show, :project_id => 1 |
|
639 | 646 | assert_response :success |
|
640 | 647 | assert_template 'show' |
|
641 | 648 | assert_no_tag :tag => 'a', :attributes => { :href => '/projects/1/wiki/CookBook_documentation/edit' } |
|
642 | 649 | end |
|
643 | 650 | |
|
644 | 651 | def test_show_pdf |
|
645 | 652 | @request.session[:user_id] = 2 |
|
646 | 653 | get :show, :project_id => 1, :format => 'pdf' |
|
647 | 654 | assert_response :success |
|
648 | 655 | assert_not_nil assigns(:page) |
|
649 | 656 | assert_equal 'application/pdf', @response.content_type |
|
650 | 657 | assert_equal 'attachment; filename="CookBook_documentation.pdf"', |
|
651 | 658 | @response.headers['Content-Disposition'] |
|
652 | 659 | end |
|
653 | 660 | |
|
654 | 661 | def test_show_html |
|
655 | 662 | @request.session[:user_id] = 2 |
|
656 | 663 | get :show, :project_id => 1, :format => 'html' |
|
657 | 664 | assert_response :success |
|
658 | 665 | assert_not_nil assigns(:page) |
|
659 | 666 | assert_equal 'text/html', @response.content_type |
|
660 | 667 | assert_equal 'attachment; filename="CookBook_documentation.html"', |
|
661 | 668 | @response.headers['Content-Disposition'] |
|
662 | 669 | end |
|
663 | 670 | |
|
664 | 671 | def test_show_txt |
|
665 | 672 | @request.session[:user_id] = 2 |
|
666 | 673 | get :show, :project_id => 1, :format => 'txt' |
|
667 | 674 | assert_response :success |
|
668 | 675 | assert_not_nil assigns(:page) |
|
669 | 676 | assert_equal 'text/plain', @response.content_type |
|
670 | 677 | assert_equal 'attachment; filename="CookBook_documentation.txt"', |
|
671 | 678 | @response.headers['Content-Disposition'] |
|
672 | 679 | end |
|
673 | 680 | |
|
674 | 681 | def test_edit_unprotected_page |
|
675 | 682 | # Non members can edit unprotected wiki pages |
|
676 | 683 | @request.session[:user_id] = 4 |
|
677 | 684 | get :edit, :project_id => 1, :id => 'Another_page' |
|
678 | 685 | assert_response :success |
|
679 | 686 | assert_template 'edit' |
|
680 | 687 | end |
|
681 | 688 | |
|
682 | 689 | def test_edit_protected_page_by_nonmember |
|
683 | 690 | # Non members can't edit protected wiki pages |
|
684 | 691 | @request.session[:user_id] = 4 |
|
685 | 692 | get :edit, :project_id => 1, :id => 'CookBook_documentation' |
|
686 | 693 | assert_response 403 |
|
687 | 694 | end |
|
688 | 695 | |
|
689 | 696 | def test_edit_protected_page_by_member |
|
690 | 697 | @request.session[:user_id] = 2 |
|
691 | 698 | get :edit, :project_id => 1, :id => 'CookBook_documentation' |
|
692 | 699 | assert_response :success |
|
693 | 700 | assert_template 'edit' |
|
694 | 701 | end |
|
695 | 702 | |
|
696 | 703 | def test_history_of_non_existing_page_should_return_404 |
|
697 | 704 | get :history, :project_id => 1, :id => 'Unknown_page' |
|
698 | 705 | assert_response 404 |
|
699 | 706 | end |
|
700 | 707 | end |
General Comments 0
You need to be logged in to leave comments.
Login now