You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

application_test.rb 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. # frozen_string_literal: true
  2. # Redmine - project management software
  3. # Copyright (C) 2006-2019 Jean-Philippe Lang
  4. #
  5. # This program is free software; you can redistribute it and/or
  6. # modify it under the terms of the GNU General Public License
  7. # as published by the Free Software Foundation; either version 2
  8. # of the License, or (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program; if not, write to the Free Software
  17. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  18. require File.expand_path('../../test_helper', __FILE__)
  19. class ApplicationTest < Redmine::IntegrationTest
  20. include Redmine::I18n
  21. fixtures :projects, :trackers, :issue_statuses, :issues,
  22. :enumerations, :users, :issue_categories,
  23. :projects_trackers,
  24. :roles,
  25. :member_roles,
  26. :members,
  27. :enabled_modules
  28. def test_set_localization
  29. Setting.default_language = 'en'
  30. # a french user
  31. get '/projects', :headers => {'HTTP_ACCEPT_LANGUAGE' => 'fr,fr-fr;q=0.8,en-us;q=0.5,en;q=0.3'}
  32. assert_response :success
  33. assert_select 'h2', :text => 'Projets'
  34. assert_equal :fr, current_language
  35. assert_select "html[lang=?]", "fr"
  36. # then an italien user
  37. get '/projects', :headers => {'HTTP_ACCEPT_LANGUAGE' => 'it;q=0.8,en-us;q=0.5,en;q=0.3'}
  38. assert_response :success
  39. assert_select 'h2', :text => 'Progetti'
  40. assert_equal :it, current_language
  41. assert_select "html[lang=?]", "it"
  42. # not a supported language: default language should be used
  43. get '/projects', :headers => {'HTTP_ACCEPT_LANGUAGE' => 'zz'}
  44. assert_response :success
  45. assert_select 'h2', :text => 'Projects'
  46. assert_select "html[lang=?]", "en"
  47. end
  48. def test_token_based_access_should_not_start_session
  49. # issue of a private project
  50. get '/issues/4.atom'
  51. assert_response 302
  52. rss_key = User.find(2).rss_key
  53. get "/issues/4.atom?key=#{rss_key}"
  54. assert_response 200
  55. assert_nil session[:user_id]
  56. end
  57. def test_missing_template_should_respond_with_4xx
  58. get '/login.png'
  59. assert_response 406
  60. end
  61. def test_invalid_token_should_call_custom_handler
  62. ActionController::Base.allow_forgery_protection = true
  63. post '/issues'
  64. assert_response 422
  65. assert_include "Invalid form authenticity token.", response.body
  66. ensure
  67. ActionController::Base.allow_forgery_protection = false
  68. end
  69. def test_localization_should_be_set_correctly_on_invalid_token
  70. ActionController::Base.allow_forgery_protection = true
  71. Setting.default_language = 'en'
  72. post '/issues', :headers => {'HTTP_ACCEPT_LANGUAGE' => 'fr,fr-fr;q=0.8,en-us;q=0.5,en;q=0.3'}
  73. assert_response 422
  74. assert_equal :fr, current_language
  75. assert_select "html[lang=?]", "fr"
  76. ensure
  77. ActionController::Base.allow_forgery_protection = false
  78. end
  79. def test_require_login_with_pdf_format_should_not_error
  80. with_settings :login_required => '1' do
  81. get '/issues/1.pdf'
  82. assert_response 302
  83. end
  84. end
  85. end