@@ -1,176 +1,175 | |||
|
1 | 1 | # Redmine - project management software |
|
2 | 2 | # Copyright (C) 2006-2015 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 | 19 | |
|
20 | 20 | class WelcomeControllerTest < ActionController::TestCase |
|
21 | 21 | fixtures :projects, :news, :users, :members |
|
22 | 22 | |
|
23 | 23 | def setup |
|
24 | 24 | Setting.default_language = 'en' |
|
25 | 25 | User.current = nil |
|
26 | 26 | end |
|
27 | 27 | |
|
28 | 28 | def test_index |
|
29 | 29 | get :index |
|
30 | 30 | assert_response :success |
|
31 | 31 | assert_template 'index' |
|
32 | 32 | assert_not_nil assigns(:news) |
|
33 | assert !assigns(:projects).include?(Project.where(:is_public => false).first) | |
|
34 | 33 | end |
|
35 | 34 | |
|
36 | 35 | def test_browser_language |
|
37 | 36 | @request.env['HTTP_ACCEPT_LANGUAGE'] = 'fr,fr-fr;q=0.8,en-us;q=0.5,en;q=0.3' |
|
38 | 37 | get :index |
|
39 | 38 | assert_equal :fr, @controller.current_language |
|
40 | 39 | end |
|
41 | 40 | |
|
42 | 41 | def test_browser_language_alternate |
|
43 | 42 | @request.env['HTTP_ACCEPT_LANGUAGE'] = 'zh-TW' |
|
44 | 43 | get :index |
|
45 | 44 | assert_equal :"zh-TW", @controller.current_language |
|
46 | 45 | end |
|
47 | 46 | |
|
48 | 47 | def test_browser_language_alternate_not_valid |
|
49 | 48 | @request.env['HTTP_ACCEPT_LANGUAGE'] = 'fr-CA' |
|
50 | 49 | get :index |
|
51 | 50 | assert_equal :fr, @controller.current_language |
|
52 | 51 | end |
|
53 | 52 | |
|
54 | 53 | def test_browser_language_should_be_ignored_with_force_default_language_for_anonymous |
|
55 | 54 | @request.env['HTTP_ACCEPT_LANGUAGE'] = 'fr,fr-fr;q=0.8,en-us;q=0.5,en;q=0.3' |
|
56 | 55 | with_settings :force_default_language_for_anonymous => '1' do |
|
57 | 56 | get :index |
|
58 | 57 | assert_equal :en, @controller.current_language |
|
59 | 58 | end |
|
60 | 59 | end |
|
61 | 60 | |
|
62 | 61 | def test_user_language_should_be_used |
|
63 | 62 | user = User.find(2).update_attribute :language, 'it' |
|
64 | 63 | @request.session[:user_id] = 2 |
|
65 | 64 | @request.env['HTTP_ACCEPT_LANGUAGE'] = 'fr,fr-fr;q=0.8,en-us;q=0.5,en;q=0.3' |
|
66 | 65 | with_settings :default_language => 'fi' do |
|
67 | 66 | get :index |
|
68 | 67 | assert_equal :it, @controller.current_language |
|
69 | 68 | end |
|
70 | 69 | end |
|
71 | 70 | |
|
72 | 71 | def test_user_language_should_be_ignored_if_force_default_language_for_loggedin |
|
73 | 72 | user = User.find(2).update_attribute :language, 'it' |
|
74 | 73 | @request.session[:user_id] = 2 |
|
75 | 74 | @request.env['HTTP_ACCEPT_LANGUAGE'] = 'fr,fr-fr;q=0.8,en-us;q=0.5,en;q=0.3' |
|
76 | 75 | with_settings :force_default_language_for_loggedin => '1', :default_language => 'fi' do |
|
77 | 76 | get :index |
|
78 | 77 | assert_equal :fi, @controller.current_language |
|
79 | 78 | end |
|
80 | 79 | end |
|
81 | 80 | |
|
82 | 81 | def test_robots |
|
83 | 82 | get :robots |
|
84 | 83 | assert_response :success |
|
85 | 84 | assert_equal 'text/plain', @response.content_type |
|
86 | 85 | assert @response.body.match(%r{^Disallow: /projects/ecookbook/issues\r?$}) |
|
87 | 86 | end |
|
88 | 87 | |
|
89 | 88 | def test_warn_on_leaving_unsaved_turn_on |
|
90 | 89 | user = User.find(2) |
|
91 | 90 | user.pref.warn_on_leaving_unsaved = '1' |
|
92 | 91 | user.pref.save! |
|
93 | 92 | @request.session[:user_id] = 2 |
|
94 | 93 | |
|
95 | 94 | get :index |
|
96 | 95 | assert_select 'script', :text => %r{warnLeavingUnsaved} |
|
97 | 96 | end |
|
98 | 97 | |
|
99 | 98 | def test_warn_on_leaving_unsaved_turn_off |
|
100 | 99 | user = User.find(2) |
|
101 | 100 | user.pref.warn_on_leaving_unsaved = '0' |
|
102 | 101 | user.pref.save! |
|
103 | 102 | @request.session[:user_id] = 2 |
|
104 | 103 | |
|
105 | 104 | get :index |
|
106 | 105 | assert_select 'script', :text => %r{warnLeavingUnsaved}, :count => 0 |
|
107 | 106 | end |
|
108 | 107 | |
|
109 | 108 | def test_logout_link_should_post |
|
110 | 109 | @request.session[:user_id] = 2 |
|
111 | 110 | |
|
112 | 111 | get :index |
|
113 | 112 | assert_select 'a[href="/logout"][data-method=post]', :text => 'Sign out' |
|
114 | 113 | end |
|
115 | 114 | |
|
116 | 115 | def test_call_hook_mixed_in |
|
117 | 116 | assert @controller.respond_to?(:call_hook) |
|
118 | 117 | end |
|
119 | 118 | |
|
120 | 119 | def test_project_jump_box_should_escape_names_once |
|
121 | 120 | Project.find(1).update_attribute :name, 'Foo & Bar' |
|
122 | 121 | @request.session[:user_id] = 2 |
|
123 | 122 | |
|
124 | 123 | get :index |
|
125 | 124 | assert_select "#header select" do |
|
126 | 125 | assert_select "option", :text => 'Foo & Bar' |
|
127 | 126 | end |
|
128 | 127 | end |
|
129 | 128 | |
|
130 | 129 | def test_api_offset_and_limit_without_params |
|
131 | 130 | assert_equal [0, 25], @controller.api_offset_and_limit({}) |
|
132 | 131 | end |
|
133 | 132 | |
|
134 | 133 | def test_api_offset_and_limit_with_limit |
|
135 | 134 | assert_equal [0, 30], @controller.api_offset_and_limit({:limit => 30}) |
|
136 | 135 | assert_equal [0, 100], @controller.api_offset_and_limit({:limit => 120}) |
|
137 | 136 | assert_equal [0, 25], @controller.api_offset_and_limit({:limit => -10}) |
|
138 | 137 | end |
|
139 | 138 | |
|
140 | 139 | def test_api_offset_and_limit_with_offset |
|
141 | 140 | assert_equal [10, 25], @controller.api_offset_and_limit({:offset => 10}) |
|
142 | 141 | assert_equal [0, 25], @controller.api_offset_and_limit({:offset => -10}) |
|
143 | 142 | end |
|
144 | 143 | |
|
145 | 144 | def test_api_offset_and_limit_with_offset_and_limit |
|
146 | 145 | assert_equal [10, 50], @controller.api_offset_and_limit({:offset => 10, :limit => 50}) |
|
147 | 146 | end |
|
148 | 147 | |
|
149 | 148 | def test_api_offset_and_limit_with_page |
|
150 | 149 | assert_equal [0, 25], @controller.api_offset_and_limit({:page => 1}) |
|
151 | 150 | assert_equal [50, 25], @controller.api_offset_and_limit({:page => 3}) |
|
152 | 151 | assert_equal [0, 25], @controller.api_offset_and_limit({:page => 0}) |
|
153 | 152 | assert_equal [0, 25], @controller.api_offset_and_limit({:page => -2}) |
|
154 | 153 | end |
|
155 | 154 | |
|
156 | 155 | def test_api_offset_and_limit_with_page_and_limit |
|
157 | 156 | assert_equal [0, 100], @controller.api_offset_and_limit({:page => 1, :limit => 100}) |
|
158 | 157 | assert_equal [200, 100], @controller.api_offset_and_limit({:page => 3, :limit => 100}) |
|
159 | 158 | end |
|
160 | 159 | |
|
161 | 160 | def test_unhautorized_exception_with_anonymous_should_redirect_to_login |
|
162 | 161 | WelcomeController.any_instance.stubs(:index).raises(::Unauthorized) |
|
163 | 162 | |
|
164 | 163 | get :index |
|
165 | 164 | assert_response 302 |
|
166 | 165 | assert_redirected_to('/login?back_url='+CGI.escape('http://test.host/')) |
|
167 | 166 | end |
|
168 | 167 | |
|
169 | 168 | def test_unhautorized_exception_with_anonymous_and_xmlhttprequest_should_respond_with_401_to_anonymous |
|
170 | 169 | WelcomeController.any_instance.stubs(:index).raises(::Unauthorized) |
|
171 | 170 | |
|
172 | 171 | @request.env["HTTP_X_REQUESTED_WITH"] = "XMLHttpRequest" |
|
173 | 172 | get :index |
|
174 | 173 | assert_response 401 |
|
175 | 174 | end |
|
176 | 175 | end |
General Comments 0
You need to be logged in to leave comments.
Login now