annotate .svn/pristine/ca/cab46c17b5b415de4f050ce745f02ed62956aa0b.svn-base @ 1524:82fac3dcf466 redmine-2.5-integration

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