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.

activities_controller_test.rb 8.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. # frozen_string_literal: true
  2. # Redmine - project management software
  3. # Copyright (C) 2006-2021 Jean-Philippe Lang
  4. #
  5. # This program is free software; you can redistribute it and/or
  6. # modify it under the terms of the GNU General Public License
  7. # as published by the Free Software Foundation; either version 2
  8. # of the License, or (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program; if not, write to the Free Software
  17. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  18. require File.expand_path('../../test_helper', __FILE__)
  19. class ActivitiesControllerTest < Redmine::ControllerTest
  20. fixtures :projects, :trackers, :issue_statuses, :issues,
  21. :enumerations, :users, :issue_categories,
  22. :projects_trackers,
  23. :roles,
  24. :member_roles,
  25. :members,
  26. :groups_users,
  27. :enabled_modules,
  28. :journals, :journal_details,
  29. :attachments, :changesets, :documents, :messages, :news, :time_entries, :wiki_content_versions
  30. def test_project_index
  31. get(
  32. :index,
  33. :params => {
  34. :id => 1,
  35. :with_subprojects => 0
  36. }
  37. )
  38. assert_response :success
  39. assert_select 'h3', :text => /#{2.days.ago.to_date.day}/
  40. assert_select 'dl dt.issue-edit a', :text => /(#{IssueStatus.find(2).name})/
  41. end
  42. def test_project_index_with_invalid_project_id_should_respond_404
  43. get(:index, :params => {:id => 299})
  44. assert_response 404
  45. end
  46. def test_previous_project_index
  47. @request.session[:user_id] = 1
  48. get(
  49. :index,
  50. :params => {
  51. :id => 1,
  52. :from => 2.days.ago.to_date
  53. }
  54. )
  55. assert_response :success
  56. assert_select 'h3', :text => /#{User.current.time_to_date(3.days.ago).day}/
  57. assert_select 'dl dt.issue a', :text => /Cannot print recipes/
  58. end
  59. def test_global_index
  60. @request.session[:user_id] = 1
  61. get :index
  62. assert_response :success
  63. i5 = Issue.find(5)
  64. d5 = User.find(1).time_to_date(i5.created_on)
  65. assert_select 'h3', :text => /#{d5.day}/
  66. assert_select 'dl dt.issue a', :text => /Subproject issue/
  67. end
  68. def test_user_index
  69. @request.session[:user_id] = 1
  70. get(
  71. :index,
  72. :params => {
  73. :user_id => 2
  74. }
  75. )
  76. assert_response :success
  77. assert_select 'h2 a[href="/users/2"]', :text => 'John Smith'
  78. assert_select '#sidebar select#user_id option[value="2"][selected=selected]'
  79. i1 = Issue.find(1)
  80. d1 = User.find(1).time_to_date(i1.created_on)
  81. assert_select 'h3', :text => /#{d1.day}/
  82. assert_select 'dl dt.issue a', :text => /Cannot print recipes/
  83. end
  84. def test_user_index_with_invalid_user_id_should_respond_404
  85. get(
  86. :index,
  87. :params => {
  88. :user_id => 299
  89. }
  90. )
  91. assert_response 404
  92. end
  93. def test_user_index_with_non_visible_user_id_should_respond_404
  94. Role.anonymous.update! :users_visibility => 'members_of_visible_projects'
  95. user = User.generate!
  96. @request.session[:user_id] = nil
  97. get :index, :params => {
  98. :user_id => user.id
  99. }
  100. assert_response 404
  101. end
  102. def test_index_atom_feed
  103. get(
  104. :index,
  105. :params => {
  106. :format => 'atom',
  107. :with_subprojects => 0
  108. }
  109. )
  110. assert_response :success
  111. assert_select 'feed' do
  112. assert_select 'link[rel=self][href=?]', 'http://test.host/activity.atom?with_subprojects=0'
  113. assert_select 'link[rel=alternate][href=?]', 'http://test.host/activity?with_subprojects=0'
  114. assert_select 'entry' do
  115. assert_select 'link[href=?]', 'http://test.host/issues/11'
  116. end
  117. end
  118. end
  119. def test_index_atom_feed_should_respect_feeds_limit_setting
  120. with_settings :feeds_limit => '20' do
  121. get(
  122. :index,
  123. :params => {
  124. :format => 'atom'
  125. }
  126. )
  127. end
  128. assert_response :success
  129. assert_select 'feed' do
  130. assert_select 'entry', :count => 20
  131. end
  132. end
  133. def test_index_atom_feed_with_explicit_selection
  134. get(
  135. :index,
  136. :params => {
  137. :format => 'atom',
  138. :with_subprojects => 0,
  139. :show_changesets => 1,
  140. :show_documents => 1,
  141. :show_files => 1,
  142. :show_issues => 1,
  143. :show_messages => 1,
  144. :show_news => 1,
  145. :show_time_entries => 1,
  146. :show_wiki_edits => 1
  147. }
  148. )
  149. assert_response :success
  150. assert_select 'feed' do
  151. 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'
  152. 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'
  153. assert_select 'entry' do
  154. assert_select 'link[href=?]', 'http://test.host/issues/11'
  155. end
  156. end
  157. end
  158. def test_index_atom_feed_with_one_item_type
  159. with_settings :default_language => 'en' do
  160. get(
  161. :index,
  162. :params => {
  163. :format => 'atom',
  164. :show_issues => '1'
  165. }
  166. )
  167. assert_response :success
  168. assert_select 'title', :text => /Issues/
  169. end
  170. end
  171. def test_index_atom_feed_with_user
  172. get(
  173. :index,
  174. :params => {
  175. :user_id => 2,
  176. :format => 'atom'
  177. }
  178. )
  179. assert_response :success
  180. assert_select 'title', :text => "Redmine: #{User.find(2).name}"
  181. end
  182. def test_index_atom_feed_with_subprojects
  183. get(
  184. :index,
  185. :params => {
  186. :format => 'atom',
  187. :id => 'ecookbook',
  188. :with_subprojects => 1,
  189. :show_issues => 1
  190. }
  191. )
  192. assert_response :success
  193. assert_select 'feed' do
  194. # eCookbook
  195. assert_select 'title', text: 'Bug #1: Cannot print recipes'
  196. # eCookbook Subproject 1
  197. assert_select 'title', text: 'eCookbook Subproject 1 - Bug #5 (New): Subproject issue'
  198. end
  199. end
  200. def test_index_should_show_private_notes_with_permission_only
  201. journal = Journal.create!(:journalized => Issue.find(2), :notes => 'Private notes', :private_notes => true)
  202. @request.session[:user_id] = 2
  203. get :index
  204. assert_response :success
  205. assert_select 'dl', :text => /Private notes/
  206. Role.find(1).remove_permission! :view_private_notes
  207. get :index
  208. assert_response :success
  209. assert_select 'dl', :text => /Private notes/, :count => 0
  210. end
  211. def test_index_with_submitted_scope_should_save_as_preference
  212. @request.session[:user_id] = 2
  213. get(
  214. :index,
  215. :params => {
  216. :show_issues => '1',
  217. :show_messages => '1',
  218. :submit => 'Apply'
  219. }
  220. )
  221. assert_response :success
  222. assert_equal %w(issues messages), User.find(2).pref.activity_scope.sort
  223. end
  224. def test_index_scope_should_default_to_user_preference
  225. pref = User.find(2).pref
  226. pref.activity_scope = %w(issues news)
  227. pref.save!
  228. @request.session[:user_id] = 2
  229. get :index
  230. assert_response :success
  231. assert_select '#activity_scope_form' do
  232. assert_select 'input[checked=checked]', 2
  233. assert_select 'input[name=show_issues][checked=checked]'
  234. assert_select 'input[name=show_news][checked=checked]'
  235. end
  236. end
  237. def test_index_should_not_show_next_page_link
  238. @request.session[:user_id] = 2
  239. get :index
  240. assert_response :success
  241. assert_select '.pagination a', :text => /Previous/
  242. assert_select '.pagination a', :text => /Next/, :count => 0
  243. end
  244. def test_index_up_to_yesterday_should_show_next_page_link
  245. @request.session[:user_id] = 2
  246. get(
  247. :index,
  248. :params => {
  249. :from => (User.find(2).today - 1)
  250. }
  251. )
  252. assert_response :success
  253. assert_select '.pagination a', :text => /Previous/
  254. assert_select '.pagination a', :text => /Next/
  255. end
  256. end