annotate .svn/pristine/e0/e03b3539b5eda7cb68bffc68e4f6d9f643e92475.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 cbb26bc654de
children
rev   line source
Chris@909 1 # Redmine - project management software
Chris@909 2 # Copyright (C) 2006-2011 Jean-Philippe Lang
Chris@909 3 #
Chris@909 4 # This program is free software; you can redistribute it and/or
Chris@909 5 # modify it under the terms of the GNU General Public License
Chris@909 6 # as published by the Free Software Foundation; either version 2
Chris@909 7 # of the License, or (at your option) any later version.
Chris@909 8 #
Chris@909 9 # This program is distributed in the hope that it will be useful,
Chris@909 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@909 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@909 12 # GNU General Public License for more details.
Chris@909 13 #
Chris@909 14 # You should have received a copy of the GNU General Public License
Chris@909 15 # along with this program; if not, write to the Free Software
Chris@909 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@909 17
Chris@909 18 require File.expand_path('../../test_helper', __FILE__)
Chris@909 19 require 'wiki_controller'
Chris@909 20
Chris@909 21 # Re-raise errors caught by the controller.
Chris@909 22 class WikiController; def rescue_action(e) raise e end; end
Chris@909 23
Chris@909 24 class WikiControllerTest < ActionController::TestCase
Chris@909 25 fixtures :projects, :users, :roles, :members, :member_roles,
Chris@909 26 :enabled_modules, :wikis, :wiki_pages, :wiki_contents,
Chris@909 27 :wiki_content_versions, :attachments
Chris@909 28
Chris@909 29 def setup
Chris@909 30 @controller = WikiController.new
Chris@909 31 @request = ActionController::TestRequest.new
Chris@909 32 @response = ActionController::TestResponse.new
Chris@909 33 User.current = nil
Chris@909 34 end
Chris@909 35
Chris@909 36 def test_show_start_page
Chris@909 37 get :show, :project_id => 'ecookbook'
Chris@909 38 assert_response :success
Chris@909 39 assert_template 'show'
Chris@909 40 assert_tag :tag => 'h1', :content => /CookBook documentation/
Chris@909 41
Chris@909 42 # child_pages macro
Chris@909 43 assert_tag :ul, :attributes => { :class => 'pages-hierarchy' },
Chris@909 44 :child => { :tag => 'li',
Chris@909 45 :child => { :tag => 'a', :attributes => { :href => '/projects/ecookbook/wiki/Page_with_an_inline_image' },
Chris@909 46 :content => 'Page with an inline image' } }
Chris@909 47 end
Chris@909 48
Chris@909 49 def test_export_link
Chris@909 50 Role.anonymous.add_permission! :export_wiki_pages
Chris@909 51 get :show, :project_id => 'ecookbook'
Chris@909 52 assert_response :success
Chris@909 53 assert_tag 'a', :attributes => {:href => '/projects/ecookbook/wiki/CookBook_documentation.txt'}
Chris@909 54 end
Chris@909 55
Chris@909 56 def test_show_page_with_name
Chris@909 57 get :show, :project_id => 1, :id => 'Another_page'
Chris@909 58 assert_response :success
Chris@909 59 assert_template 'show'
Chris@909 60 assert_tag :tag => 'h1', :content => /Another page/
Chris@909 61 # Included page with an inline image
Chris@909 62 assert_tag :tag => 'p', :content => /This is an inline image/
Chris@909 63 assert_tag :tag => 'img', :attributes => { :src => '/attachments/download/3',
Chris@909 64 :alt => 'This is a logo' }
Chris@909 65 end
Chris@909 66
Chris@909 67 def test_show_redirected_page
Chris@909 68 WikiRedirect.create!(:wiki_id => 1, :title => 'Old_title', :redirects_to => 'Another_page')
Chris@909 69
Chris@909 70 get :show, :project_id => 'ecookbook', :id => 'Old_title'
Chris@909 71 assert_redirected_to '/projects/ecookbook/wiki/Another_page'
Chris@909 72 end
Chris@909 73
Chris@909 74 def test_show_with_sidebar
Chris@909 75 page = Project.find(1).wiki.pages.new(:title => 'Sidebar')
Chris@909 76 page.content = WikiContent.new(:text => 'Side bar content for test_show_with_sidebar')
Chris@909 77 page.save!
Chris@909 78
Chris@909 79 get :show, :project_id => 1, :id => 'Another_page'
Chris@909 80 assert_response :success
Chris@909 81 assert_tag :tag => 'div', :attributes => {:id => 'sidebar'},
Chris@909 82 :content => /Side bar content for test_show_with_sidebar/
Chris@909 83 end
Chris@909 84
Chris@909 85 def test_show_unexistent_page_without_edit_right
Chris@909 86 get :show, :project_id => 1, :id => 'Unexistent page'
Chris@909 87 assert_response 404
Chris@909 88 end
Chris@909 89
Chris@909 90 def test_show_should_display_section_edit_links
Chris@909 91 @request.session[:user_id] = 2
Chris@909 92 get :show, :project_id => 1, :id => 'Page with sections'
Chris@909 93 assert_no_tag 'a', :attributes => {
Chris@909 94 :href => '/projects/ecookbook/wiki/Page_with_sections/edit?section=1'
Chris@909 95 }
Chris@909 96 assert_tag 'a', :attributes => {
Chris@909 97 :href => '/projects/ecookbook/wiki/Page_with_sections/edit?section=2'
Chris@909 98 }
Chris@909 99 assert_tag 'a', :attributes => {
Chris@909 100 :href => '/projects/ecookbook/wiki/Page_with_sections/edit?section=3'
Chris@909 101 }
Chris@909 102 end
Chris@909 103
Chris@909 104 def test_show_current_version_should_display_section_edit_links
Chris@909 105 @request.session[:user_id] = 2
Chris@909 106 get :show, :project_id => 1, :id => 'Page with sections', :version => 3
Chris@909 107
Chris@909 108 assert_tag 'a', :attributes => {
Chris@909 109 :href => '/projects/ecookbook/wiki/Page_with_sections/edit?section=2'
Chris@909 110 }
Chris@909 111 end
Chris@909 112
Chris@909 113 def test_show_old_version_should_not_display_section_edit_links
Chris@909 114 @request.session[:user_id] = 2
Chris@909 115 get :show, :project_id => 1, :id => 'Page with sections', :version => 2
Chris@909 116
Chris@909 117 assert_no_tag 'a', :attributes => {
Chris@909 118 :href => '/projects/ecookbook/wiki/Page_with_sections/edit?section=2'
Chris@909 119 }
Chris@909 120 end
Chris@909 121
Chris@909 122 def test_show_unexistent_page_with_edit_right
Chris@909 123 @request.session[:user_id] = 2
Chris@909 124 get :show, :project_id => 1, :id => 'Unexistent page'
Chris@909 125 assert_response :success
Chris@909 126 assert_template 'edit'
Chris@909 127 end
Chris@909 128
Chris@909 129 def test_create_page
Chris@909 130 @request.session[:user_id] = 2
Chris@909 131 put :update, :project_id => 1,
Chris@909 132 :id => 'New page',
Chris@909 133 :content => {:comments => 'Created the page',
Chris@909 134 :text => "h1. New page\n\nThis is a new page",
Chris@909 135 :version => 0}
Chris@909 136 assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'New_page'
Chris@909 137 page = Project.find(1).wiki.find_page('New page')
Chris@909 138 assert !page.new_record?
Chris@909 139 assert_not_nil page.content
Chris@909 140 assert_equal 'Created the page', page.content.comments
Chris@909 141 end
Chris@909 142
Chris@909 143 def test_create_page_with_attachments
Chris@909 144 @request.session[:user_id] = 2
Chris@909 145 assert_difference 'WikiPage.count' do
Chris@909 146 assert_difference 'Attachment.count' do
Chris@909 147 put :update, :project_id => 1,
Chris@909 148 :id => 'New page',
Chris@909 149 :content => {:comments => 'Created the page',
Chris@909 150 :text => "h1. New page\n\nThis is a new page",
Chris@909 151 :version => 0},
Chris@909 152 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}}
Chris@909 153 end
Chris@909 154 end
Chris@909 155 page = Project.find(1).wiki.find_page('New page')
Chris@909 156 assert_equal 1, page.attachments.count
Chris@909 157 assert_equal 'testfile.txt', page.attachments.first.filename
Chris@909 158 end
Chris@909 159
Chris@909 160 def test_edit_page
Chris@909 161 @request.session[:user_id] = 2
Chris@909 162 get :edit, :project_id => 'ecookbook', :id => 'Another_page'
Chris@909 163
Chris@909 164 assert_response :success
Chris@909 165 assert_template 'edit'
Chris@909 166
Chris@909 167 assert_tag 'textarea',
Chris@909 168 :attributes => { :name => 'content[text]' },
Chris@909 169 :content => WikiPage.find_by_title('Another_page').content.text
Chris@909 170 end
Chris@909 171
Chris@909 172 def test_edit_section
Chris@909 173 @request.session[:user_id] = 2
Chris@909 174 get :edit, :project_id => 'ecookbook', :id => 'Page_with_sections', :section => 2
Chris@909 175
Chris@909 176 assert_response :success
Chris@909 177 assert_template 'edit'
Chris@909 178
Chris@909 179 page = WikiPage.find_by_title('Page_with_sections')
Chris@909 180 section, hash = Redmine::WikiFormatting::Textile::Formatter.new(page.content.text).get_section(2)
Chris@909 181
Chris@909 182 assert_tag 'textarea',
Chris@909 183 :attributes => { :name => 'content[text]' },
Chris@909 184 :content => section
Chris@909 185 assert_tag 'input',
Chris@909 186 :attributes => { :name => 'section', :type => 'hidden', :value => '2' }
Chris@909 187 assert_tag 'input',
Chris@909 188 :attributes => { :name => 'section_hash', :type => 'hidden', :value => hash }
Chris@909 189 end
Chris@909 190
Chris@909 191 def test_edit_invalid_section_should_respond_with_404
Chris@909 192 @request.session[:user_id] = 2
Chris@909 193 get :edit, :project_id => 'ecookbook', :id => 'Page_with_sections', :section => 10
Chris@909 194
Chris@909 195 assert_response 404
Chris@909 196 end
Chris@909 197
Chris@909 198 def test_update_page
Chris@909 199 @request.session[:user_id] = 2
Chris@909 200 assert_no_difference 'WikiPage.count' do
Chris@909 201 assert_no_difference 'WikiContent.count' do
Chris@909 202 assert_difference 'WikiContent::Version.count' do
Chris@909 203 put :update, :project_id => 1,
Chris@909 204 :id => 'Another_page',
Chris@909 205 :content => {
Chris@909 206 :comments => "my comments",
Chris@909 207 :text => "edited",
Chris@909 208 :version => 1
Chris@909 209 }
Chris@909 210 end
Chris@909 211 end
Chris@909 212 end
Chris@909 213 assert_redirected_to '/projects/ecookbook/wiki/Another_page'
Chris@909 214
Chris@909 215 page = Wiki.find(1).pages.find_by_title('Another_page')
Chris@909 216 assert_equal "edited", page.content.text
Chris@909 217 assert_equal 2, page.content.version
Chris@909 218 assert_equal "my comments", page.content.comments
Chris@909 219 end
Chris@909 220
Chris@909 221 def test_update_page_with_failure
Chris@909 222 @request.session[:user_id] = 2
Chris@909 223 assert_no_difference 'WikiPage.count' do
Chris@909 224 assert_no_difference 'WikiContent.count' do
Chris@909 225 assert_no_difference 'WikiContent::Version.count' do
Chris@909 226 put :update, :project_id => 1,
Chris@909 227 :id => 'Another_page',
Chris@909 228 :content => {
Chris@909 229 :comments => 'a' * 300, # failure here, comment is too long
Chris@909 230 :text => 'edited',
Chris@909 231 :version => 1
Chris@909 232 }
Chris@909 233 end
Chris@909 234 end
Chris@909 235 end
Chris@909 236 assert_response :success
Chris@909 237 assert_template 'edit'
Chris@909 238
Chris@909 239 assert_error_tag :descendant => {:content => /Comment is too long/}
Chris@909 240 assert_tag :tag => 'textarea', :attributes => {:id => 'content_text'}, :content => 'edited'
Chris@909 241 assert_tag :tag => 'input', :attributes => {:id => 'content_version', :value => '1'}
Chris@909 242 end
Chris@909 243
Chris@909 244 def test_update_stale_page_should_not_raise_an_error
Chris@909 245 @request.session[:user_id] = 2
Chris@909 246 c = Wiki.find(1).find_page('Another_page').content
Chris@909 247 c.text = 'Previous text'
Chris@909 248 c.save!
Chris@909 249 assert_equal 2, c.version
Chris@909 250
Chris@909 251 assert_no_difference 'WikiPage.count' do
Chris@909 252 assert_no_difference 'WikiContent.count' do
Chris@909 253 assert_no_difference 'WikiContent::Version.count' do
Chris@909 254 put :update, :project_id => 1,
Chris@909 255 :id => 'Another_page',
Chris@909 256 :content => {
Chris@909 257 :comments => 'My comments',
Chris@909 258 :text => 'Text should not be lost',
Chris@909 259 :version => 1
Chris@909 260 }
Chris@909 261 end
Chris@909 262 end
Chris@909 263 end
Chris@909 264 assert_response :success
Chris@909 265 assert_template 'edit'
Chris@909 266 assert_tag :div,
Chris@909 267 :attributes => { :class => /error/ },
Chris@909 268 :content => /Data has been updated by another user/
Chris@909 269 assert_tag 'textarea',
Chris@909 270 :attributes => { :name => 'content[text]' },
Chris@909 271 :content => /Text should not be lost/
Chris@909 272 assert_tag 'input',
Chris@909 273 :attributes => { :name => 'content[comments]', :value => 'My comments' }
Chris@909 274
Chris@909 275 c.reload
Chris@909 276 assert_equal 'Previous text', c.text
Chris@909 277 assert_equal 2, c.version
Chris@909 278 end
Chris@909 279
Chris@909 280 def test_update_section
Chris@909 281 @request.session[:user_id] = 2
Chris@909 282 page = WikiPage.find_by_title('Page_with_sections')
Chris@909 283 section, hash = Redmine::WikiFormatting::Textile::Formatter.new(page.content.text).get_section(2)
Chris@909 284 text = page.content.text
Chris@909 285
Chris@909 286 assert_no_difference 'WikiPage.count' do
Chris@909 287 assert_no_difference 'WikiContent.count' do
Chris@909 288 assert_difference 'WikiContent::Version.count' do
Chris@909 289 put :update, :project_id => 1, :id => 'Page_with_sections',
Chris@909 290 :content => {
Chris@909 291 :text => "New section content",
Chris@909 292 :version => 3
Chris@909 293 },
Chris@909 294 :section => 2,
Chris@909 295 :section_hash => hash
Chris@909 296 end
Chris@909 297 end
Chris@909 298 end
Chris@909 299 assert_redirected_to '/projects/ecookbook/wiki/Page_with_sections'
Chris@909 300 assert_equal Redmine::WikiFormatting::Textile::Formatter.new(text).update_section(2, "New section content"), page.reload.content.text
Chris@909 301 end
Chris@909 302
Chris@909 303 def test_update_section_should_allow_stale_page_update
Chris@909 304 @request.session[:user_id] = 2
Chris@909 305 page = WikiPage.find_by_title('Page_with_sections')
Chris@909 306 section, hash = Redmine::WikiFormatting::Textile::Formatter.new(page.content.text).get_section(2)
Chris@909 307 text = page.content.text
Chris@909 308
Chris@909 309 assert_no_difference 'WikiPage.count' do
Chris@909 310 assert_no_difference 'WikiContent.count' do
Chris@909 311 assert_difference 'WikiContent::Version.count' do
Chris@909 312 put :update, :project_id => 1, :id => 'Page_with_sections',
Chris@909 313 :content => {
Chris@909 314 :text => "New section content",
Chris@909 315 :version => 2 # Current version is 3
Chris@909 316 },
Chris@909 317 :section => 2,
Chris@909 318 :section_hash => hash
Chris@909 319 end
Chris@909 320 end
Chris@909 321 end
Chris@909 322 assert_redirected_to '/projects/ecookbook/wiki/Page_with_sections'
Chris@909 323 page.reload
Chris@909 324 assert_equal Redmine::WikiFormatting::Textile::Formatter.new(text).update_section(2, "New section content"), page.content.text
Chris@909 325 assert_equal 4, page.content.version
Chris@909 326 end
Chris@909 327
Chris@909 328 def test_update_section_should_not_allow_stale_section_update
Chris@909 329 @request.session[:user_id] = 2
Chris@909 330
Chris@909 331 assert_no_difference 'WikiPage.count' do
Chris@909 332 assert_no_difference 'WikiContent.count' do
Chris@909 333 assert_no_difference 'WikiContent::Version.count' do
Chris@909 334 put :update, :project_id => 1, :id => 'Page_with_sections',
Chris@909 335 :content => {
Chris@909 336 :comments => 'My comments',
Chris@909 337 :text => "Text should not be lost",
Chris@909 338 :version => 3
Chris@909 339 },
Chris@909 340 :section => 2,
Chris@909 341 :section_hash => Digest::MD5.hexdigest("wrong hash")
Chris@909 342 end
Chris@909 343 end
Chris@909 344 end
Chris@909 345 assert_response :success
Chris@909 346 assert_template 'edit'
Chris@909 347 assert_tag :div,
Chris@909 348 :attributes => { :class => /error/ },
Chris@909 349 :content => /Data has been updated by another user/
Chris@909 350 assert_tag 'textarea',
Chris@909 351 :attributes => { :name => 'content[text]' },
Chris@909 352 :content => /Text should not be lost/
Chris@909 353 assert_tag 'input',
Chris@909 354 :attributes => { :name => 'content[comments]', :value => 'My comments' }
Chris@909 355 end
Chris@909 356
Chris@909 357 def test_preview
Chris@909 358 @request.session[:user_id] = 2
Chris@909 359 xhr :post, :preview, :project_id => 1, :id => 'CookBook_documentation',
Chris@909 360 :content => { :comments => '',
Chris@909 361 :text => 'this is a *previewed text*',
Chris@909 362 :version => 3 }
Chris@909 363 assert_response :success
Chris@909 364 assert_template 'common/_preview'
Chris@909 365 assert_tag :tag => 'strong', :content => /previewed text/
Chris@909 366 end
Chris@909 367
Chris@909 368 def test_preview_new_page
Chris@909 369 @request.session[:user_id] = 2
Chris@909 370 xhr :post, :preview, :project_id => 1, :id => 'New page',
Chris@909 371 :content => { :text => 'h1. New page',
Chris@909 372 :comments => '',
Chris@909 373 :version => 0 }
Chris@909 374 assert_response :success
Chris@909 375 assert_template 'common/_preview'
Chris@909 376 assert_tag :tag => 'h1', :content => /New page/
Chris@909 377 end
Chris@909 378
Chris@909 379 def test_history
Chris@909 380 get :history, :project_id => 1, :id => 'CookBook_documentation'
Chris@909 381 assert_response :success
Chris@909 382 assert_template 'history'
Chris@909 383 assert_not_nil assigns(:versions)
Chris@909 384 assert_equal 3, assigns(:versions).size
Chris@909 385 assert_select "input[type=submit][name=commit]"
Chris@909 386 end
Chris@909 387
Chris@909 388 def test_history_with_one_version
Chris@909 389 get :history, :project_id => 1, :id => 'Another_page'
Chris@909 390 assert_response :success
Chris@909 391 assert_template 'history'
Chris@909 392 assert_not_nil assigns(:versions)
Chris@909 393 assert_equal 1, assigns(:versions).size
Chris@909 394 assert_select "input[type=submit][name=commit]", false
Chris@909 395 end
Chris@909 396
Chris@909 397 def test_diff
Chris@909 398 get :diff, :project_id => 1, :id => 'CookBook_documentation', :version => 2, :version_from => 1
Chris@909 399 assert_response :success
Chris@909 400 assert_template 'diff'
Chris@909 401 assert_tag :tag => 'span', :attributes => { :class => 'diff_in'},
Chris@909 402 :content => /updated/
Chris@909 403 end
Chris@909 404
Chris@909 405 def test_annotate
Chris@909 406 get :annotate, :project_id => 1, :id => 'CookBook_documentation', :version => 2
Chris@909 407 assert_response :success
Chris@909 408 assert_template 'annotate'
Chris@909 409
Chris@909 410 # Line 1
Chris@909 411 assert_tag :tag => 'tr', :child => {
Chris@909 412 :tag => 'th', :attributes => {:class => 'line-num'}, :content => '1', :sibling => {
Chris@909 413 :tag => 'td', :attributes => {:class => 'author'}, :content => /John Smith/, :sibling => {
Chris@909 414 :tag => 'td', :content => /h1\. CookBook documentation/
Chris@909 415 }
Chris@909 416 }
Chris@909 417 }
Chris@909 418
Chris@909 419 # Line 5
Chris@909 420 assert_tag :tag => 'tr', :child => {
Chris@909 421 :tag => 'th', :attributes => {:class => 'line-num'}, :content => '5', :sibling => {
Chris@909 422 :tag => 'td', :attributes => {:class => 'author'}, :content => /redMine Admin/, :sibling => {
Chris@909 423 :tag => 'td', :content => /Some updated \[\[documentation\]\] here/
Chris@909 424 }
Chris@909 425 }
Chris@909 426 }
Chris@909 427 end
Chris@909 428
Chris@909 429 def test_get_rename
Chris@909 430 @request.session[:user_id] = 2
Chris@909 431 get :rename, :project_id => 1, :id => 'Another_page'
Chris@909 432 assert_response :success
Chris@909 433 assert_template 'rename'
Chris@909 434 assert_tag 'option',
Chris@909 435 :attributes => {:value => ''},
Chris@909 436 :content => '',
Chris@909 437 :parent => {:tag => 'select', :attributes => {:name => 'wiki_page[parent_id]'}}
Chris@909 438 assert_no_tag 'option',
Chris@909 439 :attributes => {:selected => 'selected'},
Chris@909 440 :parent => {:tag => 'select', :attributes => {:name => 'wiki_page[parent_id]'}}
Chris@909 441 end
Chris@909 442
Chris@909 443 def test_get_rename_child_page
Chris@909 444 @request.session[:user_id] = 2
Chris@909 445 get :rename, :project_id => 1, :id => 'Child_1'
Chris@909 446 assert_response :success
Chris@909 447 assert_template 'rename'
Chris@909 448 assert_tag 'option',
Chris@909 449 :attributes => {:value => ''},
Chris@909 450 :content => '',
Chris@909 451 :parent => {:tag => 'select', :attributes => {:name => 'wiki_page[parent_id]'}}
Chris@909 452 assert_tag 'option',
Chris@909 453 :attributes => {:value => '2', :selected => 'selected'},
Chris@909 454 :content => /Another page/,
Chris@909 455 :parent => {
Chris@909 456 :tag => 'select',
Chris@909 457 :attributes => {:name => 'wiki_page[parent_id]'}
Chris@909 458 }
Chris@909 459 end
Chris@909 460
Chris@909 461 def test_rename_with_redirect
Chris@909 462 @request.session[:user_id] = 2
Chris@909 463 post :rename, :project_id => 1, :id => 'Another_page',
Chris@909 464 :wiki_page => { :title => 'Another renamed page',
Chris@909 465 :redirect_existing_links => 1 }
Chris@909 466 assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'Another_renamed_page'
Chris@909 467 wiki = Project.find(1).wiki
Chris@909 468 # Check redirects
Chris@909 469 assert_not_nil wiki.find_page('Another page')
Chris@909 470 assert_nil wiki.find_page('Another page', :with_redirect => false)
Chris@909 471 end
Chris@909 472
Chris@909 473 def test_rename_without_redirect
Chris@909 474 @request.session[:user_id] = 2
Chris@909 475 post :rename, :project_id => 1, :id => 'Another_page',
Chris@909 476 :wiki_page => { :title => 'Another renamed page',
Chris@909 477 :redirect_existing_links => "0" }
Chris@909 478 assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'Another_renamed_page'
Chris@909 479 wiki = Project.find(1).wiki
Chris@909 480 # Check that there's no redirects
Chris@909 481 assert_nil wiki.find_page('Another page')
Chris@909 482 end
Chris@909 483
Chris@909 484 def test_rename_with_parent_assignment
Chris@909 485 @request.session[:user_id] = 2
Chris@909 486 post :rename, :project_id => 1, :id => 'Another_page',
Chris@909 487 :wiki_page => { :title => 'Another page', :redirect_existing_links => "0", :parent_id => '4' }
Chris@909 488 assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'Another_page'
Chris@909 489 assert_equal WikiPage.find(4), WikiPage.find_by_title('Another_page').parent
Chris@909 490 end
Chris@909 491
Chris@909 492 def test_rename_with_parent_unassignment
Chris@909 493 @request.session[:user_id] = 2
Chris@909 494 post :rename, :project_id => 1, :id => 'Child_1',
Chris@909 495 :wiki_page => { :title => 'Child 1', :redirect_existing_links => "0", :parent_id => '' }
Chris@909 496 assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'Child_1'
Chris@909 497 assert_nil WikiPage.find_by_title('Child_1').parent
Chris@909 498 end
Chris@909 499
Chris@909 500 def test_destroy_child
Chris@909 501 @request.session[:user_id] = 2
Chris@909 502 delete :destroy, :project_id => 1, :id => 'Child_1'
Chris@909 503 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
Chris@909 504 end
Chris@909 505
Chris@909 506 def test_destroy_parent
Chris@909 507 @request.session[:user_id] = 2
Chris@909 508 assert_no_difference('WikiPage.count') do
Chris@909 509 delete :destroy, :project_id => 1, :id => 'Another_page'
Chris@909 510 end
Chris@909 511 assert_response :success
Chris@909 512 assert_template 'destroy'
Chris@909 513 end
Chris@909 514
Chris@909 515 def test_destroy_parent_with_nullify
Chris@909 516 @request.session[:user_id] = 2
Chris@909 517 assert_difference('WikiPage.count', -1) do
Chris@909 518 delete :destroy, :project_id => 1, :id => 'Another_page', :todo => 'nullify'
Chris@909 519 end
Chris@909 520 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
Chris@909 521 assert_nil WikiPage.find_by_id(2)
Chris@909 522 end
Chris@909 523
Chris@909 524 def test_destroy_parent_with_cascade
Chris@909 525 @request.session[:user_id] = 2
Chris@909 526 assert_difference('WikiPage.count', -3) do
Chris@909 527 delete :destroy, :project_id => 1, :id => 'Another_page', :todo => 'destroy'
Chris@909 528 end
Chris@909 529 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
Chris@909 530 assert_nil WikiPage.find_by_id(2)
Chris@909 531 assert_nil WikiPage.find_by_id(5)
Chris@909 532 end
Chris@909 533
Chris@909 534 def test_destroy_parent_with_reassign
Chris@909 535 @request.session[:user_id] = 2
Chris@909 536 assert_difference('WikiPage.count', -1) do
Chris@909 537 delete :destroy, :project_id => 1, :id => 'Another_page', :todo => 'reassign', :reassign_to_id => 1
Chris@909 538 end
Chris@909 539 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
Chris@909 540 assert_nil WikiPage.find_by_id(2)
Chris@909 541 assert_equal WikiPage.find(1), WikiPage.find_by_id(5).parent
Chris@909 542 end
Chris@909 543
Chris@909 544 def test_index
Chris@909 545 get :index, :project_id => 'ecookbook'
Chris@909 546 assert_response :success
Chris@909 547 assert_template 'index'
Chris@909 548 pages = assigns(:pages)
Chris@909 549 assert_not_nil pages
Chris@909 550 assert_equal Project.find(1).wiki.pages.size, pages.size
Chris@909 551 assert_equal pages.first.content.updated_on, pages.first.updated_on
Chris@909 552
Chris@909 553 assert_tag :ul, :attributes => { :class => 'pages-hierarchy' },
Chris@909 554 :child => { :tag => 'li', :child => { :tag => 'a', :attributes => { :href => '/projects/ecookbook/wiki/CookBook_documentation' },
Chris@909 555 :content => 'CookBook documentation' },
Chris@909 556 :child => { :tag => 'ul',
Chris@909 557 :child => { :tag => 'li',
Chris@909 558 :child => { :tag => 'a', :attributes => { :href => '/projects/ecookbook/wiki/Page_with_an_inline_image' },
Chris@909 559 :content => 'Page with an inline image' } } } },
Chris@909 560 :child => { :tag => 'li', :child => { :tag => 'a', :attributes => { :href => '/projects/ecookbook/wiki/Another_page' },
Chris@909 561 :content => 'Another page' } }
Chris@909 562 end
Chris@909 563
Chris@909 564 def test_index_should_include_atom_link
Chris@909 565 get :index, :project_id => 'ecookbook'
Chris@909 566 assert_tag 'a', :attributes => { :href => '/projects/ecookbook/activity.atom?show_wiki_edits=1'}
Chris@909 567 end
Chris@909 568
Chris@909 569 context "GET :export" do
Chris@909 570 context "with an authorized user to export the wiki" do
Chris@909 571 setup do
Chris@909 572 @request.session[:user_id] = 2
Chris@909 573 get :export, :project_id => 'ecookbook'
Chris@909 574 end
Chris@909 575
Chris@909 576 should_respond_with :success
Chris@909 577 should_assign_to :pages
Chris@909 578 should_respond_with_content_type "text/html"
Chris@909 579 should "export all of the wiki pages to a single html file" do
Chris@909 580 assert_select "a[name=?]", "CookBook_documentation"
Chris@909 581 assert_select "a[name=?]", "Another_page"
Chris@909 582 assert_select "a[name=?]", "Page_with_an_inline_image"
Chris@909 583 end
Chris@909 584
Chris@909 585 end
Chris@909 586
Chris@909 587 context "with an unauthorized user" do
Chris@909 588 setup do
Chris@909 589 get :export, :project_id => 'ecookbook'
Chris@909 590
Chris@909 591 should_respond_with :redirect
Chris@909 592 should_redirect_to('wiki index') { {:action => 'show', :project_id => @project, :id => nil} }
Chris@909 593 end
Chris@909 594 end
Chris@909 595 end
Chris@909 596
Chris@909 597 context "GET :date_index" do
Chris@909 598 setup do
Chris@909 599 get :date_index, :project_id => 'ecookbook'
Chris@909 600 end
Chris@909 601
Chris@909 602 should_respond_with :success
Chris@909 603 should_assign_to :pages
Chris@909 604 should_assign_to :pages_by_date
Chris@909 605 should_render_template 'wiki/date_index'
Chris@909 606
Chris@909 607 should "include atom link" do
Chris@909 608 assert_tag 'a', :attributes => { :href => '/projects/ecookbook/activity.atom?show_wiki_edits=1'}
Chris@909 609 end
Chris@909 610 end
Chris@909 611
Chris@909 612 def test_not_found
Chris@909 613 get :show, :project_id => 999
Chris@909 614 assert_response 404
Chris@909 615 end
Chris@909 616
Chris@909 617 def test_protect_page
Chris@909 618 page = WikiPage.find_by_wiki_id_and_title(1, 'Another_page')
Chris@909 619 assert !page.protected?
Chris@909 620 @request.session[:user_id] = 2
Chris@909 621 post :protect, :project_id => 1, :id => page.title, :protected => '1'
Chris@909 622 assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'Another_page'
Chris@909 623 assert page.reload.protected?
Chris@909 624 end
Chris@909 625
Chris@909 626 def test_unprotect_page
Chris@909 627 page = WikiPage.find_by_wiki_id_and_title(1, 'CookBook_documentation')
Chris@909 628 assert page.protected?
Chris@909 629 @request.session[:user_id] = 2
Chris@909 630 post :protect, :project_id => 1, :id => page.title, :protected => '0'
Chris@909 631 assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'CookBook_documentation'
Chris@909 632 assert !page.reload.protected?
Chris@909 633 end
Chris@909 634
Chris@909 635 def test_show_page_with_edit_link
Chris@909 636 @request.session[:user_id] = 2
Chris@909 637 get :show, :project_id => 1
Chris@909 638 assert_response :success
Chris@909 639 assert_template 'show'
Chris@909 640 assert_tag :tag => 'a', :attributes => { :href => '/projects/1/wiki/CookBook_documentation/edit' }
Chris@909 641 end
Chris@909 642
Chris@909 643 def test_show_page_without_edit_link
Chris@909 644 @request.session[:user_id] = 4
Chris@909 645 get :show, :project_id => 1
Chris@909 646 assert_response :success
Chris@909 647 assert_template 'show'
Chris@909 648 assert_no_tag :tag => 'a', :attributes => { :href => '/projects/1/wiki/CookBook_documentation/edit' }
Chris@909 649 end
Chris@909 650
Chris@909 651 def test_show_pdf
Chris@909 652 @request.session[:user_id] = 2
Chris@909 653 get :show, :project_id => 1, :format => 'pdf'
Chris@909 654 assert_response :success
Chris@909 655 assert_not_nil assigns(:page)
Chris@909 656 assert_equal 'application/pdf', @response.content_type
Chris@909 657 assert_equal 'attachment; filename="CookBook_documentation.pdf"',
Chris@909 658 @response.headers['Content-Disposition']
Chris@909 659 end
Chris@909 660
Chris@909 661 def test_show_html
Chris@909 662 @request.session[:user_id] = 2
Chris@909 663 get :show, :project_id => 1, :format => 'html'
Chris@909 664 assert_response :success
Chris@909 665 assert_not_nil assigns(:page)
Chris@909 666 assert_equal 'text/html', @response.content_type
Chris@909 667 assert_equal 'attachment; filename="CookBook_documentation.html"',
Chris@909 668 @response.headers['Content-Disposition']
Chris@909 669 end
Chris@909 670
Chris@909 671 def test_show_txt
Chris@909 672 @request.session[:user_id] = 2
Chris@909 673 get :show, :project_id => 1, :format => 'txt'
Chris@909 674 assert_response :success
Chris@909 675 assert_not_nil assigns(:page)
Chris@909 676 assert_equal 'text/plain', @response.content_type
Chris@909 677 assert_equal 'attachment; filename="CookBook_documentation.txt"',
Chris@909 678 @response.headers['Content-Disposition']
Chris@909 679 end
Chris@909 680
Chris@909 681 def test_edit_unprotected_page
Chris@909 682 # Non members can edit unprotected wiki pages
Chris@909 683 @request.session[:user_id] = 4
Chris@909 684 get :edit, :project_id => 1, :id => 'Another_page'
Chris@909 685 assert_response :success
Chris@909 686 assert_template 'edit'
Chris@909 687 end
Chris@909 688
Chris@909 689 def test_edit_protected_page_by_nonmember
Chris@909 690 # Non members can't edit protected wiki pages
Chris@909 691 @request.session[:user_id] = 4
Chris@909 692 get :edit, :project_id => 1, :id => 'CookBook_documentation'
Chris@909 693 assert_response 403
Chris@909 694 end
Chris@909 695
Chris@909 696 def test_edit_protected_page_by_member
Chris@909 697 @request.session[:user_id] = 2
Chris@909 698 get :edit, :project_id => 1, :id => 'CookBook_documentation'
Chris@909 699 assert_response :success
Chris@909 700 assert_template 'edit'
Chris@909 701 end
Chris@909 702
Chris@909 703 def test_history_of_non_existing_page_should_return_404
Chris@909 704 get :history, :project_id => 1, :id => 'Unknown_page'
Chris@909 705 assert_response 404
Chris@909 706 end
Chris@909 707 end