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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. # Redmine - project management software
  2. # Copyright (C) 2006-2015 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 < ActionController::TestCase
  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_template 'projects'
  37. assert_not_nil assigns(:projects)
  38. # active projects only
  39. assert_nil assigns(:projects).detect {|u| !u.active?}
  40. end
  41. def test_projects_with_status_filter
  42. get :projects, :status => 1
  43. assert_response :success
  44. assert_template 'projects'
  45. assert_not_nil assigns(:projects)
  46. # active projects only
  47. assert_nil assigns(:projects).detect {|u| !u.active?}
  48. end
  49. def test_projects_with_name_filter
  50. get :projects, :name => 'store', :status => ''
  51. assert_response :success
  52. assert_template 'projects'
  53. projects = assigns(:projects)
  54. assert_not_nil projects
  55. assert_equal 1, projects.size
  56. assert_equal 'OnlineStore', projects.first.name
  57. end
  58. def test_load_default_configuration_data
  59. delete_configuration_data
  60. post :default_configuration, :lang => 'fr'
  61. assert_response :redirect
  62. assert_nil flash[:error]
  63. assert IssueStatus.find_by_name('Nouveau')
  64. end
  65. def test_load_default_configuration_data_should_rescue_error
  66. delete_configuration_data
  67. Redmine::DefaultData::Loader.stubs(:load).raises(Exception.new("Something went wrong"))
  68. post :default_configuration, :lang => 'fr'
  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_template 'plugins'
  96. assert_equal [], assigns(:plugins)
  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. end
  107. Redmine::Plugin.register :bar do
  108. end
  109. get :plugins
  110. assert_response :success
  111. assert_template 'plugins'
  112. assert_select 'tr#plugin-foo' do
  113. assert_select 'td span.name', :text => 'Foo plugin'
  114. assert_select 'td.configure a[href="/settings/plugin/foo"]'
  115. end
  116. assert_select 'tr#plugin-bar' do
  117. assert_select 'td span.name', :text => 'Bar'
  118. assert_select 'td.configure a', 0
  119. end
  120. end
  121. def test_info
  122. get :info
  123. assert_response :success
  124. assert_template 'info'
  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.delete_all('builtin = 0')
  140. Tracker.delete_all
  141. IssueStatus.delete_all
  142. Enumeration.delete_all
  143. end
  144. end