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

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