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_controller_test.rb 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. # Redmine - project management software
  2. # Copyright (C) 2006-2017 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. require File.expand_path('../../test_helper', __FILE__)
  18. class AdminControllerTest < Redmine::ControllerTest
  19. fixtures :projects, :users, :email_addresses, :roles
  20. def setup
  21. User.current = nil
  22. @request.session[:user_id] = 1 # admin
  23. end
  24. def test_index
  25. get :index
  26. assert_select 'div.nodata', 0
  27. end
  28. def test_index_with_no_configuration_data
  29. delete_configuration_data
  30. get :index
  31. assert_select 'div.nodata'
  32. end
  33. def test_projects
  34. get :projects
  35. assert_response :success
  36. assert_select 'tr.project.closed', 0
  37. end
  38. def test_projects_with_status_filter
  39. get :projects, :params => {
  40. :status => 1
  41. }
  42. assert_response :success
  43. assert_select 'tr.project.closed', 0
  44. end
  45. def test_projects_with_name_filter
  46. get :projects, :params => {
  47. :name => 'store',
  48. :status => ''
  49. }
  50. assert_response :success
  51. assert_select 'tr.project td.name', :text => 'OnlineStore'
  52. assert_select 'tr.project', 1
  53. end
  54. def test_load_default_configuration_data
  55. delete_configuration_data
  56. post :default_configuration, :params => {
  57. :lang => 'fr'
  58. }
  59. assert_response :redirect
  60. assert_nil flash[:error]
  61. assert IssueStatus.find_by_name('Nouveau')
  62. end
  63. def test_load_default_configuration_data_should_rescue_error
  64. delete_configuration_data
  65. Redmine::DefaultData::Loader.stubs(:load).raises(Exception.new("Something went wrong"))
  66. post :default_configuration, :params => {
  67. :lang => 'fr'
  68. }
  69. assert_response :redirect
  70. assert_not_nil flash[:error]
  71. assert_match /Something went wrong/, flash[:error]
  72. end
  73. def test_test_email
  74. user = User.find(1)
  75. user.pref.no_self_notified = '1'
  76. user.pref.save!
  77. ActionMailer::Base.deliveries.clear
  78. post :test_email
  79. assert_redirected_to '/settings?tab=notifications'
  80. mail = ActionMailer::Base.deliveries.last
  81. assert_not_nil mail
  82. user = User.find(1)
  83. assert_equal [user.mail], mail.bcc
  84. end
  85. def test_test_email_failure_should_display_the_error
  86. Mailer.stubs(:test_email).raises(Exception, 'Some error message')
  87. post :test_email
  88. assert_redirected_to '/settings?tab=notifications'
  89. assert_match /Some error message/, flash[:error]
  90. end
  91. def test_no_plugins
  92. Redmine::Plugin.stubs(:registered_plugins).returns({})
  93. get :plugins
  94. assert_response :success
  95. assert_select '.nodata'
  96. end
  97. def test_plugins
  98. # Register a few plugins
  99. Redmine::Plugin.register :foo do
  100. name 'Foo plugin'
  101. author 'John Smith'
  102. description 'This is a test plugin'
  103. version '0.0.1'
  104. settings :default => {'sample_setting' => 'value', 'foo'=>'bar'}, :partial => 'foo/settings'
  105. end
  106. Redmine::Plugin.register :bar do
  107. end
  108. get :plugins
  109. assert_response :success
  110. assert_select 'tr#plugin-foo' do
  111. assert_select 'td span.name', :text => 'Foo plugin'
  112. assert_select 'td.configure a[href="/settings/plugin/foo"]'
  113. end
  114. assert_select 'tr#plugin-bar' do
  115. assert_select 'td span.name', :text => 'Bar'
  116. assert_select 'td.configure a', 0
  117. end
  118. end
  119. def test_info
  120. get :info
  121. assert_response :success
  122. end
  123. def test_admin_menu_plugin_extension
  124. Redmine::MenuManager.map :admin_menu do |menu|
  125. menu.push :test_admin_menu_plugin_extension, '/foo/bar', :caption => 'Test'
  126. end
  127. get :index
  128. assert_response :success
  129. assert_select 'div#admin-menu a[href="/foo/bar"]', :text => 'Test'
  130. Redmine::MenuManager.map :admin_menu do |menu|
  131. menu.delete :test_admin_menu_plugin_extension
  132. end
  133. end
  134. private
  135. def delete_configuration_data
  136. Role.where('builtin = 0').delete_all
  137. Tracker.delete_all
  138. IssueStatus.delete_all
  139. Enumeration.delete_all
  140. end
  141. end