annotate test/functional/wiki_controller_test.rb @ 1628:9c5f8e24dadc live tip

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