Mercurial > hg > soundsoftware-site
comparison .svn/pristine/08/086f4bbd984edf33971e918b1e5330fe445e9dd7.svn-base @ 1298:4f746d8966dd redmine_2.3_integration
Merge from redmine-2.3 branch to create new branch redmine-2.3-integration
author | Chris Cannam |
---|---|
date | Fri, 14 Jun 2013 09:28:30 +0100 |
parents | 622f24f53b42 |
children |
comparison
equal
deleted
inserted
replaced
1297:0a574315af3e | 1298:4f746d8966dd |
---|---|
1 # Redmine - project management software | |
2 # Copyright (C) 2006-2013 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 | |
18 require File.expand_path('../../../../../test_helper', __FILE__) | |
19 | |
20 class Redmine::MenuManager::MenuHelperTest < ActionView::TestCase | |
21 | |
22 include Redmine::MenuManager::MenuHelper | |
23 include ERB::Util | |
24 fixtures :users, :members, :projects, :enabled_modules, :roles, :member_roles | |
25 | |
26 def setup | |
27 setup_with_controller | |
28 # Stub the current menu item in the controller | |
29 def current_menu_item | |
30 :index | |
31 end | |
32 end | |
33 | |
34 context "MenuManager#current_menu_item" do | |
35 should "be tested" | |
36 end | |
37 | |
38 context "MenuManager#render_main_menu" do | |
39 should "be tested" | |
40 end | |
41 | |
42 context "MenuManager#render_menu" do | |
43 should "be tested" | |
44 end | |
45 | |
46 context "MenuManager#menu_item_and_children" do | |
47 should "be tested" | |
48 end | |
49 | |
50 context "MenuManager#extract_node_details" do | |
51 should "be tested" | |
52 end | |
53 | |
54 def test_render_single_menu_node | |
55 node = Redmine::MenuManager::MenuItem.new(:testing, '/test', { }) | |
56 @output_buffer = render_single_menu_node(node, 'This is a test', node.url, false) | |
57 | |
58 assert_select("a.testing", "This is a test") | |
59 end | |
60 | |
61 def test_render_menu_node | |
62 single_node = Redmine::MenuManager::MenuItem.new(:single_node, '/test', { }) | |
63 @output_buffer = render_menu_node(single_node, nil) | |
64 | |
65 assert_select("li") do | |
66 assert_select("a.single-node", "Single node") | |
67 end | |
68 end | |
69 | |
70 def test_render_menu_node_with_nested_items | |
71 parent_node = Redmine::MenuManager::MenuItem.new(:parent_node, '/test', { }) | |
72 parent_node << Redmine::MenuManager::MenuItem.new(:child_one_node, '/test', { }) | |
73 parent_node << Redmine::MenuManager::MenuItem.new(:child_two_node, '/test', { }) | |
74 parent_node << | |
75 Redmine::MenuManager::MenuItem.new(:child_three_node, '/test', { }) << | |
76 Redmine::MenuManager::MenuItem.new(:child_three_inner_node, '/test', { }) | |
77 | |
78 @output_buffer = render_menu_node(parent_node, nil) | |
79 | |
80 assert_select("li") do | |
81 assert_select("a.parent-node", "Parent node") | |
82 assert_select("ul") do | |
83 assert_select("li a.child-one-node", "Child one node") | |
84 assert_select("li a.child-two-node", "Child two node") | |
85 assert_select("li") do | |
86 assert_select("a.child-three-node", "Child three node") | |
87 assert_select("ul") do | |
88 assert_select("li a.child-three-inner-node", "Child three inner node") | |
89 end | |
90 end | |
91 end | |
92 end | |
93 | |
94 end | |
95 | |
96 def test_render_menu_node_with_children | |
97 User.current = User.find(2) | |
98 | |
99 parent_node = Redmine::MenuManager::MenuItem.new(:parent_node, | |
100 '/test', | |
101 { | |
102 :children => Proc.new {|p| | |
103 children = [] | |
104 3.times do |time| | |
105 children << Redmine::MenuManager::MenuItem.new("test_child_#{time}", | |
106 {:controller => 'issues', :action => 'index'}, | |
107 {}) | |
108 end | |
109 children | |
110 } | |
111 }) | |
112 @output_buffer = render_menu_node(parent_node, Project.find(1)) | |
113 | |
114 assert_select("li") do | |
115 assert_select("a.parent-node", "Parent node") | |
116 assert_select("ul") do | |
117 assert_select("li a.test-child-0", "Test child 0") | |
118 assert_select("li a.test-child-1", "Test child 1") | |
119 assert_select("li a.test-child-2", "Test child 2") | |
120 end | |
121 end | |
122 end | |
123 | |
124 def test_render_menu_node_with_nested_items_and_children | |
125 User.current = User.find(2) | |
126 | |
127 parent_node = Redmine::MenuManager::MenuItem.new(:parent_node, | |
128 '/test', | |
129 { | |
130 :children => Proc.new {|p| | |
131 children = [] | |
132 3.times do |time| | |
133 children << Redmine::MenuManager::MenuItem.new("test_child_#{time}", {:controller => 'issues', :action => 'index'}, {}) | |
134 end | |
135 children | |
136 } | |
137 }) | |
138 | |
139 parent_node << Redmine::MenuManager::MenuItem.new(:child_node, | |
140 '/test', | |
141 { | |
142 :children => Proc.new {|p| | |
143 children = [] | |
144 6.times do |time| | |
145 children << Redmine::MenuManager::MenuItem.new("test_dynamic_child_#{time}", {:controller => 'issues', :action => 'index'}, {}) | |
146 end | |
147 children | |
148 } | |
149 }) | |
150 | |
151 @output_buffer = render_menu_node(parent_node, Project.find(1)) | |
152 | |
153 assert_select("li") do | |
154 assert_select("a.parent-node", "Parent node") | |
155 assert_select("ul") do | |
156 assert_select("li a.child-node", "Child node") | |
157 assert_select("ul") do | |
158 assert_select("li a.test-dynamic-child-0", "Test dynamic child 0") | |
159 assert_select("li a.test-dynamic-child-1", "Test dynamic child 1") | |
160 assert_select("li a.test-dynamic-child-2", "Test dynamic child 2") | |
161 assert_select("li a.test-dynamic-child-3", "Test dynamic child 3") | |
162 assert_select("li a.test-dynamic-child-4", "Test dynamic child 4") | |
163 assert_select("li a.test-dynamic-child-5", "Test dynamic child 5") | |
164 end | |
165 assert_select("li a.test-child-0", "Test child 0") | |
166 assert_select("li a.test-child-1", "Test child 1") | |
167 assert_select("li a.test-child-2", "Test child 2") | |
168 end | |
169 end | |
170 end | |
171 | |
172 def test_render_menu_node_with_children_without_an_array | |
173 parent_node = Redmine::MenuManager::MenuItem.new(:parent_node, | |
174 '/test', | |
175 { | |
176 :children => Proc.new {|p| Redmine::MenuManager::MenuItem.new("test_child", "/testing", {})} | |
177 }) | |
178 | |
179 assert_raises Redmine::MenuManager::MenuError, ":children must be an array of MenuItems" do | |
180 @output_buffer = render_menu_node(parent_node, Project.find(1)) | |
181 end | |
182 end | |
183 | |
184 def test_render_menu_node_with_incorrect_children | |
185 parent_node = Redmine::MenuManager::MenuItem.new(:parent_node, | |
186 '/test', | |
187 { | |
188 :children => Proc.new {|p| ["a string"] } | |
189 }) | |
190 | |
191 assert_raises Redmine::MenuManager::MenuError, ":children must be an array of MenuItems" do | |
192 @output_buffer = render_menu_node(parent_node, Project.find(1)) | |
193 end | |
194 | |
195 end | |
196 | |
197 def test_menu_items_for_should_yield_all_items_if_passed_a_block | |
198 menu_name = :test_menu_items_for_should_yield_all_items_if_passed_a_block | |
199 Redmine::MenuManager.map menu_name do |menu| | |
200 menu.push(:a_menu, '/', { }) | |
201 menu.push(:a_menu_2, '/', { }) | |
202 menu.push(:a_menu_3, '/', { }) | |
203 end | |
204 | |
205 items_yielded = [] | |
206 menu_items_for(menu_name) do |item| | |
207 items_yielded << item | |
208 end | |
209 | |
210 assert_equal 3, items_yielded.size | |
211 end | |
212 | |
213 def test_menu_items_for_should_return_all_items | |
214 menu_name = :test_menu_items_for_should_return_all_items | |
215 Redmine::MenuManager.map menu_name do |menu| | |
216 menu.push(:a_menu, '/', { }) | |
217 menu.push(:a_menu_2, '/', { }) | |
218 menu.push(:a_menu_3, '/', { }) | |
219 end | |
220 | |
221 items = menu_items_for(menu_name) | |
222 assert_equal 3, items.size | |
223 end | |
224 | |
225 def test_menu_items_for_should_skip_unallowed_items_on_a_project | |
226 menu_name = :test_menu_items_for_should_skip_unallowed_items_on_a_project | |
227 Redmine::MenuManager.map menu_name do |menu| | |
228 menu.push(:a_menu, {:controller => 'issues', :action => 'index' }, { }) | |
229 menu.push(:a_menu_2, {:controller => 'issues', :action => 'index' }, { }) | |
230 menu.push(:unallowed, {:controller => 'issues', :action => 'unallowed' }, { }) | |
231 end | |
232 | |
233 User.current = User.find(2) | |
234 | |
235 items = menu_items_for(menu_name, Project.find(1)) | |
236 assert_equal 2, items.size | |
237 end | |
238 | |
239 def test_menu_items_for_should_skip_items_that_fail_the_conditions | |
240 menu_name = :test_menu_items_for_should_skip_items_that_fail_the_conditions | |
241 Redmine::MenuManager.map menu_name do |menu| | |
242 menu.push(:a_menu, {:controller => 'issues', :action => 'index' }, { }) | |
243 menu.push(:unallowed, | |
244 {:controller => 'issues', :action => 'index' }, | |
245 { :if => Proc.new { false }}) | |
246 end | |
247 | |
248 User.current = User.find(2) | |
249 | |
250 items = menu_items_for(menu_name, Project.find(1)) | |
251 assert_equal 1, items.size | |
252 end | |
253 end |