@@ -1,157 +1,150 | |||
|
1 | 1 | # Redmine - project management software |
|
2 | 2 | # Copyright (C) 2006-2011 Jean-Philippe Lang |
|
3 | 3 | # |
|
4 | 4 | # This program is free software; you can redistribute it and/or |
|
5 | 5 | # modify it under the terms of the GNU General Public License |
|
6 | 6 | # as published by the Free Software Foundation; either version 2 |
|
7 | 7 | # of the License, or (at your option) any later version. |
|
8 | 8 | # |
|
9 | 9 | # This program is distributed in the hope that it will be useful, |
|
10 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | # GNU General Public License for more details. |
|
13 | 13 | # |
|
14 | 14 | # You should have received a copy of the GNU General Public License |
|
15 | 15 | # along with this program; if not, write to the Free Software |
|
16 | 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
17 | 17 | |
|
18 | 18 | require File.expand_path('../../test_helper', __FILE__) |
|
19 | require 'admin_controller' | |
|
20 | ||
|
21 | # Re-raise errors caught by the controller. | |
|
22 | class AdminController; def rescue_action(e) raise e end; end | |
|
23 | 19 | |
|
24 | 20 | class AdminControllerTest < ActionController::TestCase |
|
25 | 21 | fixtures :projects, :users, :roles |
|
26 | 22 | |
|
27 | 23 | def setup |
|
28 | @controller = AdminController.new | |
|
29 | @request = ActionController::TestRequest.new | |
|
30 | @response = ActionController::TestResponse.new | |
|
31 | 24 | User.current = nil |
|
32 | 25 | @request.session[:user_id] = 1 # admin |
|
33 | 26 | end |
|
34 | 27 | |
|
35 | 28 | def test_index |
|
36 | 29 | get :index |
|
37 | 30 | assert_no_tag :tag => 'div', |
|
38 | 31 | :attributes => { :class => /nodata/ } |
|
39 | 32 | end |
|
40 | 33 | |
|
41 | 34 | def test_index_with_no_configuration_data |
|
42 | 35 | delete_configuration_data |
|
43 | 36 | get :index |
|
44 | 37 | assert_tag :tag => 'div', |
|
45 | 38 | :attributes => { :class => /nodata/ } |
|
46 | 39 | end |
|
47 | 40 | |
|
48 | 41 | def test_projects |
|
49 | 42 | get :projects |
|
50 | 43 | assert_response :success |
|
51 | 44 | assert_template 'projects' |
|
52 | 45 | assert_not_nil assigns(:projects) |
|
53 | 46 | # active projects only |
|
54 | 47 | assert_nil assigns(:projects).detect {|u| !u.active?} |
|
55 | 48 | end |
|
56 | 49 | |
|
57 | 50 | def test_projects_with_status_filter |
|
58 | 51 | get :projects, :status => 1 |
|
59 | 52 | assert_response :success |
|
60 | 53 | assert_template 'projects' |
|
61 | 54 | assert_not_nil assigns(:projects) |
|
62 | 55 | # active projects only |
|
63 | 56 | assert_nil assigns(:projects).detect {|u| !u.active?} |
|
64 | 57 | end |
|
65 | 58 | |
|
66 | 59 | def test_projects_with_name_filter |
|
67 | 60 | get :projects, :name => 'store', :status => '' |
|
68 | 61 | assert_response :success |
|
69 | 62 | assert_template 'projects' |
|
70 | 63 | projects = assigns(:projects) |
|
71 | 64 | assert_not_nil projects |
|
72 | 65 | assert_equal 1, projects.size |
|
73 | 66 | assert_equal 'OnlineStore', projects.first.name |
|
74 | 67 | end |
|
75 | 68 | |
|
76 | 69 | def test_load_default_configuration_data |
|
77 | 70 | delete_configuration_data |
|
78 | 71 | post :default_configuration, :lang => 'fr' |
|
79 | 72 | assert_response :redirect |
|
80 | 73 | assert_nil flash[:error] |
|
81 | 74 | assert IssueStatus.find_by_name('Nouveau') |
|
82 | 75 | end |
|
83 | 76 | |
|
84 | 77 | def test_test_email |
|
85 | 78 | get :test_email |
|
86 | 79 | assert_redirected_to '/settings/edit?tab=notifications' |
|
87 | 80 | mail = ActionMailer::Base.deliveries.last |
|
88 | 81 | assert_not_nil mail |
|
89 | 82 | user = User.find(1) |
|
90 | 83 | assert_equal [user.mail], mail.bcc |
|
91 | 84 | end |
|
92 | 85 | |
|
93 | 86 | def test_test_email_failure_should_display_the_error |
|
94 | 87 | Mailer.stubs(:deliver_test_email).raises(Exception, 'Some error message') |
|
95 | 88 | get :test_email |
|
96 | 89 | assert_redirected_to '/settings/edit?tab=notifications' |
|
97 | 90 | assert_match /Some error message/, flash[:error] |
|
98 | 91 | end |
|
99 | 92 | |
|
100 | 93 | def test_no_plugins |
|
101 | 94 | Redmine::Plugin.clear |
|
102 | 95 | |
|
103 | 96 | get :plugins |
|
104 | 97 | assert_response :success |
|
105 | 98 | assert_template 'plugins' |
|
106 | 99 | end |
|
107 | 100 | |
|
108 | 101 | def test_plugins |
|
109 | 102 | # Register a few plugins |
|
110 | 103 | Redmine::Plugin.register :foo do |
|
111 | 104 | name 'Foo plugin' |
|
112 | 105 | author 'John Smith' |
|
113 | 106 | description 'This is a test plugin' |
|
114 | 107 | version '0.0.1' |
|
115 | 108 | settings :default => {'sample_setting' => 'value', 'foo'=>'bar'}, :partial => 'foo/settings' |
|
116 | 109 | end |
|
117 | 110 | Redmine::Plugin.register :bar do |
|
118 | 111 | end |
|
119 | 112 | |
|
120 | 113 | get :plugins |
|
121 | 114 | assert_response :success |
|
122 | 115 | assert_template 'plugins' |
|
123 | 116 | |
|
124 | 117 | assert_tag :td, :child => { :tag => 'span', :content => 'Foo plugin' } |
|
125 | 118 | assert_tag :td, :child => { :tag => 'span', :content => 'Bar' } |
|
126 | 119 | end |
|
127 | 120 | |
|
128 | 121 | def test_info |
|
129 | 122 | get :info |
|
130 | 123 | assert_response :success |
|
131 | 124 | assert_template 'info' |
|
132 | 125 | end |
|
133 | 126 | |
|
134 | 127 | def test_admin_menu_plugin_extension |
|
135 | 128 | Redmine::MenuManager.map :admin_menu do |menu| |
|
136 | 129 | menu.push :test_admin_menu_plugin_extension, '/foo/bar', :caption => 'Test' |
|
137 | 130 | end |
|
138 | 131 | |
|
139 | 132 | get :index |
|
140 | 133 | assert_response :success |
|
141 | 134 | assert_tag :a, :attributes => { :href => '/foo/bar' }, |
|
142 | 135 | :content => 'Test' |
|
143 | 136 | |
|
144 | 137 | Redmine::MenuManager.map :admin_menu do |menu| |
|
145 | 138 | menu.delete :test_admin_menu_plugin_extension |
|
146 | 139 | end |
|
147 | 140 | end |
|
148 | 141 | |
|
149 | 142 | private |
|
150 | 143 | |
|
151 | 144 | def delete_configuration_data |
|
152 | 145 | Role.delete_all('builtin = 0') |
|
153 | 146 | Tracker.delete_all |
|
154 | 147 | IssueStatus.delete_all |
|
155 | 148 | Enumeration.delete_all |
|
156 | 149 | end |
|
157 | 150 | end |
General Comments 0
You need to be logged in to leave comments.
Login now