Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

context_menus_controller_test.rb 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  1. # frozen_string_literal: true
  2. # Redmine - project management software
  3. # Copyright (C) 2006-2019 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 ContextMenusControllerTest < Redmine::ControllerTest
  20. fixtures :projects,
  21. :trackers,
  22. :projects_trackers,
  23. :roles,
  24. :member_roles,
  25. :members,
  26. :enabled_modules,
  27. :workflows,
  28. :journals, :journal_details,
  29. :versions,
  30. :issues, :issue_statuses, :issue_categories,
  31. :users,
  32. :enumerations,
  33. :time_entries,
  34. :custom_fields, :custom_fields_trackers, :custom_fields_projects
  35. def test_context_menu_one_issue
  36. @request.session[:user_id] = 2
  37. get :issues, :params => {
  38. :ids => [1]
  39. }
  40. assert_response :success
  41. assert_select 'a.icon-edit[href=?]', '/issues/1/edit', :text => 'Edit'
  42. assert_select 'a.icon-copy[href=?]', '/projects/ecookbook/issues/1/copy', :text => 'Copy'
  43. assert_select 'a.icon-del[href=?]', '/issues?ids%5B%5D=1', :text => 'Delete'
  44. # Statuses
  45. assert_select 'a[href=?]', '/issues/bulk_update?ids%5B%5D=1&issue%5Bstatus_id%5D=5', :text => 'Closed'
  46. assert_select 'a[href=?]', '/issues/bulk_update?ids%5B%5D=1&issue%5Bpriority_id%5D=8', :text => 'Immediate'
  47. # No inactive priorities
  48. assert_select 'a', :text => /Inactive Priority/, :count => 0
  49. # Versions
  50. assert_select 'a[href=?]', '/issues/bulk_update?ids%5B%5D=1&issue%5Bfixed_version_id%5D=3', :text => '2.0'
  51. assert_select 'a[href=?]', '/issues/bulk_update?ids%5B%5D=1&issue%5Bfixed_version_id%5D=4', :text => 'eCookbook Subproject 1 - 2.0'
  52. # Assignees
  53. assert_select 'a[href=?]', '/issues/bulk_update?ids%5B%5D=1&issue%5Bassigned_to_id%5D=3', :text => 'Dave Lopper'
  54. end
  55. def test_context_menu_one_issue_by_anonymous
  56. with_settings :default_language => 'en' do
  57. get :issues, :params => {
  58. :ids => [1]
  59. }
  60. assert_response :success
  61. assert_select 'a.icon-del.disabled[href="#"]', :text => 'Delete'
  62. end
  63. end
  64. def test_context_menu_multiple_issues_of_same_project
  65. @request.session[:user_id] = 2
  66. get :issues, :params => {
  67. :ids => [1, 2]
  68. }
  69. assert_response :success
  70. ids = [1, 2].map {|i| "ids%5B%5D=#{i}"}.join('&')
  71. assert_select 'a.icon-edit[href=?]', "/issues/bulk_edit?#{ids}", :text => 'Edit'
  72. assert_select 'a.icon-copy[href=?]', "/issues/bulk_edit?copy=1&#{ids}", :text => 'Copy'
  73. assert_select 'a.icon-del[href=?]', "/issues?#{ids}", :text => 'Delete'
  74. assert_select 'a[href=?]', "/issues/bulk_update?#{ids}&issue%5Bstatus_id%5D=5", :text => 'Closed'
  75. assert_select 'a[href=?]', "/issues/bulk_update?#{ids}&issue%5Bpriority_id%5D=8", :text => 'Immediate'
  76. assert_select 'a[href=?]', "/issues/bulk_update?#{ids}&issue%5Bassigned_to_id%5D=3", :text => 'Dave Lopper'
  77. end
  78. def test_context_menu_multiple_issues_of_different_projects
  79. @request.session[:user_id] = 2
  80. get :issues, :params => {
  81. :ids => [1, 2, 6]
  82. }
  83. assert_response :success
  84. ids = [1, 2, 6].map {|i| "ids%5B%5D=#{i}"}.join('&')
  85. assert_select 'a.icon-edit[href=?]', "/issues/bulk_edit?#{ids}", :text => 'Edit'
  86. assert_select 'a.icon-del[href=?]', "/issues?#{ids}", :text => 'Delete'
  87. assert_select 'a[href=?]', "/issues/bulk_update?#{ids}&issue%5Bstatus_id%5D=5", :text => 'Closed'
  88. assert_select 'a[href=?]', "/issues/bulk_update?#{ids}&issue%5Bpriority_id%5D=8", :text => 'Immediate'
  89. assert_select 'a[href=?]', "/issues/bulk_update?#{ids}&issue%5Bassigned_to_id%5D=2", :text => 'John Smith'
  90. end
  91. def test_context_menu_should_include_list_custom_fields
  92. field = IssueCustomField.create!(:name => 'List', :field_format => 'list',
  93. :possible_values => ['Foo', 'Bar'], :is_for_all => true, :tracker_ids => [1, 2, 3])
  94. @request.session[:user_id] = 2
  95. get :issues, :params => {
  96. :ids => [1]
  97. }
  98. assert_select "li.cf_#{field.id}" do
  99. assert_select 'a[href="#"]', :text => 'List'
  100. assert_select 'ul' do
  101. assert_select 'a', 3
  102. assert_select 'a[href=?]', "/issues/bulk_update?ids%5B%5D=1&issue%5Bcustom_field_values%5D%5B#{field.id}%5D=Foo", :text => 'Foo'
  103. assert_select 'a[href=?]', "/issues/bulk_update?ids%5B%5D=1&issue%5Bcustom_field_values%5D%5B#{field.id}%5D=__none__", :text => 'none'
  104. end
  105. end
  106. end
  107. def test_context_menu_should_not_include_null_value_for_required_custom_fields
  108. field = IssueCustomField.create!(:name => 'List', :is_required => true, :field_format => 'list',
  109. :possible_values => ['Foo', 'Bar'], :is_for_all => true, :tracker_ids => [1, 2, 3])
  110. @request.session[:user_id] = 2
  111. get :issues, :params => {
  112. :ids => [1, 2]
  113. }
  114. assert_select "li.cf_#{field.id}" do
  115. assert_select 'a[href="#"]', :text => 'List'
  116. assert_select 'ul' do
  117. assert_select 'a', 2
  118. assert_select 'a', :text => 'none', :count => 0
  119. end
  120. end
  121. end
  122. def test_context_menu_on_single_issue_should_select_current_custom_field_value
  123. field = IssueCustomField.create!(:name => 'List', :field_format => 'list',
  124. :possible_values => ['Foo', 'Bar'], :is_for_all => true, :tracker_ids => [1, 2, 3])
  125. issue = Issue.find(1)
  126. issue.custom_field_values = {field.id => 'Bar'}
  127. issue.save!
  128. @request.session[:user_id] = 2
  129. get :issues, :params => {
  130. :ids => [1]
  131. }
  132. assert_select "li.cf_#{field.id}" do
  133. assert_select 'a[href="#"]', :text => 'List'
  134. assert_select 'ul' do
  135. assert_select 'a', 3
  136. assert_select 'a.icon-checked', :text => 'Bar'
  137. end
  138. end
  139. end
  140. def test_context_menu_should_include_bool_custom_fields
  141. field = IssueCustomField.create!(:name => 'Bool', :field_format => 'bool',
  142. :is_for_all => true, :tracker_ids => [1, 2, 3])
  143. @request.session[:user_id] = 2
  144. get :issues, :params => {
  145. :ids => [1]
  146. }
  147. assert_select "li.cf_#{field.id}" do
  148. assert_select 'a[href="#"]', :text => 'Bool'
  149. assert_select 'ul' do
  150. assert_select 'a', 3
  151. assert_select 'a[href=?]', "/issues/bulk_update?ids%5B%5D=1&issue%5Bcustom_field_values%5D%5B#{field.id}%5D=0", :text => 'No'
  152. assert_select 'a[href=?]', "/issues/bulk_update?ids%5B%5D=1&issue%5Bcustom_field_values%5D%5B#{field.id}%5D=1", :text => 'Yes'
  153. assert_select 'a[href=?]', "/issues/bulk_update?ids%5B%5D=1&issue%5Bcustom_field_values%5D%5B#{field.id}%5D=__none__", :text => 'none'
  154. end
  155. end
  156. end
  157. def test_context_menu_should_include_user_custom_fields
  158. field = IssueCustomField.create!(:name => 'User', :field_format => 'user',
  159. :is_for_all => true, :tracker_ids => [1, 2, 3])
  160. @request.session[:user_id] = 2
  161. get :issues, :params => {
  162. :ids => [1]
  163. }
  164. assert_select "li.cf_#{field.id}" do
  165. assert_select 'a[href="#"]', :text => 'User'
  166. assert_select 'ul' do
  167. assert_select 'a', Project.find(1).members.count + 2 # users + 'none' + 'me'
  168. assert_select 'a[href=?]', "/issues/bulk_update?ids%5B%5D=1&issue%5Bcustom_field_values%5D%5B#{field.id}%5D=2", :text => 'John Smith'
  169. assert_select 'a[href=?]', "/issues/bulk_update?ids%5B%5D=1&issue%5Bcustom_field_values%5D%5B#{field.id}%5D=__none__", :text => 'none'
  170. end
  171. end
  172. end
  173. def test_context_menu_should_include_version_custom_fields
  174. field = IssueCustomField.create!(:name => 'Version', :field_format => 'version', :is_for_all => true, :tracker_ids => [1, 2, 3])
  175. @request.session[:user_id] = 2
  176. get :issues, :params => {
  177. :ids => [1]
  178. }
  179. assert_select "li.cf_#{field.id}" do
  180. assert_select 'a[href="#"]', :text => 'Version'
  181. assert_select 'ul' do
  182. assert_select 'a', Project.find(1).shared_versions.count + 1
  183. assert_select 'a[href=?]', "/issues/bulk_update?ids%5B%5D=1&issue%5Bcustom_field_values%5D%5B#{field.id}%5D=3", :text => '2.0'
  184. assert_select 'a[href=?]', "/issues/bulk_update?ids%5B%5D=1&issue%5Bcustom_field_values%5D%5B#{field.id}%5D=__none__", :text => 'none'
  185. end
  186. end
  187. end
  188. def test_context_menu_should_show_enabled_custom_fields_for_the_role_only
  189. enabled_cf = IssueCustomField.generate!(:field_format => 'bool', :is_for_all => true, :tracker_ids => [1], :visible => false, :role_ids => [1,2])
  190. disabled_cf = IssueCustomField.generate!(:field_format => 'bool', :is_for_all => true, :tracker_ids => [1], :visible => false, :role_ids => [2])
  191. issue = Issue.generate!(:project_id => 1, :tracker_id => 1)
  192. @request.session[:user_id] = 2
  193. get :issues, :params => {
  194. :ids => [issue.id]
  195. }
  196. assert_select "li.cf_#{enabled_cf.id}"
  197. assert_select "li.cf_#{disabled_cf.id}", 0
  198. end
  199. def test_context_menu_by_assignable_user_should_include_assigned_to_me_link
  200. @request.session[:user_id] = 2
  201. get :issues, :params => {
  202. :ids => [1]
  203. }
  204. assert_response :success
  205. assert_select 'a[href=?]', '/issues/bulk_update?ids%5B%5D=1&issue%5Bassigned_to_id%5D=2', :text => / me /
  206. end
  207. def test_context_menu_should_propose_shared_versions_for_issues_from_different_projects
  208. @request.session[:user_id] = 2
  209. version = Version.create!(:name => 'Shared', :sharing => 'system', :project_id => 1)
  210. get :issues, :params => {
  211. :ids => [1, 4]
  212. }
  213. assert_response :success
  214. assert_select 'a', :text => 'eCookbook - Shared'
  215. end
  216. def test_context_menu_with_issue_that_is_not_visible_should_fail
  217. get :issues, :params => {
  218. :ids => [1, 4] # issue 4 is not visible
  219. }
  220. assert_response 302
  221. end
  222. def test_should_respond_with_404_without_ids
  223. get :issues
  224. assert_response 404
  225. end
  226. def test_time_entries_context_menu
  227. @request.session[:user_id] = 2
  228. get :time_entries, :params => {
  229. :ids => [1, 2]
  230. }
  231. assert_response :success
  232. assert_select 'a:not(.disabled)', :text => 'Edit'
  233. end
  234. def test_context_menu_for_one_time_entry
  235. @request.session[:user_id] = 2
  236. get :time_entries, :params => {
  237. :ids => [1]
  238. }
  239. assert_response :success
  240. assert_select 'a:not(.disabled)', :text => 'Edit'
  241. end
  242. def test_time_entries_context_menu_should_include_custom_fields
  243. field = TimeEntryCustomField.generate!(:name => "Field", :field_format => "list", :possible_values => ["foo", "bar"])
  244. @request.session[:user_id] = 2
  245. get :time_entries, :params => {
  246. :ids => [1, 2]
  247. }
  248. assert_response :success
  249. assert_select "li.cf_#{field.id}" do
  250. assert_select 'a[href="#"]', :text => "Field"
  251. assert_select 'ul' do
  252. assert_select 'a', 3
  253. assert_select 'a[href=?]', "/time_entries/bulk_update?ids%5B%5D=1&ids%5B%5D=2&time_entry%5Bcustom_field_values%5D%5B#{field.id}%5D=foo", :text => 'foo'
  254. assert_select 'a[href=?]', "/time_entries/bulk_update?ids%5B%5D=1&ids%5B%5D=2&time_entry%5Bcustom_field_values%5D%5B#{field.id}%5D=bar", :text => 'bar'
  255. assert_select 'a[href=?]', "/time_entries/bulk_update?ids%5B%5D=1&ids%5B%5D=2&time_entry%5Bcustom_field_values%5D%5B#{field.id}%5D=__none__", :text => 'none'
  256. end
  257. end
  258. end
  259. def test_time_entries_context_menu_with_edit_own_time_entries_permission
  260. @request.session[:user_id] = 2
  261. Role.find_by_name('Manager').remove_permission! :edit_time_entries
  262. Role.find_by_name('Manager').add_permission! :edit_own_time_entries
  263. ids = (0..1).map {TimeEntry.generate!(:user => User.find(2)).id}
  264. get :time_entries, :params => {
  265. :ids => ids
  266. }
  267. assert_response :success
  268. assert_select 'a:not(.disabled)', :text => 'Edit'
  269. end
  270. def test_time_entries_context_menu_without_edit_permission
  271. @request.session[:user_id] = 2
  272. Role.find_by_name('Manager').remove_permission! :edit_time_entries
  273. get :time_entries, :params => {
  274. :ids => [1, 2]
  275. }
  276. assert_response :success
  277. assert_select 'a.disabled', :text => 'Edit'
  278. end
  279. end