@@ -1,739 +1,769 | |||||
1 | # Redmine - project management software |
|
1 | # Redmine - project management software | |
2 | # Copyright (C) 2006-2011 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006-2011 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 | assert_no_tag 'input', :attributes => {:name => 'page[parent_id]'} |
|
127 | assert_no_tag 'input', :attributes => {:name => 'page[parent_id]'} | |
128 | end |
|
128 | end | |
129 |
|
129 | |||
130 | def test_show_unexistent_page_with_parent |
|
130 | def test_show_unexistent_page_with_parent | |
131 | @request.session[:user_id] = 2 |
|
131 | @request.session[:user_id] = 2 | |
132 | get :show, :project_id => 1, :id => 'Unexistent page', :parent => 'Another_page' |
|
132 | get :show, :project_id => 1, :id => 'Unexistent page', :parent => 'Another_page' | |
133 | assert_response :success |
|
133 | assert_response :success | |
134 | assert_template 'edit' |
|
134 | assert_template 'edit' | |
135 | assert_tag 'input', :attributes => {:name => 'page[parent_id]', :value => '2'} |
|
135 | assert_tag 'input', :attributes => {:name => 'page[parent_id]', :value => '2'} | |
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 | :page => {:parent_id => 2} |
|
186 | :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 => WikiPage.find_by_title('Another_page').content.text |
|
201 | :content => 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 => section |
|
216 | :content => 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_failure |
|
253 | def test_update_page_with_failure | |
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_no_difference 'WikiContent::Version.count' do |
|
257 | assert_no_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 => 'a' * 300, # failure here, comment is too long |
|
261 | :comments => 'a' * 300, # failure here, comment is too long | |
262 | :text => 'edited', |
|
262 | :text => 'edited', | |
263 | :version => 1 |
|
263 | :version => 1 | |
264 | } |
|
264 | } | |
265 | end |
|
265 | end | |
266 | end |
|
266 | end | |
267 | end |
|
267 | end | |
268 | assert_response :success |
|
268 | assert_response :success | |
269 | assert_template 'edit' |
|
269 | assert_template 'edit' | |
270 |
|
270 | |||
271 | assert_error_tag :descendant => {:content => /Comment is too long/} |
|
271 | assert_error_tag :descendant => {:content => /Comment is too long/} | |
272 | assert_tag :tag => 'textarea', :attributes => {:id => 'content_text'}, :content => 'edited' |
|
272 | assert_tag :tag => 'textarea', :attributes => {:id => 'content_text'}, :content => 'edited' | |
273 | assert_tag :tag => 'input', :attributes => {:id => 'content_version', :value => '1'} |
|
273 | assert_tag :tag => 'input', :attributes => {:id => 'content_version', :value => '1'} | |
274 | end |
|
274 | end | |
275 |
|
275 | |||
|
276 | def test_update_page_with_attachments_only_should_not_create_content_version | |||
|
277 | @request.session[:user_id] = 2 | |||
|
278 | assert_no_difference 'WikiPage.count' do | |||
|
279 | assert_no_difference 'WikiContent.count' do | |||
|
280 | assert_no_difference 'WikiContent::Version.count' do | |||
|
281 | assert_difference 'Attachment.count' do | |||
|
282 | put :update, :project_id => 1, | |||
|
283 | :id => 'Another_page', | |||
|
284 | :content => { | |||
|
285 | :comments => '', | |||
|
286 | :text => Wiki.find(1).find_page('Another_page').content.text, | |||
|
287 | :version => 1 | |||
|
288 | }, | |||
|
289 | :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'test file'}} | |||
|
290 | end | |||
|
291 | end | |||
|
292 | end | |||
|
293 | end | |||
|
294 | end | |||
|
295 | ||||
276 | def test_update_stale_page_should_not_raise_an_error |
|
296 | def test_update_stale_page_should_not_raise_an_error | |
277 | @request.session[:user_id] = 2 |
|
297 | @request.session[:user_id] = 2 | |
278 | c = Wiki.find(1).find_page('Another_page').content |
|
298 | c = Wiki.find(1).find_page('Another_page').content | |
279 | c.text = 'Previous text' |
|
299 | c.text = 'Previous text' | |
280 | c.save! |
|
300 | c.save! | |
281 | assert_equal 2, c.version |
|
301 | assert_equal 2, c.version | |
282 |
|
302 | |||
283 | assert_no_difference 'WikiPage.count' do |
|
303 | assert_no_difference 'WikiPage.count' do | |
284 | assert_no_difference 'WikiContent.count' do |
|
304 | assert_no_difference 'WikiContent.count' do | |
285 | assert_no_difference 'WikiContent::Version.count' do |
|
305 | assert_no_difference 'WikiContent::Version.count' do | |
286 | put :update, :project_id => 1, |
|
306 | put :update, :project_id => 1, | |
287 | :id => 'Another_page', |
|
307 | :id => 'Another_page', | |
288 | :content => { |
|
308 | :content => { | |
289 | :comments => 'My comments', |
|
309 | :comments => 'My comments', | |
290 | :text => 'Text should not be lost', |
|
310 | :text => 'Text should not be lost', | |
291 | :version => 1 |
|
311 | :version => 1 | |
292 | } |
|
312 | } | |
293 | end |
|
313 | end | |
294 | end |
|
314 | end | |
295 | end |
|
315 | end | |
296 | assert_response :success |
|
316 | assert_response :success | |
297 | assert_template 'edit' |
|
317 | assert_template 'edit' | |
298 | assert_tag :div, |
|
318 | assert_tag :div, | |
299 | :attributes => { :class => /error/ }, |
|
319 | :attributes => { :class => /error/ }, | |
300 | :content => /Data has been updated by another user/ |
|
320 | :content => /Data has been updated by another user/ | |
301 | assert_tag 'textarea', |
|
321 | assert_tag 'textarea', | |
302 | :attributes => { :name => 'content[text]' }, |
|
322 | :attributes => { :name => 'content[text]' }, | |
303 | :content => /Text should not be lost/ |
|
323 | :content => /Text should not be lost/ | |
304 | assert_tag 'input', |
|
324 | assert_tag 'input', | |
305 | :attributes => { :name => 'content[comments]', :value => 'My comments' } |
|
325 | :attributes => { :name => 'content[comments]', :value => 'My comments' } | |
306 |
|
326 | |||
307 | c.reload |
|
327 | c.reload | |
308 | assert_equal 'Previous text', c.text |
|
328 | assert_equal 'Previous text', c.text | |
309 | assert_equal 2, c.version |
|
329 | assert_equal 2, c.version | |
310 | end |
|
330 | end | |
311 |
|
331 | |||
312 | def test_update_section |
|
332 | def test_update_section | |
313 | @request.session[:user_id] = 2 |
|
333 | @request.session[:user_id] = 2 | |
314 | page = WikiPage.find_by_title('Page_with_sections') |
|
334 | page = WikiPage.find_by_title('Page_with_sections') | |
315 | section, hash = Redmine::WikiFormatting::Textile::Formatter.new(page.content.text).get_section(2) |
|
335 | section, hash = Redmine::WikiFormatting::Textile::Formatter.new(page.content.text).get_section(2) | |
316 | text = page.content.text |
|
336 | text = page.content.text | |
317 |
|
337 | |||
318 | assert_no_difference 'WikiPage.count' do |
|
338 | assert_no_difference 'WikiPage.count' do | |
319 | assert_no_difference 'WikiContent.count' do |
|
339 | assert_no_difference 'WikiContent.count' do | |
320 | assert_difference 'WikiContent::Version.count' do |
|
340 | assert_difference 'WikiContent::Version.count' do | |
321 | put :update, :project_id => 1, :id => 'Page_with_sections', |
|
341 | put :update, :project_id => 1, :id => 'Page_with_sections', | |
322 | :content => { |
|
342 | :content => { | |
323 | :text => "New section content", |
|
343 | :text => "New section content", | |
324 | :version => 3 |
|
344 | :version => 3 | |
325 | }, |
|
345 | }, | |
326 | :section => 2, |
|
346 | :section => 2, | |
327 | :section_hash => hash |
|
347 | :section_hash => hash | |
328 | end |
|
348 | end | |
329 | end |
|
349 | end | |
330 | end |
|
350 | end | |
331 | assert_redirected_to '/projects/ecookbook/wiki/Page_with_sections' |
|
351 | assert_redirected_to '/projects/ecookbook/wiki/Page_with_sections' | |
332 | assert_equal Redmine::WikiFormatting::Textile::Formatter.new(text).update_section(2, "New section content"), page.reload.content.text |
|
352 | assert_equal Redmine::WikiFormatting::Textile::Formatter.new(text).update_section(2, "New section content"), page.reload.content.text | |
333 | end |
|
353 | end | |
334 |
|
354 | |||
335 | def test_update_section_should_allow_stale_page_update |
|
355 | def test_update_section_should_allow_stale_page_update | |
336 | @request.session[:user_id] = 2 |
|
356 | @request.session[:user_id] = 2 | |
337 | page = WikiPage.find_by_title('Page_with_sections') |
|
357 | page = WikiPage.find_by_title('Page_with_sections') | |
338 | section, hash = Redmine::WikiFormatting::Textile::Formatter.new(page.content.text).get_section(2) |
|
358 | section, hash = Redmine::WikiFormatting::Textile::Formatter.new(page.content.text).get_section(2) | |
339 | text = page.content.text |
|
359 | text = page.content.text | |
340 |
|
360 | |||
341 | assert_no_difference 'WikiPage.count' do |
|
361 | assert_no_difference 'WikiPage.count' do | |
342 | assert_no_difference 'WikiContent.count' do |
|
362 | assert_no_difference 'WikiContent.count' do | |
343 | assert_difference 'WikiContent::Version.count' do |
|
363 | assert_difference 'WikiContent::Version.count' do | |
344 | put :update, :project_id => 1, :id => 'Page_with_sections', |
|
364 | put :update, :project_id => 1, :id => 'Page_with_sections', | |
345 | :content => { |
|
365 | :content => { | |
346 | :text => "New section content", |
|
366 | :text => "New section content", | |
347 | :version => 2 # Current version is 3 |
|
367 | :version => 2 # Current version is 3 | |
348 | }, |
|
368 | }, | |
349 | :section => 2, |
|
369 | :section => 2, | |
350 | :section_hash => hash |
|
370 | :section_hash => hash | |
351 | end |
|
371 | end | |
352 | end |
|
372 | end | |
353 | end |
|
373 | end | |
354 | assert_redirected_to '/projects/ecookbook/wiki/Page_with_sections' |
|
374 | assert_redirected_to '/projects/ecookbook/wiki/Page_with_sections' | |
355 | page.reload |
|
375 | page.reload | |
356 | assert_equal Redmine::WikiFormatting::Textile::Formatter.new(text).update_section(2, "New section content"), page.content.text |
|
376 | assert_equal Redmine::WikiFormatting::Textile::Formatter.new(text).update_section(2, "New section content"), page.content.text | |
357 | assert_equal 4, page.content.version |
|
377 | assert_equal 4, page.content.version | |
358 | end |
|
378 | end | |
359 |
|
379 | |||
360 | def test_update_section_should_not_allow_stale_section_update |
|
380 | def test_update_section_should_not_allow_stale_section_update | |
361 | @request.session[:user_id] = 2 |
|
381 | @request.session[:user_id] = 2 | |
362 |
|
382 | |||
363 | assert_no_difference 'WikiPage.count' do |
|
383 | assert_no_difference 'WikiPage.count' do | |
364 | assert_no_difference 'WikiContent.count' do |
|
384 | assert_no_difference 'WikiContent.count' do | |
365 | assert_no_difference 'WikiContent::Version.count' do |
|
385 | assert_no_difference 'WikiContent::Version.count' do | |
366 | put :update, :project_id => 1, :id => 'Page_with_sections', |
|
386 | put :update, :project_id => 1, :id => 'Page_with_sections', | |
367 | :content => { |
|
387 | :content => { | |
368 | :comments => 'My comments', |
|
388 | :comments => 'My comments', | |
369 | :text => "Text should not be lost", |
|
389 | :text => "Text should not be lost", | |
370 | :version => 3 |
|
390 | :version => 3 | |
371 | }, |
|
391 | }, | |
372 | :section => 2, |
|
392 | :section => 2, | |
373 | :section_hash => Digest::MD5.hexdigest("wrong hash") |
|
393 | :section_hash => Digest::MD5.hexdigest("wrong hash") | |
374 | end |
|
394 | end | |
375 | end |
|
395 | end | |
376 | end |
|
396 | end | |
377 | assert_response :success |
|
397 | assert_response :success | |
378 | assert_template 'edit' |
|
398 | assert_template 'edit' | |
379 | assert_tag :div, |
|
399 | assert_tag :div, | |
380 | :attributes => { :class => /error/ }, |
|
400 | :attributes => { :class => /error/ }, | |
381 | :content => /Data has been updated by another user/ |
|
401 | :content => /Data has been updated by another user/ | |
382 | assert_tag 'textarea', |
|
402 | assert_tag 'textarea', | |
383 | :attributes => { :name => 'content[text]' }, |
|
403 | :attributes => { :name => 'content[text]' }, | |
384 | :content => /Text should not be lost/ |
|
404 | :content => /Text should not be lost/ | |
385 | assert_tag 'input', |
|
405 | assert_tag 'input', | |
386 | :attributes => { :name => 'content[comments]', :value => 'My comments' } |
|
406 | :attributes => { :name => 'content[comments]', :value => 'My comments' } | |
387 | end |
|
407 | end | |
388 |
|
408 | |||
389 | def test_preview |
|
409 | def test_preview | |
390 | @request.session[:user_id] = 2 |
|
410 | @request.session[:user_id] = 2 | |
391 | xhr :post, :preview, :project_id => 1, :id => 'CookBook_documentation', |
|
411 | xhr :post, :preview, :project_id => 1, :id => 'CookBook_documentation', | |
392 | :content => { :comments => '', |
|
412 | :content => { :comments => '', | |
393 | :text => 'this is a *previewed text*', |
|
413 | :text => 'this is a *previewed text*', | |
394 | :version => 3 } |
|
414 | :version => 3 } | |
395 | assert_response :success |
|
415 | assert_response :success | |
396 | assert_template 'common/_preview' |
|
416 | assert_template 'common/_preview' | |
397 | assert_tag :tag => 'strong', :content => /previewed text/ |
|
417 | assert_tag :tag => 'strong', :content => /previewed text/ | |
398 | end |
|
418 | end | |
399 |
|
419 | |||
400 | def test_preview_new_page |
|
420 | def test_preview_new_page | |
401 | @request.session[:user_id] = 2 |
|
421 | @request.session[:user_id] = 2 | |
402 | xhr :post, :preview, :project_id => 1, :id => 'New page', |
|
422 | xhr :post, :preview, :project_id => 1, :id => 'New page', | |
403 | :content => { :text => 'h1. New page', |
|
423 | :content => { :text => 'h1. New page', | |
404 | :comments => '', |
|
424 | :comments => '', | |
405 | :version => 0 } |
|
425 | :version => 0 } | |
406 | assert_response :success |
|
426 | assert_response :success | |
407 | assert_template 'common/_preview' |
|
427 | assert_template 'common/_preview' | |
408 | assert_tag :tag => 'h1', :content => /New page/ |
|
428 | assert_tag :tag => 'h1', :content => /New page/ | |
409 | end |
|
429 | end | |
410 |
|
430 | |||
411 | def test_history |
|
431 | def test_history | |
412 | get :history, :project_id => 1, :id => 'CookBook_documentation' |
|
432 | get :history, :project_id => 1, :id => 'CookBook_documentation' | |
413 | assert_response :success |
|
433 | assert_response :success | |
414 | assert_template 'history' |
|
434 | assert_template 'history' | |
415 | assert_not_nil assigns(:versions) |
|
435 | assert_not_nil assigns(:versions) | |
416 | assert_equal 3, assigns(:versions).size |
|
436 | assert_equal 3, assigns(:versions).size | |
417 | assert_select "input[type=submit][name=commit]" |
|
437 | assert_select "input[type=submit][name=commit]" | |
418 | end |
|
438 | end | |
419 |
|
439 | |||
420 | def test_history_with_one_version |
|
440 | def test_history_with_one_version | |
421 | get :history, :project_id => 1, :id => 'Another_page' |
|
441 | get :history, :project_id => 1, :id => 'Another_page' | |
422 | assert_response :success |
|
442 | assert_response :success | |
423 | assert_template 'history' |
|
443 | assert_template 'history' | |
424 | assert_not_nil assigns(:versions) |
|
444 | assert_not_nil assigns(:versions) | |
425 | assert_equal 1, assigns(:versions).size |
|
445 | assert_equal 1, assigns(:versions).size | |
426 | assert_select "input[type=submit][name=commit]", false |
|
446 | assert_select "input[type=submit][name=commit]", false | |
427 | end |
|
447 | end | |
428 |
|
448 | |||
429 | def test_diff |
|
449 | def test_diff | |
430 | get :diff, :project_id => 1, :id => 'CookBook_documentation', :version => 2, :version_from => 1 |
|
450 | get :diff, :project_id => 1, :id => 'CookBook_documentation', :version => 2, :version_from => 1 | |
431 | assert_response :success |
|
451 | assert_response :success | |
432 | assert_template 'diff' |
|
452 | assert_template 'diff' | |
433 | assert_tag :tag => 'span', :attributes => { :class => 'diff_in'}, |
|
453 | assert_tag :tag => 'span', :attributes => { :class => 'diff_in'}, | |
434 | :content => /updated/ |
|
454 | :content => /updated/ | |
435 | end |
|
455 | end | |
436 |
|
456 | |||
437 | def test_annotate |
|
457 | def test_annotate | |
438 | get :annotate, :project_id => 1, :id => 'CookBook_documentation', :version => 2 |
|
458 | get :annotate, :project_id => 1, :id => 'CookBook_documentation', :version => 2 | |
439 | assert_response :success |
|
459 | assert_response :success | |
440 | assert_template 'annotate' |
|
460 | assert_template 'annotate' | |
441 |
|
461 | |||
442 | # Line 1 |
|
462 | # Line 1 | |
443 | assert_tag :tag => 'tr', :child => { |
|
463 | assert_tag :tag => 'tr', :child => { | |
444 | :tag => 'th', :attributes => {:class => 'line-num'}, :content => '1', :sibling => { |
|
464 | :tag => 'th', :attributes => {:class => 'line-num'}, :content => '1', :sibling => { | |
445 | :tag => 'td', :attributes => {:class => 'author'}, :content => /John Smith/, :sibling => { |
|
465 | :tag => 'td', :attributes => {:class => 'author'}, :content => /John Smith/, :sibling => { | |
446 | :tag => 'td', :content => /h1\. CookBook documentation/ |
|
466 | :tag => 'td', :content => /h1\. CookBook documentation/ | |
447 | } |
|
467 | } | |
448 | } |
|
468 | } | |
449 | } |
|
469 | } | |
450 |
|
470 | |||
451 | # Line 5 |
|
471 | # Line 5 | |
452 | assert_tag :tag => 'tr', :child => { |
|
472 | assert_tag :tag => 'tr', :child => { | |
453 | :tag => 'th', :attributes => {:class => 'line-num'}, :content => '5', :sibling => { |
|
473 | :tag => 'th', :attributes => {:class => 'line-num'}, :content => '5', :sibling => { | |
454 | :tag => 'td', :attributes => {:class => 'author'}, :content => /redMine Admin/, :sibling => { |
|
474 | :tag => 'td', :attributes => {:class => 'author'}, :content => /redMine Admin/, :sibling => { | |
455 | :tag => 'td', :content => /Some updated \[\[documentation\]\] here/ |
|
475 | :tag => 'td', :content => /Some updated \[\[documentation\]\] here/ | |
456 | } |
|
476 | } | |
457 | } |
|
477 | } | |
458 | } |
|
478 | } | |
459 | end |
|
479 | end | |
460 |
|
480 | |||
461 | def test_get_rename |
|
481 | def test_get_rename | |
462 | @request.session[:user_id] = 2 |
|
482 | @request.session[:user_id] = 2 | |
463 | get :rename, :project_id => 1, :id => 'Another_page' |
|
483 | get :rename, :project_id => 1, :id => 'Another_page' | |
464 | assert_response :success |
|
484 | assert_response :success | |
465 | assert_template 'rename' |
|
485 | assert_template 'rename' | |
466 | assert_tag 'option', |
|
486 | assert_tag 'option', | |
467 | :attributes => {:value => ''}, |
|
487 | :attributes => {:value => ''}, | |
468 | :content => '', |
|
488 | :content => '', | |
469 | :parent => {:tag => 'select', :attributes => {:name => 'wiki_page[parent_id]'}} |
|
489 | :parent => {:tag => 'select', :attributes => {:name => 'wiki_page[parent_id]'}} | |
470 | assert_no_tag 'option', |
|
490 | assert_no_tag 'option', | |
471 | :attributes => {:selected => 'selected'}, |
|
491 | :attributes => {:selected => 'selected'}, | |
472 | :parent => {:tag => 'select', :attributes => {:name => 'wiki_page[parent_id]'}} |
|
492 | :parent => {:tag => 'select', :attributes => {:name => 'wiki_page[parent_id]'}} | |
473 | end |
|
493 | end | |
474 |
|
494 | |||
475 | def test_get_rename_child_page |
|
495 | def test_get_rename_child_page | |
476 | @request.session[:user_id] = 2 |
|
496 | @request.session[:user_id] = 2 | |
477 | get :rename, :project_id => 1, :id => 'Child_1' |
|
497 | get :rename, :project_id => 1, :id => 'Child_1' | |
478 | assert_response :success |
|
498 | assert_response :success | |
479 | assert_template 'rename' |
|
499 | assert_template 'rename' | |
480 | assert_tag 'option', |
|
500 | assert_tag 'option', | |
481 | :attributes => {:value => ''}, |
|
501 | :attributes => {:value => ''}, | |
482 | :content => '', |
|
502 | :content => '', | |
483 | :parent => {:tag => 'select', :attributes => {:name => 'wiki_page[parent_id]'}} |
|
503 | :parent => {:tag => 'select', :attributes => {:name => 'wiki_page[parent_id]'}} | |
484 | assert_tag 'option', |
|
504 | assert_tag 'option', | |
485 | :attributes => {:value => '2', :selected => 'selected'}, |
|
505 | :attributes => {:value => '2', :selected => 'selected'}, | |
486 | :content => /Another page/, |
|
506 | :content => /Another page/, | |
487 | :parent => { |
|
507 | :parent => { | |
488 | :tag => 'select', |
|
508 | :tag => 'select', | |
489 | :attributes => {:name => 'wiki_page[parent_id]'} |
|
509 | :attributes => {:name => 'wiki_page[parent_id]'} | |
490 | } |
|
510 | } | |
491 | end |
|
511 | end | |
492 |
|
512 | |||
493 | def test_rename_with_redirect |
|
513 | def test_rename_with_redirect | |
494 | @request.session[:user_id] = 2 |
|
514 | @request.session[:user_id] = 2 | |
495 | post :rename, :project_id => 1, :id => 'Another_page', |
|
515 | post :rename, :project_id => 1, :id => 'Another_page', | |
496 | :wiki_page => { :title => 'Another renamed page', |
|
516 | :wiki_page => { :title => 'Another renamed page', | |
497 | :redirect_existing_links => 1 } |
|
517 | :redirect_existing_links => 1 } | |
498 | assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'Another_renamed_page' |
|
518 | assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'Another_renamed_page' | |
499 | wiki = Project.find(1).wiki |
|
519 | wiki = Project.find(1).wiki | |
500 | # Check redirects |
|
520 | # Check redirects | |
501 | assert_not_nil wiki.find_page('Another page') |
|
521 | assert_not_nil wiki.find_page('Another page') | |
502 | assert_nil wiki.find_page('Another page', :with_redirect => false) |
|
522 | assert_nil wiki.find_page('Another page', :with_redirect => false) | |
503 | end |
|
523 | end | |
504 |
|
524 | |||
505 | def test_rename_without_redirect |
|
525 | def test_rename_without_redirect | |
506 | @request.session[:user_id] = 2 |
|
526 | @request.session[:user_id] = 2 | |
507 | post :rename, :project_id => 1, :id => 'Another_page', |
|
527 | post :rename, :project_id => 1, :id => 'Another_page', | |
508 | :wiki_page => { :title => 'Another renamed page', |
|
528 | :wiki_page => { :title => 'Another renamed page', | |
509 | :redirect_existing_links => "0" } |
|
529 | :redirect_existing_links => "0" } | |
510 | assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'Another_renamed_page' |
|
530 | assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'Another_renamed_page' | |
511 | wiki = Project.find(1).wiki |
|
531 | wiki = Project.find(1).wiki | |
512 | # Check that there's no redirects |
|
532 | # Check that there's no redirects | |
513 | assert_nil wiki.find_page('Another page') |
|
533 | assert_nil wiki.find_page('Another page') | |
514 | end |
|
534 | end | |
515 |
|
535 | |||
516 | def test_rename_with_parent_assignment |
|
536 | def test_rename_with_parent_assignment | |
517 | @request.session[:user_id] = 2 |
|
537 | @request.session[:user_id] = 2 | |
518 | post :rename, :project_id => 1, :id => 'Another_page', |
|
538 | post :rename, :project_id => 1, :id => 'Another_page', | |
519 | :wiki_page => { :title => 'Another page', :redirect_existing_links => "0", :parent_id => '4' } |
|
539 | :wiki_page => { :title => 'Another page', :redirect_existing_links => "0", :parent_id => '4' } | |
520 | assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'Another_page' |
|
540 | assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'Another_page' | |
521 | assert_equal WikiPage.find(4), WikiPage.find_by_title('Another_page').parent |
|
541 | assert_equal WikiPage.find(4), WikiPage.find_by_title('Another_page').parent | |
522 | end |
|
542 | end | |
523 |
|
543 | |||
524 | def test_rename_with_parent_unassignment |
|
544 | def test_rename_with_parent_unassignment | |
525 | @request.session[:user_id] = 2 |
|
545 | @request.session[:user_id] = 2 | |
526 | post :rename, :project_id => 1, :id => 'Child_1', |
|
546 | post :rename, :project_id => 1, :id => 'Child_1', | |
527 | :wiki_page => { :title => 'Child 1', :redirect_existing_links => "0", :parent_id => '' } |
|
547 | :wiki_page => { :title => 'Child 1', :redirect_existing_links => "0", :parent_id => '' } | |
528 | assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'Child_1' |
|
548 | assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'Child_1' | |
529 | assert_nil WikiPage.find_by_title('Child_1').parent |
|
549 | assert_nil WikiPage.find_by_title('Child_1').parent | |
530 | end |
|
550 | end | |
531 |
|
551 | |||
532 | def test_destroy_child |
|
552 | def test_destroy_child | |
533 | @request.session[:user_id] = 2 |
|
553 | @request.session[:user_id] = 2 | |
534 | delete :destroy, :project_id => 1, :id => 'Child_1' |
|
554 | delete :destroy, :project_id => 1, :id => 'Child_1' | |
535 | assert_redirected_to :action => 'index', :project_id => 'ecookbook' |
|
555 | assert_redirected_to :action => 'index', :project_id => 'ecookbook' | |
536 | end |
|
556 | end | |
537 |
|
557 | |||
538 | def test_destroy_parent |
|
558 | def test_destroy_parent | |
539 | @request.session[:user_id] = 2 |
|
559 | @request.session[:user_id] = 2 | |
540 | assert_no_difference('WikiPage.count') do |
|
560 | assert_no_difference('WikiPage.count') do | |
541 | delete :destroy, :project_id => 1, :id => 'Another_page' |
|
561 | delete :destroy, :project_id => 1, :id => 'Another_page' | |
542 | end |
|
562 | end | |
543 | assert_response :success |
|
563 | assert_response :success | |
544 | assert_template 'destroy' |
|
564 | assert_template 'destroy' | |
545 | end |
|
565 | end | |
546 |
|
566 | |||
547 | def test_destroy_parent_with_nullify |
|
567 | def test_destroy_parent_with_nullify | |
548 | @request.session[:user_id] = 2 |
|
568 | @request.session[:user_id] = 2 | |
549 | assert_difference('WikiPage.count', -1) do |
|
569 | assert_difference('WikiPage.count', -1) do | |
550 | delete :destroy, :project_id => 1, :id => 'Another_page', :todo => 'nullify' |
|
570 | delete :destroy, :project_id => 1, :id => 'Another_page', :todo => 'nullify' | |
551 | end |
|
571 | end | |
552 | assert_redirected_to :action => 'index', :project_id => 'ecookbook' |
|
572 | assert_redirected_to :action => 'index', :project_id => 'ecookbook' | |
553 | assert_nil WikiPage.find_by_id(2) |
|
573 | assert_nil WikiPage.find_by_id(2) | |
554 | end |
|
574 | end | |
555 |
|
575 | |||
556 | def test_destroy_parent_with_cascade |
|
576 | def test_destroy_parent_with_cascade | |
557 | @request.session[:user_id] = 2 |
|
577 | @request.session[:user_id] = 2 | |
558 | assert_difference('WikiPage.count', -3) do |
|
578 | assert_difference('WikiPage.count', -3) do | |
559 | delete :destroy, :project_id => 1, :id => 'Another_page', :todo => 'destroy' |
|
579 | delete :destroy, :project_id => 1, :id => 'Another_page', :todo => 'destroy' | |
560 | end |
|
580 | end | |
561 | assert_redirected_to :action => 'index', :project_id => 'ecookbook' |
|
581 | assert_redirected_to :action => 'index', :project_id => 'ecookbook' | |
562 | assert_nil WikiPage.find_by_id(2) |
|
582 | assert_nil WikiPage.find_by_id(2) | |
563 | assert_nil WikiPage.find_by_id(5) |
|
583 | assert_nil WikiPage.find_by_id(5) | |
564 | end |
|
584 | end | |
565 |
|
585 | |||
566 | def test_destroy_parent_with_reassign |
|
586 | def test_destroy_parent_with_reassign | |
567 | @request.session[:user_id] = 2 |
|
587 | @request.session[:user_id] = 2 | |
568 | assert_difference('WikiPage.count', -1) do |
|
588 | assert_difference('WikiPage.count', -1) do | |
569 | delete :destroy, :project_id => 1, :id => 'Another_page', :todo => 'reassign', :reassign_to_id => 1 |
|
589 | delete :destroy, :project_id => 1, :id => 'Another_page', :todo => 'reassign', :reassign_to_id => 1 | |
570 | end |
|
590 | end | |
571 | assert_redirected_to :action => 'index', :project_id => 'ecookbook' |
|
591 | assert_redirected_to :action => 'index', :project_id => 'ecookbook' | |
572 | assert_nil WikiPage.find_by_id(2) |
|
592 | assert_nil WikiPage.find_by_id(2) | |
573 | assert_equal WikiPage.find(1), WikiPage.find_by_id(5).parent |
|
593 | assert_equal WikiPage.find(1), WikiPage.find_by_id(5).parent | |
574 | end |
|
594 | end | |
575 |
|
595 | |||
576 | def test_index |
|
596 | def test_index | |
577 | get :index, :project_id => 'ecookbook' |
|
597 | get :index, :project_id => 'ecookbook' | |
578 | assert_response :success |
|
598 | assert_response :success | |
579 | assert_template 'index' |
|
599 | assert_template 'index' | |
580 | pages = assigns(:pages) |
|
600 | pages = assigns(:pages) | |
581 | assert_not_nil pages |
|
601 | assert_not_nil pages | |
582 | assert_equal Project.find(1).wiki.pages.size, pages.size |
|
602 | assert_equal Project.find(1).wiki.pages.size, pages.size | |
583 | assert_equal pages.first.content.updated_on, pages.first.updated_on |
|
603 | assert_equal pages.first.content.updated_on, pages.first.updated_on | |
584 |
|
604 | |||
585 | assert_tag :ul, :attributes => { :class => 'pages-hierarchy' }, |
|
605 | assert_tag :ul, :attributes => { :class => 'pages-hierarchy' }, | |
586 | :child => { :tag => 'li', :child => { :tag => 'a', :attributes => { :href => '/projects/ecookbook/wiki/CookBook_documentation' }, |
|
606 | :child => { :tag => 'li', :child => { :tag => 'a', :attributes => { :href => '/projects/ecookbook/wiki/CookBook_documentation' }, | |
587 | :content => 'CookBook documentation' }, |
|
607 | :content => 'CookBook documentation' }, | |
588 | :child => { :tag => 'ul', |
|
608 | :child => { :tag => 'ul', | |
589 | :child => { :tag => 'li', |
|
609 | :child => { :tag => 'li', | |
590 | :child => { :tag => 'a', :attributes => { :href => '/projects/ecookbook/wiki/Page_with_an_inline_image' }, |
|
610 | :child => { :tag => 'a', :attributes => { :href => '/projects/ecookbook/wiki/Page_with_an_inline_image' }, | |
591 | :content => 'Page with an inline image' } } } }, |
|
611 | :content => 'Page with an inline image' } } } }, | |
592 | :child => { :tag => 'li', :child => { :tag => 'a', :attributes => { :href => '/projects/ecookbook/wiki/Another_page' }, |
|
612 | :child => { :tag => 'li', :child => { :tag => 'a', :attributes => { :href => '/projects/ecookbook/wiki/Another_page' }, | |
593 | :content => 'Another page' } } |
|
613 | :content => 'Another page' } } | |
594 | end |
|
614 | end | |
595 |
|
615 | |||
596 | def test_index_should_include_atom_link |
|
616 | def test_index_should_include_atom_link | |
597 | get :index, :project_id => 'ecookbook' |
|
617 | get :index, :project_id => 'ecookbook' | |
598 | assert_tag 'a', :attributes => { :href => '/projects/ecookbook/activity.atom?show_wiki_edits=1'} |
|
618 | assert_tag 'a', :attributes => { :href => '/projects/ecookbook/activity.atom?show_wiki_edits=1'} | |
599 | end |
|
619 | end | |
600 |
|
620 | |||
601 | context "GET :export" do |
|
621 | context "GET :export" do | |
602 | context "with an authorized user to export the wiki" do |
|
622 | context "with an authorized user to export the wiki" do | |
603 | setup do |
|
623 | setup do | |
604 | @request.session[:user_id] = 2 |
|
624 | @request.session[:user_id] = 2 | |
605 | get :export, :project_id => 'ecookbook' |
|
625 | get :export, :project_id => 'ecookbook' | |
606 | end |
|
626 | end | |
607 |
|
627 | |||
608 | should_respond_with :success |
|
628 | should_respond_with :success | |
609 | should_assign_to :pages |
|
629 | should_assign_to :pages | |
610 | should_respond_with_content_type "text/html" |
|
630 | should_respond_with_content_type "text/html" | |
611 | should "export all of the wiki pages to a single html file" do |
|
631 | should "export all of the wiki pages to a single html file" do | |
612 | assert_select "a[name=?]", "CookBook_documentation" |
|
632 | assert_select "a[name=?]", "CookBook_documentation" | |
613 | assert_select "a[name=?]", "Another_page" |
|
633 | assert_select "a[name=?]", "Another_page" | |
614 | assert_select "a[name=?]", "Page_with_an_inline_image" |
|
634 | assert_select "a[name=?]", "Page_with_an_inline_image" | |
615 | end |
|
635 | end | |
616 |
|
636 | |||
617 | end |
|
637 | end | |
618 |
|
638 | |||
619 | context "with an unauthorized user" do |
|
639 | context "with an unauthorized user" do | |
620 | setup do |
|
640 | setup do | |
621 | get :export, :project_id => 'ecookbook' |
|
641 | get :export, :project_id => 'ecookbook' | |
622 |
|
642 | |||
623 | should_respond_with :redirect |
|
643 | should_respond_with :redirect | |
624 | should_redirect_to('wiki index') { {:action => 'show', :project_id => @project, :id => nil} } |
|
644 | should_redirect_to('wiki index') { {:action => 'show', :project_id => @project, :id => nil} } | |
625 | end |
|
645 | end | |
626 | end |
|
646 | end | |
627 | end |
|
647 | end | |
628 |
|
648 | |||
629 | context "GET :date_index" do |
|
649 | context "GET :date_index" do | |
630 | setup do |
|
650 | setup do | |
631 | get :date_index, :project_id => 'ecookbook' |
|
651 | get :date_index, :project_id => 'ecookbook' | |
632 | end |
|
652 | end | |
633 |
|
653 | |||
634 | should_respond_with :success |
|
654 | should_respond_with :success | |
635 | should_assign_to :pages |
|
655 | should_assign_to :pages | |
636 | should_assign_to :pages_by_date |
|
656 | should_assign_to :pages_by_date | |
637 | should_render_template 'wiki/date_index' |
|
657 | should_render_template 'wiki/date_index' | |
638 |
|
658 | |||
639 | should "include atom link" do |
|
659 | should "include atom link" do | |
640 | assert_tag 'a', :attributes => { :href => '/projects/ecookbook/activity.atom?show_wiki_edits=1'} |
|
660 | assert_tag 'a', :attributes => { :href => '/projects/ecookbook/activity.atom?show_wiki_edits=1'} | |
641 | end |
|
661 | end | |
642 | end |
|
662 | end | |
643 |
|
663 | |||
644 | def test_not_found |
|
664 | def test_not_found | |
645 | get :show, :project_id => 999 |
|
665 | get :show, :project_id => 999 | |
646 | assert_response 404 |
|
666 | assert_response 404 | |
647 | end |
|
667 | end | |
648 |
|
668 | |||
649 | def test_protect_page |
|
669 | def test_protect_page | |
650 | page = WikiPage.find_by_wiki_id_and_title(1, 'Another_page') |
|
670 | page = WikiPage.find_by_wiki_id_and_title(1, 'Another_page') | |
651 | assert !page.protected? |
|
671 | assert !page.protected? | |
652 | @request.session[:user_id] = 2 |
|
672 | @request.session[:user_id] = 2 | |
653 | post :protect, :project_id => 1, :id => page.title, :protected => '1' |
|
673 | post :protect, :project_id => 1, :id => page.title, :protected => '1' | |
654 | assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'Another_page' |
|
674 | assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'Another_page' | |
655 | assert page.reload.protected? |
|
675 | assert page.reload.protected? | |
656 | end |
|
676 | end | |
657 |
|
677 | |||
658 | def test_unprotect_page |
|
678 | def test_unprotect_page | |
659 | page = WikiPage.find_by_wiki_id_and_title(1, 'CookBook_documentation') |
|
679 | page = WikiPage.find_by_wiki_id_and_title(1, 'CookBook_documentation') | |
660 | assert page.protected? |
|
680 | assert page.protected? | |
661 | @request.session[:user_id] = 2 |
|
681 | @request.session[:user_id] = 2 | |
662 | post :protect, :project_id => 1, :id => page.title, :protected => '0' |
|
682 | post :protect, :project_id => 1, :id => page.title, :protected => '0' | |
663 | assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'CookBook_documentation' |
|
683 | assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'CookBook_documentation' | |
664 | assert !page.reload.protected? |
|
684 | assert !page.reload.protected? | |
665 | end |
|
685 | end | |
666 |
|
686 | |||
667 | def test_show_page_with_edit_link |
|
687 | def test_show_page_with_edit_link | |
668 | @request.session[:user_id] = 2 |
|
688 | @request.session[:user_id] = 2 | |
669 | get :show, :project_id => 1 |
|
689 | get :show, :project_id => 1 | |
670 | assert_response :success |
|
690 | assert_response :success | |
671 | assert_template 'show' |
|
691 | assert_template 'show' | |
672 | assert_tag :tag => 'a', :attributes => { :href => '/projects/1/wiki/CookBook_documentation/edit' } |
|
692 | assert_tag :tag => 'a', :attributes => { :href => '/projects/1/wiki/CookBook_documentation/edit' } | |
673 | end |
|
693 | end | |
674 |
|
694 | |||
675 | def test_show_page_without_edit_link |
|
695 | def test_show_page_without_edit_link | |
676 | @request.session[:user_id] = 4 |
|
696 | @request.session[:user_id] = 4 | |
677 | get :show, :project_id => 1 |
|
697 | get :show, :project_id => 1 | |
678 | assert_response :success |
|
698 | assert_response :success | |
679 | assert_template 'show' |
|
699 | assert_template 'show' | |
680 | assert_no_tag :tag => 'a', :attributes => { :href => '/projects/1/wiki/CookBook_documentation/edit' } |
|
700 | assert_no_tag :tag => 'a', :attributes => { :href => '/projects/1/wiki/CookBook_documentation/edit' } | |
681 | end |
|
701 | end | |
682 |
|
702 | |||
683 | def test_show_pdf |
|
703 | def test_show_pdf | |
684 | @request.session[:user_id] = 2 |
|
704 | @request.session[:user_id] = 2 | |
685 | get :show, :project_id => 1, :format => 'pdf' |
|
705 | get :show, :project_id => 1, :format => 'pdf' | |
686 | assert_response :success |
|
706 | assert_response :success | |
687 | assert_not_nil assigns(:page) |
|
707 | assert_not_nil assigns(:page) | |
688 | assert_equal 'application/pdf', @response.content_type |
|
708 | assert_equal 'application/pdf', @response.content_type | |
689 | assert_equal 'attachment; filename="CookBook_documentation.pdf"', |
|
709 | assert_equal 'attachment; filename="CookBook_documentation.pdf"', | |
690 | @response.headers['Content-Disposition'] |
|
710 | @response.headers['Content-Disposition'] | |
691 | end |
|
711 | end | |
692 |
|
712 | |||
693 | def test_show_html |
|
713 | def test_show_html | |
694 | @request.session[:user_id] = 2 |
|
714 | @request.session[:user_id] = 2 | |
695 | get :show, :project_id => 1, :format => 'html' |
|
715 | get :show, :project_id => 1, :format => 'html' | |
696 | assert_response :success |
|
716 | assert_response :success | |
697 | assert_not_nil assigns(:page) |
|
717 | assert_not_nil assigns(:page) | |
698 | assert_equal 'text/html', @response.content_type |
|
718 | assert_equal 'text/html', @response.content_type | |
699 | assert_equal 'attachment; filename="CookBook_documentation.html"', |
|
719 | assert_equal 'attachment; filename="CookBook_documentation.html"', | |
700 | @response.headers['Content-Disposition'] |
|
720 | @response.headers['Content-Disposition'] | |
701 | end |
|
721 | end | |
702 |
|
722 | |||
703 | def test_show_txt |
|
723 | def test_show_txt | |
704 | @request.session[:user_id] = 2 |
|
724 | @request.session[:user_id] = 2 | |
705 | get :show, :project_id => 1, :format => 'txt' |
|
725 | get :show, :project_id => 1, :format => 'txt' | |
706 | assert_response :success |
|
726 | assert_response :success | |
707 | assert_not_nil assigns(:page) |
|
727 | assert_not_nil assigns(:page) | |
708 | assert_equal 'text/plain', @response.content_type |
|
728 | assert_equal 'text/plain', @response.content_type | |
709 | assert_equal 'attachment; filename="CookBook_documentation.txt"', |
|
729 | assert_equal 'attachment; filename="CookBook_documentation.txt"', | |
710 | @response.headers['Content-Disposition'] |
|
730 | @response.headers['Content-Disposition'] | |
711 | end |
|
731 | end | |
712 |
|
732 | |||
713 | def test_edit_unprotected_page |
|
733 | def test_edit_unprotected_page | |
714 | # Non members can edit unprotected wiki pages |
|
734 | # Non members can edit unprotected wiki pages | |
715 | @request.session[:user_id] = 4 |
|
735 | @request.session[:user_id] = 4 | |
716 | get :edit, :project_id => 1, :id => 'Another_page' |
|
736 | get :edit, :project_id => 1, :id => 'Another_page' | |
717 | assert_response :success |
|
737 | assert_response :success | |
718 | assert_template 'edit' |
|
738 | assert_template 'edit' | |
719 | end |
|
739 | end | |
720 |
|
740 | |||
721 | def test_edit_protected_page_by_nonmember |
|
741 | def test_edit_protected_page_by_nonmember | |
722 | # Non members can't edit protected wiki pages |
|
742 | # Non members can't edit protected wiki pages | |
723 | @request.session[:user_id] = 4 |
|
743 | @request.session[:user_id] = 4 | |
724 | get :edit, :project_id => 1, :id => 'CookBook_documentation' |
|
744 | get :edit, :project_id => 1, :id => 'CookBook_documentation' | |
725 | assert_response 403 |
|
745 | assert_response 403 | |
726 | end |
|
746 | end | |
727 |
|
747 | |||
728 | def test_edit_protected_page_by_member |
|
748 | def test_edit_protected_page_by_member | |
729 | @request.session[:user_id] = 2 |
|
749 | @request.session[:user_id] = 2 | |
730 | get :edit, :project_id => 1, :id => 'CookBook_documentation' |
|
750 | get :edit, :project_id => 1, :id => 'CookBook_documentation' | |
731 | assert_response :success |
|
751 | assert_response :success | |
732 | assert_template 'edit' |
|
752 | assert_template 'edit' | |
733 | end |
|
753 | end | |
734 |
|
754 | |||
735 | def test_history_of_non_existing_page_should_return_404 |
|
755 | def test_history_of_non_existing_page_should_return_404 | |
736 | get :history, :project_id => 1, :id => 'Unknown_page' |
|
756 | get :history, :project_id => 1, :id => 'Unknown_page' | |
737 | assert_response 404 |
|
757 | assert_response 404 | |
738 | end |
|
758 | end | |
|
759 | ||||
|
760 | def test_add_attachment | |||
|
761 | @request.session[:user_id] = 2 | |||
|
762 | assert_difference 'Attachment.count' do | |||
|
763 | post :add_attachment, :project_id => 1, :id => 'CookBook_documentation', | |||
|
764 | :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'test file'}} | |||
|
765 | end | |||
|
766 | attachment = Attachment.first(:order => 'id DESC') | |||
|
767 | assert_equal Wiki.find(1).find_page('CookBook_documentation'), attachment.container | |||
|
768 | end | |||
739 | end |
|
769 | end |
General Comments 0
You need to be logged in to leave comments.
Login now