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.

context_menus_controller_test.rb 12KB

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