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