##// END OF EJS Templates
Merged r7971 from trunk (#9682)....
Jean-Philippe Lang -
r7996:d19a0b70e0c3
parent child
Show More
@@ -1,61 +1,61
1 <div class="contextual">
1 <div class="contextual">
2 <% if @editable %>
2 <% if @editable %>
3 <%= link_to_if_authorized(l(:button_edit), {:action => 'edit', :id => @page.title}, :class => 'icon icon-edit', :accesskey => accesskey(:edit)) if @content.version == @page.content.version %>
3 <%= link_to_if_authorized(l(:button_edit), {:action => 'edit', :id => @page.title}, :class => 'icon icon-edit', :accesskey => accesskey(:edit)) if @content.version == @page.content.version %>
4 <%= watcher_tag(@page, User.current) %>
4 <%= watcher_tag(@page, User.current) %>
5 <%= link_to_if_authorized(l(:button_lock), {:action => 'protect', :id => @page.title, :protected => 1}, :method => :post, :class => 'icon icon-lock') if !@page.protected? %>
5 <%= link_to_if_authorized(l(:button_lock), {:action => 'protect', :id => @page.title, :protected => 1}, :method => :post, :class => 'icon icon-lock') if !@page.protected? %>
6 <%= link_to_if_authorized(l(:button_unlock), {:action => 'protect', :id => @page.title, :protected => 0}, :method => :post, :class => 'icon icon-unlock') if @page.protected? %>
6 <%= link_to_if_authorized(l(:button_unlock), {:action => 'protect', :id => @page.title, :protected => 0}, :method => :post, :class => 'icon icon-unlock') if @page.protected? %>
7 <%= link_to_if_authorized(l(:button_rename), {:action => 'rename', :id => @page.title}, :class => 'icon icon-move') if @content.version == @page.content.version %>
7 <%= link_to_if_authorized(l(:button_rename), {:action => 'rename', :id => @page.title}, :class => 'icon icon-move') if @content.version == @page.content.version %>
8 <%= link_to_if_authorized(l(:button_delete), {:action => 'destroy', :id => @page.title}, :method => :delete, :confirm => l(:text_are_you_sure), :class => 'icon icon-del') %>
8 <%= link_to_if_authorized(l(:button_delete), {:action => 'destroy', :id => @page.title}, :method => :delete, :confirm => l(:text_are_you_sure), :class => 'icon icon-del') %>
9 <%= link_to_if_authorized(l(:button_rollback), {:action => 'edit', :id => @page.title, :version => @content.version }, :class => 'icon icon-cancel') if @content.version < @page.content.version %>
9 <%= link_to_if_authorized(l(:button_rollback), {:action => 'edit', :id => @page.title, :version => @content.version }, :class => 'icon icon-cancel') if @content.version < @page.content.version %>
10 <% end %>
10 <% end %>
11 <%= link_to_if_authorized(l(:label_history), {:action => 'history', :id => @page.title}, :class => 'icon icon-history') %>
11 <%= link_to_if_authorized(l(:label_history), {:action => 'history', :id => @page.title}, :class => 'icon icon-history') %>
12 </div>
12 </div>
13
13
14 <%= breadcrumb(@page.ancestors.reverse.collect {|parent| link_to h(parent.pretty_title), {:id => parent.title, :project_id => parent.project}}) %>
14 <%= breadcrumb(@page.ancestors.reverse.collect {|parent| link_to h(parent.pretty_title), {:id => parent.title, :project_id => parent.project}}) %>
15
15
16 <% if @content.version != @page.content.version %>
16 <% if @content.version != @page.content.version %>
17 <p>
17 <p>
18 <%= link_to(('&#171; ' + l(:label_previous)), :action => 'show', :id => @page.title, :project_id => @page.project, :version => (@content.version - 1)) + " - " if @content.version > 1 %>
18 <%= link_to(('&#171; ' + l(:label_previous)), :action => 'show', :id => @page.title, :project_id => @page.project, :version => (@content.version - 1)) + " - " if @content.version > 1 %>
19 <%= "#{l(:label_version)} #{@content.version}/#{@page.content.version}" %>
19 <%= "#{l(:label_version)} #{@content.version}/#{@page.content.version}" %>
20 <%= '(' + link_to('diff', :controller => 'wiki', :action => 'diff', :id => @page.title, :project_id => @page.project, :version => @content.version) + ')' if @content.version > 1 %> -
20 <%= '(' + link_to('diff', :controller => 'wiki', :action => 'diff', :id => @page.title, :project_id => @page.project, :version => @content.version) + ')' if @content.version > 1 %> -
21 <%= link_to((l(:label_next) + ' &#187;'), :action => 'show', :id => @page.title, :project_id => @page.project, :version => (@content.version + 1)) + " - " if @content.version < @page.content.version %>
21 <%= link_to((l(:label_next) + ' &#187;'), :action => 'show', :id => @page.title, :project_id => @page.project, :version => (@content.version + 1)) + " - " if @content.version < @page.content.version %>
22 <%= link_to(l(:label_current_version), :action => 'show', :id => @page.title, :project_id => @page.project) %>
22 <%= link_to(l(:label_current_version), :action => 'show', :id => @page.title, :project_id => @page.project) %>
23 <br />
23 <br />
24 <em><%= @content.author ? @content.author.name : "anonyme" %>, <%= format_time(@content.updated_on) %> </em><br />
24 <em><%= @content.author ? @content.author.name : "anonyme" %>, <%= format_time(@content.updated_on) %> </em><br />
25 <%=h @content.comments %>
25 <%=h @content.comments %>
26 </p>
26 </p>
27 <hr />
27 <hr />
28 <% end %>
28 <% end %>
29
29
30 <%= render(:partial => "wiki/content", :locals => {:content => @content}) %>
30 <%= render(:partial => "wiki/content", :locals => {:content => @content}) %>
31
31
32 <%= link_to_attachments @page %>
32 <%= link_to_attachments @page %>
33
33
34 <% if @editable && authorize_for('wiki', 'add_attachment') %>
34 <% if @editable && authorize_for('wiki', 'add_attachment') %>
35 <div id="wiki_add_attachment">
35 <div id="wiki_add_attachment">
36 <p><%= link_to l(:label_attachment_new), {}, :onclick => "Element.show('add_attachment_form'); Element.hide(this); Element.scrollTo('add_attachment_form'); return false;",
36 <p><%= link_to l(:label_attachment_new), {}, :onclick => "Element.show('add_attachment_form'); Element.hide(this); Element.scrollTo('add_attachment_form'); return false;",
37 :id => 'attach_files_link' %></p>
37 :id => 'attach_files_link' %></p>
38 <% form_tag({ :controller => 'wiki', :action => 'add_attachment', :project_id => @project, :id => @page.title }, :multipart => true, :id => "add_attachment_form", :style => "display:none;") do %>
38 <% form_tag({ :controller => 'wiki', :action => 'add_attachment', :project_id => @project, :id => @page.title }, :multipart => true, :id => "add_attachment_form", :style => "display:none;") do %>
39 <div class="box">
39 <div class="box">
40 <p><%= render :partial => 'attachments/form' %></p>
40 <p><%= render :partial => 'attachments/form' %></p>
41 </div>
41 </div>
42 <%= submit_tag l(:button_add) %>
42 <%= submit_tag l(:button_add) %>
43 <%= link_to l(:button_cancel), {}, :onclick => "Element.hide('add_attachment_form'); Element.show('attach_files_link'); return false;" %>
43 <%= link_to l(:button_cancel), {}, :onclick => "Element.hide('add_attachment_form'); Element.show('attach_files_link'); return false;" %>
44 <% end %>
44 <% end %>
45 </div>
45 </div>
46 <% end %>
46 <% end %>
47
47
48 <% other_formats_links do |f| %>
48 <% other_formats_links do |f| %>
49 <%= f.link_to 'HTML', :url => {:id => @page.title, :version => @content.version} %>
49 <%= f.link_to 'HTML', :url => {:id => @page.title, :version => params[:version]} %>
50 <%= f.link_to 'TXT', :url => {:id => @page.title, :version => @content.version} %>
50 <%= f.link_to 'TXT', :url => {:id => @page.title, :version => params[:version]} %>
51 <% end if User.current.allowed_to?(:export_wiki_pages, @project) %>
51 <% end if User.current.allowed_to?(:export_wiki_pages, @project) %>
52
52
53 <% content_for :header_tags do %>
53 <% content_for :header_tags do %>
54 <%= stylesheet_link_tag 'scm' %>
54 <%= stylesheet_link_tag 'scm' %>
55 <% end %>
55 <% end %>
56
56
57 <% content_for :sidebar do %>
57 <% content_for :sidebar do %>
58 <%= render :partial => 'sidebar' %>
58 <%= render :partial => 'sidebar' %>
59 <% end %>
59 <% end %>
60
60
61 <% html_title @page.pretty_title %>
61 <% html_title @page.pretty_title %>
@@ -1,521 +1,528
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, :enabled_modules, :wikis, :wiki_pages, :wiki_contents, :wiki_content_versions, :attachments
25 fixtures :projects, :users, :roles, :members, :member_roles, :enabled_modules, :wikis, :wiki_pages, :wiki_contents, :wiki_content_versions, :attachments
26
26
27 def setup
27 def setup
28 @controller = WikiController.new
28 @controller = WikiController.new
29 @request = ActionController::TestRequest.new
29 @request = ActionController::TestRequest.new
30 @response = ActionController::TestResponse.new
30 @response = ActionController::TestResponse.new
31 User.current = nil
31 User.current = nil
32 end
32 end
33
33
34 def test_show_start_page
34 def test_show_start_page
35 get :show, :project_id => 'ecookbook'
35 get :show, :project_id => 'ecookbook'
36 assert_response :success
36 assert_response :success
37 assert_template 'show'
37 assert_template 'show'
38 assert_tag :tag => 'h1', :content => /CookBook documentation/
38 assert_tag :tag => 'h1', :content => /CookBook documentation/
39
39
40 # child_pages macro
40 # child_pages macro
41 assert_tag :ul, :attributes => { :class => 'pages-hierarchy' },
41 assert_tag :ul, :attributes => { :class => 'pages-hierarchy' },
42 :child => { :tag => 'li',
42 :child => { :tag => 'li',
43 :child => { :tag => 'a', :attributes => { :href => '/projects/ecookbook/wiki/Page_with_an_inline_image' },
43 :child => { :tag => 'a', :attributes => { :href => '/projects/ecookbook/wiki/Page_with_an_inline_image' },
44 :content => 'Page with an inline image' } }
44 :content => 'Page with an inline image' } }
45 end
45 end
46
47 def test_export_link
48 Role.anonymous.add_permission! :export_wiki_pages
49 get :show, :project_id => 'ecookbook'
50 assert_response :success
51 assert_tag 'a', :attributes => {:href => '/projects/ecookbook/wiki/CookBook_documentation.txt'}
52 end
46
53
47 def test_show_page_with_name
54 def test_show_page_with_name
48 get :show, :project_id => 1, :id => 'Another_page'
55 get :show, :project_id => 1, :id => 'Another_page'
49 assert_response :success
56 assert_response :success
50 assert_template 'show'
57 assert_template 'show'
51 assert_tag :tag => 'h1', :content => /Another page/
58 assert_tag :tag => 'h1', :content => /Another page/
52 # Included page with an inline image
59 # Included page with an inline image
53 assert_tag :tag => 'p', :content => /This is an inline image/
60 assert_tag :tag => 'p', :content => /This is an inline image/
54 assert_tag :tag => 'img', :attributes => { :src => '/attachments/download/3',
61 assert_tag :tag => 'img', :attributes => { :src => '/attachments/download/3',
55 :alt => 'This is a logo' }
62 :alt => 'This is a logo' }
56 end
63 end
57
64
58 def test_show_redirected_page
65 def test_show_redirected_page
59 WikiRedirect.create!(:wiki_id => 1, :title => 'Old_title', :redirects_to => 'Another_page')
66 WikiRedirect.create!(:wiki_id => 1, :title => 'Old_title', :redirects_to => 'Another_page')
60
67
61 get :show, :project_id => 'ecookbook', :id => 'Old_title'
68 get :show, :project_id => 'ecookbook', :id => 'Old_title'
62 assert_redirected_to '/projects/ecookbook/wiki/Another_page'
69 assert_redirected_to '/projects/ecookbook/wiki/Another_page'
63 end
70 end
64
71
65 def test_show_with_sidebar
72 def test_show_with_sidebar
66 page = Project.find(1).wiki.pages.new(:title => 'Sidebar')
73 page = Project.find(1).wiki.pages.new(:title => 'Sidebar')
67 page.content = WikiContent.new(:text => 'Side bar content for test_show_with_sidebar')
74 page.content = WikiContent.new(:text => 'Side bar content for test_show_with_sidebar')
68 page.save!
75 page.save!
69
76
70 get :show, :project_id => 1, :id => 'Another_page'
77 get :show, :project_id => 1, :id => 'Another_page'
71 assert_response :success
78 assert_response :success
72 assert_tag :tag => 'div', :attributes => {:id => 'sidebar'},
79 assert_tag :tag => 'div', :attributes => {:id => 'sidebar'},
73 :content => /Side bar content for test_show_with_sidebar/
80 :content => /Side bar content for test_show_with_sidebar/
74 end
81 end
75
82
76 def test_show_unexistent_page_without_edit_right
83 def test_show_unexistent_page_without_edit_right
77 get :show, :project_id => 1, :id => 'Unexistent page'
84 get :show, :project_id => 1, :id => 'Unexistent page'
78 assert_response 404
85 assert_response 404
79 end
86 end
80
87
81 def test_show_unexistent_page_with_edit_right
88 def test_show_unexistent_page_with_edit_right
82 @request.session[:user_id] = 2
89 @request.session[:user_id] = 2
83 get :show, :project_id => 1, :id => 'Unexistent page'
90 get :show, :project_id => 1, :id => 'Unexistent page'
84 assert_response :success
91 assert_response :success
85 assert_template 'edit'
92 assert_template 'edit'
86 end
93 end
87
94
88 def test_create_page
95 def test_create_page
89 @request.session[:user_id] = 2
96 @request.session[:user_id] = 2
90 put :update, :project_id => 1,
97 put :update, :project_id => 1,
91 :id => 'New page',
98 :id => 'New page',
92 :content => {:comments => 'Created the page',
99 :content => {:comments => 'Created the page',
93 :text => "h1. New page\n\nThis is a new page",
100 :text => "h1. New page\n\nThis is a new page",
94 :version => 0}
101 :version => 0}
95 assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'New_page'
102 assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'New_page'
96 page = Project.find(1).wiki.find_page('New page')
103 page = Project.find(1).wiki.find_page('New page')
97 assert !page.new_record?
104 assert !page.new_record?
98 assert_not_nil page.content
105 assert_not_nil page.content
99 assert_equal 'Created the page', page.content.comments
106 assert_equal 'Created the page', page.content.comments
100 end
107 end
101
108
102 def test_create_page_with_attachments
109 def test_create_page_with_attachments
103 @request.session[:user_id] = 2
110 @request.session[:user_id] = 2
104 assert_difference 'WikiPage.count' do
111 assert_difference 'WikiPage.count' do
105 assert_difference 'Attachment.count' do
112 assert_difference 'Attachment.count' do
106 put :update, :project_id => 1,
113 put :update, :project_id => 1,
107 :id => 'New page',
114 :id => 'New page',
108 :content => {:comments => 'Created the page',
115 :content => {:comments => 'Created the page',
109 :text => "h1. New page\n\nThis is a new page",
116 :text => "h1. New page\n\nThis is a new page",
110 :version => 0},
117 :version => 0},
111 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}}
118 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}}
112 end
119 end
113 end
120 end
114 page = Project.find(1).wiki.find_page('New page')
121 page = Project.find(1).wiki.find_page('New page')
115 assert_equal 1, page.attachments.count
122 assert_equal 1, page.attachments.count
116 assert_equal 'testfile.txt', page.attachments.first.filename
123 assert_equal 'testfile.txt', page.attachments.first.filename
117 end
124 end
118
125
119 def test_update_page
126 def test_update_page
120 @request.session[:user_id] = 2
127 @request.session[:user_id] = 2
121 assert_no_difference 'WikiPage.count' do
128 assert_no_difference 'WikiPage.count' do
122 assert_no_difference 'WikiContent.count' do
129 assert_no_difference 'WikiContent.count' do
123 assert_difference 'WikiContent::Version.count' do
130 assert_difference 'WikiContent::Version.count' do
124 put :update, :project_id => 1,
131 put :update, :project_id => 1,
125 :id => 'Another_page',
132 :id => 'Another_page',
126 :content => {
133 :content => {
127 :comments => "my comments",
134 :comments => "my comments",
128 :text => "edited",
135 :text => "edited",
129 :version => 1
136 :version => 1
130 }
137 }
131 end
138 end
132 end
139 end
133 end
140 end
134 assert_redirected_to '/projects/ecookbook/wiki/Another_page'
141 assert_redirected_to '/projects/ecookbook/wiki/Another_page'
135
142
136 page = Wiki.find(1).pages.find_by_title('Another_page')
143 page = Wiki.find(1).pages.find_by_title('Another_page')
137 assert_equal "edited", page.content.text
144 assert_equal "edited", page.content.text
138 assert_equal 2, page.content.version
145 assert_equal 2, page.content.version
139 assert_equal "my comments", page.content.comments
146 assert_equal "my comments", page.content.comments
140 end
147 end
141
148
142 def test_update_page_with_failure
149 def test_update_page_with_failure
143 @request.session[:user_id] = 2
150 @request.session[:user_id] = 2
144 assert_no_difference 'WikiPage.count' do
151 assert_no_difference 'WikiPage.count' do
145 assert_no_difference 'WikiContent.count' do
152 assert_no_difference 'WikiContent.count' do
146 assert_no_difference 'WikiContent::Version.count' do
153 assert_no_difference 'WikiContent::Version.count' do
147 put :update, :project_id => 1,
154 put :update, :project_id => 1,
148 :id => 'Another_page',
155 :id => 'Another_page',
149 :content => {
156 :content => {
150 :comments => 'a' * 300, # failure here, comment is too long
157 :comments => 'a' * 300, # failure here, comment is too long
151 :text => 'edited',
158 :text => 'edited',
152 :version => 1
159 :version => 1
153 }
160 }
154 end
161 end
155 end
162 end
156 end
163 end
157 assert_response :success
164 assert_response :success
158 assert_template 'edit'
165 assert_template 'edit'
159
166
160 assert_error_tag :descendant => {:content => /Comment is too long/}
167 assert_error_tag :descendant => {:content => /Comment is too long/}
161 assert_tag :tag => 'textarea', :attributes => {:id => 'content_text'}, :content => 'edited'
168 assert_tag :tag => 'textarea', :attributes => {:id => 'content_text'}, :content => 'edited'
162 assert_tag :tag => 'input', :attributes => {:id => 'content_version', :value => '1'}
169 assert_tag :tag => 'input', :attributes => {:id => 'content_version', :value => '1'}
163 end
170 end
164
171
165 def test_update_stale_page_should_not_raise_an_error
172 def test_update_stale_page_should_not_raise_an_error
166 @request.session[:user_id] = 2
173 @request.session[:user_id] = 2
167 c = Wiki.find(1).find_page('Another_page').content
174 c = Wiki.find(1).find_page('Another_page').content
168 c.text = 'Previous text'
175 c.text = 'Previous text'
169 c.save!
176 c.save!
170 assert_equal 2, c.version
177 assert_equal 2, c.version
171
178
172 assert_no_difference 'WikiPage.count' do
179 assert_no_difference 'WikiPage.count' do
173 assert_no_difference 'WikiContent.count' do
180 assert_no_difference 'WikiContent.count' do
174 assert_no_difference 'WikiContent::Version.count' do
181 assert_no_difference 'WikiContent::Version.count' do
175 put :update, :project_id => 1,
182 put :update, :project_id => 1,
176 :id => 'Another_page',
183 :id => 'Another_page',
177 :content => {
184 :content => {
178 :comments => 'My comments',
185 :comments => 'My comments',
179 :text => 'Text should not be lost',
186 :text => 'Text should not be lost',
180 :version => 1
187 :version => 1
181 }
188 }
182 end
189 end
183 end
190 end
184 end
191 end
185 assert_response :success
192 assert_response :success
186 assert_template 'edit'
193 assert_template 'edit'
187 assert_tag :div,
194 assert_tag :div,
188 :attributes => { :class => /error/ },
195 :attributes => { :class => /error/ },
189 :content => /Data has been updated by another user/
196 :content => /Data has been updated by another user/
190 assert_tag 'textarea',
197 assert_tag 'textarea',
191 :attributes => { :name => 'content[text]' },
198 :attributes => { :name => 'content[text]' },
192 :content => /Text should not be lost/
199 :content => /Text should not be lost/
193 assert_tag 'input',
200 assert_tag 'input',
194 :attributes => { :name => 'content[comments]', :value => 'My comments' }
201 :attributes => { :name => 'content[comments]', :value => 'My comments' }
195
202
196 c.reload
203 c.reload
197 assert_equal 'Previous text', c.text
204 assert_equal 'Previous text', c.text
198 assert_equal 2, c.version
205 assert_equal 2, c.version
199 end
206 end
200
207
201 def test_preview
208 def test_preview
202 @request.session[:user_id] = 2
209 @request.session[:user_id] = 2
203 xhr :post, :preview, :project_id => 1, :id => 'CookBook_documentation',
210 xhr :post, :preview, :project_id => 1, :id => 'CookBook_documentation',
204 :content => { :comments => '',
211 :content => { :comments => '',
205 :text => 'this is a *previewed text*',
212 :text => 'this is a *previewed text*',
206 :version => 3 }
213 :version => 3 }
207 assert_response :success
214 assert_response :success
208 assert_template 'common/_preview'
215 assert_template 'common/_preview'
209 assert_tag :tag => 'strong', :content => /previewed text/
216 assert_tag :tag => 'strong', :content => /previewed text/
210 end
217 end
211
218
212 def test_preview_new_page
219 def test_preview_new_page
213 @request.session[:user_id] = 2
220 @request.session[:user_id] = 2
214 xhr :post, :preview, :project_id => 1, :id => 'New page',
221 xhr :post, :preview, :project_id => 1, :id => 'New page',
215 :content => { :text => 'h1. New page',
222 :content => { :text => 'h1. New page',
216 :comments => '',
223 :comments => '',
217 :version => 0 }
224 :version => 0 }
218 assert_response :success
225 assert_response :success
219 assert_template 'common/_preview'
226 assert_template 'common/_preview'
220 assert_tag :tag => 'h1', :content => /New page/
227 assert_tag :tag => 'h1', :content => /New page/
221 end
228 end
222
229
223 def test_history
230 def test_history
224 get :history, :project_id => 1, :id => 'CookBook_documentation'
231 get :history, :project_id => 1, :id => 'CookBook_documentation'
225 assert_response :success
232 assert_response :success
226 assert_template 'history'
233 assert_template 'history'
227 assert_not_nil assigns(:versions)
234 assert_not_nil assigns(:versions)
228 assert_equal 3, assigns(:versions).size
235 assert_equal 3, assigns(:versions).size
229 assert_select "input[type=submit][name=commit]"
236 assert_select "input[type=submit][name=commit]"
230 end
237 end
231
238
232 def test_history_with_one_version
239 def test_history_with_one_version
233 get :history, :project_id => 1, :id => 'Another_page'
240 get :history, :project_id => 1, :id => 'Another_page'
234 assert_response :success
241 assert_response :success
235 assert_template 'history'
242 assert_template 'history'
236 assert_not_nil assigns(:versions)
243 assert_not_nil assigns(:versions)
237 assert_equal 1, assigns(:versions).size
244 assert_equal 1, assigns(:versions).size
238 assert_select "input[type=submit][name=commit]", false
245 assert_select "input[type=submit][name=commit]", false
239 end
246 end
240
247
241 def test_diff
248 def test_diff
242 get :diff, :project_id => 1, :id => 'CookBook_documentation', :version => 2, :version_from => 1
249 get :diff, :project_id => 1, :id => 'CookBook_documentation', :version => 2, :version_from => 1
243 assert_response :success
250 assert_response :success
244 assert_template 'diff'
251 assert_template 'diff'
245 assert_tag :tag => 'span', :attributes => { :class => 'diff_in'},
252 assert_tag :tag => 'span', :attributes => { :class => 'diff_in'},
246 :content => /updated/
253 :content => /updated/
247 end
254 end
248
255
249 def test_annotate
256 def test_annotate
250 get :annotate, :project_id => 1, :id => 'CookBook_documentation', :version => 2
257 get :annotate, :project_id => 1, :id => 'CookBook_documentation', :version => 2
251 assert_response :success
258 assert_response :success
252 assert_template 'annotate'
259 assert_template 'annotate'
253
260
254 # Line 1
261 # Line 1
255 assert_tag :tag => 'tr', :child => {
262 assert_tag :tag => 'tr', :child => {
256 :tag => 'th', :attributes => {:class => 'line-num'}, :content => '1', :sibling => {
263 :tag => 'th', :attributes => {:class => 'line-num'}, :content => '1', :sibling => {
257 :tag => 'td', :attributes => {:class => 'author'}, :content => /John Smith/, :sibling => {
264 :tag => 'td', :attributes => {:class => 'author'}, :content => /John Smith/, :sibling => {
258 :tag => 'td', :content => /h1\. CookBook documentation/
265 :tag => 'td', :content => /h1\. CookBook documentation/
259 }
266 }
260 }
267 }
261 }
268 }
262
269
263 # Line 5
270 # Line 5
264 assert_tag :tag => 'tr', :child => {
271 assert_tag :tag => 'tr', :child => {
265 :tag => 'th', :attributes => {:class => 'line-num'}, :content => '5', :sibling => {
272 :tag => 'th', :attributes => {:class => 'line-num'}, :content => '5', :sibling => {
266 :tag => 'td', :attributes => {:class => 'author'}, :content => /redMine Admin/, :sibling => {
273 :tag => 'td', :attributes => {:class => 'author'}, :content => /redMine Admin/, :sibling => {
267 :tag => 'td', :content => /Some updated \[\[documentation\]\] here/
274 :tag => 'td', :content => /Some updated \[\[documentation\]\] here/
268 }
275 }
269 }
276 }
270 }
277 }
271 end
278 end
272
279
273 def test_get_rename
280 def test_get_rename
274 @request.session[:user_id] = 2
281 @request.session[:user_id] = 2
275 get :rename, :project_id => 1, :id => 'Another_page'
282 get :rename, :project_id => 1, :id => 'Another_page'
276 assert_response :success
283 assert_response :success
277 assert_template 'rename'
284 assert_template 'rename'
278 assert_tag 'option',
285 assert_tag 'option',
279 :attributes => {:value => ''},
286 :attributes => {:value => ''},
280 :content => '',
287 :content => '',
281 :parent => {:tag => 'select', :attributes => {:name => 'wiki_page[parent_id]'}}
288 :parent => {:tag => 'select', :attributes => {:name => 'wiki_page[parent_id]'}}
282 assert_no_tag 'option',
289 assert_no_tag 'option',
283 :attributes => {:selected => 'selected'},
290 :attributes => {:selected => 'selected'},
284 :parent => {:tag => 'select', :attributes => {:name => 'wiki_page[parent_id]'}}
291 :parent => {:tag => 'select', :attributes => {:name => 'wiki_page[parent_id]'}}
285 end
292 end
286
293
287 def test_get_rename_child_page
294 def test_get_rename_child_page
288 @request.session[:user_id] = 2
295 @request.session[:user_id] = 2
289 get :rename, :project_id => 1, :id => 'Child_1'
296 get :rename, :project_id => 1, :id => 'Child_1'
290 assert_response :success
297 assert_response :success
291 assert_template 'rename'
298 assert_template 'rename'
292 assert_tag 'option',
299 assert_tag 'option',
293 :attributes => {:value => ''},
300 :attributes => {:value => ''},
294 :content => '',
301 :content => '',
295 :parent => {:tag => 'select', :attributes => {:name => 'wiki_page[parent_id]'}}
302 :parent => {:tag => 'select', :attributes => {:name => 'wiki_page[parent_id]'}}
296 assert_tag 'option',
303 assert_tag 'option',
297 :attributes => {:value => '2', :selected => 'selected'},
304 :attributes => {:value => '2', :selected => 'selected'},
298 :content => /Another page/,
305 :content => /Another page/,
299 :parent => {
306 :parent => {
300 :tag => 'select',
307 :tag => 'select',
301 :attributes => {:name => 'wiki_page[parent_id]'}
308 :attributes => {:name => 'wiki_page[parent_id]'}
302 }
309 }
303 end
310 end
304
311
305 def test_rename_with_redirect
312 def test_rename_with_redirect
306 @request.session[:user_id] = 2
313 @request.session[:user_id] = 2
307 post :rename, :project_id => 1, :id => 'Another_page',
314 post :rename, :project_id => 1, :id => 'Another_page',
308 :wiki_page => { :title => 'Another renamed page',
315 :wiki_page => { :title => 'Another renamed page',
309 :redirect_existing_links => 1 }
316 :redirect_existing_links => 1 }
310 assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'Another_renamed_page'
317 assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'Another_renamed_page'
311 wiki = Project.find(1).wiki
318 wiki = Project.find(1).wiki
312 # Check redirects
319 # Check redirects
313 assert_not_nil wiki.find_page('Another page')
320 assert_not_nil wiki.find_page('Another page')
314 assert_nil wiki.find_page('Another page', :with_redirect => false)
321 assert_nil wiki.find_page('Another page', :with_redirect => false)
315 end
322 end
316
323
317 def test_rename_without_redirect
324 def test_rename_without_redirect
318 @request.session[:user_id] = 2
325 @request.session[:user_id] = 2
319 post :rename, :project_id => 1, :id => 'Another_page',
326 post :rename, :project_id => 1, :id => 'Another_page',
320 :wiki_page => { :title => 'Another renamed page',
327 :wiki_page => { :title => 'Another renamed page',
321 :redirect_existing_links => "0" }
328 :redirect_existing_links => "0" }
322 assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'Another_renamed_page'
329 assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'Another_renamed_page'
323 wiki = Project.find(1).wiki
330 wiki = Project.find(1).wiki
324 # Check that there's no redirects
331 # Check that there's no redirects
325 assert_nil wiki.find_page('Another page')
332 assert_nil wiki.find_page('Another page')
326 end
333 end
327
334
328 def test_rename_with_parent_assignment
335 def test_rename_with_parent_assignment
329 @request.session[:user_id] = 2
336 @request.session[:user_id] = 2
330 post :rename, :project_id => 1, :id => 'Another_page',
337 post :rename, :project_id => 1, :id => 'Another_page',
331 :wiki_page => { :title => 'Another page', :redirect_existing_links => "0", :parent_id => '4' }
338 :wiki_page => { :title => 'Another page', :redirect_existing_links => "0", :parent_id => '4' }
332 assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'Another_page'
339 assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'Another_page'
333 assert_equal WikiPage.find(4), WikiPage.find_by_title('Another_page').parent
340 assert_equal WikiPage.find(4), WikiPage.find_by_title('Another_page').parent
334 end
341 end
335
342
336 def test_rename_with_parent_unassignment
343 def test_rename_with_parent_unassignment
337 @request.session[:user_id] = 2
344 @request.session[:user_id] = 2
338 post :rename, :project_id => 1, :id => 'Child_1',
345 post :rename, :project_id => 1, :id => 'Child_1',
339 :wiki_page => { :title => 'Child 1', :redirect_existing_links => "0", :parent_id => '' }
346 :wiki_page => { :title => 'Child 1', :redirect_existing_links => "0", :parent_id => '' }
340 assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'Child_1'
347 assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'Child_1'
341 assert_nil WikiPage.find_by_title('Child_1').parent
348 assert_nil WikiPage.find_by_title('Child_1').parent
342 end
349 end
343
350
344 def test_destroy_child
351 def test_destroy_child
345 @request.session[:user_id] = 2
352 @request.session[:user_id] = 2
346 delete :destroy, :project_id => 1, :id => 'Child_1'
353 delete :destroy, :project_id => 1, :id => 'Child_1'
347 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
354 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
348 end
355 end
349
356
350 def test_destroy_parent
357 def test_destroy_parent
351 @request.session[:user_id] = 2
358 @request.session[:user_id] = 2
352 assert_no_difference('WikiPage.count') do
359 assert_no_difference('WikiPage.count') do
353 delete :destroy, :project_id => 1, :id => 'Another_page'
360 delete :destroy, :project_id => 1, :id => 'Another_page'
354 end
361 end
355 assert_response :success
362 assert_response :success
356 assert_template 'destroy'
363 assert_template 'destroy'
357 end
364 end
358
365
359 def test_destroy_parent_with_nullify
366 def test_destroy_parent_with_nullify
360 @request.session[:user_id] = 2
367 @request.session[:user_id] = 2
361 assert_difference('WikiPage.count', -1) do
368 assert_difference('WikiPage.count', -1) do
362 delete :destroy, :project_id => 1, :id => 'Another_page', :todo => 'nullify'
369 delete :destroy, :project_id => 1, :id => 'Another_page', :todo => 'nullify'
363 end
370 end
364 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
371 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
365 assert_nil WikiPage.find_by_id(2)
372 assert_nil WikiPage.find_by_id(2)
366 end
373 end
367
374
368 def test_destroy_parent_with_cascade
375 def test_destroy_parent_with_cascade
369 @request.session[:user_id] = 2
376 @request.session[:user_id] = 2
370 assert_difference('WikiPage.count', -3) do
377 assert_difference('WikiPage.count', -3) do
371 delete :destroy, :project_id => 1, :id => 'Another_page', :todo => 'destroy'
378 delete :destroy, :project_id => 1, :id => 'Another_page', :todo => 'destroy'
372 end
379 end
373 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
380 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
374 assert_nil WikiPage.find_by_id(2)
381 assert_nil WikiPage.find_by_id(2)
375 assert_nil WikiPage.find_by_id(5)
382 assert_nil WikiPage.find_by_id(5)
376 end
383 end
377
384
378 def test_destroy_parent_with_reassign
385 def test_destroy_parent_with_reassign
379 @request.session[:user_id] = 2
386 @request.session[:user_id] = 2
380 assert_difference('WikiPage.count', -1) do
387 assert_difference('WikiPage.count', -1) do
381 delete :destroy, :project_id => 1, :id => 'Another_page', :todo => 'reassign', :reassign_to_id => 1
388 delete :destroy, :project_id => 1, :id => 'Another_page', :todo => 'reassign', :reassign_to_id => 1
382 end
389 end
383 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
390 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
384 assert_nil WikiPage.find_by_id(2)
391 assert_nil WikiPage.find_by_id(2)
385 assert_equal WikiPage.find(1), WikiPage.find_by_id(5).parent
392 assert_equal WikiPage.find(1), WikiPage.find_by_id(5).parent
386 end
393 end
387
394
388 def test_index
395 def test_index
389 get :index, :project_id => 'ecookbook'
396 get :index, :project_id => 'ecookbook'
390 assert_response :success
397 assert_response :success
391 assert_template 'index'
398 assert_template 'index'
392 pages = assigns(:pages)
399 pages = assigns(:pages)
393 assert_not_nil pages
400 assert_not_nil pages
394 assert_equal Project.find(1).wiki.pages.size, pages.size
401 assert_equal Project.find(1).wiki.pages.size, pages.size
395 assert_equal pages.first.content.updated_on, pages.first.updated_on
402 assert_equal pages.first.content.updated_on, pages.first.updated_on
396
403
397 assert_tag :ul, :attributes => { :class => 'pages-hierarchy' },
404 assert_tag :ul, :attributes => { :class => 'pages-hierarchy' },
398 :child => { :tag => 'li', :child => { :tag => 'a', :attributes => { :href => '/projects/ecookbook/wiki/CookBook_documentation' },
405 :child => { :tag => 'li', :child => { :tag => 'a', :attributes => { :href => '/projects/ecookbook/wiki/CookBook_documentation' },
399 :content => 'CookBook documentation' },
406 :content => 'CookBook documentation' },
400 :child => { :tag => 'ul',
407 :child => { :tag => 'ul',
401 :child => { :tag => 'li',
408 :child => { :tag => 'li',
402 :child => { :tag => 'a', :attributes => { :href => '/projects/ecookbook/wiki/Page_with_an_inline_image' },
409 :child => { :tag => 'a', :attributes => { :href => '/projects/ecookbook/wiki/Page_with_an_inline_image' },
403 :content => 'Page with an inline image' } } } },
410 :content => 'Page with an inline image' } } } },
404 :child => { :tag => 'li', :child => { :tag => 'a', :attributes => { :href => '/projects/ecookbook/wiki/Another_page' },
411 :child => { :tag => 'li', :child => { :tag => 'a', :attributes => { :href => '/projects/ecookbook/wiki/Another_page' },
405 :content => 'Another page' } }
412 :content => 'Another page' } }
406 end
413 end
407
414
408 def test_index_should_include_atom_link
415 def test_index_should_include_atom_link
409 get :index, :project_id => 'ecookbook'
416 get :index, :project_id => 'ecookbook'
410 assert_tag 'a', :attributes => { :href => '/projects/ecookbook/activity.atom?show_wiki_edits=1'}
417 assert_tag 'a', :attributes => { :href => '/projects/ecookbook/activity.atom?show_wiki_edits=1'}
411 end
418 end
412
419
413 context "GET :export" do
420 context "GET :export" do
414 context "with an authorized user to export the wiki" do
421 context "with an authorized user to export the wiki" do
415 setup do
422 setup do
416 @request.session[:user_id] = 2
423 @request.session[:user_id] = 2
417 get :export, :project_id => 'ecookbook'
424 get :export, :project_id => 'ecookbook'
418 end
425 end
419
426
420 should_respond_with :success
427 should_respond_with :success
421 should_assign_to :pages
428 should_assign_to :pages
422 should_respond_with_content_type "text/html"
429 should_respond_with_content_type "text/html"
423 should "export all of the wiki pages to a single html file" do
430 should "export all of the wiki pages to a single html file" do
424 assert_select "a[name=?]", "CookBook_documentation"
431 assert_select "a[name=?]", "CookBook_documentation"
425 assert_select "a[name=?]", "Another_page"
432 assert_select "a[name=?]", "Another_page"
426 assert_select "a[name=?]", "Page_with_an_inline_image"
433 assert_select "a[name=?]", "Page_with_an_inline_image"
427 end
434 end
428
435
429 end
436 end
430
437
431 context "with an unauthorized user" do
438 context "with an unauthorized user" do
432 setup do
439 setup do
433 get :export, :project_id => 'ecookbook'
440 get :export, :project_id => 'ecookbook'
434
441
435 should_respond_with :redirect
442 should_respond_with :redirect
436 should_redirect_to('wiki index') { {:action => 'show', :project_id => @project, :id => nil} }
443 should_redirect_to('wiki index') { {:action => 'show', :project_id => @project, :id => nil} }
437 end
444 end
438 end
445 end
439 end
446 end
440
447
441 context "GET :date_index" do
448 context "GET :date_index" do
442 setup do
449 setup do
443 get :date_index, :project_id => 'ecookbook'
450 get :date_index, :project_id => 'ecookbook'
444 end
451 end
445
452
446 should_respond_with :success
453 should_respond_with :success
447 should_assign_to :pages
454 should_assign_to :pages
448 should_assign_to :pages_by_date
455 should_assign_to :pages_by_date
449 should_render_template 'wiki/date_index'
456 should_render_template 'wiki/date_index'
450
457
451 should "include atom link" do
458 should "include atom link" do
452 assert_tag 'a', :attributes => { :href => '/projects/ecookbook/activity.atom?show_wiki_edits=1'}
459 assert_tag 'a', :attributes => { :href => '/projects/ecookbook/activity.atom?show_wiki_edits=1'}
453 end
460 end
454 end
461 end
455
462
456 def test_not_found
463 def test_not_found
457 get :show, :project_id => 999
464 get :show, :project_id => 999
458 assert_response 404
465 assert_response 404
459 end
466 end
460
467
461 def test_protect_page
468 def test_protect_page
462 page = WikiPage.find_by_wiki_id_and_title(1, 'Another_page')
469 page = WikiPage.find_by_wiki_id_and_title(1, 'Another_page')
463 assert !page.protected?
470 assert !page.protected?
464 @request.session[:user_id] = 2
471 @request.session[:user_id] = 2
465 post :protect, :project_id => 1, :id => page.title, :protected => '1'
472 post :protect, :project_id => 1, :id => page.title, :protected => '1'
466 assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'Another_page'
473 assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'Another_page'
467 assert page.reload.protected?
474 assert page.reload.protected?
468 end
475 end
469
476
470 def test_unprotect_page
477 def test_unprotect_page
471 page = WikiPage.find_by_wiki_id_and_title(1, 'CookBook_documentation')
478 page = WikiPage.find_by_wiki_id_and_title(1, 'CookBook_documentation')
472 assert page.protected?
479 assert page.protected?
473 @request.session[:user_id] = 2
480 @request.session[:user_id] = 2
474 post :protect, :project_id => 1, :id => page.title, :protected => '0'
481 post :protect, :project_id => 1, :id => page.title, :protected => '0'
475 assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'CookBook_documentation'
482 assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'CookBook_documentation'
476 assert !page.reload.protected?
483 assert !page.reload.protected?
477 end
484 end
478
485
479 def test_show_page_with_edit_link
486 def test_show_page_with_edit_link
480 @request.session[:user_id] = 2
487 @request.session[:user_id] = 2
481 get :show, :project_id => 1
488 get :show, :project_id => 1
482 assert_response :success
489 assert_response :success
483 assert_template 'show'
490 assert_template 'show'
484 assert_tag :tag => 'a', :attributes => { :href => '/projects/1/wiki/CookBook_documentation/edit' }
491 assert_tag :tag => 'a', :attributes => { :href => '/projects/1/wiki/CookBook_documentation/edit' }
485 end
492 end
486
493
487 def test_show_page_without_edit_link
494 def test_show_page_without_edit_link
488 @request.session[:user_id] = 4
495 @request.session[:user_id] = 4
489 get :show, :project_id => 1
496 get :show, :project_id => 1
490 assert_response :success
497 assert_response :success
491 assert_template 'show'
498 assert_template 'show'
492 assert_no_tag :tag => 'a', :attributes => { :href => '/projects/1/wiki/CookBook_documentation/edit' }
499 assert_no_tag :tag => 'a', :attributes => { :href => '/projects/1/wiki/CookBook_documentation/edit' }
493 end
500 end
494
501
495 def test_edit_unprotected_page
502 def test_edit_unprotected_page
496 # Non members can edit unprotected wiki pages
503 # Non members can edit unprotected wiki pages
497 @request.session[:user_id] = 4
504 @request.session[:user_id] = 4
498 get :edit, :project_id => 1, :id => 'Another_page'
505 get :edit, :project_id => 1, :id => 'Another_page'
499 assert_response :success
506 assert_response :success
500 assert_template 'edit'
507 assert_template 'edit'
501 end
508 end
502
509
503 def test_edit_protected_page_by_nonmember
510 def test_edit_protected_page_by_nonmember
504 # Non members can't edit protected wiki pages
511 # Non members can't edit protected wiki pages
505 @request.session[:user_id] = 4
512 @request.session[:user_id] = 4
506 get :edit, :project_id => 1, :id => 'CookBook_documentation'
513 get :edit, :project_id => 1, :id => 'CookBook_documentation'
507 assert_response 403
514 assert_response 403
508 end
515 end
509
516
510 def test_edit_protected_page_by_member
517 def test_edit_protected_page_by_member
511 @request.session[:user_id] = 2
518 @request.session[:user_id] = 2
512 get :edit, :project_id => 1, :id => 'CookBook_documentation'
519 get :edit, :project_id => 1, :id => 'CookBook_documentation'
513 assert_response :success
520 assert_response :success
514 assert_template 'edit'
521 assert_template 'edit'
515 end
522 end
516
523
517 def test_history_of_non_existing_page_should_return_404
524 def test_history_of_non_existing_page_should_return_404
518 get :history, :project_id => 1, :id => 'Unknown_page'
525 get :history, :project_id => 1, :id => 'Unknown_page'
519 assert_response 404
526 assert_response 404
520 end
527 end
521 end
528 end
General Comments 0
You need to be logged in to leave comments. Login now