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.7KB

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