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

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