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

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