summaryrefslogtreecommitdiffstats
path: root/test/functional/activities_controller_test.rb
blob: fe112da484677db89f7756e8f00ba3c5c6329fd9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
# frozen_string_literal: true

# Redmine - project management software
# Copyright (C) 2006-2022  Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

require File.expand_path('../../test_helper', __FILE__)

class ActivitiesControllerTest < Redmine::ControllerTest
  fixtures :projects, :trackers, :issue_statuses, :issues,
           :enumerations, :users, :issue_categories,
           :projects_trackers,
           :roles,
           :member_roles,
           :members,
           :groups_users,
           :enabled_modules,
           :journals, :journal_details,
           :attachments, :changesets, :documents, :messages, :news, :time_entries, :wiki_content_versions

  def test_project_index
    get(
      :index,
      :params => {
        :id => 1,
        :with_subprojects => 0
      }
    )
    assert_response :success

    assert_select 'h3', :text => /#{2.days.ago.to_date.day}/
    assert_select 'dl dt.issue-edit a', :text => /(#{IssueStatus.find(2).name})/
  end

  def test_project_index_with_invalid_project_id_should_respond_404
    get(:index, :params => {:id => 299})
    assert_response 404
  end

  def test_previous_project_index
    @request.session[:user_id] = 1
    get(
      :index,
      :params => {
        :id => 1,
        :from => 2.days.ago.to_date
      }
    )
    assert_response :success

    assert_select 'h3', :text => /#{User.current.time_to_date(3.days.ago).day}/
    assert_select 'dl dt.issue a', :text => /Cannot print recipes/
  end

  def test_global_index
    @request.session[:user_id] = 1
    get :index
    assert_response :success

    i5 = Issue.find(5)
    d5 = User.find(1).time_to_date(i5.created_on)

    assert_select 'h3', :text => /#{d5.day}/
    assert_select 'dl dt.issue a', :text => /Subproject issue/
  end

  def test_user_index
    @request.session[:user_id] = 1
    get(
      :index,
      :params => {
        :user_id => 2
      }
    )
    assert_response :success

    assert_select 'h2 a[href="/users/2"]', :text => 'John Smith'
    assert_select '#sidebar select#user_id option[value="2"][selected=selected]'

    i1 = Issue.find(1)
    d1 = User.find(1).time_to_date(i1.created_on)

    assert_select 'h3', :text => /#{d1.day}/
    assert_select 'dl dt.issue a', :text => /Cannot print recipes/
  end

  def test_user_index_with_invalid_user_id_should_respond_404
    get(
      :index,
      :params => {
        :user_id => 299
      }
    )
    assert_response 404
  end

  def test_user_index_with_non_visible_user_id_should_respond_404
    Role.anonymous.update! :users_visibility => 'members_of_visible_projects'
    user = User.generate!

    @request.session[:user_id] = nil
    get :index, :params => {
      :user_id => user.id
    }

    assert_response 404
  end

  def test_index_atom_feed
    get(
      :index,
      :params => {
        :format => 'atom',
        :with_subprojects => 0
      }
    )
    assert_response :success

    assert_select 'feed' do
      assert_select 'link[rel=self][href=?]', 'http://test.host/activity.atom?with_subprojects=0'
      assert_select 'link[rel=alternate][href=?]', 'http://test.host/activity?with_subprojects=0'
      assert_select 'entry' do
        assert_select 'link[href=?]', 'http://test.host/issues/11'
      end
    end
  end

  def test_index_atom_feed_should_respect_feeds_limit_setting
    with_settings :feeds_limit => '20' do
      get(
        :index,
        :params => {
          :format => 'atom'
        }
      )
    end
    assert_response :success

    assert_select 'feed' do
      assert_select 'entry', :count => 20
    end
  end

  def test_index_atom_feed_with_explicit_selection
    get(
      :index,
      :params => {
        :format => 'atom',
        :with_subprojects => 0,
        :show_changesets => 1,
        :show_documents => 1,
        :show_files => 1,
        :show_issues => 1,
        :show_messages => 1,
        :show_news => 1,
        :show_time_entries => 1,
        :show_wiki_edits => 1
      }
    )
    assert_response :success

    assert_select 'feed' do
      assert_select 'link[rel=self][href=?]', 'http://test.host/activity.atom?show_changesets=1&show_documents=1&show_files=1&show_issues=1&show_messages=1&show_news=1&show_time_entries=1&show_wiki_edits=1&with_subprojects=0'
      assert_select 'link[rel=alternate][href=?]', 'http://test.host/activity?show_changesets=1&show_documents=1&show_files=1&show_issues=1&show_messages=1&show_news=1&show_time_entries=1&show_wiki_edits=1&with_subprojects=0'
      assert_select 'entry' do
        assert_select 'link[href=?]', 'http://test.host/issues/11'
      end
    end
  end

  def test_index_atom_feed_with_one_item_type
    with_settings :default_language => 'en' do
      get(
        :index,
        :params => {
          :format => 'atom',
          :show_issues => '1'
        }
      )
      assert_response :success
      assert_select 'title', :text => /Issues/
    end
  end

  def test_index_atom_feed_with_user
    get(
      :index,
      :params => {
        :user_id => 2,
        :format => 'atom'
      }
    )
    assert_response :success
    assert_select 'title', :text => "Redmine: #{User.find(2).name}"
  end

  def test_index_atom_feed_with_subprojects
    get(
      :index,
      :params => {
        :format => 'atom',
        :id => 'ecookbook',
        :with_subprojects => 1,
        :show_issues => 1
      }
    )
    assert_response :success

    assert_select 'feed' do
      # eCookbook
      assert_select 'title', text: 'Bug #1: Cannot print recipes'
      # eCookbook Subproject 1
      assert_select 'title', text: 'eCookbook Subproject 1 - Bug #5 (New): Subproject issue'
    end
  end

  def test_index_should_show_private_notes_with_permission_only
    journal = Journal.create!(:journalized => Issue.find(2), :notes => 'Private notes', :private_notes => true)
    @request.session[:user_id] = 2

    get :index
    assert_response :success
    assert_select 'dl', :text => /Private notes/

    Role.find(1).remove_permission! :view_private_notes
    get :index
    assert_response :success
    assert_select 'dl', :text => /Private notes/, :count => 0
  end

  def test_index_with_submitted_scope_should_save_as_preference
    @request.session[:user_id] = 2
    get(
      :index,
      :params => {
        :show_issues => '1',
        :show_messages => '1',
        :submit => 'Apply'
      }
    )
    assert_response :success
    assert_equal %w(issues messages), User.find(2).pref.activity_scope.sort
  end

  def test_index_scope_should_default_to_user_preference
    pref = User.find(2).pref
    pref.activity_scope = %w(issues news)
    pref.save!
    @request.session[:user_id] = 2

    get :index
    assert_response :success

    assert_select '#activity_scope_form' do
      assert_select 'input[checked=checked]', 2
      assert_select 'input[name=show_issues][checked=checked]'
      assert_select 'input[name=show_news][checked=checked]'
    end
  end

  def test_index_should_not_show_next_page_link
    @request.session[:user_id] = 2

    get :index
    assert_response :success
    assert_select '.pagination a', :text => /Previous/
    assert_select '.pagination a', :text => /Next/, :count => 0
  end

  def test_index_up_to_yesterday_should_show_next_page_link
    @request.session[:user_id] = 2
    get(
      :index,
      :params => {
        :from => (User.find(2).today - 1)
      }
    )
    assert_response :success
    assert_select '.pagination a', :text => /Previous/
    assert_select '.pagination a', :text => /Next/
  end
end