comparison .svn/pristine/99/996a1b6e4446763a10437d55b49224da9e67f637.svn-base @ 1517:dffacf8a6908 redmine-2.5

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