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.

admin_test.rb 2.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. # frozen_string_literal: true
  2. # Redmine - project management software
  3. # Copyright (C) 2006-2021 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 AdminTest < Redmine::IntegrationTest
  20. fixtures :projects, :trackers, :issue_statuses, :issues,
  21. :enumerations, :users, :issue_categories,
  22. :projects_trackers,
  23. :roles,
  24. :member_roles,
  25. :members,
  26. :enabled_modules
  27. def test_add_user
  28. log_user("admin", "admin")
  29. get "/users/new"
  30. assert_response :success
  31. post(
  32. "/users",
  33. :params => {
  34. :user => {
  35. :login => "psmith", :firstname => "Paul",
  36. :lastname => "Smith", :mail => "psmith@somenet.foo",
  37. :language => "en", :password => "psmith09",
  38. :password_confirmation => "psmith09"
  39. }
  40. }
  41. )
  42. user = User.find_by_login("psmith")
  43. assert_kind_of User, user
  44. assert_redirected_to "/users/#{ user.id }/edit"
  45. logged_user = User.try_to_login("psmith", "psmith09")
  46. assert_kind_of User, logged_user
  47. assert_equal "Paul", logged_user.firstname
  48. put(
  49. "/users/#{user.id}",
  50. :params => {
  51. :id => user.id,
  52. :user => {
  53. :status => User::STATUS_LOCKED
  54. }
  55. }
  56. )
  57. assert_redirected_to "/users/#{ user.id }/edit"
  58. locked_user = User.try_to_login("psmith", "psmith09")
  59. assert_nil locked_user
  60. end
  61. test "Add a user as an anonymous user should fail" do
  62. post(
  63. '/users',
  64. :params => {
  65. :user => {
  66. :login => 'psmith', :firstname => 'Paul',
  67. :password => "psmith09", :password_confirmation => "psmith09"
  68. }
  69. }
  70. )
  71. assert_response :redirect
  72. assert_redirected_to "/login?back_url=http%3A%2F%2Fwww.example.com%2Fusers"
  73. end
  74. end