annotate .svn/pristine/7c/7c19633b83470d5b364c2c777a693d3cc9b87ee1.svn-base @ 1516:b450a9d58aed redmine-2.4

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