annotate .svn/pristine/a0/a0cb5d986928907b89ed6e9fd9c7a2000dd01933.svn-base @ 1327:287f201c2802 redmine-2.2-integration

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