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.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  1. # frozen_string_literal: true
  2. # Redmine - project management software
  3. # Copyright (C) 2006- 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_relative '../test_helper'
  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_index_subproject_checkbox_should_check_descendants_visibility
  43. @request.session[:user_id] = 2
  44. get(
  45. :index,
  46. :params => {
  47. :id => 5,
  48. }
  49. )
  50. assert_response :success
  51. assert_select '#sidebar input#with_subprojects'
  52. project = Project.find(6)
  53. project.is_public = false
  54. project.save
  55. get(
  56. :index,
  57. :params => {
  58. :id => 5,
  59. }
  60. )
  61. assert_response :success
  62. assert_select '#sidebar input#with_subprojects', :count => 0
  63. end
  64. def test_project_index_with_invalid_project_id_should_respond_404
  65. get(:index, :params => {:id => 299})
  66. assert_response 404
  67. end
  68. def test_previous_project_index
  69. @request.session[:user_id] = 1
  70. get(
  71. :index,
  72. :params => {
  73. :id => 1,
  74. :from => 2.days.ago.to_date
  75. }
  76. )
  77. assert_response :success
  78. assert_select 'h3', :text => /#{User.current.time_to_date(3.days.ago).day}/
  79. assert_select 'dl dt.issue a', :text => /Cannot print recipes/
  80. end
  81. def test_global_index
  82. @request.session[:user_id] = 1
  83. get :index
  84. assert_response :success
  85. i5 = Issue.find(5)
  86. d5 = User.find(1).time_to_date(i5.created_on)
  87. assert_select 'h3', :text => /#{d5.day}/
  88. assert_select 'dl dt.issue a', :text => /Subproject issue/
  89. end
  90. def test_user_index
  91. @request.session[:user_id] = 1
  92. get(
  93. :index,
  94. :params => {
  95. :user_id => 2
  96. }
  97. )
  98. assert_response :success
  99. assert_select 'h2 a[href="/users/2"]', :text => 'John Smith'
  100. assert_select '#sidebar select#user_id option[value="2"][selected=selected]'
  101. i1 = Issue.find(1)
  102. d1 = User.find(1).time_to_date(i1.created_on)
  103. assert_select 'h3', :text => /#{d1.day}/
  104. assert_select 'dl dt.issue a', :text => /Cannot print recipes/
  105. end
  106. def test_user_index_with_invalid_user_id_should_respond_404
  107. get(
  108. :index,
  109. :params => {
  110. :user_id => 299
  111. }
  112. )
  113. assert_response 404
  114. end
  115. def test_user_index_with_non_visible_user_id_should_respond_404
  116. Role.anonymous.update! :users_visibility => 'members_of_visible_projects'
  117. user = User.generate!
  118. @request.session[:user_id] = nil
  119. get :index, :params => {
  120. :user_id => user.id
  121. }
  122. assert_response 404
  123. end
  124. def test_index_atom_feed
  125. get(
  126. :index,
  127. :params => {
  128. :format => 'atom',
  129. :with_subprojects => 0
  130. }
  131. )
  132. assert_response :success
  133. assert_select 'feed' do
  134. assert_select 'link[rel=self][href=?]', 'http://test.host/activity.atom?with_subprojects=0'
  135. assert_select 'link[rel=alternate][href=?]', 'http://test.host/activity?with_subprojects=0'
  136. assert_select 'entry' do
  137. assert_select 'link[href=?]', 'http://test.host/issues/11'
  138. end
  139. end
  140. end
  141. def test_index_atom_feed_should_respect_feeds_limit_setting
  142. with_settings :feeds_limit => '20' do
  143. get(
  144. :index,
  145. :params => {
  146. :format => 'atom'
  147. }
  148. )
  149. end
  150. assert_response :success
  151. assert_select 'feed' do
  152. assert_select 'entry', :count => 20
  153. end
  154. end
  155. def test_index_atom_feed_with_explicit_selection
  156. get(
  157. :index,
  158. :params => {
  159. :format => 'atom',
  160. :with_subprojects => 0,
  161. :show_changesets => 1,
  162. :show_documents => 1,
  163. :show_files => 1,
  164. :show_issues => 1,
  165. :show_messages => 1,
  166. :show_news => 1,
  167. :show_time_entries => 1,
  168. :show_wiki_edits => 1
  169. }
  170. )
  171. assert_response :success
  172. assert_select 'feed' do
  173. 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'
  174. 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'
  175. assert_select 'entry' do
  176. assert_select 'link[href=?]', 'http://test.host/issues/11'
  177. end
  178. end
  179. end
  180. def test_index_atom_feed_with_one_item_type
  181. with_settings :default_language => 'en' do
  182. get(
  183. :index,
  184. :params => {
  185. :format => 'atom',
  186. :show_issues => '1'
  187. }
  188. )
  189. assert_response :success
  190. assert_select 'title', :text => /Issues/
  191. end
  192. end
  193. def test_index_atom_feed_with_user
  194. get(
  195. :index,
  196. :params => {
  197. :user_id => 2,
  198. :format => 'atom'
  199. }
  200. )
  201. assert_response :success
  202. assert_select 'title', :text => "Redmine: #{User.find(2).name}"
  203. end
  204. def test_index_atom_feed_with_subprojects
  205. get(
  206. :index,
  207. :params => {
  208. :format => 'atom',
  209. :id => 'ecookbook',
  210. :with_subprojects => 1,
  211. :show_issues => 1
  212. }
  213. )
  214. assert_response :success
  215. assert_select 'feed' do
  216. # eCookbook
  217. assert_select 'title', text: 'Bug #1: Cannot print recipes'
  218. # eCookbook Subproject 1
  219. assert_select 'title', text: 'eCookbook Subproject 1 - Bug #5 (New): Subproject issue'
  220. end
  221. end
  222. def test_index_should_show_private_notes_with_permission_only
  223. journal = Journal.create!(:journalized => Issue.find(2), :notes => 'Private notes', :private_notes => true)
  224. @request.session[:user_id] = 2
  225. get :index
  226. assert_response :success
  227. assert_select 'dl', :text => /Private notes/
  228. Role.find(1).remove_permission! :view_private_notes
  229. get :index
  230. assert_response :success
  231. assert_select 'dl', :text => /Private notes/, :count => 0
  232. end
  233. def test_index_with_submitted_scope_should_save_as_preference
  234. @request.session[:user_id] = 2
  235. get(
  236. :index,
  237. :params => {
  238. :show_issues => '1',
  239. :show_messages => '1',
  240. :submit => 'Apply'
  241. }
  242. )
  243. assert_response :success
  244. assert_equal %w(issues messages), User.find(2).pref.activity_scope.sort
  245. end
  246. def test_index_scope_should_default_to_user_preference
  247. pref = User.find(2).pref
  248. pref.activity_scope = %w(issues news)
  249. pref.save!
  250. @request.session[:user_id] = 2
  251. get :index
  252. assert_response :success
  253. assert_select '#activity_scope_form' do
  254. assert_select 'input[checked=checked]', 2
  255. assert_select 'input[name=show_issues][checked=checked]'
  256. assert_select 'input[name=show_news][checked=checked]'
  257. end
  258. end
  259. def test_index_should_not_show_next_page_link
  260. @request.session[:user_id] = 2
  261. get :index
  262. assert_response :success
  263. assert_select '.pagination a', :text => /Previous/
  264. assert_select '.pagination a', :text => /Next/, :count => 0
  265. end
  266. def test_index_up_to_yesterday_should_show_next_page_link
  267. @request.session[:user_id] = 2
  268. get(
  269. :index,
  270. :params => {
  271. :from => (User.find(2).today - 1)
  272. }
  273. )
  274. assert_response :success
  275. assert_select '.pagination a', :text => /Previous/
  276. assert_select '.pagination a', :text => /Next/
  277. end
  278. end