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